CN104699536A - Active assembly progress space distributing method and corresponding device thereof - Google Patents

Active assembly progress space distributing method and corresponding device thereof Download PDF

Info

Publication number
CN104699536A
CN104699536A CN201510119610.8A CN201510119610A CN104699536A CN 104699536 A CN104699536 A CN 104699536A CN 201510119610 A CN201510119610 A CN 201510119610A CN 104699536 A CN104699536 A CN 104699536A
Authority
CN
China
Prior art keywords
hole
movable component
state
loaded
target
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201510119610.8A
Other languages
Chinese (zh)
Other versions
CN104699536B (en
Inventor
宋照春
张炅轩
姚彤
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Qihoo Technology Co Ltd
Original Assignee
Beijing Qihoo Technology Co Ltd
Qizhi Software Beijing Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Qihoo Technology Co Ltd, Qizhi Software Beijing Co Ltd filed Critical Beijing Qihoo Technology Co Ltd
Priority to CN201510119610.8A priority Critical patent/CN104699536B/en
Publication of CN104699536A publication Critical patent/CN104699536A/en
Application granted granted Critical
Publication of CN104699536B publication Critical patent/CN104699536B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Abstract

The invention provides an active assembly progress space distributing method which includes the following steps: receiving a request for distributing active assembly pits for active components to be loaded; utilizing a preset preferable strategy to preferably select matched target active assembly pits for the active assemblies to be loaded from a pit list, wherein the pit list is used for storing characteristic information of the pre-registered active assembly pits; marking the use state of the target pit in the pit list to show that target pit is distributed and providing the target pit in response to the request. In addition, the device matched with the method is provided based on modularization programming thought. Reserved pits matched with the active assemblies to be loaded can be distributed efficiently, flexible expanding and loading of the active assemblies of the application program is facilitated, upgrading of the application program can be simplified, and resource load of the cloud service system is simplified.

Description

Movable component process space distribution method and corresponding device thereof
Technical field
The present invention relates to the programming Control technology of computer applied algorithm, particularly relate to a kind of movable component process space distribution method based on Android principle and corresponding device thereof.
Background technology
Android operation system has it to be different from the principle of other operating systems, Android provides four large assemblies for developer, the assemblies such as concrete finger Activity, Service, Receiver and Content Provider, wherein Activity is the movable component alleged by the present invention, by applying in a flexible way to each assembly, application program can be customized out by developer.Android application program is supplied to user with the form of APK installation kit and installs, in APK installation kit, there is the Androidmanifest.xml configuration file of classes.dex code file for encapsulating the program code realizing each assembly and the content such as log-on message and authority application information for Expression and Application program each assembly used.Activity assembly is generally used for realizing user interface so that application program can carry out man-machine interaction with user, and its code can be encapsulated in classes.dex file, and needs to realize registration in this configuration file.In configuration file, the log-on message of each activity can be considered as independent registrations information module, is considered as " position, hole ".Android system is when application programs is installed; by PackageManageService (PMS), each assembly of APK installation kit is verified; ActivityManagerSevice (AMS) can be then that movable component sets up process entrance (ActivityThread) according to log-on message, to guarantee the normal operation of movable component.
Usually, Activity movable component should carry out the registration of position, hole in advance in Androidmanafest.xml configuration file, and one_to_one corresponding and determinacy should be kept between other attributes of cheating position and component Name and movable component, the normal registration of these movable components can be guaranteed like this.In this case, whole application program should just determine these movable components when developing, and is then integrally supplied to terminal installs by the application program of these movable component organic assembling.It is all that basis based on a complete application program is carried out that terminal is installed each time, and each movable component has wherein carried out registering expression one to one in configuration file, there is not any uncertainty.In other words, any Activity movable component without registering at Androidmanifest.xml, the process that all can not be scheduled as under regular situation is run.It can thus be appreciated that be application extensions for Microsoft Internet Explorer & Microsoft Office and provide new movable component each time, all need application program to re-start packing, and be supplied to client with the installation file after packing and install, each installation is all full doses.For the situation of remote download, both waste flow, again reduce efficiency, be more unfavorable for the flexible expansion of the functional module of application program.
In order to overcome application version alternate cause flow waste problem, prior art is often to provide the form of delta package to reduce installation flow, this mode then needs to set up heavy cloud service framework, and it is also proposed higher requirement to the calculated amount of terminal.More crucial, this mode can not meet this demand of function of application module flexible expansion.
Prior art also attempts providing web page access interface further in the interface provided at Activity, even in conjunction with new techniques such as HTML5, function to realizing application program expands, but, the interactive function that webpage provides is limited after all, fully may not necessarily develop the maximum performance of terminal, Consumer's Experience also will decline to some extent.
In order to overcome these problems above-mentioned, except needing to propose except new technological frame, also need to provide the necessary technical preparation for implementing these technological frames.
Summary of the invention
Primary and foremost purpose of the present invention is intended to solve at least one problem above-mentioned, provides a kind of movable component process space distribution method and its corresponding device.
To achieve these goals, the present invention takes following technical scheme:
A kind of movable component process space distribution method provided by the invention, comprises the steps:
Be received as the request of position, movable component allocation activities assembly to be loaded hole;
Utilize the preference policy preset, rank position, goal activities assembly hole preferably suitable for movable component to be loaded table from hole, rank table in described hole, for storing the characteristic information of the position, movable component hole of multiple pre-registration;
Rank in table the using state marking position, this target hole to characterize it be assigned with in hole, provide in response to this request this target to cheat position.
Preferably, the position, movable component hole of described pre-registration, what utilize its configuration file to state by the host's functional module implementing this method registers for the log-on message of expressing reserved movable component.This configuration file is Androidmanifest.xml file.
Preferably, described hole is ranked when table is started by the host's functional module implementing this method and is run for adding described movable component to cheat the code command of the characteristic information of position and realize building.
Specifically, the direct or indirect foundation of table is ranked in described hole characteristic information: the mapping relations between position, movable component hole name, position, hole using state, suitable movable component to be loaded.
Preferably, described position, hole using state is arranged in the following manner:
The host's functional module implementing this method carries out initialization in its Application.attachBaseContext method, and the using state of position, each movable component hole is set to non-working condition;
After position, this movable component hole is assigned with, its using state is set to the state be assigned with;
When position, movable component hole to be returned as position, target hole and after being loaded, its using state is set to the state be loaded;
After the onCreate method of movable component to be loaded is called, the using state of position, corresponding target hole is set to the state created;
When plug-in unit is released, its using state is set to and reclaims state.
Concrete, the position, movable component hole that described default preference policy is the preferred adaptation of foundation with described position, hole using state.
Further, table is ranked in described hole, include summary table and type list, described summary table includes the characteristic information of position, all movable components hole, described type list only stores the characteristic information belonging to the position, movable component hole with identical type feature, when applying the preference policy preset, first type list is retrieved, just retrieve further in summary table when type list does not find adaptive movable component.
Concrete, provide described position, target hole by returning position, the hole name of position, described target hole in response to described request.
Especially, when implementing described default preference policy, launchMode, taskAffinity and/or theme attribute according to movable component carries out differentiating to determine specifically corresponding type list.
A kind of movable component process space distributor provided by the invention, comprising:
Receiver module, for being received as the request of position, movable component allocation activities assembly to be loaded hole;
Preferred module, for utilizing default preference policy, rank position, goal activities assembly hole preferably suitable for movable component to be loaded table from hole, rank table in described hole, for storing the characteristic information of the position, movable component hole of multiple pre-registration;
Respond module, characterizes it be assigned with for ranking in table the using state marking position, this target hole in hole, provide this target to cheat position in response to this request.
Preferably, the position, movable component hole of described pre-registration, what utilize its configuration file to state by the host's functional module containing this device registers for the log-on message of expressing reserved movable component.This configuration file is Androidmanifest.xml file.
Preferably, described hole is ranked when table is started by the host's functional module containing this device and is run for adding described movable component to cheat the code command of the characteristic information of position and realize building.
Further, the direct or indirect foundation of table is ranked in described hole characteristic information: the mapping relations between position, movable component hole name, position, hole using state, suitable movable component to be loaded.
Concrete, described position, hole using state is arranged in the following manner:
The host's functional module containing this device carries out initialization in its Application.attachBaseContext method, and the using state of position, each movable component hole is set to non-working condition;
After position, this movable component hole is assigned with, its using state is set to the state be assigned with;
When position, movable component hole to be returned as position, target hole and after being loaded, its using state is set to the state be loaded;
After the onCreate method of movable component to be loaded is called, the using state of position, corresponding target hole is set to the state created;
When plug-in unit is released, its using state is set to and reclaims state.
Further, described preferred module, with the position, movable component hole that described position, hole using state is the preferred adaptation of foundation when being configured to implement described default preference policy.
Especially, table is ranked in described hole, include summary table and type list, described summary table includes the characteristic information of position, all movable components hole, described type list only stores the characteristic information belonging to the position, movable component hole with identical type feature, described preferred module is configured to, when applying the preference policy preset, first retrieve type list, just retrieves further in summary table when type list does not find adaptive movable component.
Further, described respond module, is configured to position, the hole name by returning to position, described target hole in response to described request and provides described position, target hole.
Further, described preferred module, when being configured to implement described default preference policy, launchMode, taskAffinity and/or theme attribute according to movable component carries out differentiating to determine specifically corresponding type list.
Compared with prior art, the solution of the present invention has the following advantages:
1, by technological means provided by the invention, table can be ranked by the hole of prebuild, for movable component to be loaded distributes suitable reserved position, movable component hole, like this, just the dynamic dispatching of movable component is made to become possibility, the completely self-defined of movable component (Activity) can be realized, thus, loading activity assembly is without the need to revising master routine, the host's functional module as master routine can be made to need upgrading never, only need the technological means of the present invention implemented with host's functional module, the corresponding movable component of on-demand loading can be realized, in theory can the function of infinite expanding master routine.
2, owing to implementing master routine of the present invention without the need to upgrading, and the movable component expanded is convenient to the packaged pin function module that is processed into, and therefore, when upgrading, only need download corresponding pin function module at every turn.This just has really accomplished to minimize installation, greatly saves flow, does not need again the resource consuming terminal in a large number, not only economizes flow but also can Effec-tive Function.
3, by enforcement of the present invention, pin function module can realize in standardization, and the high in the clouds that just can simplify application dissemination system thus realizes, and is conducive to the resource sharing between different application.Implement framework of the present invention as long as construct between different application, namely by downloading some common pin function modules to realize same function, obviously significantly reducing the work of developer, also simplify the complexity of the program resource of server.
In sum, application of the present invention, can distribute position, reserved hole suitable with it efficiently for movable component to be loaded, and the flexible expansion being convenient to the movable component of application program loads, the upgrading of application program can be simplified, also can simplify the resource load of cloud service system.
The aspect that the present invention adds and advantage will part provide in the following description, and these will become obvious from the following description, or be recognized by practice of the present invention.
Accompanying drawing explanation
The present invention above-mentioned and/or additional aspect and advantage will become obvious and easy understand from the following description of the accompanying drawings of embodiments, wherein:
Fig. 1 is the schematic flow sheet of movable component dispatching method of the present invention;
Fig. 2 is the schematic flow sheet of movable component process space distribution method of the present invention;
Fig. 3 is the theory diagram of movable component dispatching device of the present invention;
Fig. 4 is the theory diagram of movable component process space distributor of the present invention.
Embodiment
Be described below in detail embodiments of the invention, the example of described embodiment is shown in the drawings, and wherein same or similar label represents same or similar element or has element that is identical or similar functions from start to finish.Being exemplary below by the embodiment be described with reference to the drawings, only for explaining the present invention, and can not limitation of the present invention being interpreted as.
Those skilled in the art of the present technique are appreciated that unless expressly stated, and singulative used herein " ", " one ", " described " and " being somebody's turn to do " also can comprise plural form.Should be further understood that, the wording used in instructions of the present invention " comprises " and refers to there is described feature, integer, step, operation, element and/or assembly, but does not get rid of and exist or add other features one or more, integer, step, operation, element, assembly and/or their group.Should be appreciated that, when we claim element to be " connected " or " coupling " to another element time, it can be directly connected or coupled to other elements, or also can there is intermediary element.In addition, " connection " used herein or " coupling " can comprise wireless connections or wirelessly to couple.Wording "and/or" used herein comprises one or more whole or arbitrary unit listing item be associated and all combinations.
Those skilled in the art of the present technique are appreciated that unless otherwise defined, and all terms used herein (comprising technical term and scientific terminology), have the meaning identical with the general understanding of the those of ordinary skill in field belonging to the present invention.It should also be understood that, those terms defined in such as general dictionary, should be understood to that there is the meaning consistent with the meaning in the context of prior art, unless and by specific definitions as here, otherwise can not explain by idealized or too formal implication.
Those skilled in the art of the present technique are appreciated that, here used " terminal ", " terminal device " had both comprised the equipment of wireless signal receiver, it only possesses the equipment of the wireless signal receiver without emissive ability, comprise again the equipment receiving and launch hardware, it has and on bidirectional communication link, can perform the reception of two-way communication and launch the equipment of hardware.This equipment can comprise: honeycomb or other communication facilitiess, its honeycomb or other communication facilities of having single line display or multi-line display or not having multi-line display; PCS (Personal Communications Service, PCS Personal Communications System), it can combine voice, data processing, fax and/or its communication ability; PDA (PersonalDigital Assistant, personal digital assistant), it can comprise radio frequency receiver, pager, the Internet/intranet access, web browser, notepad, calendar and/or GPS (Global PositioningSystem, GPS) receiver; Conventional laptop and/or palmtop computer or other equipment, it has and/or comprises the conventional laptop of radio frequency receiver and/or palmtop computer or other equipment.Here used " terminal ", " terminal device " can be portable, can transport, be arranged in the vehicles (aviation, sea-freight and/or land), or be suitable for and/or be configured at local runtime, and/or with distribution form, any other position operating in the earth and/or space is run.Here used " terminal ", " terminal device " can also be communication terminal, access terminals, music/video playback terminal, can be such as PDA, MID (Mobile Internet Device, mobile internet device) and/or there is the mobile phone of music/video playing function, also can be the equipment such as intelligent television, Set Top Box.
Those skilled in the art of the present technique are appreciated that used remote network devices here, and it includes but not limited to the cloud that computing machine, network host, single network server, multiple webserver collection or multiple server are formed.At this, cloud is formed by based on a large amount of computing machine of cloud computing (Cloud Computing) or the webserver, and wherein, cloud computing is the one of Distributed Calculation, the super virtual machine be made up of a group loosely-coupled computing machine collection.In embodiments of the invention, realize communicating by any communication mode between remote network devices, terminal device with WNS server, include but not limited to, the mobile communication based on 3GPP, LTE, WIMAX, the computer network communication based on TCP/IP, udp protocol and the low coverage wireless transmission method based on bluetooth, Infrared Transmission standard.
The improvement that the present invention makes, mainly proposes based on the Dalvik virtual machine of Android, certainly, if framework is similar to the mechanism of Dalvik in other operating system, also the present invention can be promoted it in theory.In order to understand the present invention, please first understand the installation file structure of the following android system disclosed:
In android system, each application program installation kit is APK file, i.e. the abbreviation of AndroidApplication Package File, its essence is the file of zip form, carries out decompression can obtain following file structure to it:
Table 1 APK file structure
Usually, during exploitation Android application program, the four large assemblies that provide with Android for unit is developed, this four large assembly is Activity, Service, Receiver, Provider respectively, the code that four large assemblies are relevant can be integrated in classes.dex file, but this four large log-on message needed for assembly and rights request message then can be declared in Androidmanifest.xml file.Include an AndroidManifest.xml file in each apk file, it records the global configuration information of installation kit, is typical configuration file.In this configuration file, except information such as bag name package name, start context versionCode, version number versionName, also comprise the system components such as activity, service, receiver, Provider of application program registration, the log-on message of each large assembly is stated in this configuration file, when mounted, be supplied to application program to system registry, specifically read this configuration file to complete registration by the PackageManagerService of system.Well-known, under normal circumstances, the movable component (Activity) only stated in Androidmanifest.xml by routine call, just can be able to be opened, thus show events interface, so that realize man-machine interaction in terminal.And movable component dispatching party rule provided by the invention can overcome this inadequate natural endowment.
Movable component dispatching method of the present invention as disclosed in the system of fig. 1, can be implemented in the host's functional module used as master routine, it specifically comprises the steps:
S11, be supplied to position, system pre-registration multiple movable component hole.
As previously mentioned, under regular situation, movable component needs to state in as the Androidmanifest.xml file in host's functional module of master routine, so that when system is installed, registers relevant movable component with the log-on message in this statement.And the present invention arranges multiple movable component log-on message for reserved object in the Androidmanifest.xml configuration file of host's functional module, but the true content of the movable component pointed by these log-on messages is not determined, therefore, in the present invention, visually these configuration files have been reserved the movable component of log-on message, and this configuration file be supplied to after system is installed formed the virtual unit of movable component be referred to as movable component hole position.Specifically, the log-on message of multiple movable component is stated in advance, when master routine is installed, to be registered according to these log-on messages by PMS in the Androidmanifest.xml file of master routine, by AMS for it sets up process entrance, thus the position, movable component hole described in being formed.
Consider in the present invention, by the different attribute according to movable component, the attributes such as such as launchMode, taskAffinity, theme carry out Classification Management to movable component, therefore, the bag name used in described log-on message, different characteristic characters can be used in the suffix of bag name for characterizing dissimilar position, hole, is also refer to the different process spaces, is beneficial to identify.The such as following example quoted:
Wherein the shape of the Bao Mingzhong of movable component is as the just characteristic character of the X in ActivityX, which process space characteristic character X deputy activity assembly should run in, " N1 " given by upper example is comparatively special, it is the characteristic character for retaining, representing host process (UI process), can be then refer to the dissimilar movable component provided according to aforementioned various movable component attribute after " N1 ".The suffix ActivityN1ST0 of the bag name given by upper example can characterize position, this hole and run in system default (UI) process, and use the SingleTask of follow-up announcement to show, Activity0ST0 then represents and runs in loader0 process, and uses SingleTask table.About the relation between these different characteristic characters and the dissimilar table that corresponds, will disclose follow-up.
Need preferential it is mentioned that, scheduler object of the present invention, also namely movable component to be loaded normally provides with the form of pin function module, such as, be supplied to user with the form of a compressed package and carry out downloading and loaded by technological means of the present invention.This pin function module is except the function code comprising movable component, its intrinsic log-on message can also be expressed by built-in configuration filename a such as Androidmanifest.xml, the log-on message of the configuration file of plug-in unit alleged here then can be write flexibly even without restrictions, such as, can write according to following form:
That is, the log-on message of pin function module self can not determine which process it runs in, but by method of the present invention decide above-mentioned AntitheftEntryActivity finally can drop in ActivityN1ST0, ActivityN1ST1 (one process) Activity0ST0, Activity1ST0 which hole position in.
Table is ranked in the hole that S12, structure comprise the characteristic information of position, described multiple movable component hole.
Build the process that table is ranked in hole, will the utilization to Application class be related to, therefore introduce Application class in advance.
Application with Activity, Service are the same is a system component of Android framework, and when Android program starts, system can create an Application object, is used for some information of storage system.Android system automatically can for creating the object of an Application class and only creating one, so Application can be described as a class of single example (singleton) pattern when each program is run.Appointment Application is not needed during usual use, system can create such automatically for it, if need to create own Application, only need create a Similar integral Application and carry out registering (only need to increase name attribute to application label, and add the name of the Application of oneself) in application label in AndroidManifest.xml file.
When starting Application, system can create PID, i.e. a process ID, and all Activity can run in this process.If so initialization global variable when Application creates, all Activity of same application can get the value of these global variables, in other words, if change the value of these global variables in some Activity, so will change in other Activity intermediate values of same application.The life cycle of Application object is the longest in whole program, and its life cycle just equals the life cycle of this program.Because it is single example of the overall situation, so the object obtained in different Activity, Service is all same object.So can be undertaken by Application, as: the operations such as data transmission, data sharing and data buffer storage.Realize the global variable of application-level by inheriting Application class, this global variable method relative quiescent class is more secure, just can be released until all Activity of application are all fallen by destory.
In like manner, the launchMode attribute that the Activity please understanding Android further provides.
Whether launchMode plays important role in the process of multiple Activity redirect, and it can determine whether generate new Activity example, whether reuse already present Activity example, a task stack public with other Activity examples.Here simply introduce the concept of task, task is an object with stack architexture, and a task can manage multiple Activity, starts an application, the task that also just establishment one is corresponding with it.
The total following four kinds of launchMode of Activity mono-, several modes and being described below:
1.standard
Standard pattern is the start-up mode of acquiescence, and need not configure android:launchMode attribute for <activity>, can certainly designated value be standard.No matter standard start-up mode, have and do not have already present example, all generates new example.
2.singleTop
SingleTop start-up mode, if find that there is corresponding Activity example to be sitting at stack top, then reuses, the example that regeneration is not new.
3.singleTask
SingleTask pattern, if find that there is corresponding Activity example, then makes other Activity examples on this Activity example completely pop, makes this Activity example become stack top object, before being shown to curtain
4.singleInstance
This start-up mode is more special, because it can enable a new stack architexture, is positioned over by Acitvity in this new stack architexture, and ensures that no longer including other Activity examples enters.
The android:launchMode attribute that can configure <activity> at AndroidManifest.xml is one of above four kinds.
In view of the above characteristic of Application and launchMode, the present invention, by reconstruct Application.onCreate method, writing the code command for adding position, each movable component hole characteristic information wherein, realizing the structure that table is ranked in described hole.
The following table provided, namely hole rank table, it is in fact achieve the index to concrete list that table is ranked in this hole, shape as:
In code above, String field is character string, and represent that Activity cheats position, the hole name of position, ActivityState is then status information.Table is ranked as can be seen from this hole, although it can be the characteristic information establishing mapping relations directly comprising position, each movable component hole that table is ranked in this hole, but in the embodiment that this table provides, be then set up management to position, movable component hole characteristic information by comprising a summary table and multiple type list.Each table given by above-mentioned code, from top to bottom, is followed successively by:
MStates: summary table, as the term suggests all Activity will be stored in this table, using as the use gathered.
MStatesST: represent that launchMode is the table of SingleTask, its log-on message can be expressed in the following manner:
MStatesTA: represent that taskAffinity is the table of designated value, the ownership of taskAffinity attribute representation Activity, namely Activity should in which Task, the absorption relation of Activity and Task.Generally in same application, the Activity of startup is in same Task, and they spend oneself life cycle in this Task.If an Activity does not have the explicit taskAffinity indicating this Activity, so its this attribute just equals the taskAffinity that Application indicates, if Application does not also indicate, so the value of this taskAffinity just equals bag name.And Task also has the affinity attribute of oneself, its value equals the value of the taskAffinity of its root Activity.At the beginning, the Activity of establishment can in the Task creating it, and major part has spent its whole life all here.But having certain situation, the Activity of establishment can be assigned with in other Task and go, and has even, originally in a Task, has occurred transfer afterwards.Therefore, be necessary to be according to internus table with taskAffinity.The log-on message of this table can be expressed in the following manner:
MStatesNR: expression launchMode is the table of Standard (default value), and its log-on message can be expressed in the following manner:
MStatesF: represent that theme attribute is the table of FullScreen (full screen), its log-on message can be expressed in the following manner:
MStatesT: represent that theme attribute is the table of Translucent (transparent background), its log-on message can be expressed in the following manner:
MStatesTF: represent that theme attribute is the table of Translucent.FullScreen (full frame and transparent), its log-on message can be expressed in the following manner:
MStatesD: represent that theme is the table of Dialog, its log-on message can be expressed in the following manner:
MStatesSID: represent that launchMode is SingleInstance and Theme is the table of Dialog, its log-on message can be expressed in the following manner:
More than made introductions all round the summary table and type list of cheating and ranking in table, be mainly used in illustrating that an embodiment of table is ranked in hole to reader, those skilled in the art are to be understood that, the realization of table is ranked in hole, as long as establish the management of the characteristic information to position, described movable component hole, no matter its specific implementation form how, and also no matter it directly or indirectly contains described characteristic information, all can apply in a flexible way according to Spirit Essence of the present invention for those skilled in the art.
As previously mentioned, on the basis knowing above-mentioned implementation, by the code of reconstruct Application.onCreate method, the foundation of described hole being ranked to table can be realized.Below provide example code shape as:
By the enforcement of shape example code described above, finally, position, each movable component hole is created in mStates summary table and other type list respectively, and wherein Containers represents " mContainerActivity " object of Activity.
By above-mentioned mode, just set up the index relative that each sublist included by table is ranked in hole, form a data framework thus.Then, for position, each hole, need to understand it and be recorded hole and rank table, be specifically stored into the structure of the characteristic information in each corresponding form.The characteristic information of position, each hole, mainly by timestamp when there is position, the hole name of mapping relations, using state, movable component title to be loaded (i.e. the title of pin function module), amendment using state, form data item such as the weak references of movable component, if desired, the increase and decrease of modified also can be carried out to these critical items.These characteristic information items, are summarized as follows:
(1) container: position, the hole name of position, movable component hole correspondence;
(2) state: position, movable component hole using state, has following several mark:
Private static final int STATE_NONE=0//expression non-working condition
Private static final int STATE_REGISTERED=1//represent distribution state
Private static final int STATE_LOADED=2//represent stress state
Private static final int STATE_CREATED=3//represent creation state
Private static final int STATE_RECYCLED=4//expression reclaims state
(3) mCN: corresponding target plug-in functional module and title thereof;
(4) timestamp: timestamp during amendment using state;
(5) ref: retain the weak reference to movable component.
Above characteristic information is can assignment as required in several cases.Such as mCN field can carry out assignment at allocated phase, and state situation is special, illustrates respectively below:
When 1, entering master routine, can in Application.attachBaseContext, the above-mentioned information of initialize process, is set to STATE_NONE by the state of position, each movable component hole;
2, when the movable component to be loaded in pin function module is assigned with position, hole, state state can be set to STATE_REGISTERED;
3, after movable component to be loaded is loaded by Classloader classLoader, position, movable component hole is returned and after being loaded, state state can be set to STATE_LOADED;
4, when the onCreate method of movable component to be loaded is called, the state state of position, corresponding target hole can be set to STATE_CREATED;
5, when movable component to be loaded is released (call Activity.onDestroy, or position, hole being full, during distribution), then state state can be set to STATE_RECYCLED.
Above, disclosed in detail and realize the example that table is ranked in described hole, those skilled in the art, according to the above-mentioned exemplary illustration for this step, are enough to specific implementation and the variants thereof of knowing this step.Through the process of this step, rank table by constructing the required for the present invention hole including position, multiple movable component hole characteristic information.It is also realize movable component process space distribution method of the present invention and the necessary preparation of device that table is ranked in this hole.
The table goal activities assembly hole position suitable for movable component to be loaded distributes is ranked in step S13, utilization hole.
In order to implement this step, the present invention and then disclose a kind of movable component process space distribution method, uses this method to rank table to described hole and is used, and be finally that movable component to be loaded in pin function module distributes and cheats position.The method realizes primarily of following step S21, S22, S23, is described in detail to each step below in conjunction with Fig. 2:
Step S21, be received as movable component allocation activities assembly to be loaded hole position request.
In like manner, because movable component process space distribution method of the present invention is as a part for movable component dispatching method of the present invention, be programmed in the host's functional module be implemented in as master routine, thus, it mainly utilizes process thinking to be programmed to functional module, external receiving parameter to receive request, and feeds back corresponding result to requesting party.Based on this principle, by this step, when master routine needs the movable component to be loaded of loading of plug-in functional module, by the functional module that the relevant information being transmitted movable component to be loaded by master routine or its component part constructs to this distribution method, to carry out follow-up process by this distribution method to it.
It is to be noted, this distribution method treats the position, movable component hole will carrying out distributing, position, movable component hole namely constructed by dispatching method of the present invention, therefore, namely position, these movable components hole is state log-on message and the process space formed to system registry in Androidmanifest.xml file as host's functional module of master routine.The more excellent part of this distribution method is, in some processes, can manage the movable component to be loaded of multiple pin function module.
The preference policy that step S22, utilization are preset, ranks position, goal activities assembly hole preferably suitable for movable component to be loaded table from hole.
Table is ranked in described hole, and table is ranked in the hole also namely constructed by abovementioned steps S12, for storing the characteristic information of the position, movable component hole of multiple pre-registration.Due in foregoing example, hole is ranked table and is included summary table and all kinds table, summary table wherein includes the characteristic information of position, all movable components hole, type list wherein only stores the characteristic information belonging to the position, movable component hole with identical type feature, therefore, when implementing the preference policy preset, first can retrieve type list, just retrieving further in summary table when type list does not find the movable component of sweet acid.And when implementing retrieval, table design concept is ranked in the hole according to aforementioned announcement, correspondingly, also should carry out differentiating to determine specifically corresponding type list according to launchMode, taskAffinity and/or theme attribute of movable component.
This step is preferred to position, described goal activities assembly hole, and mainly foundation using state is wherein according to carrying out.
Below disclose the flow process using described preference policy:
This dispatching method stores all ActivityInfo objects in advance in PackageInfo, so can directly use these information here.In this sub-step, differentiated and the type list belonging to the movable component to be loaded of request dispatching by attributes such as launchMode, taskAffinity, theme, start to retrieve type list.Code sample is as follows:
Then, from corresponding type list, determine suitable position, goal activities assembly hole, in code above, the signature of alloc method is:
Wherein, ai represents ActivityInfo, and map is exactly that table is ranked in the hole of specifying, plugin and activity represents pin function module title and movable component title to be loaded thereof respectively.
Adopt following strategy to carry out preferably, carrying out according to the order of sequence, as long as any rule is met below, directly can return results, need not subsequent step be carried out:
(1) preferred for SingleTask and SingleInstance type preferably searches one with the example crossed.Consult following code:
As previously mentioned, SingleTask and SingleInstance is more special, and these two kinds of modular systems require that Activity example can only have portion, therefore must look for an example opened.And other LaunchMode does not have this to limit, Multi-instance can be used.
Such as, opened before the BarcodeActivity of Quick Response Code plug-in unit, if so still will open, then here can make a decision: first its using state must be STATE_CREATED, and target plug-in must be Quick Response Code, and Activity must be corresponding title as BarcodeActivity, and also have Activity object, so could directly return this result.Otherwise arbitrary condition does not meet, all next step will be carried out.
(2) adopt position, unworn hole, consult following code:
If by detecting, this position, hole does not use, then directly use, return results, and does not carry out subsequent step.
(3) adopt and used but stopped, noting not distinguishing launchMode here, wherein SI and ST both of these case is in step process mistake before.Consult code:
In like manner, if found, return results, do not carry out subsequent step.
(4) position, hole be translated the earliest is found.Consult code as follows:
In like manner, if found, return results, do not carry out subsequent step.
(5) with (4) article of strategy unlike, even be assigned with state here, but not used position, hole (this situation is fewer, and normally Activity is once creating release or creating unsuccessfully etc.), will reclaim wherein the earliest that here.Consult following code:
In like manner, if found, return results, do not carry out subsequent step.
(6), when not finding suitable position, hole at exhaustive above-mentioned various strategy, that load the earliest can only be reclaimed.Consult following code:
If found, return results, do not carry out subsequent step.
(7) in like manner, when above various strategy is searched all failed, just with last strategy, the earliest the Activity run can only be reclaimed.Consult following code:
Through the effect of above-mentioned preference policy, obtain position, unique goal activities assembly hole the most at last, complete position, hole and distribute.
Step 23, to be obtained position, this target hole by previous step after, using state state in the characteristic information of this position, hole can be set to STATE_REGISTERED, obtain position, the hole name Activity.mContainer of this position, hole simultaneously, return to requesting party as a result.
The movable component process space distribution method provided by the invention described above, can be optimized a goal activities assembly suitable with movable component to be loaded and cheat position.After obtaining position, this target hole, just on the basis of the relevant information returned, subsequent treatment can be done by dispatching method of the present invention.
Step S14, this movable component to be loaded is loaded in the process space of target hole corresponding to position and runs.
Based on the result of implementation of abovementioned steps, movable component to be loaded to be loaded in the corresponding process space according to following concrete steps and to run by the present invention then:
Step 141, to rank table the position, goal activities assembly hole obtaining and be assigned with from described hole.
As previously mentioned, in step 13, finally can determine position, unique target hole by distribution method provided by the invention, and return the information of position, this target hole.These information spinners will comprise position, hole title, after determining position, hole title, namely load movable component to be loaded by Classloader.
Due in step 13, the using state state target having been cheated position is labeled as STATE_REGISTERED and returns position, hole name, therefore, in this sub-step, only need, with this mark, table (specific to certain type list) is ranked to hole and search.With reference to following code:
The Classloader of step 142, operation reconstruct is the movable component determination class object to be loaded being assigned with position, hole.
Classloader alleged by the present invention is realized by the ClassLoader of reconfiguration system.The object of reconstruct Classloader, is wish that changing system when master routine starts generates the method for new class, thus guarantees correctly to load movable component to be loaded, makes it run on target and cheats the process space that position refers to.
In a kind of prior art, generate DexClassLoader, call realize when plug-in unit starts usually through oneself, its shortcoming is apparent, calls very not directly perceived exactly, must obtain the designation method first calling DexClassLoader and realize.As follows:
Existing: XXX my=mDexClassLoader.findClass (XXX) .newInstance ();
This work: XXX my=new XXX ();
In another kind of prior art, realized by the contextClassLoader mode of replacing Thread.The maximum problem of this mode does not support the scenes such as Activity, Service, AIDL, and these regional system acquiescences can use the ClassLoader of PackageInfo, but not Thread, use scenes is subject to serious restriction.
The ClassLoader of reconstruct of the present invention will realize the replacement completely to the Classloader of system, particular by the ClassLoader replacing PackageInfo, guarantee to replace without dead angle, not only Thread can use, connect the assemblies such as Activity, Service and can use self-defining ClassLoader to realize loading, its application scenarios is more extensive, and invoked procedure is very directly perceived, caller, without the need to considering any fallback relationship, directly uses.
Realize the method for self defined class loader, can carry out with reference to following steps:
First, during each process initiation, all can call Application object, this object also can be self-defined by the mode inherited.System can call Application.attachBaseContext method at first, therefore, and the suitable ClassLoader importing reconstruct herein.
Then, PackageInfo is obtained.In this course, realize according to following sub-step:
(1) first need to obtain ContextWrapper object.Also namely: reflection obtains the mBase field in Application object.The object obtained keeps for subsequent use.
(2) mPackageInfo is obtained.
The mBase object obtained, different android system can represent different types, is then ContextImpl if Android 2.1 be ApplicationContext, Android 2.2, Android 2.3 and above be then AppContextImpl.But no matter which is, has common feature, namely have one to be named as " mPackageInfo " field, directly reflection obtains the mPackageInfo field in mBase object, can obtain PackageInfo object.
Above two useable code illustrate:
Then, self-defining ClassLoader object is generated.
As long as self-defining Similar integral ClassLoader or its subclass object, just mean and complete self-defining operation.On this basis, it will be understood by those skilled in the art that and can do a large amount of work relevant with pin function module.
Except self-defined, also must override all methods in ClassLoader, each method finally should point to before ClassLoader, the successful reconstruct of ClassLoader can be guaranteed thus and normal to use.As follows with the example code not adding any custom feature:
As mentioned above, mBase be exactly before ClassLoader.After processing customized event, if necessary, then the corresponding method calling mBase is needed.
Finally, the mClassLoader of PackageInfo is replaced
The mPackageInfo object retained before is taken out, the self-defined ClassLoader object that mClassLoader field is above-mentioned generation is set by reflection.
For code, following code sample can be inserted at " ... " clipped of the example code obtaining mPackageInfo:
Thus, the process of the ClassLoader of replacement system terminates, and completes the self-defined reconstruct of ClassLoader.ClassLoader due to system has been replaced by self-defining ClassLoader, according to its use scenes and character, generally speaking, obtain category information as long as have, generate new class, call the situations such as Native method, be just bound to be loaded by this self-defined ClassLoader.
Therefore, by the self-defined ClassLoader of above-mentioned realization, the DexClassLoader of succession, its findClass method is also reconstructed, and is embodied as described movable component to be loaded and searches object in findClass.Once have found the title of position, target hole object, next only need the ClassLoader of current pin function module to get, then perform invoke method, the Class object of this plug-in unit can be obtained.
Step S143, operating instruction are opened position, target hole and are run to make movable component to be loaded load in the process space.
Specifically, because the process space is set, and the class object of movable component to be loaded also finds, and connects down and only needs to splice both.First by the process space of position, ComponentName (inherent function of system Intent) object transfer target hole, utilize this object formation Intent, then with this Intent of context.startActivity method call, position, target hole can be opened, thus movable component to be loaded is loaded in the set process space run.
In other embodiments of the invention, carry out the process space run for described movable component to be loaded, can through a preferred step, to provide a set and preferred process space before position, aforementioned distribution target hole.
Visible, movable component dispatching method provided by the invention, can realize the flexible dispatching treating loading activity assembly, and movable component to be loaded can be added in the mode of pin function module flexibly independent of outside host's functional module of master routine.
Further, movable component dispatching method example of the present invention can be changed into program, be attached in the host's functional module used as master routine, and a kind of control method is provided, when master routine runs, implement this dispatching method, scheduling is implemented to the movable component that described pin function module comprises, this movable component is run in the process space created by host's functional module.The upgrading of this master routine will become more simple and easy and economize flow, and in theory only otherwise relate to the framework amendment of master routine, master routine just can never be upgraded.
And movable component process space distribution method provided by the invention, then achieving the efficient management based on loading movable component to be loaded in one process situation, making the flexible interpolation to this movable component to be loaded, upgrading becomes possibility.
Based on the modularized thoughts of computer program, can programme with Spirit Essence of the present invention, be formed by the some modules performing standalone feature, based on this thinking, continue below to disclose a kind of movable component dispatching device provided by the invention.
As shown in Figure 3, movable component dispatching device of the present invention comprises registering unit 11, construction unit 12, allocation units 13 and loading unit 14.
Described registering unit 11, for being supplied to position, system pre-registration multiple movable component hole.
As previously mentioned, under regular situation, movable component needs to state in as the Androidmanifest.xml file in host's functional module of master routine, so that when system is installed, registers relevant movable component with the log-on message in this statement.And the present invention arranges multiple movable component log-on message for reserved object in the Androidmanifest.xml configuration file of host's functional module, but the true content of the movable component pointed by these log-on messages is not determined, therefore, in the present invention, visually these configuration files have been reserved the movable component of log-on message, and this configuration file be supplied to after system is installed formed the virtual unit of movable component be referred to as movable component hole position.Specifically, the log-on message of multiple movable component is stated in advance, when master routine is installed, to be registered according to these log-on messages by PMS in the Androidmanifest.xml file of master routine, by AMS for it sets up process entrance, thus the position, movable component hole described in being formed.
Consider in the present invention, by the different attribute according to movable component, the attributes such as such as launchMode, taskAffinity, theme carry out Classification Management to movable component, therefore, the bag name used in described log-on message, different characteristic characters can be used in the suffix of bag name for characterizing dissimilar position, hole, is also refer to the different process spaces, is beneficial to identify.The such as following example quoted:
Wherein the shape of the Bao Mingzhong of movable component is as the just characteristic character of the X in ActivityX, which process space characteristic character X deputy activity assembly should run in, " N1 " given by upper example is comparatively special, it is the characteristic character for retaining, representing host process (UI process), can be then refer to the dissimilar movable component provided according to aforementioned various movable component attribute after " N1 ".The suffix ActivityN1ST0 of the bag name given by upper example can characterize position, this hole and run in system default (UI) process, and use the SingleTask of follow-up announcement to show, Activity0ST0 then represents and runs in loader0 process, and uses SingleTask table.About the relation between these different characteristic characters and the dissimilar table that corresponds, will disclose follow-up.
Need preferential it is mentioned that, scheduler object of the present invention, also namely movable component to be loaded normally provides with the form of pin function module, such as, be supplied to user with the form of a compressed package and carry out downloading and loaded by technological means of the present invention.This pin function module is except the function code comprising movable component, its intrinsic log-on message can also be expressed by built-in configuration filename a such as Androidmanifest.xml, the log-on message of the configuration file of plug-in unit alleged here then can be write flexibly even without restrictions, such as, can write according to following form:
That is, the log-on message of pin function module self can not determine which process it runs in, but by the present invention decide above-mentioned AntitheftEntryActivity finally can drop in ActivityN1ST0, ActivityN1ST1 (one process) Activity0ST0, Activity1ST0 which hole position in.
Described construction unit 12, ranks table for the hole building the characteristic information comprising position, described multiple movable component hole.
Construction unit 12 builds the process that table is ranked in hole, will relate to the utilization to Application class, therefore introduces Application class in advance.
Application with Activity, Service are the same is a system component of Android framework, and when Android program starts, system can create an Application object, is used for some information of storage system.Android system automatically can for creating the object of an Application class and only creating one, so Application can be described as a class of single example (singleton) pattern when each program is run.Appointment Application is not needed during usual use, system can create such automatically for it, if need to create own Application, only need create a Similar integral Application and carry out registering (only need to increase name attribute to application label, and add the name of the Application of oneself) in application label in AndroidManifest.xml file.
When starting Application, system can create PID, i.e. a process ID, and all Activity can run in this process.If so initialization global variable when Application creates, all Activity of same application can get the value of these global variables, in other words, if change the value of these global variables in some Activity, so will change in other Activity intermediate values of same application.The life cycle of Application object is the longest in whole program, and its life cycle just equals the life cycle of this program.Because it is single example of the overall situation, so the object obtained in different Activity, Service is all same object.So can be undertaken by Application, as: the operations such as data transmission, data sharing and data buffer storage.Realize the global variable of application-level by inheriting Application class, this global variable method relative quiescent class is more secure, just can be released until all Activity of application are all fallen by destory.
In like manner, the launchMode attribute that the Activity please understanding Android further provides.
Whether launchMode plays important role in the process of multiple Activity redirect, and it can determine whether generate new Activity example, whether reuse already present Activity example, a task stack public with other Activity examples.Here simply introduce the concept of task, task is an object with stack architexture, and a task can manage multiple Activity, starts an application, the task that also just establishment one is corresponding with it.
The total following four kinds of launchMode of Activity mono-, several modes and being described below:
1.standard
Standard pattern is the start-up mode of acquiescence, and need not configure android:launchMode attribute for <activity>, can certainly designated value be standard.No matter standard start-up mode, have and do not have already present example, all generates new example.
2.singleTop
SingleTop start-up mode, if find that there is corresponding Activity example to be sitting at stack top, then reuses, the example that regeneration is not new.
3.singleTask
SingleTask pattern, if find that there is corresponding Activity example, then makes other Activity examples on this Activity example completely pop, makes this Activity example become stack top object, before being shown to curtain
4.singleInstance
This start-up mode is more special, because it can enable a new stack architexture, is positioned over by Acitvity in this new stack architexture, and ensures that no longer including other Activity examples enters.
The android:launchMode attribute that can configure <activity> at AndroidManifest.xml is one of above four kinds.
In view of the above characteristic of Application and launchMode, the present invention, by reconstruct Application.onCreate method, writing the code command for adding position, each movable component hole characteristic information wherein, realizing the structure that table is ranked in described hole.
The following table provided, namely hole rank table, it is in fact achieve the index to concrete list that table is ranked in this hole, shape as:
In code above, String field is character string, and represent that Activity cheats position, the hole name of position, ActivityState is then status information.Table is ranked as can be seen from this hole, although it can be the characteristic information establishing mapping relations directly comprising position, each movable component hole that table is ranked in this hole, but in the embodiment that this table provides, be then set up management to position, movable component hole characteristic information by comprising a summary table and multiple type list.Each table given by above-mentioned code, from top to bottom, is followed successively by:
MStates: summary table, as the term suggests all Activity will be stored in this table, using as the use gathered.
MStatesST: represent that launchMode is the table of SingleTask, its log-on message can be expressed in the following manner:
MStatesTA: represent that taskAffinity is the table of designated value, the ownership of taskAffinity attribute representation Activity, namely Activity should in which Task, the absorption relation of Activity and Task.Generally in same application, the Activity of startup is in same Task, and they spend oneself life cycle in this Task.If an Activity does not have the explicit taskAffinity indicating this Activity, so its this attribute just equals the taskAffinity that Application indicates, if Application does not also indicate, so the value of this taskAffinity just equals bag name.And Task also has the Affinity attribute of oneself, its value equals the value of the taskAffinity of its root Activity.At the beginning, the Activity of establishment can in the Task creating it, and major part has spent its whole life all here.But having certain situation, the Activity of establishment can be assigned with in other Task and go, and has even, originally in a Task, has occurred transfer afterwards.Therefore, be necessary to be according to internus table with taskAffinity.The log-on message of this table can be expressed in the following manner:
MStatesNR: expression launchMode is the table of Standard (default value), and its log-on message can be expressed in the following manner:
MStatesSI: represent that launchMode is the table of SingleInstance, its log-on message can be expressed in the following manner:
MStatesF: represent that theme attribute is the table of FullScreen (full screen), its log-on message can be expressed in the following manner:
MStatesT: represent that theme attribute is the table of Translucent (transparent background), its log-on message can be expressed in the following manner:
MStatesTF: represent that theme attribute is the table of Translucent.FullScreen (full frame and transparent), its log-on message can be expressed in the following manner:
MStatesD: represent that theme is the table of Dialog, its log-on message can be expressed in the following manner:
MStatesSID: represent that launchMode is SingleInstance and Theme is the table of Dialog, its log-on message can be expressed in the following manner:
More than made introductions all round the summary table and type list of cheating and ranking in table, be mainly used in illustrating that an embodiment of table is ranked in hole to reader, those skilled in the art are to be understood that, the realization of table is ranked in hole, as long as establish the management of the characteristic information to position, described movable component hole, no matter its specific implementation form how, and also no matter it directly or indirectly contains described characteristic information, all can apply in a flexible way according to Spirit Essence of the present invention for those skilled in the art.
As previously mentioned, on the basis knowing above-mentioned implementation, by the code of reconstruct Application.onCreate method, the foundation of described hole being ranked to table can be realized.Below provide example code shape as:
By the enforcement of shape example code described above, finally, position, each movable component hole is created in mStates summary table and other type list respectively, and wherein Containers represents " mContainerActivity " object of Activity.
By above-mentioned mode, just set up the index relative that each sublist included by table is ranked in hole, form a data framework thus.Then, for position, each hole, need to understand it and be recorded hole and rank table, be specifically stored into the structure of the characteristic information in each corresponding form.The characteristic information of position, each hole, mainly by timestamp when there is position, the hole name of mapping relations, using state, movable component title to be loaded (i.e. the title of pin function module), amendment using state, form data item such as the weak references of movable component, if desired, the increase and decrease of modified also can be carried out to these critical items.These characteristic information items, are summarized as follows:
(1) container: position, the hole name of position, movable component hole correspondence;
(2) state: position, movable component hole using state, has following several mark:
Private static final int STATE_NONE=0//expression non-working condition
Private static final int STATE_REGISTERED=1//represent distribution state
Private static final int STATE_LOADED=2//represent stress state
Private static final int STATE_CREATED=3//represent creation state
Private static final int STATE_RECYCLED=4//expression reclaims state
(3) mCN: corresponding target plug-in functional module and title thereof;
(4) timestamp: timestamp during amendment using state;
(5) ref: retain the weak reference to movable component.
Above characteristic information is can assignment as required in several cases.Such as mCN field can carry out assignment at allocated phase, and state situation is special, illustrates respectively below:
When 1, entering master routine, can in Application.attachBaseContext, the above-mentioned information of initialize process, is set to STATE_NONE by the state of position, each movable component hole;
2, when the movable component to be loaded in pin function module is assigned with position, hole, state state can be set to STATE_REGISTERED;
3, after movable component to be loaded is loaded by Classloader classLoader, position, movable component hole is returned and after being loaded, state state can be set to STATE_LOADED;
4, when the onCreate method of movable component to be loaded is called, the state state of position, corresponding target hole can be set to STATE_CREATED;
5, when movable component to be loaded is released (call Activity.onDestroy, or position, hole being full, during distribution), then state state can be set to STATE_RECYCLED.
Above, disclosed in detail and realize the example that table is ranked in described hole, those skilled in the art, according to the above-mentioned exemplary illustration for this construction unit 12, are enough to specific implementation and the variants thereof of knowing this construction unit 12.Through the process of this construction unit 12, rank table by constructing the required for the present invention hole including position, multiple movable component hole characteristic information.It is also realize movable component process space distribution method of the present invention and the necessary preparation of device that table is ranked in this hole.
Described allocation units 13, rank the table goal activities assembly hole position suitable for movable component to be loaded distributes for utilizing hole.
In order to construct these allocation units 13, the present invention so disclose these allocation units 13 be equipped with a kind of movable component process space distributor, using this device to rank table to described hole to be used, is finally that the movable component to be loaded in pin function module distributes position, hole.This device mainly comprises receiver module 21, preferred module 22 and respond module 23, is described in detail to the function that modules realizes below in conjunction with Fig. 4:
Described receiver module 21, for being received as the request of position, movable component allocation activities assembly to be loaded hole.
In like manner, because movable component process space distributor of the present invention is equipped to described allocation units 13, thus, it mainly utilizes process thinking to be programmed to functional module, and external receiving parameter to receive request, and feeds back corresponding result to requesting party.Based on this principle, by this distributor, when master routine needs the movable component to be loaded of loading of plug-in functional module, by the functional module that the relevant information being transmitted movable component to be loaded by master routine or its component part constructs to this distributor, to carry out follow-up process by this distributor to it.
It is to be noted, the position, movable component hole will carrying out distributing treated by this distributor, position, movable component hole namely constructed by dispatching device of the present invention, therefore, namely position, these movable components hole is state log-on message and the process space formed to system registry in Androidmanifest.xml file as host's functional module of master routine.The more excellent part of this distributor is, in some processes, can manage the movable component to be loaded of multiple pin function module.
Described preferred module 22, for utilizing default preference policy, ranks position, goal activities assembly hole preferably suitable for movable component to be loaded table from hole.
Table is ranked in described hole, and table is ranked in the hole also namely constructed by aforementioned construction unit 12, for storing the characteristic information of the position, movable component hole of multiple pre-registration.Due in foregoing example, hole is ranked table and is included summary table and all kinds table, summary table wherein includes the characteristic information of position, all movable components hole, type list wherein only stores the characteristic information belonging to the position, movable component hole with identical type feature, therefore, when implementing the preference policy preset, first can retrieve type list, just retrieving further in summary table when type list does not find adaptive movable component.And when implementing retrieval, table design concept is ranked in the hole according to aforementioned announcement, correspondingly, also should carry out differentiating to determine specifically corresponding type list according to launchMode, taskAffinity and/or theme attribute of movable component.
This preferred module 22 is preferred to position, described goal activities assembly hole, and mainly foundation using state is wherein according to carrying out.
Below disclose the flow process using described preference policy:
This dispatching device stores all ActivityInfo objects in advance in PackageInfo, so can directly use these information here.In this preferred module 22, differentiated and the type list belonging to the movable component to be loaded of request dispatching by attributes such as launchMode, taskAffinity, theme, start to retrieve type list.Code sample is as follows:
Then, from corresponding type list, determine suitable position, goal activities assembly hole, in code above, the signature of alloc method is:
Wherein, ai represents ActivityInfo, and map is exactly that table is ranked in the hole of specifying, plugin and activity represents pin function module title and movable component title to be loaded thereof respectively.
Adopt following strategy to carry out preferably, carrying out according to the order of sequence, as long as any rule is met below, directly can return results, need not subsequent step be carried out:
(1) preferred for SingleTask and SingleInstance type preferably searches one with the example crossed.Consult following code:
As previously mentioned, SingleTask and SingleInstance is more special, and these two kinds of modular systems require that Activity example can only have portion, therefore must look for an example opened.And other LaunchMode does not have this to limit, Multi-instance can be used.
Such as, opened before the BarcodeActivity of Quick Response Code plug-in unit, if so still will open, then here can make a decision: first its using state must be STATE_CREATED, and target plug-in must be Quick Response Code, and Activity must be corresponding title as BarcodeActivity, and also have Activity object, so could directly return this result.Otherwise arbitrary condition does not meet, all next step will be carried out.
(2) adopt position, unworn hole, consult following code:
If by detecting, this position, hole does not use, then directly use, return results, and does not carry out subsequent step.
(3) adopt and used but stopped, noting not distinguishing launchMode here, wherein SI and ST both of these case is in step process mistake before.Consult code:
In like manner, if found, return results, do not carry out subsequent step.
(4) position, hole be translated the earliest is found.Consult code as follows:
In like manner, if found, return results, do not carry out subsequent step.
(5) with (4) article of strategy unlike, even be assigned with state here, but not used position, hole (this situation is fewer, and normally Activity is once creating release or creating unsuccessfully etc.), will reclaim wherein the earliest that here.Consult following code:
In like manner, if found, return results, do not carry out subsequent step.
(6), when not finding suitable position, hole at exhaustive above-mentioned various strategy, that load the earliest can only be reclaimed.Consult following code:
If found, return results, do not carry out subsequent step.
(7) in like manner, when above various strategy is searched all failed, just with last strategy, the earliest the Activity run can only be reclaimed.Consult following code:
Through the effect of above-mentioned preference policy, obtain position, unique goal activities assembly hole the most at last, complete position, hole and distribute.
Described respond module 23, characterizes it be assigned with for ranking in table the using state marking position, this target hole in hole, provide this target to cheat position in response to this request.
After obtaining position, this target hole by last unit, the using state state in the characteristic information of this position, hole can be set to STATE_REGISTERED, obtain position, the hole name Activity.mContainer of this position, hole simultaneously, return to requesting party as a result.
The execution of the movable component process space distributor provided by the invention described above, can be optimized a goal activities assembly suitable with movable component to be loaded and cheat position.After obtaining position, this target hole, just on the basis of the relevant information returned, subsequent treatment can be done by dispatching device of the present invention.
Described loading unit 14, runs for being loaded into by this movable component to be loaded in the process space corresponding to position, target hole.
Based on the result of implementation of aforementioned each unit, the present invention then by loading unit 14 have following specifically construct movable component to be loaded to be loaded in the corresponding process space run:
Acquisition module, for ranking in table the position, goal activities assembly hole obtaining and be assigned with from described hole.
As previously mentioned, in described allocation units 13, finally can determine position, unique target hole by distributor provided by the invention, and return the information of position, this target hole.These information spinners will comprise position, hole title, after determining position, hole title, namely load movable component to be loaded by Classloader.
Due in described allocation units 13, the using state state target having been cheated position is labeled as STATE_REGISTERED and returns position, hole name, therefore, in this acquisition module, only need, with this mark, table (specific to certain type list) is ranked to hole and search.With reference to following code:
Creation module is the movable component determination class object to be loaded being assigned with position, hole for running the Classloader of reconstruct.
Classloader alleged by the present invention is realized by the ClassLoader of reconfiguration system.The object of reconstruct Classloader, is wish that changing system when master routine starts generates the method for new class, thus guarantees correctly to load movable component to be loaded, makes it run on target and cheats the process space that position refers to.
In a kind of prior art, generate DexClassLoader, call realize when plug-in unit starts usually through oneself, its shortcoming is apparent, calls very not directly perceived exactly, must obtain the designation method first calling DexClassLoader and realize.As follows:
Existing: XXX my=mDexClassLoader.findClass (XXX) .newInstance ();
This work: XXX my=new XXX ();
In another kind of prior art, realized by the contextClassLoader mode of replacing Thread.The maximum problem of this mode does not support the scenes such as Activity, Service, AIDL, and these regional system acquiescences can use the ClassLoader of PackageInfo, but not Thread, use scenes is subject to serious restriction.
The ClassLoader of reconstruct of the present invention will realize the replacement completely to the Classloader of system, particular by the ClassLoader replacing PackageInfo, guarantee to replace without dead angle, not only Thread can use, connect the assemblies such as Activity, Service and can use self-defining ClassLoader to realize loading, its application scenarios is more extensive, and invoked procedure is very directly perceived, caller, without the need to considering any fallback relationship, directly uses.
Realize the method for self defined class loader, can carry out with reference to following steps:
First, during each process initiation, all can call Application object, this object also can be self-defined by the mode inherited.System can call Application.attachBaseContext method at first, therefore, and the suitable ClassLoader importing reconstruct herein.
Then, PackageInfo is obtained.In this course, realize according to following sub-step:
(1) first need to obtain ContextWrapper object.Also namely: reflection obtains the mBase field in Application object.The object obtained keeps for subsequent use.
(2) mPackageInfo is obtained.
The mBase object obtained, different android system can represent different types, is then ContextImpl if Android 2.1 be ApplicationContext, Android 2.2, Android 2.3 and above be then AppContextImpl.But no matter which is, has common feature, namely have one to be named as " mPackageInfo " field, directly reflection obtains the mPackageInfo field in mBase object, can obtain PackageInfo object.
Above two useable code illustrate:
Then, self-defining ClassLoader object is generated.
As long as self-defining Similar integral ClassLoader or its subclass object, just mean and complete self-defining operation.On this basis, it will be understood by those skilled in the art that and can do a large amount of work relevant with pin function module.
Except self-defined, also must override all methods in ClassLoader, each method finally should point to before ClassLoader, the successful reconstruct of ClassLoader can be guaranteed thus and normal to use.As follows with the example code not adding any custom feature:
As mentioned above, mBase be exactly before ClassLoader.After processing customized event, if necessary, then the corresponding method calling mBase is needed.
Finally, the mClassLoader of PackageInfo is replaced
The mPackageInfo object retained before is taken out, the self-defined ClassLoader object that mClassLoader field is above-mentioned generation is set by reflection.
For code, following code sample can be inserted at " ... " clipped of the example code obtaining mPackageInfo:
Thus, the process of the ClassLoader of replacement system terminates, and completes the self-defined reconstruct of ClassLoader.ClassLoader due to system has been replaced by self-defining ClassLoader, according to its use scenes and character, generally speaking, obtain category information as long as have, generate new class, call the situations such as Native method, be just bound to be loaded by this self-defined ClassLoader.
Therefore, by the self-defined ClassLoader of above-mentioned realization, the DexClassLoader of succession, its findClass method is also reconstructed, and is embodied as described movable component to be loaded and searches object in findClass.Once have found the title of position, target hole object, next only need the ClassLoader of current pin function module to get, then perform invoke method, the Class object of this plug-in unit can be obtained.
Run module, open position, target hole for operating instruction and run to make movable component to be loaded load in the process space.
Specifically, because the process space is set, and the class object of movable component to be loaded also finds, and connects down and only needs to splice both.First by the process space of position, ComponentName (inherent function of system Intent) object transfer target hole, utilize this object formation Intent, then with this Intent of context.startActivity method call, position, target hole can be opened, thus movable component to be loaded is loaded in the set process space run.
In other embodiments of the invention, carry out the process space run for described movable component to be loaded, can through a preferred step, to provide a set and preferred process space before position, aforementioned distribution target hole.
Visible, movable component dispatching device provided by the invention, can realize the flexible dispatching treating loading activity assembly, and movable component to be loaded can be added in the mode of pin function module flexibly independent of outside host's functional module of master routine.
Further, movable component dispatching device example of the present invention can be changed into program, be attached in the host's functional module used as master routine, when master routine runs, run this dispatching device, scheduling is implemented to the movable component that described pin function module comprises, this movable component is run in the process space created by host's functional module.The upgrading of this master routine will become more simple and easy and economize flow, and in theory only otherwise relate to the framework amendment of master routine, master routine just can never be upgraded.
And movable component process space distributor provided by the invention, then achieving the efficient management based on loading movable component to be loaded in one process situation, making the flexible interpolation to this movable component to be loaded, upgrading becomes possibility.
The above is only some embodiments of the present invention; it should be pointed out that for those skilled in the art, under the premise without departing from the principles of the invention; can also make some improvements and modifications, these improvements and modifications also should be considered as protection scope of the present invention.

Claims (10)

1. a movable component process space distribution method, is characterized in that, comprises the steps:
Be received as the request of position, movable component allocation activities assembly to be loaded hole;
Utilize the preference policy preset, rank position, goal activities assembly hole preferably suitable for movable component to be loaded table from hole, rank table in described hole, for storing the characteristic information of the position, movable component hole of multiple pre-registration;
Rank in table the using state marking position, this target hole to characterize it be assigned with in hole, provide in response to this request this target to cheat position.
2. movable component process space distribution method according to claim 1, it is characterized in that, the position, movable component hole of described pre-registration, what utilize its configuration file to state by the host's functional module implementing this method registers for the log-on message of expressing reserved movable component.
3. movable component process space distribution method according to claim 1, it is characterized in that, described hole is ranked when table is started by the host's functional module implementing this method and is run for adding described movable component to cheat the code command of the characteristic information of position and realize building.
4. movable component process space distribution method according to claim 1, it is characterized in that, the direct or indirect foundation of table is ranked in described hole characteristic information: the mapping relations between position, movable component hole name, position, hole using state, suitable movable component to be loaded.
5. movable component process space distribution method according to claim 4, is characterized in that, described position, hole using state is arranged in the following manner:
The host's functional module implementing this method carries out initialization in its Application.attachBaseContext method, and the using state of position, each movable component hole is set to non-working condition;
After position, this movable component hole is assigned with, its using state is set to the state be assigned with;
When position, movable component hole to be returned as position, target hole and after being loaded, its using state is set to the state be loaded;
After the onCreate method of movable component to be loaded is called, the using state of position, corresponding target hole is set to the state created;
When plug-in unit is released, its using state is set to and reclaims state.
6. movable component process space distribution method according to claim 4, is characterized in that, the position, movable component hole that described default preference policy is the preferred adaptation of foundation with described position, hole using state.
7. movable component process space distribution method according to claim 1, it is characterized in that, table is ranked in described hole, include summary table and type list, described summary table includes the characteristic information of position, all movable components hole, and described type list only stores the characteristic information belonging to the position, movable component hole with identical type feature, when applying the preference policy preset, first type list is retrieved, just retrieve further in summary table when type list does not find adaptive movable component.
8. movable component process space distribution method according to claim 1, is characterized in that, provides described position, target hole by returning position, the hole name of position, described target hole in response to described request.
9. movable component process space distribution method according to claim 1, it is characterized in that, when implementing described default preference policy, launchMode, taskAffinity and/or theme attribute according to movable component carries out differentiating to determine specifically corresponding type list.
10. a movable component process space distributor, is characterized in that, comprising:
Receiver module, for being received as the request of position, movable component allocation activities assembly to be loaded hole;
Preferred module, for utilizing default preference policy, rank position, goal activities assembly hole preferably suitable for movable component to be loaded table from hole, rank table in described hole, for storing the characteristic information of the position, movable component hole of multiple pre-registration;
Respond module, characterizes it be assigned with for ranking in table the using state marking position, this target hole in hole, provide this target to cheat position in response to this request.
CN201510119610.8A 2015-03-18 2015-03-18 Moving component process space distribution method and its corresponding device Active CN104699536B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510119610.8A CN104699536B (en) 2015-03-18 2015-03-18 Moving component process space distribution method and its corresponding device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510119610.8A CN104699536B (en) 2015-03-18 2015-03-18 Moving component process space distribution method and its corresponding device

Publications (2)

Publication Number Publication Date
CN104699536A true CN104699536A (en) 2015-06-10
CN104699536B CN104699536B (en) 2017-03-15

Family

ID=53346699

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510119610.8A Active CN104699536B (en) 2015-03-18 2015-03-18 Moving component process space distribution method and its corresponding device

Country Status (1)

Country Link
CN (1) CN104699536B (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107944266A (en) * 2017-12-15 2018-04-20 北京奇虎科技有限公司 Assembly management method, device and mobile terminal
CN108038370A (en) * 2017-12-28 2018-05-15 北京奇虎科技有限公司 Sandbox movable component process space distribution method, distributor and distribution terminal
CN108089895A (en) * 2017-12-19 2018-05-29 珠海市君天电子科技有限公司 The register method of Activity, device, electronic equipment and storage medium in a kind of plug-in unit
CN109144692A (en) * 2018-07-16 2019-01-04 北京奇虎科技有限公司 A kind of method, apparatus and terminal for the process of distributing
CN110347453A (en) * 2018-04-04 2019-10-18 北京神州泰岳软件股份有限公司 A kind of page display method and device
CN111352710A (en) * 2018-12-24 2020-06-30 北京奇虎科技有限公司 Process management method and device, computing equipment and storage medium

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103744669A (en) * 2013-12-26 2014-04-23 世纪龙信息网络有限责任公司 Method and system for creation and calling of Android system Activity plug-ins
CN104375861A (en) * 2014-11-04 2015-02-25 北京奇虎科技有限公司 Installation-free operation method and device for application programs based on Android platform and terminal

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103744669A (en) * 2013-12-26 2014-04-23 世纪龙信息网络有限责任公司 Method and system for creation and calling of Android system Activity plug-ins
CN104375861A (en) * 2014-11-04 2015-02-25 北京奇虎科技有限公司 Installation-free operation method and device for application programs based on Android platform and terminal

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107944266A (en) * 2017-12-15 2018-04-20 北京奇虎科技有限公司 Assembly management method, device and mobile terminal
CN108089895A (en) * 2017-12-19 2018-05-29 珠海市君天电子科技有限公司 The register method of Activity, device, electronic equipment and storage medium in a kind of plug-in unit
CN108038370A (en) * 2017-12-28 2018-05-15 北京奇虎科技有限公司 Sandbox movable component process space distribution method, distributor and distribution terminal
CN110347453A (en) * 2018-04-04 2019-10-18 北京神州泰岳软件股份有限公司 A kind of page display method and device
CN110347453B (en) * 2018-04-04 2022-12-09 北京神州泰岳软件股份有限公司 Page display method and device
CN109144692A (en) * 2018-07-16 2019-01-04 北京奇虎科技有限公司 A kind of method, apparatus and terminal for the process of distributing
CN111352710A (en) * 2018-12-24 2020-06-30 北京奇虎科技有限公司 Process management method and device, computing equipment and storage medium
CN111352710B (en) * 2018-12-24 2024-02-06 三六零科技集团有限公司 Process management method and device, computing equipment and storage medium

Also Published As

Publication number Publication date
CN104699536B (en) 2017-03-15

Similar Documents

Publication Publication Date Title
CN104699537A (en) Program control method, activity module scheduling method and corresponding devices thereof
CN104699536A (en) Active assembly progress space distributing method and corresponding device thereof
CN105094922A (en) Application installation-free operation control method and device
CN101833465B (en) Embedded system supporting dynamic loading operation of application programs
CN102855152B (en) The method and system of resource file in upgrade applications
US8176114B2 (en) Distributed cross-application server deployment
CN104714828A (en) Methods and devices for installing and operating application
US20100313197A1 (en) System and method for operating domain profile using database in core framework for sdr mobile terminals
CN102682014A (en) Open-type plug-in module management platform implemented on browser and open-type plug-in module management method
CN100549957C (en) One kind is loaded the method and a kind of isolating and is loaded the device of isolating
CN103473696A (en) Method and system for collecting, analyzing and distributing internet business information
CN106569880B (en) Method and system for dynamically sharing resources between Android applications
CN104750528A (en) Management method and device for components in Android program
CN104219078A (en) Method and device for processing multiple runtime environment data
CN101789012A (en) J2EE (Java 2 Platform Enterprise Edition) based solution for staticizing WEB dynamic page
CN105516154A (en) Security policy configuration method and device applied to SEAndroid (Security-Enhanced Android) system
CN101490645A (en) Method and apparatus for virtualization of appliances
US8738746B2 (en) Configuration management for real-time server
CN103647811A (en) A method and an apparatus for application&#39;s accessing backstage service
US20070174697A1 (en) Generic, WSRF-compliant checkpointing for WS-Resources
CN112363728B (en) Cross-platform compiling method and system supporting continuous integrated construction
CN113296891A (en) Multi-scene knowledge graph processing method and device based on platform
CN112130953A (en) Application deployment method for Windows Hyper-V virtualization
US8335215B2 (en) Process data for a data packet
CN105635264A (en) File system based on network game application

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
TR01 Transfer of patent right
TR01 Transfer of patent right

Effective date of registration: 20220727

Address after: Room 801, 8th floor, No. 104, floors 1-19, building 2, yard 6, Jiuxianqiao Road, Chaoyang District, Beijing 100015

Patentee after: BEIJING QIHOO TECHNOLOGY Co.,Ltd.

Address before: 100088 room 112, block D, 28 new street, new street, Xicheng District, Beijing (Desheng Park)

Patentee before: BEIJING QIHOO TECHNOLOGY Co.,Ltd.

Patentee before: Qizhi software (Beijing) Co.,Ltd.