| Reply | « Previous Thread | Next Thread » |
|
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 |
| thejakumarsk |
| View Public Profile |
| Find all posts by thejakumarsk |
|
You cannot implement JNI on CLDC. CLDC is specifically intended to prevent that.
Graham. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
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 |
| thejakumarsk |
| View Public Profile |
| Find all posts by thejakumarsk |
|
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. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
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 |
| thejakumarsk |
| View Public Profile |
| Find all posts by thejakumarsk |
|
Would you care to elaborate on this technique?
Graham. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
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 |
| thejakumarsk |
| View Public Profile |
| Find all posts by thejakumarsk |
|
But the class won't load, because the VM's verifier will reject it.
Graham. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
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 |
| thejakumarsk |
| View Public Profile |
| Find all posts by thejakumarsk |
|
Way. As soon as the verifier hits that method, verification will fail.
But... good luck with it! :) Graham. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
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 |
| thejakumarsk |
| View Public Profile |
| Find all posts by thejakumarsk |
|
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. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
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 |
| thejakumarsk |
| View Public Profile |
| Find all posts by thejakumarsk |
|
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 |
| gorkem.ercan |
| View Public Profile |
| Find all posts by gorkem.ercan |
|
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:
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. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| 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 |