A kind of method, apparatus and mobile terminal loading plug-in unit
Technical field
The present invention relates to computer fields, and in particular to a kind of method, apparatus and mobile terminal for loading plug-in unit.
Background technique
Currently, Android (Android) operating system is widely used in field of mobile terminals, a large amount of mobile phone,
Tablet computer uses Android operation system.Android operation system uses linux kernel, due to the safety of linux kernel
Mechanism, along with the special mechanism of the dalvik of Android operation system, the application program in Android operation system is difficult
It is extended.
Under Android operation system, after the apk of application program is mounted in operating system, it is difficult to be extended.
It to small upgrading is carried out in application program, requires again to be packaged code, user need to reuse new apk and carry out
Installation, so that the application program in android system is less flexible.
Recently there is Plugin Mechanism, by the function division module of application, each module corresponds to a plug-in unit and concentrates on
In one apk.There is this Plugin Mechanism, when being expanded or being upgraded to application program, it is only necessary to change corresponding plug-in unit
?.
Currently, the load to plug-in unit is realized under Android operation system by DexClassLoader.But usually
In the case of, a plug-in unit is made of the part such as class, resource, and the resource of plug-in unit may include the contents such as its interface images, background music,
And DexClassLoader can only realize the load to the class of plug-in unit, but can not achieve the load to the resource of plug-in unit, will lead to
The problems such as showing mistake after plug-in unit load, can not showing completely.
Summary of the invention
In view of the above problems, it proposes on the present invention overcomes the above problem or at least be partially solved in order to provide one kind
State method, correspondingly device and the mobile terminal of a kind of load plug-in unit of problem.
According to one aspect of the present invention, a kind of method loading plug-in unit is provided, comprising:
When plug-in unit is triggered, the resource of the plug-in unit is obtained;
The context context of the plug-in unit is created, and is in advance the distribution of the main application of the plug-in unit by operating system
Context replace with the context of the plug-in unit, wherein the context of the plug-in unit is directed toward the resource of the plug-in unit;
The main application loads the resource of the plug-in unit according to the context after being replaced, wherein it is described be replaced after
Context is the context of the plug-in unit.
Optionally, before the resource for obtaining the plug-in unit, further includes:
Obtain the installation kit archive information of the plug-in unit.
Optionally, the installation kit archive information for obtaining the plug-in unit, comprising:
Obtain the PackageManager object of the plug-in unit;
According to the installation kit archive information of plug-in unit described in the PackageManager object acquisition;
Design variables under the installation kit archive information are revised as preset path;
Wherein, the preset path is the store path of the plug-in unit.
Optionally, before the context for creating the plug-in unit, the method also includes:
Create the DexClassLoader class of the plug-in unit;
Wherein, the DexClassLoader class is used to transmit the executable code path of the plug-in unit.
Optionally, the context context for creating the plug-in unit, and be in advance the master of the plug-in unit by operating system
The context of the distribution of application replaces with the context of the plug-in unit, comprising:
The context for being inherited from ContextThemeWrapper class is established for the plug-in unit;
It rewrites for loading the resource of the plug-in unit and the method function of executable code, in the function after the rewriting
Return to the context of the plug-in unit.
It is optionally, described for loading the method function of the resource and executable code of the plug-in unit, comprising:
GetClassLoader, getResources and getAssets.
Optionally, before the plug-in unit is triggered or when the plug-in unit is triggered, the method also includes:
Judge whether the plug-in unit can be used;
When the plug-in unit is unavailable, the request for obtaining plug-in unit list is sent to server;Wherein, in the plug-in unit list
Under plugin name, plug-in version, the digital digest value of plug-in unit and the plug-in unit of preserving plug-in unit included by the main application
Set address.
Receive the plug-in unit list sent;
The plug-in unit of new version is downloaded according to the download address of plug-in unit described in the plug-in unit list.
Optionally, after the plug-in unit of the download address downloading new version of the plug-in unit according to the plug-in unit list,
The method also includes:
The digest value saved in the digital digest value and plug-in unit list of the plug-in unit of new version that verifying downloading obtains whether phase
Together, when identical, the step of executing the resource for obtaining the plug-in unit.
Optionally, the method also includes;
The ClassLoader object of replacement operation system is the main customized ClassLoader object of application;
Wherein, the customized ClassLoader object for realizing the plug-in unit load.
According to another aspect of the invention, a kind of device loading plug-in unit is provided, comprising:
Source obtaining module, suitable for obtaining the resource of the plug-in unit when plug-in unit is triggered;
First establishes module, suitable for creating the context context of the plug-in unit, and is in advance described insert by operating system
The context of the distribution of the main application of part replaces with the context of the plug-in unit, wherein the context of the plug-in unit is directed toward institute
State the resource of plug-in unit;
Loading module loads the resource of the plug-in unit suitable for the main application according to the context after being replaced, wherein
It is described be replaced after context be the plug-in unit context.
Optionally, described device further include:
Data obtaining module, the installation kit suitable for before the resource for obtaining the plug-in unit, obtaining the plug-in unit achieve letter
Breath.
Optionally, the data obtaining module, comprising:
Object acquisition unit, suitable for obtaining the PackageManager object of the plug-in unit;
Information acquisition unit, the installation kit suitable for the plug-in unit according to the PackageManager object acquisition achieve letter
Breath;
Variable modifies unit, suitable for the design variables under the installation kit archive information are revised as preset path;
Wherein, the preset path is the store path of the plug-in unit.
Optionally, described device further include:
Second establishes module, suitable for creating the plug-in unit before the context for creating the plug-in unit
DexClassLoader class;
Wherein, the DexClassLoader class is used to transmit the executable code path of the plug-in unit.
Optionally, it described first establishes module and includes:
Context establishes unit, is suitable for the plug-in unit foundation and is inherited from ContextThemeWrapper class
context;
Rewriting unit, suitable for rewriteeing for loading the resource of the plug-in unit and the method function of executable code, described
The context of the plug-in unit is returned in function after rewriting.
It is optionally, described for loading the method function of the resource and executable code of the plug-in unit, comprising:
GetClassLoader, getResources and getAssets.
Optionally, described device further include: plug-in download module;
The plug-in download module includes:
Judging unit can be used, suitable for before the plug-in unit is triggered or when the plug-in unit is triggered, judging that the plug-in unit is
It is no available;
Request transmitting unit is suitable for when the plug-in unit is unavailable, and the request for obtaining plug-in unit list is sent to server;Its
In, the plugin name of plug-in unit included by the main application, plug-in version, the number of plug-in unit are preserved in the plug-in unit list plucks
It is worth and the download address of plug-in unit.
List reception unit, suitable for receiving the plug-in unit list sent;
Plug-in download unit, the download address suitable for the plug-in unit according to the plug-in unit list download inserting for new version
Part.
Optionally, described device further include:
Authentication module, suitable for the plug-in unit according to the plug-in unit list download address downloading new version plug-in unit it
Afterwards, whether the digest value saved in the digital digest value and plug-in unit list of the plug-in unit for the new version that verifying downloading obtains is identical, when
When identical, the step of executing the resource for obtaining the plug-in unit.
Optionally, described device further includes;
Entrance realizes module, and the ClassLoader object suitable for replacement operation system is that the main application is customized
ClassLoader object;
Wherein, the customized ClassLoader object for realizing the plug-in unit load.
According to another aspect of the invention, a kind of mobile terminal is provided, the mobile terminal includes:
Memory;
One or more processors;
Wherein, one or more of processors are configured as executing following method:
When plug-in unit is triggered, the resource of the plug-in unit is obtained;
The context context of the plug-in unit is created, and is in advance the distribution of the main application of the plug-in unit by operating system
Context replace with the context of the plug-in unit, wherein the context of the plug-in unit is directed toward the resource of the plug-in unit;
The main application loads the resource of the plug-in unit according to the context after being replaced, wherein it is described be replaced after
Context is the context of the plug-in unit.
The embodiment of the invention provides a kind of method, apparatus and mobile terminal for loading plug-in unit, by being triggered when plug-in unit
When, the resource of plug-in unit is obtained, the context of plug-in unit is created, and is in advance the distribution of the main application of plug-in unit by operating system
Context replaces with the context of plug-in unit, according to the resource of the context load plug-in unit after being replaced, can solve
The problem of under Android native system since the resource that cannot load plug-in unit caused by plug-in unit context cannot be obtained, and should
Method does not influence other objects that system generates, and not will lead to compatibility issue, even if evolution has occurred in system, plug-in unit is still
So can correctly it load.
The above description is only an overview of the technical scheme of the present invention, in order to better understand the technical means of the present invention,
And it can be implemented in accordance with the contents of the specification, and in order to allow above and other objects of the present invention, feature and advantage can
It is clearer and more comprehensible, the followings are specific embodiments of the present invention.
According to the following detailed description of specific embodiments of the present invention in conjunction with the accompanying drawings, those skilled in the art will be brighter
The above and other objects, advantages and features of the present invention.
Detailed description of the invention
By reading the following detailed description of the preferred embodiment, various other advantages and benefits are common for this field
Technical staff will become clear.The drawings are only for the purpose of illustrating a preferred embodiment, and is not considered as to the present invention
Limitation.And throughout the drawings, the same reference numbers will be used to refer to the same parts.In the accompanying drawings:
Fig. 1 is a kind of method flow diagram for loading plug-in unit provided by one embodiment of the present invention;
Fig. 2 is a kind of specific method flow chart for loading plug-in unit provided by one embodiment of the present invention;
Fig. 3 is a kind of apparatus structure block diagram for loading plug-in unit provided by one embodiment of the present invention.
Specific embodiment
Exemplary embodiments of the present disclosure are described in more detail below with reference to accompanying drawings.Although showing the disclosure in attached drawing
Exemplary embodiment, it being understood, however, that may be realized in various forms the disclosure without the implementation that should be illustrated here
Example is limited.It is to be able to thoroughly understand the disclosure on the contrary, providing these embodiments, and can be by the scope of the present disclosure
It is fully disclosed to those skilled in the art.
Embodiment one
The embodiment of the invention provides a kind of methods for loading plug-in unit.It can be by the application program under Android
Realization is improved, is implemented on the terminal device for being equipped with Android operation system, such as mobile phone, plate, handheld computer etc.
Customer mobile terminal equipment.
Fig. 1 is a kind of method flow diagram for loading plug-in unit provided in this embodiment.This method specifically includes step S102 extremely
Step S106.
S102: when plug-in unit is triggered, the resource of plug-in unit is obtained.
S104: the context of newly-built plug-in unit, and be in advance the context of the distribution of the main application of plug-in unit by operating system
Replace with the context of plug-in unit.
Wherein, the context of plug-in unit is directed toward the resource of plug-in unit.
S106: main application loads the resource of plug-in unit according to the context after being replaced, wherein the context after being replaced
For the context of plug-in unit.
The embodiment of the invention provides a kind of methods for loading plug-in unit.When plug-in unit is triggered, the resource of plug-in unit is obtained, newly
The context of plug-in unit is built, and is in advance that the context of the distribution of the main application of plug-in unit replaces with plug-in unit by operating system
Context can solve under Android native system according to the resource of the context load plug-in unit after being replaced due to not
The problem of resource that plug-in unit cannot be loaded caused by plug-in unit context can be obtained, and this method system is generated other are right
As not influencing, compatibility issue not will lead to, even if evolution has occurred in system, plug-in unit still is able to correctly load.
Embodiment two
The present embodiment is a kind of concrete application scene of above-described embodiment one, through this embodiment, being capable of clearer, tool
Illustrate to body method provided by the present invention.
As shown in Fig. 2, for a kind of specific method flow chart for loading plug-in unit provided in an embodiment of the present invention, this method includes
Step S201 to S206.
Firstly, executing step S201 obtains the installation kit archive information of plug-in unit when plug-in unit is triggered
PackageArchiveInfo。
Wherein, plug-in unit is a module of main program.It usually may include more in the application program based on developing plug
A module, wherein each module can be realized by a plug-in unit.Currently, due to the liter of the application program under Android
Grade is inconvenient, and the plug-in unit of application program has become a kind of trend.
For example, may include the functions such as rubbish cleaning, self-triggered program management, wooden horse scanning in a optimization software,
Wherein, each function can individually develop into a module, a plug-in unit as optimization software.When optimization software needs to increase
When new function " hardware testing ", a plug-in unit only need to be write again and is discharged under main program, without updating entire application program,
Developer is also not required to carry out packing compiling to entire application program again again.
Under normal conditions, plug-in unit is an apk file, and user after downloading, can be directly released into the specified mesh of main program
In record, that is, complete the installation of plug-in unit.
It should be noted that in order to enable plug-in unit can be loaded, inside the apk of plug-in unit should by developer to it at least
An entrance (Entry) is provided, for completing the loading procedure of plug-in unit.
It, in the present embodiment, can be in the following way in order to realize the entrance of plug-in unit:
The primary ClassLoader object of system is replaced using ClassLoader object customized in main program.
The particular load mode of the class or resource to application program, example may be implemented in customized ClassLoader
Such as, when loading the activity component of plug-in unit, the context of re-direction applications program is the context of plug-in unit, with realization pair
The complete load of plug-in unit.
Specifically, primary for using in main program customized ClassLoader object to replace system
The method of ClassLoader object may include:
When the process initiation of application program, obtaining operating system is the PackageInfo object that application program is established, and is obtained
The mClassLoader field in PackageInfo object is taken, the address in mClassLoader field is modified, is directed toward it certainly
The ClassLoader object address of definition, so as to complete customized ClassLoader object to primary
The replacement of ClassLoader allows to through customized ClassLoader object loading application programs.
Triggering for plug-in unit usually may include two kinds of situations:
One is the active of user click, when user needs the corresponding function of plug-in unit, the plug-in unit is clicked to start.
Another kind is when main program starting, and triggering plug-in unit loads automatically.For example, certain optimization functions, are opened in main program
Plug-in component operation is needed when dynamic.
In this step S201, the installation kit archive information PackageArchiveInfo for obtaining plug-in unit can be by such as lower section
Method:
Firstly, obtaining the object of the PackageManager of plug-in unit;
Then, mContext.getPackageManager () interface is recalled to realize that the installation kit for obtaining plug-in unit achieves
Information.
For example, being pm by PackageManager object definition in the present embodiment, then it can be realized and be obtained by following code
Take the PackageManager object of plug-in unit:
In above-mentioned code, mPath is the path of plug-in unit, GET_ACTIVITIES, GET_SERVICES, GET_
PROVIDERS, GET_META_DATA respectively indicate the letter for obtaining Activity, Service, Provider of apk of plug-in unit
Breath and Android Manifest in META_DATA information.
Wherein, the installation kit archive information PackageArchiveInfo of plug-in unit be include apk Activity,
The information and the META_DATA information in Android Manifest of Service, Provider.
Also, installation kit archive information of the four kinds of information as above as plug-in unit in the present embodiment, is only obtained, can be mentioned
The loading velocity of high plug-in unit, improving performance.
It should be noted that may include multiple plug-in units under a main program.For example, under security guard's software, it can
To there is the plug-in unit of the functions such as sweep-drug, cleaning, encryption, user can select download plug-in according to demand.It is developed based on Plugin Mechanism
Program, carry out plug-in unit iteration when, update can also be downloaded just for single plug-in unit.
In the present embodiment, it can choose and plug-in unit be downloaded or updated by cloud server, method can be such that
Step A, before plug-in unit is triggered or triggers, whether detection plug-in unit be can be used, if available, step S202 be executed, if not
It can use, execute step B;
Wherein, unavailable includes not downloading or the version of plug-in unit is too low.
Step B sends the request for obtaining plug-in unit list to server;
Wherein, server preserves the plug-in unit list of current main program, in the list record have plug-in unit plugin name,
Plug-in version, the digital digest value of plug-in unit and the download address of plug-in unit.
As shown in table 1 below, the as example of plug-in unit list:
Plug-in unit name |
Plug-in version |
Plug-in unit MD5 |
Plug-in unit URL |
Plug-in unit A |
1 |
A111 |
http://a.360.cn/a.apk |
Plug-in unit A |
2 |
A222 |
http://a.360.cn/a2.apk |
Plug-in unit B |
1 |
B111 |
http://a.360.cn/b.apk |
Table 1
Wherein, MD5 (Message Digest Algorithm 5rd, Message Digest Algorithm 5) value is digital digest
One kind of value.
Step C receives the plug-in unit list that server is sent;
Step D downloads the plug-in unit of new version according to the download address of the plug-in unit in plug-in unit list;
Whether step E, the digital digest and the digital digest in plug-in unit list for verifying the plug-in unit of the new version of downloading meet,
If it is, plug-in download or update are completed, if it is not, re-downloading.
After getting the installation kit archive information of plug-in unit, step S202 is executed, it will be default under installation kit archive information
Variable is revised as preset path.
It should be noted that realizing the load to plug-in resource in the present embodiment, the normal initial of plug-in unit is changed
Change process (such as context of replacement main program), therefore, needs to modify in this step default under installation kit archive information
Variable, to prevent the program throw exception in the loading procedure of plug-in unit.
In the present embodiment, design variables include: sourceDir and publicSourceDir.
Preset path is the path mPath of plug-in unit.
For example, the modification to design variables can be realized by following code:
MPackageInfo.applicationInfo.sourceDir=mPath;
MPackageInfo.applicationInfo.publicSourceDir=mPath;
After modifying design variables, i.e., executable step S203 obtains the resource of plug-in unit.
In this step S203, the resource of plug-in unit can be obtained in the following way:
By call PackageManager object (namely customized pm in step S201, it is complete in step s 201
At obtain operate) in getResourcesForApplication method, to obtain the Resources object of the plug-in unit, then
Pass through the resource of Resources object acquisition plug-in unit.
It wherein, include the related all resource informations of the plug-in unit in Resources object.
For example, can be realized by following code:
Wherein, mPkgResources is the resource of plug-in unit.
After acquiring the resource of plug-in unit, step S204 is executed, creates DexClassLoader class for plug-in unit.
Wherein, a plug-in unit is usually made of dex (binary code under Android) file and resource, if completing to insert
The load of part then needs to load the dex file and resource of plug-in unit simultaneously.In android system, load for dex file,
It is completed by DexClassLoader class.DexClassLoader also becomes class loaders.
In order to enable DexClassLoader can correctly load the dex file of plug-in unit, need newly-built
The path that the dex file of plug-in unit is stored in DexClassLoader, transmits plug-in unit by newly-built DexClassLoader
The path of dex file.
For example, can be realized by following code:
String out=mContext.getDir (DIR, 0) .getPath ();
MClassLoader=new DexClassLoader (mPath, out, null, parent);
Wherein, parent indicates that newly-built DexClassLoader is parent loader, has more than is needed in order to avoid occurring adjusting
The problem of android system class.
After newly-built DexClassLoader, that is, guarantee to load the dex file of plug-in unit.In the present embodiment,
In order to the resource of normal load plug-in unit, also need to execute step S205, i.e., the context of newly-built plug-in unit oneself, and replace
The context of main program.
Wherein, context is the unique identifier of application program in android system, is equivalent in windows system
Handle all need to complete by context when needing to call dex file, the resource etc. of application program.In normal condition
Under, when an application program launching, operating system can be one context of the application initialization, and without being slotting
Part distributes context, and therefore, in existing android system, the load for plug-in unit is always a difficult point.
Therefore, in the present invention, need to create a context for plug-in unit to be loaded, in order to be different from main program
The context of context, plug-in unit can be defined as PluginContext.
For example, creating PluginContext for plug-in unit can be realized by following code:
Wherein, the PluginContext of plug-in unit has to be inherited from ContextThemeWrapper, it is Context
Encapsulate class.
After establishing the PluginContext of plug-in unit, for the Context for distributing its replacement system main program, also
Below step need to be executed:
Override method function relevant to plug-in unit load.
In the present embodiment, method function relevant to plug-in unit load mainly includes following three:
GetClassLoader, getResources and getAssets.
Wherein, getClassLoader is used for loading classes, such as DexClassLoader;
GetResources and getAssets is used to load the resource of plug-in unit.
It how is exemplified below to these three method letters of getClassLoader, getResources and getAssets
Number is override:
(1)getClassLoader
Wherein, as long as being related to the place of Context calling, the side Context.getClassLoader all can preferentially be used
Method can call this method when application program launching, since we have override this method, being returned is us in step
The DexClassLoader created in rapid S204 completes adding to the class of plug-in unit by the DexClassLoader that we create
It carries.
(2)getResources
Wherein, the place for obtaining resource is generally involved, getResources method function can be all called, after overriding
In getResources method function, when the function is called, i.e., the Resources object of plug-in unit can be returned to, to complete
Load to the resource of plug-in unit.
(3)getAssets
Wherein, getAssets is also the resource for obtaining plug-in unit, when loading the part resource of plug-in unit, be will use
GetAssets method function.When the function is called, i.e., the Assets object of plug-in unit can be returned to, to complete to plug-in unit
The load of resource.
After rewriteeing above three method function, the load of dex file and resource for plug-in unit can all realize replacement, can
Plug-in unit under perfect load main program.
Finally, step S206 is executed, according to the resource and dex file of the context load plug-in unit after being replaced.
It should be noted that generally there is an entrance (Entry) when program starts, after the triggering in order to realize plug-in unit
The load of resource can be carried out, we can realize an Entry in plug-in unit.In all entrances, Entry is to be adjusted earliest
, it is similar to the Dalvik.main of Android, is the place of entire plug-in unit most entrance.
Such as following code, the entrance of as one plug-in unit:
String className=PACKAGE_PREFIX+ " _ "+mName+ " _ "+CLASS_NAME
Class<?>C=mClassLoader.loadClass (className);
McreateMethod=c.getDeclareMethod (Factory.METHOD_NAME, Factory_METHOD_
PARAMS);
Mplugin=(IPlugin) mCreateMethod.invoke (null, mPkgContext, manager);
We can first obtain the entry method of Entry, be in the present embodiment Create, then call the party by reflection
Method, mPkgContext and manager (cache interface is shown in " plug-in unit scheme " series) etc. are passed to plug-in unit entrance can (as above
It states shown in code).
In addition, we use mClassLoader, this is the ClassLoader of plug-in unit, that is to say, that
Entry.create is present in plug-in unit, rather than other places.This is arrived, entire loading procedure terminates, and plug-in unit can start to make
With.
It is illustrated Entry in order to clearer, the example that an Entry class is shown below is as follows:
Wherein, " package com.qihoo360.plugin.antitheft " indicates the packet of the packet where the Entry class
Entitled " com.qihoo360.plugin.antitheft ";
" public class Entry " indicates that the class of newly-built class is entitled " Entry ";
" public static final IBinder create " indicates that the earliest entrance of entire plug-in unit is " cerate "
Method, and parameter " ClassLoader of plug-in unit Context, plug-in unit IBinder and main program " is delivered wherein;
" return new Plugin (context, cl) " is indicated to return to an interface used by main program, be may is that
IBinder may is that IPlugin or other, but howsoever, which is all finally main program to be returned, by main program
It is scheduled.
The embodiment of the invention provides a kind of methods for loading plug-in unit.When plug-in unit is triggered, the resource of plug-in unit is obtained, newly
The context of plug-in unit is built, and is in advance that the context of the distribution of the main application of plug-in unit replaces with plug-in unit by operating system
Context can solve under Android native system according to the resource of the context load plug-in unit after being replaced due to not
The problem of resource that plug-in unit cannot be loaded caused by plug-in unit context can be obtained, and this method system is generated other are right
As not influencing, compatibility issue not will lead to, even if evolution has occurred in system, plug-in unit still is able to correctly load.
Embodiment three
Fig. 3 is a kind of structural block diagram of device for loading plug-in unit provided by one embodiment of the present invention, the device 300 packet
It includes:
Source obtaining module 310, suitable for obtaining the resource of plug-in unit when plug-in unit is triggered;
First establishes module 320, suitable for creating the context context of plug-in unit, and is in advance plug-in unit by operating system
The context of the distribution of main application replaces with the context of plug-in unit, and wherein the context of plug-in unit is directed toward the resource of plug-in unit;
Loading module 330, suitable for main application according to the resource of the context load plug-in unit after being replaced, wherein be replaced
Context afterwards is the context of plug-in unit.
Optionally, the device 300 further include:
Data obtaining module 340, suitable for obtaining the installation kit archive information of plug-in unit before the resource for obtaining plug-in unit.
Optionally, data obtaining module 340, comprising:
Object acquisition unit 341, suitable for obtaining the PackageManager object of plug-in unit;
Information acquisition unit, suitable for the installation kit archive information according to PackageManager object acquisition plug-in unit;
Variable modifies unit 342, suitable for the design variables under installation kit archive information are revised as preset path;
Wherein, preset path is the store path of plug-in unit.
Optionally, the device 300 further include:
Second establishes module 350, suitable for creating the DexClassLoader of plug-in unit before the context of newly-built plug-in unit
Class;
Wherein, DexClassLoader class is used to transmit the executable code path of plug-in unit.
Optionally, it first establishes module 320 and includes:
Context establishes unit 321, is suitable for plug-in unit and establishes the context for being inherited from ContextThemeWrapper class;
Rewriting unit 322, suitable for rewriteeing for loading the resource of plug-in unit and the method function of executable code, after rewriting
Function in return plug-in unit context.
Optionally, for loading the resource of plug-in unit and the method function of executable code, comprising:
GetClassLoader, getResources and getAssets.
Optionally, device 300 further include: plug-in download module 360;
The plug-in download module 360 includes:
Judging unit 361 can be used, suitable for judging above-mentioned plug-in unit before above-mentioned plug-in unit is triggered or when above-mentioned plug-in unit is triggered
Whether can be used;
Request transmitting unit 362 is suitable for when above-mentioned plug-in unit is unavailable, sends to server and obtains asking for plug-in unit list
It asks;Wherein, the plugin name of plug-in unit included by above-mentioned main application, plug-in version, plug-in unit are preserved in above-mentioned plug-in unit list
The download address of digital digest value and plug-in unit.
List reception unit 363, suitable for receiving the above-mentioned plug-in unit list sent;
Plug-in download unit 364, suitable for according to the download address downloading new version of above-mentioned plug-in unit in above-mentioned plug-in unit list
Plug-in unit.
Optionally, the device 300 further include:
Authentication module 370, suitable for downloading inserting for new version in the download address according to above-mentioned plug-in unit in above-mentioned plug-in unit list
After part, the digest value that is saved in the digital digest value and plug-in unit list of the plug-in unit of new version that verifying downloading obtains whether phase
Together, when identical, the step of executing the resource of the above-mentioned plug-in unit of above-mentioned acquisition.
Optionally, which further includes;
Entrance realizes module 380, and the ClassLoader object suitable for replacement operation system is that above-mentioned main application is customized
ClassLoader object;
Wherein, above-mentioned customized ClassLoader object for realizing above-mentioned plug-in unit load.
The embodiment of the invention provides a kind of devices for loading plug-in unit to obtain the resource of plug-in unit, newly when plug-in unit is triggered
The context of plug-in unit is built, and is in advance that the context of the distribution of the main application of plug-in unit replaces with plug-in unit by operating system
Context can solve under Android native system according to the resource of the context load plug-in unit after being replaced due to not
The problem of resource that plug-in unit cannot be loaded caused by plug-in unit context can be obtained, and this method system is generated other are right
As not influencing, compatibility issue not will lead to, even if evolution has occurred in system, plug-in unit still is able to correctly load.
In addition, the embodiment of the invention also provides a kind of mobile terminal, which includes:
Memory;
One or more processors;
Wherein, which is configured as executing following method:
When plug-in unit is triggered, the resource of above-mentioned plug-in unit is obtained;
The context context of above-mentioned plug-in unit is created, and is in advance the distribution of the main application of above-mentioned plug-in unit by operating system
Context replace with the context of above-mentioned plug-in unit, wherein the context of above-mentioned plug-in unit is directed toward the resource of above-mentioned plug-in unit;
Above-mentioned main application loads the resource of above-mentioned plug-in unit according to the context after being replaced, wherein it is above-mentioned be replaced after
Context is the context of above-mentioned plug-in unit.
In the instructions provided here, numerous specific details are set forth.It is to be appreciated, however, that implementation of the invention
Example can be practiced without these specific details.In some instances, well known method, structure is not been shown in detail
And technology, so as not to obscure the understanding of this specification.
Similarly, it should be understood that in order to simplify the disclosure and help to understand one or more of the various inventive aspects,
Above in the description of exemplary embodiment of the present invention, each feature of the invention is grouped together into single implementation sometimes
In example, figure or descriptions thereof.However, the disclosed method should not be interpreted as reflecting the following intention: i.e. required to protect
Shield the present invention claims features more more than feature expressly recited in each claim.More precisely, as following
Claims reflect as, inventive aspect is all features less than single embodiment disclosed above.Therefore,
Thus the claims for following specific embodiment are expressly incorporated in the specific embodiment, wherein each claim itself
All as a separate embodiment of the present invention.
Those skilled in the art will understand that can be carried out adaptively to the module in the equipment in embodiment
Change and they are arranged in one or more devices different from this embodiment.It can be the module or list in embodiment
Member or component are combined into a module or unit or component, and furthermore they can be divided into multiple submodule or subelement or
Sub-component.Other than such feature and/or at least some of process or unit exclude each other, it can use any
Combination is to all features disclosed in this specification (including adjoint claim, abstract and attached drawing) and so disclosed
All process or units of what method or apparatus are combined.Unless expressly stated otherwise, this specification is (including adjoint power
Benefit require, abstract and attached drawing) disclosed in each feature can carry out generation with an alternative feature that provides the same, equivalent, or similar purpose
It replaces.
In addition, it will be appreciated by those of skill in the art that although some embodiments described herein include other embodiments
In included certain features rather than other feature, but the combination of the feature of different embodiments mean it is of the invention
Within the scope of and form different embodiments.For example, in detail in the claims, embodiment claimed it is one of any
Can in any combination mode come using.
Various component embodiments of the invention can be implemented in hardware, or to run on one or more processors
Software module realize, or be implemented in a combination thereof.It will be understood by those of skill in the art that can be used in practice
It is some in the device of microprocessor or digital signal processor (DSP) to realize load plug-in unit according to an embodiment of the present invention
Or some or all functions of whole components.The present invention is also implemented as one for executing method as described herein
Partly or completely device or device program (for example, computer program and computer program product).Such realization is originally
The program of invention can store on a computer-readable medium, or may be in the form of one or more signals.In this way
Signal can be downloaded from an internet website to obtain, be perhaps provided on the carrier signal or be provided in any other form.
It should be noted that the above-mentioned embodiments illustrate rather than limit the invention, and ability
Field technique personnel can be designed alternative embodiment without departing from the scope of the appended claims.In the claims,
Any reference symbol between parentheses should not be configured to limitations on claims.Word "comprising" does not exclude the presence of not
Element or step listed in the claims.Word "a" or "an" located in front of the element does not exclude the presence of multiple such
Element.The present invention can be by means of including the hardware of several different elements and being come by means of properly programmed computer real
It is existing.In the unit claims listing several devices, several in these devices can be through the same hardware branch
To embody.The use of word first, second, and third does not indicate any sequence.These words can be explained and be run after fame
Claim.
So far, although those skilled in the art will appreciate that present invention has been shown and described in detail herein multiple shows
Example property embodiment still without departing from the spirit and scope of the present invention, still can according to the present disclosure directly
Determine or deduce out many other variations or modifications consistent with the principles of the invention.Therefore, the scope of the present invention is understood that and recognizes
It is set to and covers all such other variations or modifications.
The embodiment of the invention also discloses a kind of methods for loading plug-in unit of A1., comprising:
When plug-in unit is triggered, the resource of the plug-in unit is obtained;
The context context of the plug-in unit is created, and is in advance the distribution of the main application of the plug-in unit by operating system
Context replace with the context of the plug-in unit, wherein the context of the plug-in unit is directed toward the resource of the plug-in unit;
The main application loads the resource of the plug-in unit according to the context after being replaced, wherein it is described be replaced after
Context is the context of the plug-in unit.
A2. method according to a1, wherein before the resource for obtaining the plug-in unit, further includes:
Obtain the installation kit archive information of the plug-in unit.
A3. the method according to A2, wherein the installation kit archive information for obtaining the plug-in unit, comprising:
Obtain the PackageManager object of the plug-in unit;
According to the installation kit archive information of plug-in unit described in the PackageManager object acquisition;
Design variables under the installation kit archive information are revised as preset path;
Wherein, the preset path is the store path of the plug-in unit.
A4. according to the described in any item methods of A1 to A3, wherein before the context for creating the plug-in unit, the side
Method further include:
Create the DexClassLoader class of the plug-in unit;
Wherein, the DexClassLoader class is used to transmit the executable code path of the plug-in unit.
A5. method according to a4, wherein the context context for creating the plug-in unit, and by operating system
The context for the distribution of the main application of the plug-in unit replaces with the context of the plug-in unit in advance, comprising:
The context for being inherited from ContextThemeWrapper class is established for the plug-in unit;
It rewrites for loading the resource of the plug-in unit and the method function of executable code, in the function after the rewriting
Return to the context of the plug-in unit.
A6. method according to a5, wherein the method for loading the resource and executable code of the plug-in unit
Function, comprising:
GetClassLoader, getResources and getAssets.
A7. method according to a1, wherein before the plug-in unit is triggered or when the plug-in unit is triggered, the side
Method further include:
Judge whether the plug-in unit can be used;
When the plug-in unit is unavailable, the request for obtaining plug-in unit list is sent to server;Wherein, in the plug-in unit list
Under plugin name, plug-in version, the digital digest value of plug-in unit and the plug-in unit of preserving plug-in unit included by the main application
Set address.
Receive the plug-in unit list sent;
The plug-in unit of new version is downloaded according to the download address of plug-in unit described in the plug-in unit list.
A8. the method according to A7, wherein the download address of the plug-in unit according to the plug-in unit list is downloaded
After the plug-in unit of new version, the method also includes:
The digest value saved in the digital digest value and plug-in unit list of the plug-in unit of new version that verifying downloading obtains whether phase
Together, when identical, the step of executing the resource for obtaining the plug-in unit.
A9. method according to a1, wherein the method also includes;
The ClassLoader object of replacement operation system is the main customized ClassLoader object of application;
Wherein, the customized ClassLoader object for realizing the plug-in unit load.
The embodiment of the invention also discloses a kind of devices for loading plug-in unit of B10., comprising:
Source obtaining module, suitable for obtaining the resource of the plug-in unit when plug-in unit is triggered;
First establishes module, suitable for creating the context context of the plug-in unit, and is in advance described insert by operating system
The context of the distribution of the main application of part replaces with the context of the plug-in unit, wherein the context of the plug-in unit is directed toward institute
State the resource of plug-in unit;
Loading module loads the resource of the plug-in unit suitable for the main application according to the context after being replaced, wherein
It is described be replaced after context be the plug-in unit context.
B11. device according to b10, wherein described device further include:
Data obtaining module, the installation kit suitable for before the resource for obtaining the plug-in unit, obtaining the plug-in unit achieve letter
Breath.
B12. the device according to B11, wherein the data obtaining module, comprising:
Object acquisition unit, suitable for obtaining the PackageManager object of the plug-in unit;
Information acquisition unit, the installation kit suitable for the plug-in unit according to the PackageManager object acquisition achieve letter
Breath;
Variable modifies unit, suitable for the design variables under the installation kit archive information are revised as preset path;
Wherein, the preset path is the store path of the plug-in unit.
B13. according to the described in any item devices of B10 to B12, wherein described device further include:
Second establishes module, suitable for creating the plug-in unit before the context for creating the plug-in unit
DexClassLoader class;
Wherein, the DexClassLoader class is used to transmit the executable code path of the plug-in unit.
B14. device according to b13, wherein described first, which establishes module, includes:
Context establishes unit, is suitable for the plug-in unit foundation and is inherited from ContextThemeWrapper class
context;
Rewriting unit, suitable for rewriteeing for loading the resource of the plug-in unit and the method function of executable code, described
The context of the plug-in unit is returned in function after rewriting.
B15. device according to b14, wherein described for loading the side of the resource and executable code of the plug-in unit
Method function, comprising:
GetClassLoader, getResources and getAssets.
B16. device according to b10, wherein described device further include: plug-in download module;
The plug-in download module includes:
Judging unit can be used, suitable for before the plug-in unit is triggered or when the plug-in unit is triggered, judging that the plug-in unit is
It is no available;
Request transmitting unit is suitable for when the plug-in unit is unavailable, and the request for obtaining plug-in unit list is sent to server;Its
In, the plugin name of plug-in unit included by the main application, plug-in version, the number of plug-in unit are preserved in the plug-in unit list plucks
It is worth and the download address of plug-in unit.
List reception unit, suitable for receiving the plug-in unit list sent;
Plug-in download unit, the download address suitable for the plug-in unit according to the plug-in unit list download inserting for new version
Part.
B17. the device according to B16, wherein described device further include:
Authentication module, suitable for the plug-in unit according to the plug-in unit list download address downloading new version plug-in unit it
Afterwards, whether the digest value saved in the digital digest value and plug-in unit list of the plug-in unit for the new version that verifying downloading obtains is identical, when
When identical, the step of executing the resource for obtaining the plug-in unit.
B18. device according to b10, wherein described device further includes;
Entrance realizes module, and the ClassLoader object suitable for replacement operation system is that the main application is customized
ClassLoader object;
Wherein, the customized ClassLoader object for realizing the plug-in unit load.
The embodiment of the invention also discloses a kind of mobile terminals of C19., which is characterized in that the mobile terminal includes:
Memory;
One or more processors;
Wherein, one or more of processors are configured as executing following method:
When plug-in unit is triggered, the resource of the plug-in unit is obtained;
The context context of the plug-in unit is created, and is in advance the distribution of the main application of the plug-in unit by operating system
Context replace with the context of the plug-in unit, wherein the context of the plug-in unit is directed toward the resource of the plug-in unit;
The main application loads the resource of the plug-in unit according to the context after being replaced, wherein it is described be replaced after
Context is the context of the plug-in unit.