Summary of the invention
For overcoming Problems existing in correlation technique, the invention provides and a kind of in second system, access the method for the third party library for the first system, system and terminal unit.
First aspect according to disclosure embodiment, it is provided that a kind of method accessing the third party library for the first system in second system, including:
By the Java Virtual Machine for second system with the form loading third-party JNI library compatible with the JNI loading interface for the first system;
The relevant API (ApplicationProgrammingInterface, application programming interface) of described third party's JNI library is derived by described Java Virtual Machine;
By API relevant described in JNI reverse calling with third party's JNI library described in dereference.
In an embodiment, described the first system is Android system, and described third party's JNI library is third party's JNI library of compatible Android system.
In an embodiment, by including with the operation of the form loading third-party JNI library compatible with the JNI loading interface for the first system for the Java Virtual Machine of second system: by the Java Virtual Machine for described second system with the form loading third-party JNI library of Java local interface JNI.
In an embodiment, included by the operation of the relevant API of the described Java Virtual Machine described third party's JNI library of derivation: in JVM (JavaVirtualMachine, the abbreviation of Java Virtual Machine), create access interface and pass through the access interface described third party's JNI library of access created.
In an embodiment, described method also includes the concrete function of the third party's JNI library according to described the first system and described relevant API is selected.
In an embodiment, described the first system is Android system, and described second system is non-Android system, and described method also includes the relevant API encapsulating described reverse calling for the localization of described non-Android system.
In an embodiment, described non-Android system is linux system, iOS system or WindowsPhone system.
In an embodiment, the operation encapsulating the relevant API of described reverse calling for the localization of described non-Android system includes being encapsulated by QBus, DBus or Socket localization the relevant API of described reverse calling for described non-Android system.
Second aspect according to disclosure embodiment, it is provided that a kind of system accessing the third party library for the first system in second system, including:
Load-on module, is used for by the Java Virtual Machine for second system with the form loading third-party JNI library compatible with the JNI loading interface for the first system;
Derive module, for being derived the relevant API of described third party's JNI library by described Java Virtual Machine;
Reverse calling module, is used for by API relevant described in JNI reverse calling with third party's JNI library described in dereference.
In an embodiment, described the first system is Android system, and described third party's JNI library is third party's JNI library of compatible Android system.
In an embodiment, described load-on module is used for: by the Java Virtual Machine for described second system with the form loading third-party JNI library of Java local interface JNI.
In an embodiment, described derivation module is used for: creates access interface in JVM and passes through the access interface described third party's JNI library of access created.
In an embodiment, the described system accessing the third party library for the first system in second system also includes selecting module, and described relevant API is selected by the concrete function for the third party's JNI library according to described the first system.
In an embodiment, described the first system is Android system, described second system is non-Android system, and the described system accessing the third party library for the first system in second system also includes package module, for encapsulating the relevant API of described reverse calling for the localization of described non-Android system.
In an embodiment, described non-Android system is linux system, iOS system or WindowsPhone system.
In an embodiment, described package module is used for, and is encapsulated the relevant API of described reverse calling by QBus, DBus or Socket localization for described non-Android system.
The third aspect according to disclosure embodiment, it is provided that a kind of terminal unit, including:
Processor;
For storing the memorizer of processor executable;
Wherein, described processor is configured to:
By the Java Virtual Machine for second system with the form loading third-party JNI library compatible with the JNI loading interface for the first system;
The relevant API of described third party's JNI library is derived by described Java Virtual Machine;
By API relevant described in JNI reverse calling with third party's JNI library described in dereference.
Embodiment of the disclosure that the technical scheme of offer can include following beneficial effect:
Embodiment of the disclosure and provide calling and realizing method of a kind of quick compatible Android third-party Runtime Library, in order to non-Android system, it is possible to quickly use related peripherals and non-comercial operation storehouse, be greatly enriched the function of non-Android system.It should be appreciated that it is only exemplary and explanatory that above general description and details hereinafter describe, the disclosure can not be limited.
Detailed description of the invention
Here in detail exemplary embodiment being illustrated, its example representation is in the accompanying drawings.When as explained below relates to accompanying drawing, unless otherwise indicated, the same numbers in different accompanying drawings represents same or analogous key element.Embodiment described in following exemplary embodiment does not represent all embodiments consistent with the present invention.On the contrary, they only with in appended claims describe in detail, the present invention some in the example of consistent system and method.
Fig. 1 is the flow chart of a kind of method accessing the third party library for the first system in second system according to an exemplary embodiment, the present embodiment is applicable to the situation realizing accessing the third party library for the first system in second system, as it is shown in figure 1, the method accessing the third party library for the first system in second system described in the present embodiment includes:
In step s 110, by the Java Virtual Machine for second system with the form loading third-party JNI library compatible with the JNI loading interface for the first system.
The JNI standard that mostly can adopt Android due to presently relevant peripheral hardware provides third-party Runtime Library, quickly to coordinate operation with Android system, as example, owing to manufacturer is for the consideration of maintenance cost, Runtime Library available in the non-Android operation system of typically not offer.Although Android system by enhancing Java compatible degree under Android system and improve service efficiency to the customization of Java, but which also limits the use scope of the third-party application for its exploitation.In order to compatible Android third-party Runtime Library uses for non-Android system, it is necessary first to go Androidization, and standard Java language is exactly a kind of well selection.
The example of the present embodiment encapsulates the access interface to third party's Runtime Library with standard Java language, so, no matter runs under any Java Virtual Machine (JVM), and its result is all identical.
As the example implemented, standard Java language one access interface class of definition can be used, wherein comprising Java Localization methodologies (NativeMethod), it implements and is completed by third party's JNI library, is referred to Java local interface JNI mode and realizes.
JNI is the abbreviation of JavaNativeInterface, it provides some API and achieves communicate (mainly the C&C++) of Java and other language.From Java1.1, JNI standard becomes a part for Java platform, and it allows the code that Java code and other language are write to interact.
For local compiled language at the beginning of JNI design, especially C and C++ and design, but it and do not interfere with you and use other programming languages, as long as calling convention is supported just passable.Use Java mutual with the local code compiled, it will usually to lose platform portable.But, do so is acceptable in some cases, or even necessary.Such as, use the storehouse that some are old, interact with hardware, operating system, or in order to improve the performance of program.
In the step s 120, the relevant API of described third party's JNI library is derived by described Java Virtual Machine.
When in step S110 with pass through the Java Virtual Machine for second system with the form loading third-party JNI library compatible with the JNI loading interface for the first system after, it is possible to by this loading third-party JNI library instantiation for accessing described third party's JNI library.
For the example in step S110, after loading corresponding third party's JNI library, namely can call its Localization methodologies by access interface class described in instantiation, thus the specific function performed in third party's JNI library.
In step s 130, by API relevant described in JNI reverse calling with third party's JNI library described in dereference.
After creating the described access interface example to third party's JNI library, non-Android system can obtain this interface instance under home environment, and indirectly accesses third party's JNI library by this interface instance, thus calling the function realized by third party's JNI library.This calls the angle from JVM is reverse calling, namely calls the class/object/method within JVM from the non-Android system outside JVM, therefore, is called reverse calling in the present embodiment.By the access interface example in reverse calling JVM, non-Android system and the third party's Runtime Library communications conduit therebetween for Android exploitation are got through, so that described third party's Runtime Library can be compatible with non-Android system, the scope of this available devices greatly having widened non-Android system and third party's JNI library, enrich the function of non-Android system, simultaneously, third party manufacturer modifies without to the Runtime Library being originally Android system exploitation, get final product slitless connection to non-Android system, reduce research and development and the lower deployment cost of third party manufacturer.
It should be noted that this example is using third party's Runtime Library of compatible Android system as described third party's JNI library.But this is merely illustrative of, it practice, for particular system exploitation third party's JNI library be diverted to other system time, can realize with reference to aforesaid way, this is not construed as limiting by the present embodiment.
Further, in order to provide customizability more flexibly, Java Virtual Machine JVM involved in above-mentioned example can be JVM, for instance the JVM etc. provided by OpenJDK.But, the complete java runtime storehouse (RuntimeLibrary) no matter comprised in any JVM, it is all redundancy and huge for the concrete function of the described access interface accessing third party's JNI library, because the concrete function realizing described access interface mostly just relates to a part in java runtime storehouse (sometimes or even seldom part) class and function.If complete java runtime storehouse being loaded in JVM can increase much unnecessary room and time expense, for some embedded system (such as the intelligent terminal such as Set Top Box, wearable device) of software and hardware limited ability, bigger java runtime storehouse is unacceptable sometimes.In order to overcome drawbacks described above, concrete kind that the present embodiment may be able to be used according to the concrete function realizing described access interface and the scope of function, described java runtime storehouse is carried out suitable cutting, delete and quote storehouse corresponding to those classes that will not use and function, even can realize with minimum java runtime storehouse to run JVM, thus resource occupation amount when JVM run is greatly lowered, correspondingly improve the operational efficiency of JVM, the platform limited for operational capability is very applicable, and the technical scheme of the present embodiment can be applied to the system of lightweight.
Present disclose provides calling and realizing method of a kind of quick compatible Android third-party Runtime Library, in order to non-Android system, it is possible to quickly use related peripherals and non-comercial operation storehouse, be greatly enriched the function of non-Android system.
Fig. 2 is the flow chart of a kind of method accessing the third party library for the first system in second system according to an exemplary embodiment, as in figure 2 it is shown, the method accessing the third party's JNI library for the first system in second system described in the present embodiment includes:
In step S210, by the Java Virtual Machine for second system with the form loading third-party JNI library compatible with the JNI loading interface for the first system.
In step S220, derived the relevant API of described third party's JNI library by described Java Virtual Machine.
In step S230, by API relevant described in JNI reverse calling with third party's JNI library described in dereference.
Above-mentioned steps S110-S230 is identical with embodiment one, does not repeat them here, specifically can referring to the description in embodiment one.
In step S240, encapsulate the relevant API of described reverse calling for the localization of described non-Android system.
On the basis of embodiment one, the present embodiment can further include step S240, namely encapsulates the interface of reverse calling in described step S230 for the localization of above-mentioned non-Android system.Described non-Android system has a variety of in the prior art, for instance linux system, iOS system, WindowsPhone system, etc..Generally, operating system has communication mode available between its internal process, for instance QBus, DBus or Socket etc..Although in described step S230, namely non-Android system can complete the access to described third party's JNI library indirectly by the above-mentioned access interface in JVM described in reverse calling, but between its occupation mode and above-mentioned non-Android system, compatible degree is still inadequate, and it is still convenient not to use.In order to enable above-mentioned non-Android system to complete the above-mentioned access to third party's JNI library by local interface method of calling easily, the present embodiment is according further to the application demand of above-mentioned non-Android system, the interface of reverse calling in described step S230 is localized encapsulation, and the concrete mode of encapsulation can be passed through the localizations such as such as QBus, DBus or Socket and encapsulate the relevant API of described reverse calling.After localizing encapsulation, described third party's JNI library can be called and be accessed to the application under described non-Android system and this environment just according to the mode that oneself had or was familiar with, it is possible to simplified access interface, improves service efficiency.
The present embodiment, by being encapsulated into the access interface of third party's JNI library for the localization of non-Android system, further increases convenience compatible with non-Android system for third party's JNI library, improves the efficiency using third party's JNI library under non-Android system.
Fig. 3 is the block diagram of a kind of system accessing the third party's JNI library for the first system in second system according to an exemplary embodiment, as it is shown on figure 3, the system accessing the third party's JNI library for the first system in second system described in the present embodiment includes load-on module 310, derives module 320 and reverse calling module 330.
This load-on module 310 is configured to by the Java Virtual Machine for second system with the form loading third-party JNI library compatible with the JNI loading interface for the first system.
This derivation module 320 is configured to be derived the relevant API of described third party's JNI library by described Java Virtual Machine.
This reverse calling module 330 is configured to by API relevant described in JNI reverse calling with third party's JNI library described in dereference.
Third party's JNI library described in the present embodiment is the functional packet for operating local device, third party manufacturer provide.In order to realize the efficient access to local device, local compiled code is generally adopted to realize, for instance C, C++ etc..It addition, for third party's JNI library of Android system exploitation, the JNI mechanism being additionally based upon Android provides the JNI calling interface that can be used for Android platform, and Android system can directly invoke the function in third party's JNI library by this interface.But, this interface restriction third party's JNI library can be only applied to Android system.
In an embodiment, described the first system is Android system, and described third party's JNI library is third party's JNI library of compatible Android system.
In an embodiment, described load-on module 310 for by the Java Virtual Machine for described second system with the form loading third-party JNI library of Java local interface JNI.
In an embodiment, described derivation module 320 is used for: creates access interface in JVM and passes through the access interface described third party's JNI library of access created.
In an embodiment, the described system accessing the third party library for the first system in second system also includes selecting module (not shown in Fig. 3), and described relevant API is selected by the concrete function for the third party's JNI library according to described the first system.
In an embodiment, described the first system is Android system, described second system is non-Android system, the described system accessing the third party library for the first system in second system also includes package module (not shown in Fig. 3), for encapsulating the relevant API of described reverse calling for the localization of described non-Android system.
In an embodiment, described non-Android system is linux system, iOS system or WindowsPhone system.
In an embodiment, described package module is used for, and is encapsulated the relevant API of described reverse calling by QBus, DBus or Socket localization for described non-Android system.
The JNI standard that mostly can adopt Android due to presently relevant peripheral hardware provides third-party Runtime Library, quickly to coordinate operation with Android system, owing to manufacturer is for the consideration of maintenance cost, Runtime Library available in the non-Android operation system of typically not offer.Although Android system by enhancing Java compatible degree under Android system and improve service efficiency to the customization of Java, but which also limits the use scope of the third-party application for its exploitation.In order to compatible Android third-party Runtime Library uses for non-Android system, it is necessary first to go Androidization.And standard Java language is exactly a kind of well selection.
In an exemplary embodiment, encapsulating the access interface to third party's Runtime Library with standard Java language, so, no matter run under any Java Virtual Machine (JVM), its result is all identical.
As the example implemented, standard Java language one access interface class of definition can be used, wherein comprising Java Localization methodologies (NativeMethod), it implements and is completed by third party's JNI library, is referred to Java local interface JNI mode and realizes.
After encapsulating the access interface to third party's JNI library with standard Java language, it is possible to by this interface instantiation for accessing described third party's JNI library.For above-mentioned example, after loading corresponding third party's JNI library, namely can call its Localization methodologies by access interface class described in instantiation, thus the specific function performed in third party's JNI library.
After creating the described access interface example to third party's JNI library, non-Android system can obtain this interface instance under home environment, and indirectly accesses third party's JNI library by this interface instance, thus calling the function realized by third party's JNI library.This calls the angle from JVM is reverse calling, namely calls the class/object/method within JVM from the non-Android system outside JVM, therefore, is called reverse calling in the present embodiment.By the access interface example in reverse calling JVM, non-Android system and the third party's Runtime Library communications conduit therebetween for Android exploitation are got through, so that described third party's Runtime Library can be compatible with non-Android system, the scope of this available devices greatly having widened non-Android system and third party's JNI library, enrich the function of non-Android system, simultaneously, third party manufacturer modifies without to the Runtime Library being originally Android system exploitation, get final product slitless connection to non-Android system, reduce research and development and the lower deployment cost of third party manufacturer.
Further, in order to provide customizability more flexibly, Java Virtual Machine JVM involved in above-mentioned example can be JVM, for instance the JVM etc. provided by OpenJDK.But, the complete java runtime storehouse (RuntimeLibrary) no matter comprised in any JVM, it is all redundancy and huge for the concrete function of the described access interface accessing third party's JNI library, because the concrete function realizing described access interface mostly just relates to a part in java runtime storehouse (sometimes or even seldom part) class and function.
If complete java runtime storehouse being loaded in JVM can increase much unnecessary room and time expense, for some embedded system (such as the intelligent terminal such as Set Top Box, wearable device) of software and hardware limited ability, bigger java runtime storehouse is unacceptable sometimes.
In order to overcome drawbacks described above, concrete kind that the present embodiment may be able to be used according to the concrete function realizing described access interface and the scope of function, described java runtime storehouse is carried out suitable cutting, delete and quote storehouse corresponding to those classes that will not use and function, even can realize with minimum java runtime storehouse to run JVM, thus resource occupation amount when JVM run is greatly lowered, correspondingly improve the operational efficiency of JVM, the platform limited for operational capability is very applicable, and the technical scheme of the present embodiment can be applied to the system of lightweight.
In an exemplary embodiment, reverse calling module 330 can also be for the localization of above-mentioned non-Android system and encapsulates the interface of described reverse calling.Described non-Android system has a variety of in the prior art, for instance linux system, iOS system, WindowsPhone system, etc..Generally, operating system has communication mode available between its internal process, for instance, QBus, DBus or Socket etc..Although namely described non-Android system can complete the access to described third party's JNI library indirectly by the above-mentioned access interface in JVM described in reverse calling, but the compatible degree between its occupation mode and above-mentioned non-Android system is still inadequate, and it is still convenient not to use.
In order to enable above-mentioned non-Android system to complete the above-mentioned access to third party's JNI library by local interface method of calling easily, the present embodiment is according further to the application demand of above-mentioned non-Android system.The interface of described reverse calling is localized encapsulation, concrete mode such as QBus, DBus or Socket etc. of encapsulation.After localizing encapsulation, described third party's JNI library can be called and be accessed to the application under described non-Android system and this environment just according to the mode that oneself had or was familiar with, it is possible to simplified access interface, improves service efficiency.
By being encapsulated into the access interface of third party's JNI library for the localization of non-Android system, further increase convenience compatible with non-Android system for third party's JNI library, improve the efficiency using third party's JNI library under non-Android system.
About the system in above-described embodiment, the concrete mode that wherein unit performs to operate has been described in detail in about the embodiment of the method, and explanation will be not set forth in detail herein.
The method accessing the third party's JNI library for the first system in second system that the system of third party's JNI library for the first system that accesses in second system that the present embodiment provides can perform the embodiment of the present invention one and embodiment two provides, possesses the corresponding functional module of execution method and beneficial effect.
Fig. 4 is a kind of block diagram for terminal unit 400 according to an exemplary embodiment.Such as, terminal unit 400 can be mobile phone, computer, digital broadcast terminal, messaging devices, game console, tablet device, armarium, body-building equipment, personal digital assistant etc..
With reference to Fig. 4, terminal unit 400 can include following one or more assembly: processes assembly 402, memorizer 404, electric power assembly 406, multimedia groupware 408, audio-frequency assembly 410, the interface 412 of input/output (I/O), sensor cluster 414, and communications component 416.
Process assembly 402 and generally control the integrated operation of terminal unit 400, such as with display, call, data communication, the operation that camera operation and record operation are associated.Process assembly 402 and can include one or more processor 420 to perform instruction, to complete all or part of step of above-mentioned method.Additionally, process assembly 402 can include one or more module, it is simple to what process between assembly 402 and other assemblies is mutual.Such as, process assembly 402 and can include multi-media module, with facilitate multimedia groupware 408 and process between assembly 402 mutual.
Memorizer 404 is configured to store various types of data to support the operation at equipment 400.The example of these data includes any application program for operation on terminal unit 400 or the instruction of method, contact data, telephone book data, message, picture, video etc..Memorizer 404 can be realized by any kind of volatibility or non-volatile memory device or their combination, such as static RAM (SRAM), Electrically Erasable Read Only Memory (EEPROM), Erasable Programmable Read Only Memory EPROM (EPROM), programmable read only memory (PROM), read only memory (ROM), magnetic memory, flash memory, disk or CD.
The various assemblies that electric power assembly 406 is terminal unit 400 provide electric power.Electric power assembly 406 can include power-supply management system, one or more power supplys, and other generate, manage and distribute, with for terminal unit 400, the assembly that electric power is associated.
Multimedia groupware 408 includes the screen providing an output interface between described terminal unit 400 and user.In certain embodiments, screen can include liquid crystal display (LCD) and touch panel (TP).If screen includes touch panel, screen may be implemented as touch screen, to receive the input signal from user.Touch panel includes one or more touch sensor to sense the gesture on touch, slip and touch panel.Described touch sensor can not only sense the border of touch or sliding action, but also detects the persistent period relevant to described touch or slide and pressure.In certain embodiments, multimedia groupware 408 includes a front-facing camera and/or post-positioned pick-up head.When equipment 400 is in operator scheme, during such as screening-mode or video mode, front-facing camera and/or post-positioned pick-up head can receive the multi-medium data of outside.Each front-facing camera and post-positioned pick-up head can be a fixing optical lens system or have focal length and optical zoom ability.
Audio-frequency assembly 410 is configured to output and/or input audio signal.Such as, audio-frequency assembly 410 includes a mike (MIC), and when terminal unit 400 is in operator scheme, during such as call model, logging mode and speech recognition mode, mike is configured to receive external audio signal.The audio signal received can be further stored at memorizer 404 or send via communications component 416.In certain embodiments, audio-frequency assembly 410 also includes a speaker, is used for exporting audio signal.
I/O interface 412 provides interface for processing between assembly 402 and peripheral interface module, above-mentioned peripheral interface module can be keyboard, puts striking wheel, button etc..These buttons may include but be not limited to: home button, volume button, startup button and locking press button.
Sensor cluster 414 includes one or more sensor, for providing the state estimation of various aspects for terminal unit 400.Such as, what sensor cluster 414 can detect equipment 400 opens/closed mode, the relative localization of assembly, such as described assembly is display and the keypad of terminal unit 400, sensor cluster 414 can also detect terminal unit 400 or the position change of 400 1 assemblies of terminal unit, the presence or absence that user contacts with terminal unit 400, the variations in temperature of terminal unit 400 orientation or acceleration/deceleration and terminal unit 400.Sensor cluster 414 can include proximity transducer, is configured to when not having any physical contact object near detection.Sensor cluster 414 can also include optical sensor, such as CMOS or ccd image sensor, for using in imaging applications.In certain embodiments, this sensor cluster 414 can also include acceleration transducer, gyro sensor, Magnetic Sensor, pressure transducer or temperature sensor.
Communications component 416 is configured to facilitate between terminal unit 400 and other equipment the communication of wired or wireless mode.Terminal unit 400 can access the wireless network based on communication standard, such as WiFi, 2G or 3G, or their combination.In one exemplary embodiment, communications component 416 receives the broadcast singal or the broadcast related information that manage system from external broadcasting via broadcast channel.In one exemplary embodiment, described communications component 416 also includes near-field communication (NFC) module, to promote junction service.Such as, can based on RF identification (RFID) technology in NFC module, Infrared Data Association (IrDA) technology, ultra broadband (UWB) technology, bluetooth (BT) technology and other technologies realize.
In the exemplary embodiment, terminal unit 400 can be realized by one or more application specific integrated circuits (ASIC), digital signal processor (DSP), digital signal processing appts (DSPD), PLD (PLD), field programmable gate array (FPGA), controller, microcontroller, microprocessor or other electronic components, is used for performing said method.
In the exemplary embodiment, additionally providing a kind of non-transitory computer-readable recording medium including instruction, for instance include the memorizer 404 of instruction, above-mentioned instruction can have been performed said method by the processor 420 of terminal unit 400.Such as, described non-transitory computer-readable recording medium can be ROM, random access memory (RAM), CD-ROM, tape, floppy disk and optical data storage devices etc..
A kind of non-transitory computer-readable recording medium, when the instruction in described storage medium is performed by the processor of mobile terminal, making mobile terminal be able to carry out a kind of method accessing the third party's JNI library for the first system in second system, described method includes:
By the Java Virtual Machine for second system with the form loading third-party JNI library compatible with the JNI loading interface for the first system;
The relevant API of described third party's JNI library is derived by described Java Virtual Machine;
By API relevant described in JNI reverse calling with third party's JNI library described in dereference.
Those skilled in the art, after considering description and putting into practice invention disclosed herein, will readily occur to other embodiment of the present invention.The application is intended to any modification of the present invention, purposes or adaptations, and these modification, purposes or adaptations are followed the general principle of the present invention and include the undocumented known general knowledge in the art of the disclosure or conventional techniques means.Description and embodiments is considered only as exemplary, and the true scope of the present invention and spirit are pointed out by claim below.
It should be appreciated that the invention is not limited in precision architecture described above and illustrated in the accompanying drawings, and various amendment and change can carried out without departing from the scope.The scope of the present invention is only limited by appended claim.