CN105573891A - Android application electricity consumption statistics method and device - Google Patents

Android application electricity consumption statistics method and device Download PDF

Info

Publication number
CN105573891A
CN105573891A CN201510938736.8A CN201510938736A CN105573891A CN 105573891 A CN105573891 A CN 105573891A CN 201510938736 A CN201510938736 A CN 201510938736A CN 105573891 A CN105573891 A CN 105573891A
Authority
CN
China
Prior art keywords
power consumption
application
authority verification
function
privately owned
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
CN201510938736.8A
Other languages
Chinese (zh)
Other versions
CN105573891B (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 CN201510938736.8A priority Critical patent/CN105573891B/en
Publication of CN105573891A publication Critical patent/CN105573891A/en
Application granted granted Critical
Publication of CN105573891B publication Critical patent/CN105573891B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3058Monitoring arrangements for monitoring environmental properties or parameters of the computing system or of the computing system component, e.g. monitoring of power, currents, temperature, humidity, position, vibrations
    • G06F11/3062Monitoring arrangements for monitoring environmental properties or parameters of the computing system or of the computing system component, e.g. monitoring of power, currents, temperature, humidity, position, vibrations where the monitored property is the power consumption
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Computing Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Telephone Function (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The embodiment of the invention provides an Android application electricity consumption statistics method, and relates to the technical field of a computer. The method comprises the following steps of accessing system electricity consumption service by a first process by aiming at an application, and triggering the calling for a permission validation function; intercepting the calling for the permission validation function through a hook function; and calling a preset electricity consumption private class, and obtaining the electricity consumption quantity of the application. The method solves the problems that in the prior art, the electricity consumption information of each application in Android 4.4 systems or higher systems cannot be accessed; the precision of the common use electricity consumption statistics scheme is not high; and the operation is complicated, and the like. The method has the beneficial effects that the electricity consumption information of each application in the Android systems including the Android 4.4 systems or higher systems in any version can be obtained; the operation is fast and convenient; and the accuracy of the obtained electricity consumption is improved.

Description

A kind of Android application power consumption statistical method and device
Technical field
The present invention relates to field of computer technology, particularly relate to a kind of Android application power consumption statistical method and a kind of Android application power consumption statistic device.
Background technology
Along with the development of smart mobile phone, there is the system of multiple support smart mobile phone.Such as Android (Android) system.Android is a kind of open source code operating system based on Linux, is mainly used in the mobile terminals such as mobile phone.Android platform is made up of operating system, middleware, user interface and application software.
Along with the increase of the market share of android system, increasing developer develops APP (Application, application) based on android system, makes user use Android phone more convenient.
For developer, need the power consumption adding up each APP, to improve the performance of corresponding APP further.Now for the system of below Android4.4, the power consumption mechanism code of Android itself can be extracted, the power consumption of each APP of more accurate statistics, but for Android4.4 and above system, itself all has Authority Verification, control of authority has been done comprising to electricity statistical information, nonsystematic is accessed, can remind and occur extremely, so electricity statistical correlation information cannot be accessed, the power consumption statistical project that current each APP power consumption statistical software commonly uses is based on each APP time taking CPU from starting up to current time and the internal memory taken, build empirical value algorithm, but the power consumption degree of accuracy that the program is added up is not high, and the process of operation is also more loaded down with trivial details.
Summary of the invention
In view of the above problems, the present invention is proposed to provide a kind of overcoming the problems referred to above or the Android application power consumption statistical method solved the problem at least in part and corresponding Android application power consumption statistic device.
According to one aspect of the present invention, provide a kind of Android application power consumption statistical method, comprising:
By the first process for an application, access system power consumption is served, and triggers calling Authority Verification function;
By Hook Function interception calling Authority Verification function;
Call default power consumption and add up privately owned class, obtain the power consumption of described application.
Preferably, described by the step called of Hook Function interception to Authority Verification function, comprising:
At system call Authority Verification function, get Authority Verification result and after returning, the Authority Verification result returned described in being tackled by Hook Function.
Preferably, by the first process for an application, access system power consumption is served, and triggers before the calling of Authority Verification function, also comprises:
Described Hook Function is injected described first process, and to the privately owned class of system registry.
Preferably, the described step described Hook Function being injected described first process, comprising:
When system starts, initial hatching process system carried replaces with the first predetermined hatching process;
By described first hatching process, described Hook Function is injected described first process, and to the privately owned class of system registry.
Preferably, the described step by described first hatching process, described Hook Function being injected described first process, being comprised:
Whether start to start by the first process described in described first hatching process monitoring;
If described first process starts to start, then described hook is injected described first process, complete the startup of the first process.
Preferably, described in call default power consumption and add up privately owned class, obtain the step of the power consumption of described application, comprising:
Served by AIDL, call default power consumption and add up privately owned class, read the power consumption applied described in the power consumption configuration file of each application.
Preferably, add up privately owned class calling default power consumption, after obtaining the step of the power consumption of described application, also comprise:
The power consumption of the described application of continuous acquisition also carries out record according to the time;
The power consumption variable condition applied according to described record analysis.
According to a further aspect in the invention, provide a kind of Android application power consumption statistic device, comprising:
Trigger module, is suitable for by the first process for an application, and access system power consumption is served, and triggers calling Authority Verification function;
Blocking module, is suitable for by Hook Function interception calling Authority Verification function;
Power consumption acquisition module, is suitable for calling default power consumption and adds up privately owned class, obtain the power consumption of described application.
Preferably, described blocking module, comprising:
Authority Verification result interception submodule, is suitable at system call Authority Verification function, gets Authority Verification result and after returning, the Authority Verification result returned described in being tackled by Hook Function.
Preferably, before trigger module, also comprise:
Injection module, is suitable for described Hook Function to inject described first process, and to the privately owned class of system registry.
Preferably, described injection module, comprising:
Hatching process replaces submodule, and be suitable for when system starts, initial hatching process system carried replaces with the first predetermined hatching process;
Inject submodule, be suitable for, by described first hatching process, described Hook Function is injected described first process, and to the privately owned class of system registry.
Preferably, described injection submodule, comprising:
Start monitoring submodule, be suitable for whether starting to start by the first process described in described first hatching process monitoring;
Hook Function injects submodule, starts to start, then described hook is injected described first process, complete the startup of the first process if be suitable for described first process.
Preferably, described power consumption acquisition module, comprising:
Power consumption reading submodule, is suitable for being served by AIDL, calls default power consumption and adds up privately owned class, reads the power consumption applied described in the power consumption configuration file of each application.
Preferably, after power consumption acquisition module, also comprise:
Power consumption logging modle, is suitable for constantly obtaining the power consumption of described application and carrying out record according to the time;
Power consumption analysis module, is suitable for the power consumption variable condition applied according to described record analysis.
According to a further aspect in the invention, provide a kind of Android application power consumption statistics equipment, comprising:
Storer, is loaded with many executable instructions;
Processor, performs described many executable instructions; Described many executable instructions comprise the method performing following steps:
By the first process for an application, access system power consumption is served, and triggers calling Authority Verification function;
By Hook Function interception calling Authority Verification function;
Call default power consumption and add up privately owned class, obtain the power consumption of described application.
Can by the first process for an application according to a kind of Android application power consumption statistical method of the present invention, access system power consumption is served, trigger calling Authority Verification function, by Hook Function interception calling Authority Verification function, call default power consumption and add up privately owned class, obtain the power consumption of described application, solve the power consumption information that first technology cannot access each application in Android4.4 and above system thus, and the not high and problems such as complex operation of the degree of accuracy of conventional power consumption statistical project, achieve the power consumption information of each application in the android system that can obtain and comprise Android4.4 and above any version, swift to operate and improve the beneficial effect of the accuracy of the power consumption of acquisition.
Above-mentioned explanation is only the general introduction of technical solution of the present invention, in order to technological means of the present invention can be better understood, and can be implemented according to the content of instructions, and can become apparent, below especially exemplified by the specific embodiment of the present invention to allow above and other objects of the present invention, feature and advantage.
Accompanying drawing explanation
By reading hereafter detailed description of the preferred embodiment, various other advantage and benefit will become cheer and bright for those of ordinary skill in the art.Accompanying drawing only for illustrating the object of preferred implementation, and does not think limitation of the present invention.And in whole accompanying drawing, represent identical parts by identical reference symbol.In the accompanying drawings:
Fig. 1 shows a kind of according to an embodiment of the invention flow chart of steps of Android application power consumption statistical method embodiment;
Fig. 2 shows a kind of according to an embodiment of the invention flow chart of steps of Android application power consumption statistical method embodiment;
Fig. 3 shows a kind of according to an embodiment of the invention structured flowchart of Android application power consumption statistic device embodiment;
Fig. 4 shows a kind of according to an embodiment of the invention structured flowchart of Android application power consumption statistic device embodiment; And
Fig. 5 shows the structured flowchart of a kind of according to an embodiment of the invention Android application power consumption statistics apparatus embodiments.
Embodiment
Below with reference to accompanying drawings exemplary embodiment of the present disclosure is described in more detail.Although show exemplary embodiment of the present disclosure in accompanying drawing, however should be appreciated that can realize the disclosure in a variety of manners and not should limit by the embodiment set forth here.On the contrary, provide these embodiments to be in order to more thoroughly the disclosure can be understood, and complete for the scope of the present disclosure can be conveyed to those skilled in the art.
Embodiment one
With reference to Fig. 1, show a kind of according to an embodiment of the invention flow chart of steps of Android application power consumption statistical method embodiment, specifically can comprise the steps:
Step 110, by the first process for an application, access system power consumption is served, and triggers calling Authority Verification function.
Application (APP, Application) wherein comprises the application that can run in android system, as 360 security guards, 360 secure browsers etc.
Existing android system self all has power consumption service, can distinguish in statistical system the power consumption respectively applied each nextport hardware component NextPort in real time.Android power consumption service can read the power consumption of each nextport hardware component NextPort, is then recorded in the configuration file of power_profile.xml, and this configuration file defines in Android system can only be accessed by system process, but not system process can not be accessed.
For the system of Android4.4 and above version, there is the process of Authority Verification, for nonsystematic access, namely for the access coming from its exterior, can remind and occur abnormal, and not allow access.The control of authority to access system power consumption service is comprised at Authority Verification.Therefore when for an application, during access system power consumption service, calling Authority Verification function can be triggered, after performing this Authority Verification function, if discovery access power consumption service is nonsystematic process, then can eject exception.Authority Verification function is as checkCallingPermission (), and throw exception time this function returns false, when so returning true, scope check passes through.
In actual applications, Authority Verification function can verify whether current access is system access, if then by checking; If not then by checking, exception can not be returned.
In embodiments of the present invention, if will add up the power consumption of an application, the embodiment of the present invention then starts the first process, then access system power consumption can be served by the first process, now can trigger calling Authority Verification function.
Step 120, by Hook Function interception calling Authority Verification function.
In actual applications, for the system of Android4.4 and above version, in order to obtain the power consumption information of each application, can the power consumption service of access system, but this access is non-system access, by the checking of checking function, so in embodiments of the present invention, cannot can tackle calling Authority Verification function by Hook Function.
The essence of hook (Hook) function is wherein one section of program in order to disposal system message, can pass through system call, and it is injected android system.
In embodiments of the present invention, Hook Function can be infused in the interface that android system calls Authority Verification function, if system is by interface interchange Authority Verification function, then utilize Hook Function interception the calling Authority Verification function at this interface.
Certainly, Hook Function can also be infused in other positions of android system, and to this, the embodiment of the present invention is not limited.
In actual applications, tackling calling Authority Verification function, is that Hook Function is redirected in the address of Authority Verification function, and the parameter then imported into according to caller performs oneself logic, such as performs step 130.
Step 130, calls default power consumption and adds up privately owned class, obtain the power consumption of described application.
In actual applications, android system can record the power consumption of each application to each nextport hardware component NextPort, and be stored in aforementioned power_profile.xml configuration file, in fact the power_profile.xml of each manufacturer is different, therefore the present invention can directly read this configuration file by privately owned class, then calculate the power consumption of the application needing statistics, thus make power consumption add up more accurate.
In android system, power consumption can be preset for each APP and add up privately owned class, wherein privately owned class is added up in power consumption is the logical code replicating android system power consumption service, and arrange a privately owned class calling interface for this privately owned class, then this privately owned class then can be supplied to the first process transfer of the embodiment of the present invention.In embodiments of the present invention, a privately owned class calling interface can be injected in android system, add up privately owned class in order to call default power consumption from assigned address, the power consumption that privately owned class can obtain each application from the configuration file of the power consumption of each nextport hardware component NextPort of above-mentioned storage is added up in this power consumption.And the process obtaining the power consumption of each application from the configuration file of the power consumption of each nextport hardware component NextPort of above-mentioned storage is gone in the power consumption service getting around calling system.
In actual applications, in privately owned class, realize processAppUsage () function, this function, based on aforementioned arrangements file, calculates the power consumption to each several part of APP:
The power consumption of each Process (process) under part 1, calculating Uid; Wherein, the power consumption of each process is that unit interval power consumption when enlivening based on working time of the CPU of this Process and CPU calculates; Wherein for application to be counted, a Process after this application start, may be only had also may to have several Process.Each application can a corresponding Uid.
The wakelock power consumption of part 2, calculating Uid; Wherein this is applied in backstage when waking up, when namely screen is not bright, and the calculating that wakeup time and the power consumption of CPU when backstage is waken up based on this application carry out.
Data traffic (datatraffic) power consumption of part 3, calculating Uid; The power consumption produced when namely calculating this application usage data passage.
Part 4, calculating UidWIFI power consumption: namely calculate power consumption during this application use WIFI (wireless network).
Part 5, other sensor power consumption of calculating Uid; When startup namely according to each sensor and the unit interval power consumption of sensor calculate the power consumption of each sensor.Such as gravity sensor, acceleration sensor etc.
In embodiments of the present invention, because each is applied in all cases, the information such as parameter, time of each nextport hardware component NextPort as CPU, sensor, wifi etc. is used all to be written into aforementioned arrangements file.The privately owned class of the embodiment of the present invention, then according to above-mentioned five parts, the information such as relevant parameter, time of extraction calculates corresponding power consumption.
Certainly, also can preset power consumption by other means and add up privately owned class, to this, the embodiment of the present invention is not limited.
In embodiments of the present invention, can by the first process for an application, access system power consumption is served, trigger calling Authority Verification function, and by Hook Function interception calling Authority Verification function, then call default power consumption and add up privately owned class, obtain the power consumption of described application.Thus the power consumption information of each application can be obtained in the android system comprising Android4.4 and above any version, swift to operate and improve the accuracy of the power consumption of acquisition.
Embodiment two
With reference to Fig. 2, show a kind of according to an embodiment of the invention flow chart of steps of Android application power consumption statistical method embodiment, specifically can comprise the steps:
Step 210, injects the first process by described Hook Function, and to the privately owned class of system registry.
In embodiments of the present invention, the Authority Verification result that Hook Function returns for tackling Authority Verification function, performs the logical process Authority Verification result represented by checking being back to system simultaneously.So the embodiment of the present invention needs first Hook Function to be injected each first process.
In embodiments of the present invention, in order to record the power consumption of different APP respectively, can register privately owned class in android system, for each application, the privately owned class calling interface that can call this privately owned class respectively realizes the power consumption quantitative statistics of applying each.
Preferably, step 210, specifically comprises:
Sub-step 211, when system starts, initial hatching process system carried replaces with the first predetermined hatching process.
In actual applications, the normal boot process of android system is roughly: start up system->init process reads init.rc->init process creation zygote (incubator) process that starts->zygote process creation java virtual machine loading zygoteInit class-> and waits for that the establishment message->zygote process of ActivityManagerService to socket write establishment process is according to the corresponding process of described establishment message establishing by socket-> that described virtual machine registration needs are monitored.
In embodiments of the present invention, in order to realize the monitoring to each application call Authority Verification function, first initial to android system incubator process and zygote process is needed to replace, replace with the first incubator process of specifying, an i.e. zygote process, one zygote process can monitor the first process the need of establishment, namely monitor aforementioned socket and whether have establishment message for this first process, if had, create this first process, in constructive process by this first process of function call injection that respectively hooks up of the embodiment of the present invention simultaneously a zygote process can create an appointment process in android system, read privately owned class in order to calling interface from assigned address and complete the read registration of privately owned class android system, the each privately owned class being about to read normal operation also can not have influence on the operation of other programs in android system.
Inject this first process by hooking up SO storehouse corresponding to function in actual applications, this SO storehouse comprises the logical code of Hook Function, thus can monitor this first process and whether call Authority Verification function.
In android system, all program process and system service process SystemServer breed (fork) out by zygote process, therefore, the present invention replaces with a zygote process by the zygote process that android system is initial and realizes monitoring and injection process.
Certainly, after the zygote process that replacement android system is initial is a zygote process, need to restart android system.The function of the zygote process after replacement, except comprising the function of initial zygote process, also added each application of monitoring and whether calls Authority Verification function.
Certainly, in the embodiment of the present invention, the logic that creates the first process directly can be set in a zygote process, this first process be compiled as simultaneously, when going out Ah sending out to after the calling of Authority Verification function, by after intercepting api calls calling Authority Verification function again.
In actual applications, Xposed framework can be utilized to realize incubator process initial for android system being replaced with the first incubator process of specifying.Wherein, Xposed framework aly can not revise APK (AndroidPackage, Android installation kit) when affect program run framework services, many powerful modules can be produced based on it, and operate when function is not conflicted simultaneously.So, in embodiments of the present invention, utilize Xposed framework, incubator process initial for android system is replaced with the first incubator process of specifying, but other original any functions of android system can not be affected.
Sub-step 212, injects described first process by described first hatching process by described Hook Function, and to the privately owned class of system registry.
Based on the logic of an aforementioned zygote process, by a zygote process by each for Hook Function function call injection the first process, and privately owned class can be registered in android system.
Preferably, sub-step 212, comprising:
Whether sub-step 2121, start to start by the first process described in described first hatching process monitoring.
In actual applications, before the first process is added up, first need to start this first process, so whether a zygote process of the embodiment of the present invention is then monitored this first process and is started.
In embodiments of the present invention, can by first hatching process monitoring each first process whether start.
Sub-step 2122, if described first process starts to start, then injects described first process by described hook, completes the startup of the first process.
The essence of hook (Hook) function is one section of program in order to disposal system message, can pass through system call, its injected system.In embodiments of the present invention, when the first process initiation, by a zygote process, Hook Function can be injected the first process, then completes the startup of the first process.
Inject this first process by hooking up SO storehouse corresponding to function in actual applications, this SO storehouse comprises the logical code of Hook Function, thus can monitor this first process and whether call Authority Verification function.
Step 220, by the first process for an application, access system power consumption is served, and triggers calling Authority Verification function.
Step 230, at system call Authority Verification function, gets Authority Verification result and after returning, the Authority Verification result returned described in being tackled by Hook Function.
Authority Verification function can for the access to system power consumption service be currently received, judge whether this access is system access, if the Authority Verification result that then Authority Verification function returns is by checking, if not the Authority Verification result that then Authority Verification function returns is verified for not passing through.
In embodiments of the present invention be non-system access for the access of an application to system power consumption service, so after triggering Authority Verification function, get Authority Verification result for not by checking.And in order to by checking, the power consumption information of each application can be obtained, so need the Authority Verification result that interception Authority Verification function returns.
In embodiments of the present invention, Authority Verification function whether can be called by a zygote process monitoring android system, and whether Authority Verification function returns authority the result, if Authority Verification function returns authority the result, then Hook Function can tackle Authority Verification result.
In actual applications, interception Authority Verification result, that Hook Function is redirected in the address of Authority Verification result, then the parameter imported into according to caller performs oneself logic, as by Authority Verification results modification be by checking, to make android system allow access system power consumption service, then continue to perform original logic.
Step 240, is served by AIDL, calls default power consumption and adds up privately owned class, reads the power consumption applied described in the power consumption configuration file of each application.
For each application in android system, android system can add up the power consumption information of each application, is stored in aforesaid configuration file.
In actual applications, can not shared drive between the process in android system, therefore, need to provide some mechanism to carry out data communication between different process.Android provides this work of AIDL tool for processing.In embodiments of the present invention, can oneself definition AIDL service, the rules of interaction of the process of this AIDL service definition the first process and store configuration files.In AIDL service, provide the contents such as the calling interface of privately owned class, thus the first process can pass through the privately owned class of AIDL service call, realizes adding up the power consumption of each application.
Wherein AIDL (AndroidInterfaceDefinitionLanguage, Android IDL (Interface Definition Language)) be a kind of IDL (InterfaceDescriptionLanguage, interface description language) language, for generating the code that can carry out interprocess communication (InterProcessCommunication, IPC) in Android device between two processes.If the operation of object in another process will be called in a process, AIDL just can be used to generate the parameter of serializability.
In embodiments of the present invention, in order to ensure can to communicate between different process, so being served by AIDL, calling default power consumption and adding up privately owned class, read the power consumption applied described in the power consumption configuration file of each application.
Preferably, after step 240, also comprise:
Step 250, constantly obtains the power consumption of described application and carries out record according to the time.
In actual application, the cycle can be spaced apart with certain hour, repeated execution of steps 220-240, thus constantly can obtain the power consumption of same application.
After acquisition power consumption, according to time sequencing, the power consumption of this application can be carried out record.
Such as, for 360 security guards, can get 1s is the cycle, extracts the power consumption of corresponding current time at interval of 1s from the power consumption configuration file of 360 security guards, and by the power consumption of extraction according to the time order and function journal of extracting.
Certainly, in actual applications, each time interval obtained between application power consumption can be fixing, and also can be unfixed, to this, the embodiment of the present invention be limited.
Step 260, the power consumption variable condition applied according to described record analysis.
According to the power consumption of record in step 250, the power consumption variable condition of corresponding application can be analyzed.Such as, the power consumption of each application and the relation of service time can be analyzed, or the power consumption situation at different interfaces respectively applied of com-parison and analysis etc.
In embodiments of the present invention, equally can by the first process for an application, access system power consumption is served, trigger calling Authority Verification function, and by Hook Function interception calling Authority Verification function, then call default power consumption and add up privately owned class, obtain the power consumption of described application.Thus the power consumption information of each application can be obtained in the android system comprising Android4.4 and above any version, swift to operate and improve the accuracy of the power consumption of acquisition.
In addition, the embodiment of the present invention utilizes specific first hatching process to replace hatching process original in android system, thus achieves the first process Hook Function being injected android system, registers privately owned class in systems in which simultaneously.Utilize Hook Function to monitor the first process and whether call Authority Verification function, if then utilize Hook Function to tackle Authority Verification result, thus Authority Verification process can be walked around, access is used for the privately owned class of statistics application power consumption, with the power consumption information in reading system power consumption configuration file, further increasing the convenience, agility and the operability that obtain each application power consumption in android system, and the accuracy of the power consumption information obtained.
For embodiment of the method, in order to simple description, therefore it is all expressed as a series of combination of actions, but those skilled in the art should know, the embodiment of the present invention is not by the restriction of described sequence of movement, because according to the embodiment of the present invention, some step can adopt other orders or carry out simultaneously.Secondly, those skilled in the art also should know, the embodiment described in instructions all belongs to preferred embodiment, and involved action might not be that the embodiment of the present invention is necessary.
Embodiment three
With reference to Fig. 3, show a kind of according to an embodiment of the invention structured flowchart of Android application power consumption statistic device embodiment, specifically can comprise as lower module:
Trigger module 310, is suitable for by the first process for an application, and access system power consumption is served, and triggers calling Authority Verification function.
Blocking module 320, is suitable for by Hook Function interception calling Authority Verification function.
Power consumption acquisition module 330, is suitable for calling default power consumption and adds up privately owned class, obtain the power consumption of described application.
In embodiments of the present invention, can by the first process for an application, access system power consumption is served, trigger calling Authority Verification function, and by Hook Function interception calling Authority Verification function, then call default power consumption and add up privately owned class, obtain the power consumption of described application.Thus the power consumption information of each application can be obtained in the android system comprising Android4.4 and above any version, swift to operate and improve the accuracy of the power consumption of acquisition.
Embodiment four
With reference to Fig. 4, show a kind of according to an embodiment of the invention structured flowchart of Android application power consumption statistic device embodiment, specifically can comprise as lower module:
Injection module 410, is suitable for described Hook Function to inject described first process, and to the privately owned class of system registry.
Preferably, injection module 410 comprises:
Hatching process replaces submodule 411, and be suitable for when system starts, initial hatching process system carried replaces with the first predetermined hatching process.
Inject submodule 412, be suitable for, by described first hatching process, described Hook Function is injected described first process, and to the privately owned class of system registry.
Preferably, in embodiments of the present invention, inject submodule 412, comprising:
Start monitoring submodule, be suitable for whether starting to start by the first process described in described first hatching process monitoring.
Hook Function injects submodule, starts to start, then described hook is injected described first process, complete the startup of the first process if be suitable for described first process.
Trigger module 420, is suitable for by the first process for an application, and access system power consumption is served, and triggers calling Authority Verification function.
Blocking module 430, is suitable for by Hook Function interception calling Authority Verification function.Specifically comprise:
Authority Verification result interception submodule 431, is suitable at system call Authority Verification function, gets Authority Verification result and after returning, the Authority Verification result returned described in being tackled by Hook Function.
Power consumption acquisition module 440, is suitable for calling default power consumption and adds up privately owned class, obtain the power consumption of described application.Specifically comprise:
Power consumption reading submodule 441, is suitable for being served by AIDL, calls default power consumption and adds up privately owned class, reads the power consumption applied described in each power consumption configuration file of application.
Preferably, after power consumption acquisition module 440, also comprise:
Power consumption logging modle, is suitable for constantly obtaining the power consumption of described application and carrying out record according to the time.
Power consumption analysis module, is suitable for the power consumption variable condition applied according to described record analysis.
In embodiments of the present invention, equally can by the first process for an application, access system power consumption is served, trigger calling Authority Verification function, and by Hook Function interception calling Authority Verification function, then call default power consumption and add up privately owned class, obtain the power consumption of described application.Thus the power consumption information of each application can be obtained in the android system comprising Android4.4 and above any version, swift to operate and improve the accuracy of the power consumption of acquisition.
In addition, the embodiment of the present invention utilizes specific first hatching process to replace hatching process original in android system, thus achieves the first process Hook Function being injected android system, registers privately owned class in systems in which simultaneously.Utilize Hook Function to monitor the first process and whether call Authority Verification function, if then utilize Hook Function to tackle Authority Verification result, thus Authority Verification process can be walked around, access is used for the privately owned class of statistics application power consumption, with the power consumption information in reading system power consumption configuration file, further increasing the convenience, agility and the operability that obtain each application power consumption in android system, and the accuracy of the power consumption information obtained.
For device embodiment, due to itself and embodiment of the method basic simlarity, so description is fairly simple, relevant part illustrates see the part of embodiment of the method.
Embodiment five
With reference to Fig. 5, show the structured flowchart of a kind of according to an embodiment of the invention Android application power consumption statistics apparatus embodiments, equipment 500 can comprise as lower module:
Storer 510, is loaded with many executable instructions.
Processor 520, performs described many executable instructions; Described many executable instructions comprise the method performing following steps:
By the first process for an application, access system power consumption is served, and triggers calling Authority Verification function;
By Hook Function interception calling Authority Verification function;
Call default power consumption and add up privately owned class, obtain the power consumption of described application.
Intrinsic not relevant to any certain computer, virtual system or miscellaneous equipment with display at this algorithm provided.Various general-purpose system also can with use based on together with this teaching.According to description above, the structure constructed required by this type systematic is apparent.In addition, the present invention is not also for any certain programmed language.It should be understood that and various programming language can be utilized to realize content of the present invention described here, and the description done language-specific is above to disclose preferred forms of the present invention.
In instructions provided herein, describe a large amount of detail.But can understand, embodiments of the invention can be put into practice when not having these details.In some instances, be not shown specifically known method, structure and technology, so that not fuzzy understanding of this description.
Similarly, be to be understood that, in order to simplify the disclosure and to help to understand in each inventive aspect one or more, in the description above to exemplary embodiment of the present invention, each feature of the present invention is grouped together in single embodiment, figure or the description to it sometimes.But, the method for the disclosure should be construed to the following intention of reflection: namely the present invention for required protection requires feature more more than the feature clearly recorded in each claim.Or rather, as claims below reflect, all features of disclosed single embodiment before inventive aspect is to be less than.Therefore, the claims following embodiment are incorporated to this embodiment thus clearly, and wherein each claim itself is as independent embodiment of the present invention.
Those skilled in the art are appreciated that and adaptively can change the module in the equipment in embodiment and they are arranged in one or more equipment different from this embodiment.Module in embodiment or unit or assembly can be combined into a module or unit or assembly, and multiple submodule or subelement or sub-component can be put them in addition.Except at least some in such feature and/or process or unit be mutually repel except, any combination can be adopted to combine all processes of all features disclosed in this instructions (comprising adjoint claim, summary and accompanying drawing) and so disclosed any method or equipment or unit.Unless expressly stated otherwise, each feature disclosed in this instructions (comprising adjoint claim, summary and accompanying drawing) can by providing identical, alternative features that is equivalent or similar object replaces.
In addition, those skilled in the art can understand, although embodiments more described herein to comprise in other embodiment some included feature instead of further feature, the combination of the feature of different embodiment means and to be within scope of the present invention and to form different embodiments.Such as, in the following claims, the one of any of embodiment required for protection can use with arbitrary array mode.
All parts embodiment of the present invention with hardware implementing, or can realize with the software module run on one or more processor, or realizes with their combination.It will be understood by those of skill in the art that and microprocessor or digital signal processor (DSP) can be used in practice to realize according to the embodiment of the present invention android application power consumption is added upthe some or all functions of the some or all parts in equipment.The present invention can also be embodied as part or all equipment for performing method as described herein or device program (such as, computer program and computer program).Realizing program of the present invention and can store on a computer-readable medium like this, or the form of one or more signal can be had.Such signal can be downloaded from internet website and obtain, or provides on carrier signal, or provides with any other form.
The present invention will be described instead of limit the invention to it should be noted above-described embodiment, and those skilled in the art can design alternative embodiment when not departing from the scope of claims.In the claims, any reference symbol between bracket should be configured to limitations on claims.Word " comprises " not to be got rid of existence and does not arrange element in the claims or step.Word "a" or "an" before being positioned at element is not got rid of and be there is multiple such element.The present invention can by means of including the hardware of some different elements and realizing by means of the computing machine of suitably programming.In the unit claim listing some devices, several in these devices can be carry out imbody by same hardware branch.Word first, second and third-class use do not represent any order.Can be title by these word explanations.
The invention discloses A1, a kind of Android application power consumption statistical method, comprising:
By the first process for an application, access system power consumption is served, and triggers calling Authority Verification function;
By Hook Function interception calling Authority Verification function;
Call default power consumption and add up privately owned class, obtain the power consumption of described application.
A2, method as described in A1, described by the step called of Hook Function interception to Authority Verification function, comprising:
At system call Authority Verification function, get Authority Verification result and after returning, the Authority Verification result returned described in being tackled by Hook Function.
A3, method as described in A1, by the first process for an application, access system power consumption is served, and triggers before the calling of Authority Verification function, also comprises:
Described Hook Function is injected described first process, and to the privately owned class of system registry.
A4, method as described in A3, the described step described Hook Function being injected described first process, comprising:
When system starts, initial hatching process system carried replaces with the first predetermined hatching process;
By described first hatching process, described Hook Function is injected described first process, and to the privately owned class of system registry.
A5, method as described in A1, the described step by described first hatching process, described Hook Function being injected described first process, being comprised:
Whether start to start by the first process described in described first hatching process monitoring;
If described first process starts to start, then described hook is injected described first process, complete the startup of the first process.
A6, method as described in A1, described in call default power consumption and add up privately owned class, obtain the step of the power consumption of described application, comprising:
Served by AIDL, call default power consumption and add up privately owned class, read the power consumption applied described in the power consumption configuration file of each application.
A7, method as described in A1, add up privately owned class calling default power consumption, after obtaining the step of the power consumption of described application, also comprise:
The power consumption of the described application of continuous acquisition also carries out record according to the time;
The power consumption variable condition applied according to described record analysis.
The invention also discloses B8, a kind of Android application power consumption statistic device, comprising:
Trigger module, is suitable for by the first process for an application, and access system power consumption is served, and triggers calling Authority Verification function;
Blocking module, is suitable for by Hook Function interception calling Authority Verification function;
Power consumption acquisition module, is suitable for calling default power consumption and adds up privately owned class, obtain the power consumption of described application.
B9, device as described in B8, described blocking module, comprising:
Authority Verification result interception submodule, is suitable at system call Authority Verification function, gets Authority Verification result and after returning, the Authority Verification result returned described in being tackled by Hook Function.
B10, device as described in B8, before trigger module, also comprise:
Injection module, is suitable for described Hook Function to inject described first process, and to the privately owned class of system registry.
B11, device as described in B10, described injection module, comprising:
Hatching process replaces submodule, and be suitable for when system starts, initial hatching process system carried replaces with the first predetermined hatching process;
Inject submodule, be suitable for, by described first hatching process, described Hook Function is injected described first process, and to the privately owned class of system registry.
B12, device as described in B8, described injection submodule, comprising:
Start monitoring submodule, be suitable for whether starting to start by the first process described in described first hatching process monitoring;
Hook Function injects submodule, starts to start, then described hook is injected described first process, complete the startup of the first process if be suitable for described first process.
B13, device as described in B8, described power consumption acquisition module, comprising:
Power consumption reading submodule, is suitable for being served by AIDL, calls default power consumption and adds up privately owned class, reads the power consumption applied described in the power consumption configuration file of each application.
B14, device as described in B8, after power consumption acquisition module, also comprise:
Power consumption logging modle, is suitable for constantly obtaining the power consumption of described application and carrying out record according to the time;
Power consumption analysis module, is suitable for the power consumption variable condition applied according to described record analysis.
The invention also discloses C15, a kind of Android application power consumption statistics equipment, comprising:
Storer, is loaded with many executable instructions;
Processor, performs described many executable instructions; Described many executable instructions comprise the method performing following steps:
By the first process for an application, access system power consumption is served, and triggers calling Authority Verification function;
By Hook Function interception calling Authority Verification function;
Call default power consumption and add up privately owned class, obtain the power consumption of described application.

Claims (10)

1. an Android application power consumption statistical method, comprising:
By the first process for an application, access system power consumption is served, and triggers calling Authority Verification function;
By Hook Function interception calling Authority Verification function;
Call default power consumption and add up privately owned class, obtain the power consumption of described application.
2. method according to claim 1, is characterized in that, described by the step called of Hook Function interception to Authority Verification function, comprising:
At system call Authority Verification function, get Authority Verification result and after returning, the Authority Verification result returned described in being tackled by Hook Function.
3. method according to claim 1, is characterized in that, by the first process for an application, access system power consumption is served, and triggers before the calling of Authority Verification function, also comprises:
Described Hook Function is injected described first process, and to the privately owned class of system registry.
4. method according to claim 3, is characterized in that, the described step described Hook Function being injected described first process, comprising:
When system starts, initial hatching process system carried replaces with the first predetermined hatching process;
By described first hatching process, described Hook Function is injected described first process, and to the privately owned class of system registry.
5. method according to claim 1, is characterized in that, the described step by described first hatching process, described Hook Function being injected described first process, being comprised:
Whether start to start by the first process described in described first hatching process monitoring;
If described first process starts to start, then described hook is injected described first process, complete the startup of the first process.
6. method according to claim 1, is characterized in that, described in call default power consumption and add up privately owned class, obtain the step of the power consumption of described application, comprising:
Served by AIDL, call default power consumption and add up privately owned class, read the power consumption applied described in the power consumption configuration file of each application.
7. method according to claim 1, is characterized in that, adds up privately owned class calling default power consumption, after obtaining the step of the power consumption of described application, also comprises:
The power consumption of the described application of continuous acquisition also carries out record according to the time;
The power consumption variable condition applied according to described record analysis.
8. an Android application power consumption statistic device, comprising:
Trigger module, is suitable for by the first process for an application, and access system power consumption is served, and triggers calling Authority Verification function;
Blocking module, is suitable for by Hook Function interception calling Authority Verification function;
Power consumption acquisition module, is suitable for calling default power consumption and adds up privately owned class, obtain the power consumption of described application.
9. device according to claim 8, is characterized in that, described blocking module, comprising:
Authority Verification result interception submodule, is suitable at system call Authority Verification function, gets Authority Verification result and after returning, the Authority Verification result returned described in being tackled by Hook Function.
10. an Android application power consumption statistics equipment, comprising:
Storer, is loaded with many executable instructions;
Processor, performs described many executable instructions; Described many executable instructions comprise the method performing following steps:
By the first process for an application, access system power consumption is served, and triggers calling Authority Verification function;
By Hook Function interception calling Authority Verification function;
Call default power consumption and add up privately owned class, obtain the power consumption of described application.
CN201510938736.8A 2015-12-15 2015-12-15 A kind of Android application power consumption statistical method and device Active CN105573891B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510938736.8A CN105573891B (en) 2015-12-15 2015-12-15 A kind of Android application power consumption statistical method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510938736.8A CN105573891B (en) 2015-12-15 2015-12-15 A kind of Android application power consumption statistical method and device

Publications (2)

Publication Number Publication Date
CN105573891A true CN105573891A (en) 2016-05-11
CN105573891B CN105573891B (en) 2019-03-08

Family

ID=55884057

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510938736.8A Active CN105573891B (en) 2015-12-15 2015-12-15 A kind of Android application power consumption statistical method and device

Country Status (1)

Country Link
CN (1) CN105573891B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107291211A (en) * 2017-06-05 2017-10-24 北京奇虎科技有限公司 The electric quantity consumption of application program determines method and device
CN107515811A (en) * 2017-08-31 2017-12-26 北京麒麟合盛网络技术有限公司 A kind of method and apparatus for obtaining application program power consumption

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103257320A (en) * 2013-05-08 2013-08-21 百度在线网络技术(北京)有限公司 Method and device for electric quantity environment construction of mobile terminal
CN103729052A (en) * 2013-12-31 2014-04-16 贝壳网际(北京)安全技术有限公司 Processing method and system for power consumption of application program and mobile terminal
CN104516806A (en) * 2014-12-26 2015-04-15 北京奇虎科技有限公司 Power consumption information detection result display method and system for mobile terminal

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103257320A (en) * 2013-05-08 2013-08-21 百度在线网络技术(北京)有限公司 Method and device for electric quantity environment construction of mobile terminal
CN103729052A (en) * 2013-12-31 2014-04-16 贝壳网际(北京)安全技术有限公司 Processing method and system for power consumption of application program and mobile terminal
CN104516806A (en) * 2014-12-26 2015-04-15 北京奇虎科技有限公司 Power consumption information detection result display method and system for mobile terminal

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107291211A (en) * 2017-06-05 2017-10-24 北京奇虎科技有限公司 The electric quantity consumption of application program determines method and device
CN107515811A (en) * 2017-08-31 2017-12-26 北京麒麟合盛网络技术有限公司 A kind of method and apparatus for obtaining application program power consumption

Also Published As

Publication number Publication date
CN105573891B (en) 2019-03-08

Similar Documents

Publication Publication Date Title
Sun et al. Taintart: A practical multi-level information-flow tracking system for android runtime
US10705811B2 (en) Method and system for automated, static instrumentation for applications designed for execution in environments with restricted resources, like mobile devices or TV set top boxes
Zheng et al. DroidTrace: A ptrace based Android dynamic analysis system with forward execution capability
CN109032825B (en) Fault injection method, device and equipment
CN104885092A (en) Security system and method for operating systems
CN105094797A (en) Application analysis system for electronic devices
US20130263094A1 (en) Setting breakpoints in optimized instructions
Liu et al. Diagnosing energy efficiency and performance for mobile internetware applications
US9104781B2 (en) Obtaining metadata set by imperative statement
US11294791B2 (en) Code optimization for connected managed runtime environments
CN105512015A (en) Android target application crash calculation method and device
CN105915546A (en) Traffic monitoring method and device of android application
CN103577747A (en) Mobile equipment privacy protection device and method
CN112130926B (en) Application program running method, device, terminal equipment and storage medium
EP4334816A1 (en) Automatic performance telemetry
Sun et al. Mining android api usage to generate unit test cases for pinpointing compatibility issues
CN105573891A (en) Android application electricity consumption statistics method and device
CN111949529B (en) System debugging method, device, computer equipment and storage medium
US9489179B2 (en) Application programming interface tracing mechanism
EP2885712A1 (en) Imperative attribution for elements in managed runtimes
CN111290740A (en) Application program development method and device, computer equipment and storage medium
CN113342376B (en) Method and device for upgrading operating system of Internet of things equipment
Gracioli et al. ELUS: A dynamic software reconfiguration infrastructure for embedded systems
CN110908882A (en) Performance analysis method and device of application program, terminal equipment and medium
CN112631949B (en) Debugging method and device, computer equipment and storage medium

Legal Events

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

Effective date of registration: 20220725

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.

TR01 Transfer of patent right