You Are Here:

Community: Developer Discussion Boards

Reply « Previous Thread | Next Thread »

#1 Old JNI in MIDP using eSWT implementation LIbrary.loadLibrary? - 2009-06-30, 07:50

Join Date: May 2006
Posts: 30
thejakumarsk
Offline
Registered User
Hi,

I am trying to implement jni in my midlet using S60 3rd edition FP2 sdk, which has eSWT support, If I see eSWT implementation, they are loading native (symbian) dll using org.eclipse.swt.internal.Libray class using Libary.loadLibary method. I tried to use the same method to load my native dll, midlet is giving Authorization failed error during installation. It is because of lack of permission to access org.eclipse.swt.Libary class, Is there any other way of using jni implementation.

Your help will be appreciated great.

Thanks
Theja
Reply With Quote

#2 Old Re: JNI in MIDP using eSWT implementation LIbrary.loadLibrary? - 2009-06-30, 12:55

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
You cannot implement JNI on CLDC. CLDC is specifically intended to prevent that.

Graham.
Reply With Quote

#3 Old Re: JNI in MIDP using eSWT implementation LIbrary.loadLibrary? - 2009-06-30, 13:40

Join Date: May 2006
Posts: 30
thejakumarsk
Offline
Registered User
Hi grahamhughes,

Thanks for your reply.

I understand that, there is no direct method to implement jni. But, If you look at eswt implementation for S60, they are using jni. You can check org.eclipse.swt.internal.Libary.loadLibray method where they are using it to load eswt.dll. And it is public, static method. So it is likely, AMS(application manager software) failed to recognizet Library.java class existance or my midlet is not granted with appropriate permission, So, installation is failing saying "Authorization failed". Is there a way I can set the midlet permission to make it work. I checked eswt implementation I could not find, where they have imposed package restriction on swt classes. How can I use Browser.java where I cannot use Libary.java. I may be wrong in understanding the eswt package, Any help?

Thanks & Regards
Theja
Reply With Quote

#4 Old Re: JNI in MIDP using eSWT implementation LIbrary.loadLibrary? - 2009-06-30, 15:06

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
There is not direct way, nor an indirect way.

Classes that are part of the Java Runtime on the device are able to do things that classes in an installed JAR are not. You can only access the runtime library using the public API (the API that is documented in the JavaDocs). You can't use other classes. Some classes will be implementation-specific (for example, they might exist on the emulator, but not on the device). Other classes might be subject to security restrictions. In this case, the JVM might not let you access classes in the org.eclipse.swt.internal packages. There is no "permission" you can enable to change this.

Similarly, it is forbiden for a class in an installed JAR to contain any methods declared "native". Classes in the on-device run-time can contain native methods. This is a strict rule of CLDC.

I'm afraid JNI on CLDC is not an option.

Graham.
Reply With Quote

#5 Old Re: JNI in MIDP using eSWT implementation LIbrary.loadLibrary? - 2009-06-30, 15:33

Join Date: May 2006
Posts: 30
thejakumarsk
Offline
Registered User
Hi Graham,

Yes, you are correct, some classes are not accessible unless they are exposed as public api.
But, You can still use 'native' method in midlet classes using 'dummy class and outside jar updation' technique. Only missing part is
dll loading mechanism. Thanks for your help.

Regards
Theja
Reply With Quote

#6 Old Re: JNI in MIDP using eSWT implementation LIbrary.loadLibrary? - 2009-06-30, 15:38

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
Would you care to elaborate on this technique?

Graham.
Reply With Quote

#7 Old Re: JNI in MIDP using eSWT implementation LIbrary.loadLibrary? - 2009-06-30, 15:57

Join Date: May 2006
Posts: 30
thejakumarsk
Offline
Registered User
Ya sure,

Ex : You want to implement a JNI class called HelloWorld.java, But, if you use 'native' keyoword in method signature preverification will fail. So, in order to avoid this conflict: implement a dummy method like this.

dummy class just to pass preverification:

public class HelloWorld{

public String sayHello(){
}
}

use above class in your midlet while generating jar file(preverification will pass). Once you generate the jar file, Make a new class externally like below one.

Actual class to be installed on device:

public class HelloWorld{

public native String sayHello();
}

using 'jar -uf' java command line tool update the jar file with the above class. Update your jad attributes with latest jar size. Now try installing this jar on emulator/device, Application will install without any problem.
I tested it on emulator, It works fine. I dont know about it's fate on actual device. I hope it works fine on device too!

But, this exercise is worthless untill we get a class to load native dll from cldc.

Regards
Theja
Reply With Quote

#8 Old Re: JNI in MIDP using eSWT implementation LIbrary.loadLibrary? - 2009-06-30, 16:07

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
But the class won't load, because the VM's verifier will reject it.

Graham.
Reply With Quote

#9 Old Re: JNI in MIDP using eSWT implementation LIbrary.loadLibrary? - 2009-06-30, 16:23

Join Date: May 2006
Posts: 30
thejakumarsk
Offline
Registered User
No way,

It ran like a charm. I was not able to call jni method(coz, lack of jni facility), But, I called other member method, It worked.
so, technique is flawless.

Regards
Theja
Reply With Quote

#10 Old Re: JNI in MIDP using eSWT implementation LIbrary.loadLibrary? - 2009-06-30, 16:47

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
Way. As soon as the verifier hits that method, verification will fail.

But... good luck with it! :)

Graham.
Reply With Quote

#11 Old Re: JNI in MIDP using eSWT implementation LIbrary.loadLibrary? - 2009-06-30, 16:58

Join Date: May 2006
Posts: 30
thejakumarsk
Offline
Registered User
I doubt, It should have checked this cldc violation as soon as it loaded class. Anyway, there is no support for loading dll now, so, i cant test it. :-)

I dont think, it will differentiate user classes and library classes at runtime. Once, it is installed, It might treat both classes equal. Its just my guess.

Regards
Theja
Reply With Quote

#12 Old Re: JNI in MIDP using eSWT implementation LIbrary.loadLibrary? - 2009-06-30, 18:25

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
Not necessarily. Verification doesn't need to happen at load time. Verification of a method can wait until the method is invoked.

The VM will certainly differentiate between user and system classes. It's fundamental to the CLDC security model. This is why, for example, you cannot instantiate a MIDlet class, and why you get an error when you try to call the loadLibrary() method (while the eSWT classes can call it without problem).

As you say, since you cannot load a library anyway, it is a moot point. Preventing you from using your own native methods requires nothing more than to block access to loading external libraries.

Graham.
Reply With Quote

#13 Old Re: JNI in MIDP using eSWT implementation LIbrary.loadLibrary? - 2009-07-01, 06:35

Join Date: May 2006
Posts: 30
thejakumarsk
Offline
Registered User
No, you have mistaken, I said, I am not able to install a midlet which uses org.eclipse.swt.internal.Library class because of "Authorization failed" error. This is during installation time. I guess, If I succeeded in this step, I would be able to use 'native' method just like library classes. I dont see any reason why it will block a midlet from calling native method after successfull installation. Is there any reference docs about cldc architecture and restriction. I am interested to go through it.

Regards
Theja
Reply With Quote

#14 Old Re: JNI in MIDP using eSWT implementation LIbrary.loadLibrary? - 2009-07-01, 10:56

Join Date: Nov 2008
Posts: 35
gorkem.ercan
Offline
Registered User
Hi Theja,

Graham is very correct on this one. The internal classes are accessible by only runtime's own implementation classes. If a midlet refers to internal implementation classes, java installer will fail at installation time(just like you are experiencing). There are no security permissions available that will enable you to pass java installer's checks. Even if you could pass the install time check runtime has a more rigorous check that would not allow your midlet to execute internal implementation classes.

--
Gorkem
Reply With Quote

#15 Old Re: JNI in MIDP using eSWT implementation LIbrary.loadLibrary? - 2009-07-01, 11:00

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
The reason why it would block access to native methods is: because it is required to do so.

You can get the CLDC-1.1 specification from here.

Both the CLDC-1.0 and 1.1 specs state:

Quote:
The set of native functions accessible to the virtual machine is closed, meaning that the application programmer cannot download any new libraries containing native functionality, or access any native functions that are not part of the Java libraries provided by the CLDC, profiles or licensee open classes.
A compliant CLDC implementation is required to ensure that an installed application cannot increase the number of native methods accessible to it, above those made available through public APIs.

That's not to say that it is impossible to find a bug that could be exploited, but if you did that, you would probably be writing an application that works only on one firmware version of one device (before the bug was fixed).

Graham.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
What does it mean: MIDP implementation merkol@gmx.de Mobile Java General 2 2005-04-05 18:43
MIDP 2.0 implementation maxagaze Mobile Java Networking & Messaging & Security 2 2004-12-15 15:05
Series 60 Concept Emulator (SDK Beta 0.2 Linux) not working mattbee Mobile Java Tools & SDKs 1 2003-06-10 12:43
Series 60Series 60 MIDP Concept SDK Beta 0.2 Linux bug? kauppi Mobile Java Tools & SDKs 3 2003-04-07 10:05
Http connection problem in 6310i teahola Mobile Java General 1 2002-10-03 19:46

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia