WO2018094908A1 - 对终端的应用程序进行唤醒的方法及装置 - Google Patents

对终端的应用程序进行唤醒的方法及装置 Download PDF

Info

Publication number
WO2018094908A1
WO2018094908A1 PCT/CN2017/075722 CN2017075722W WO2018094908A1 WO 2018094908 A1 WO2018094908 A1 WO 2018094908A1 CN 2017075722 W CN2017075722 W CN 2017075722W WO 2018094908 A1 WO2018094908 A1 WO 2018094908A1
Authority
WO
WIPO (PCT)
Prior art keywords
application
file lock
listener
layer
state
Prior art date
Application number
PCT/CN2017/075722
Other languages
English (en)
French (fr)
Inventor
丁鹏
Original Assignee
武汉斗鱼网络科技有限公司
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 武汉斗鱼网络科技有限公司 filed Critical 武汉斗鱼网络科技有限公司
Publication of WO2018094908A1 publication Critical patent/WO2018094908A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/4401Bootstrapping
    • G06F9/4418Suspend and resume; Hibernate and awake

Definitions

  • the present invention relates to the field of computer technologies, and in particular, to a method and apparatus for waking up an application of a terminal.
  • the application of the terminal runs in user mode, which can interact with the user and generally has a visual user interface.
  • Each application runs on a separate process and has its own separate address space.
  • the current application will inevitably be killed by the system on each terminal (such as a mobile phone). If the application is killed by the system, some background programs cannot be executed, which cannot be satisfied. The needs of some users (for example, the user wants an app to be launched or reminded at a specific time). Because Android manufacturers have different customizations, when developers develop applications, they will be killed when they enter the background on some mobile phones. If there is a solution that can be started after the Android application is killed, This will ensure the necessity of the application, especially for some applications that exit the application to the background and also need the application's service to start.
  • the present invention has been made in order to provide a method and apparatus for waking up an application of a terminal that overcomes the above problems or at least partially solves the above problems.
  • a method for waking up an application of a terminal comprising: creating a file lock for a process of the application, such that the file lock can be executed in a process of the application; Creating a listener for the application, listening to the state of the file lock by running the listener; determining whether the file lock is executed by monitoring the state of the file lock; when the file lock is not executed And determining that the process of the application does not exist, then starting an operation of waking up the application.
  • the creating a file lock for the process of the application includes: acquiring a process identifier of the application; acquiring, according to the process identifier, a current file lock state of a process of the application; according to a Linux operation command, Perform a file lock operation on the process of the application.
  • the determining, by the state of the file lock that is monitored, whether the file lock is executed comprises: obtaining a state value of the monitored file lock, and determining the file lock by using a predefined meaning of the state value. Whether it is executed.
  • the method further comprises: calculating, by the counter, the number of open listeners, thereby ensuring that the open listener is unique.
  • the operating system of the terminal comprises an underlying layer, a framework layer and an application layer, and the listener is created for the application at the framework layer, the method further comprising: defining, at the framework layer, the application The layer invokes the listener call interface of the listener; the application layer reads the listener by calling the listener call interface, thereby acquiring the state of the file lock monitored by the listener.
  • an apparatus for waking up an application of a terminal comprising: a file lock creating unit, configured to create a file lock for a process of the application, such that the file lock is available in the application a program is executed in the process; a listener creation unit is configured to create a listener for the application, and monitor the state of the file lock by running the listener; and the monitor result judgment unit is configured to listen to the file lock a state of determining whether the file lock is executed; waking up an execution unit, configured to, when the file lock is not executed, determine that the process of the application does not exist, initiate an operation of waking up the application.
  • the file lock creating unit is specifically configured to: acquire a process identifier of the application; acquire a current file lock state of the process of the application according to the process identifier; and, according to a Linux operation command, The process of the application performs a file lock operation.
  • the monitoring result judging unit is configured to: obtain a state value of the monitored file lock, and determine whether the file lock is executed by using a predefined meaning of the state value.
  • the device further comprises: a listener unique control unit, configured to calculate the number of open listeners by the counter, thereby ensuring that the open listener is unique.
  • a listener unique control unit configured to calculate the number of open listeners by the counter, thereby ensuring that the open listener is unique.
  • the operating system of the terminal includes an underlying layer, a framework layer, and an application layer, where the listener is created for the application at the framework layer, and the device further includes: a listener call interface setting unit, configured to The framework layer defines a listener call interface that is available to the application layer to invoke the listener; wherein the application layer reads the listener by calling the listener call interface, thereby obtaining the listener The state of the file lock that was listened to.
  • a listener call interface setting unit configured to The framework layer defines a listener call interface that is available to the application layer to invoke the listener; wherein the application layer reads the listener by calling the listener call interface, thereby obtaining the listener The state of the file lock that was listened to.
  • the present invention monitors the state of the file lock corresponding to the process of the application by the listener; determines whether the file lock is executed by monitoring, and determines that the process of the application does not exist when the file lock is not executed, and starts the wake-up application at this time. Operation.
  • the killed application can be awakened in time.
  • the listener is a native independent process, so it will be independent of the application itself after startup. When the application is killed, the started independent listener can detect it and restart the application. Ensure that the application will be re-awakened after being killed.
  • FIG. 1 is a flow chart showing a method for waking up an application of a terminal according to an embodiment of the present invention
  • FIG. 2 is a schematic structural diagram of an apparatus for waking up an application of a terminal according to an embodiment of the present invention.
  • the operating system includes an application underlying layer (linux layer), a framework layer (framework layer, native layer), and an application layer (app layer, java layer, upper layer), as well as other layers that may be included in the functional division.
  • the invention is not discussed.
  • the app layer can be understood as the upper layer, which is responsible for interacting with the user, such as application maintenance, and identifying different kinds of click content when the page is clicked to display different context menus.
  • the framework layer acts as the middle layer.
  • the main responsibility of this layer is to forward the user requests obtained by the app layer, such as launching the application, clicking the link, clicking to save the image, etc., and forwarding it to the bottom layer; Or distribute it to the upper layer through a message or through an intermediate proxy class to present it to the user.
  • a preferred implementation of the present invention is to improve the underlying layer, the framework layer, and the app layer by using the Android system as an example, thereby utilizing the synergy of these layers to implement wake-up of the killed application.
  • the Linux file lock is encapsulated at the bottom layer (the file lock is a file lock of the application process) to supply the layer call; the listener is created in the framework layer to monitor the state of the file lock; in the app layer, the frame is read.
  • the listener of the layer determines whether the process of the application exists by the state of the file lock. If it does not exist, it can be determined that the application is killed. At this time, the operation of waking up the application is started.
  • FIG. 1 a method for waking up an application of a terminal according to the present invention is provided.
  • the listening process of the native process of the framework layer is mainly used. Order to pull the application.
  • the Android system uses the Linux system as its kernel to handle various events, while in the Linux system, the fork mechanism can be used (the fork mechanism is used to create a child process) to create a Native process, and in the Native process.
  • the Linux process can be seen as an implementation of the program. Under Linux, each process uses a unique PID (port ID) to identify the process.
  • the PID is a positive integer from 1 to 32768, where 1 is generally a special process init, and other processes are numbered sequentially from 2. When you run out of 32768, start over from 2.
  • the role of fork is to copy a process that is the same as the current process. All data (variables, environment variables, program counters, etc.) of the new process are the same as the original process, but are a completely new process and are used as child processes of the original process.
  • Android is an operating system with Linux as the kernel. Therefore, some operations on Linux are equally applicable on Android, and since the life cycle of all processes and system components in Android is managed by the ActivityManagerService (active management service), and the process created by the Linux fork mechanism is Pure Linux process, its life cycle is not managed by Android, so you can use the Linux fork mechanism to achieve the purpose of waking up the application.
  • ActivityManagerService active management service
  • Linux fork mechanism Pure Linux process
  • embodiments of the present invention create a file lock for a process of an application (generally referred to as the main process of the application). Since the applications in Android are all running on the virtual machine, the file lock of the application layer is different from the file lock of the underlying layer. To implement this function, the file lock supply layer call of the Linux layer needs to be encapsulated. This method is passive to monitor whether the application is killed, so there is no power consumption, as long as the application is killed, the judgment will start.
  • S101 Create a file lock for the application process, so that the file lock can be executed in the process of the application.
  • creating a file lock for the application process includes: obtaining a process identifier of the application; obtaining a current file lock state of the application process according to the process identifier; and performing a file lock operation on the application process according to the Linux operation command.
  • the package is implemented using the C language.
  • the file is locked by the file lock that comes with Linux, and the status value of the file lock is returned.
  • the success is 0, and the failure is -1, -2, -3.
  • the process ID (PID) of the application is obtained as the object of judgment. First, it is judged whether the file operated by the process exists, and it is judged that only the process ID needs to be passed in. If it does not exist, it is judged that the process is invalid, and returns - 1, continue if it exists.
  • the process when the process tries to lock the file using flock, if the file has been locked by another process, the process will be blocked until the lock is released, or When calling flock, the LOCKNB parameter is used.
  • the file lock status value is -1.
  • the process number is passed in, and the return value of the int type can be obtained. According to the above judgment, as long as it is equal to -1, it is judged that the file has been locked. Therefore, as long as -1 is returned, error code-2 is returned to the App layer, and if it is not equal to -1, the operation is started. After the operation is completed, you need to perform close shutdown.
  • the process of the application can be used to use the file lock, and the process of the subsequent listening application is currently present (step S102), because if the file is latched and the file lock can be executed, the return value is 0.
  • the process already exists. If the file lock status value is -1 or -2, it is determined that the process does not exist. When the return value is -3, it is judged that the file lock has been executed before.
  • S102 Create a listener for the application, and monitor the state of the file lock by running the listener.
  • step S101 After the step S101 is completed, it is necessary to call the file lock to the application layer.
  • the listener In a nutshell, the listener is defined at the framework level, and the file lock state is obtained by calling the listener at the application layer, thereby achieving the purpose of calling the file lock to the application layer.
  • the C language in the framework layer uses the C language in the framework layer to create a listener that continuously monitors the state of the file lock to determine whether the application's process exists. Since the listener is a separate program, it does not affect the operation of its application's process (the main process). For example, put the code of the above listener into a separate listener to see if the process of the application exists as an observer.
  • S103 Determine whether the file lock is executed by monitoring the state of the file lock.
  • the status value of the monitored file lock is obtained, and the file lock is determined to be executed by a predefined meaning of the status value.
  • the value of the returned file lock is 0, -2, it is determined that the application is executing normally, and no processing is performed, and the loop is still executed normally.
  • the return value is -1, -3, it is determined that the application may have been killed, and then the process of waking up the application is required.
  • the method of waking up is to pull the application's process through the Native process, that is, to pull through the am command.
  • the process is pulled in the forestop state by specifying the "-include-stopped-packages" parameter.
  • the above command will pass in the package name of the application, which is called the application's unique identifier. Through the above command, after the process that listens to the application is killed, the process can be restarted to ensure the process is active.
  • the uniqueness of the listener needs to be guaranteed. Because the listener needs to constantly call the application to determine whether it exists, there can only be one listener, and the listener and the main process are designed into C/S structure mode from the aspects of scalability and process uniqueness. The process communicates with the listener via the Localsocket. The use of Localsocket in the listener guarantees the uniqueness of the listener, so that there are no problems such as creating multiple listeners and the listener becoming invalid. The implementation is to use a counter to record the number of local open, if the number is greater than or equal to 1, it will not be executed, if it is less than 1, the listener will be started.
  • a listener call interface is provided in the framework layer for the application layer to call the listener; the application layer reads the listener by calling the listener call interface, thereby obtaining the file lock monitored by the listener. status.
  • the C language file is compiled into a so (shared object) file, in order to enable the Android application to call the already compiled listener.
  • the C language program is changed into a program that can be executed by the application layer.
  • the implementation steps are as follows:
  • the listener that has been compiled and generated will be called at the same time each time the application starts. In this way, each time the application starts, it will start to execute the listener. Since the started listener is a native independent process, it will be independent of the application itself after startup. When the application is killed, the independent listener started. It can be detected to restart the application, thus ensuring that the application will be able to wake up again after being killed.
  • the present invention further provides a device for waking up an application of a terminal, and the device may be a terminal itself or a functional module in the terminal, and may be combined by hardware, software or software and hardware. Way to achieve.
  • the terminal mentioned in the embodiment of the present invention includes a mobile phone, a PC, Terminals such as PAD.
  • the device includes:
  • a file lock creating unit 201 configured to create a file lock for the process of the application, so that the file lock can be executed in a process of the application;
  • the listener creating unit 202 is configured to create a listener for the application, and monitor the state of the file lock by running the listener;
  • the monitoring result judging unit 203 is configured to judge whether the file lock is executed by monitoring the state of the file lock
  • the wake-up execution unit 204 is configured to, when the file lock is not executed, determine that the process of the application does not exist, initiate an operation of waking up the application.
  • the file lock creating unit 201 is specifically configured to: acquire a process identifier of the application; acquire a current file lock state of a process of the application according to the process identifier; and, according to a Linux operation command, The application's process performs a file lock operation.
  • the monitoring result judging unit 203 is specifically configured to: obtain a state value of the monitored file lock, and determine whether the file lock is executed by using a predefined meaning of the state value.
  • the device further comprises: a listener unique control unit 205, configured to calculate the number of open listeners by a counter, thereby ensuring that the open listener is unique.
  • a listener unique control unit 205 configured to calculate the number of open listeners by a counter, thereby ensuring that the open listener is unique.
  • the operating system of the terminal includes a bottom layer, a framework layer, and an application layer, where the listener is created for the application at the framework layer, and the device further includes: a listener call interface setting unit 206, configured to: Determining, at the framework layer, a listener call interface that is available to the application layer to invoke the listener; wherein the application layer reads the listener by calling the listener call interface, thereby obtaining the listener The state of the file lock that the program listens to.
  • a listener call interface setting unit 206 configured to: Determining, at the framework layer, a listener call interface that is available to the application layer to invoke the listener; wherein the application layer reads the listener by calling the listener call interface, thereby obtaining the listener The state of the file lock that the program listens to.
  • the various component embodiments of the present invention may be implemented in hardware, or in a software module running on one or more processors, or in a combination thereof.
  • a microprocessor or digital signal processor may be used in practice to implement some or all of the functionality of some or all of the components of the user morphing control system in accordance with embodiments of the present invention.
  • the invention can also be implemented as a device or device program (e.g., a computer program and a computer program product) for performing some or all of the methods described herein.
  • a program implementing the invention may be stored on a computer readable medium or may be in the form of one or more signals.
  • the signal can be downloaded from the Internet website, or provided on a carrier signal, or in any other form.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

一种对终端的应用程序进行唤醒的方法及装置,其中方法包括:为应用程序的进程创建文件锁,使得所述文件锁可在所述应用程序的进程中被执行(S101);为所述应用程序创建监听程序,通过运行监听程序监听所述文件锁的状态(S102);通过监听到的文件锁的状态,判断所述文件锁是否被执行(S103);当文件锁没有被执行时,确定应用程序的进程不存在,则启动唤醒应用程序的操作(S104)。通过该方法,可及时将被杀的应用程序唤醒。

Description

对终端的应用程序进行唤醒的方法及装置 技术领域
本发明涉及计算机技术领域,具体涉及一种对终端的应用程序进行唤醒的方法及装置。
背景技术
终端的应用程序(Application)运行在用户模式,它可以和用户进行交互,一般具有可视的用户界面。每一个应用程序运行于独立的进程,并拥有自己独立的地址空间。
以Android系统为例,当前应用程序在各个终端(例如手机)上难免会遇到被系统杀死(kill)的情况,如果应用程序被系统杀死,则无法执行一些后台的程序,从而无法满足一些用户的需求(例如,用户希望某个APP在特定时间启动或提醒)。由于Android各个手机的厂商定制不同,当开发人员在开发应用程序时,会出现在部分手机上进入后台时会被系统杀死,如果有一种方案可以在Android的应用程序被杀死后又启动,这就可以保证应用程序存在的必要性,对于一些退出应用程序到后台,还需要应用程序的服务启动的情况,这种需求尤为突出。
发明内容
鉴于上述问题,提出了本发明以便提供一种克服上述问题或者至少部分地解决上述问题的对终端的应用程序进行唤醒的方法及装置。
依据本发明的一个方面,提供一种对终端的应用程序进行唤醒的方法,包括:为所述应用程序的进程创建文件锁,使得所述文件锁可在所述应用程序的进程中被执行;为所述应用程序创建监听程序,通过运行所述监听程序监听所述文件锁的状态;通过监听到的文件锁的状态,判断所述文件锁是否被执行;当所述文件锁没有被执行时,确定所述应用程序的进程不存在,则启动唤醒所述应用程序的操作。
优选的,所述为所述应用程序的进程创建文件锁包括:获取所述应用程序的进程标识;根据所述进程标识,获取所述应用程序的进程的当前文件锁状态;根据Linux操作命令,对所述应用程序的进程执行文件锁操作。
优选的,所述通过监听到的文件锁的状态,判断所述文件锁是否被执行,包括:获取监听到的文件锁的状态值,通过所述状态值预先定义的含义,判断所述文件锁是否被执行。
优选的,所述方法还包括:通过计数器计算开启的监听程序的数量,从而确保开启的监听程序是唯一的。
优选的,所述终端的操作系统包括底层、框架层和应用层,在所述框架层为所述应用程序创建所述监听程序,所述方法还包括:在所述框架层定义供所述应用层调用所述监听程序的监听程序调用接口;所述应用层通过调用所述监听程序调用接口读取所述监听程序,从而获取到所述监听程序监听到的所述文件锁的状态。
根据本发明另一个方面,提供一种对终端的应用程序进行唤醒的装置,包括:文件锁创建单元,用于为所述应用程序的进程创建文件锁,使得所述文件锁可在所述应用程序的进程中被执行;监听程序创建单元,用于为所述应用程序创建监听程序,通过运行所述监听程序监听所述文件锁的状态;监听结果判断单元,用于通过监听到的文件锁的状态,判断所述文件锁是否被执行;唤醒执行单元,用于当所述文件锁没有被执行时,确定所述应用程序的进程不存在,则启动唤醒所述应用程序的操作。
优选的,所述文件锁创建单元具体用于:获取所述应用程序的进程标识;根据所述进程标识,获取所述应用程序的进程的当前文件锁状态;以及,根据Linux操作命令,对所述应用程序的进程执行文件锁操作。
优选的,所述监听结果判断单元具体用于:获取监听到的文件锁的状态值,通过所述状态值预先定义的含义,判断所述文件锁是否被执行。
优选的,所述装置还包括:监听程序唯一控制单元,用于通过计数器计算开启的监听程序的数量,从而确保开启的监听程序是唯一的。
优选的,所述终端的操作系统包括底层、框架层和应用层,在所述框架层为所述应用程序创建所述监听程序,所述装置还包括:监听程序调用接口设置单元,用于在所述框架层定义可供所述应用层调用所述监听程序的监听程序调用接口;其中,所述应用层通过调用所述监听程序调用接口读取所述监听程序,从而获取到所述监听程序监听到的所述文件锁的状态。
可见,本发明通过监听程序监听应用程序的进程对应的文件锁的状态;通过监听确定文件锁是否被执行,在文件锁没有被执行时,确定应用程序的进程不存在,此时启动唤醒应用程序的操作。通过本发明可及时唤醒被杀的应用程序。在一个优选方式中,监听程序是native的独立进程,因此启动后将与应用程序本身无关,当应用程序被杀后,启动的独立监听程序就可以检测到,从而重新开始启动应用程序,由此保证应用程序在被杀后将可以重新被唤醒。
上述说明仅是本发明技术方案的概述,为了能够更清楚了解本发明的技术手段,而可依照说明书的内容予以实施,并且为了让本发明的上述和其它目的、 特征和优点能够更明显易懂,以下特举本发明的具体实施方式。
附图说明
通过阅读下文优选实施方式的详细描述,各种其他的优点和益处对于本领域普通技术人员将变得清楚明了。附图仅用于示出优选实施方式的目的,而并不认为是对本发明的限制。而且在整个附图中,用相同的参考符号表示相同的部件。在附图中:
图1示出了根据本发明的一个实施例提供的对终端的应用程序进行唤醒的方法流程图;
图2示出了根据本发明一个实施例提供的对终端的应用程序进行唤醒的装置结构示意图。
具体实施方式
下面将参照附图更详细地描述本公开的示例性实施例。虽然附图中显示了本公开的示例性实施例,然而应当理解,可以以各种形式实现本公开而不应被这里阐述的实施例所限制。相反,提供这些实施例是为了能够更透彻地理解本公开,并且能够将本公开的范围完整的传达给本领域的技术人员。
本领域技术人员理解,操作系统包括应用底层(linux层)、框架层(framework层、native层)和应用层(app层、java层、上层),至于从功能划分上有可能包括的的其他层本发明则不作讨论。其中,通常app层可以理解为上层,负责与用户交互的界面,例如应用程序维护、以及点击页面时识别不同种类的点击内容从而显示不同的上下文菜单等。通常framework层作为中间层,这一层的主要职责是,将app层获得的用户请求,如启动用用程序、点击链接、点击保存图片之类,转发往底层去;将底层处理好的内容,或者通过消息,或者通过中间代理类,来分发至上层,对用户展现出来。
本发明一种优选实现方式是,以Android系统为例,对底层、framework层和app层进行改进,从而利用这几层的协同配合实现对被杀死的应用程序的唤醒。具体的,在底层封装Linux文件锁(该文件锁是应用程序的进程的文件锁)以供应用层调用;在framework层创建监听程序,用于监听文件锁的状态;在app层,读取framework层的监听程序,通过文件锁的状态确定应用程序的进程是否存在,如果不存在,则可确定应用程序被杀死了,此时,启动唤醒应用程序的操作。
参见图1,为本发明提供的一种对终端的应用程序进行唤醒的方法。
本发明实施例中,主要使用framework层的本地(Native)进程的监听程 序来拉活应用程序。
本领域技术人员了解,Android系统使用的是Linux系统作为其内核来处理各种事件,而在Linux系统中则可以使用fork机制(fork机制用于创建子进程)来创建Native进程,并在Native进程中监控应用程序的进程的存活,当进程挂掉后,在Native进程中立即对进程进行拉活。而Linux的进程可以看做程序的一次执行过程。在Linux下,每个进程采用唯一的PID(port ID)标识进程。PID是一个从1到32768的正整数,其中1一般是特殊进程init,其它进程从2开始依次编号。当用完32768后,从2重新开始。而fork的作用是复制一个与当前进程一样的进程。新进程的所有数据(变量、环境变量、程序计数器等)数值都和原进程一致,但是是一个全新的进程,并作为原进程的子进程。
前面已经提到,Android是以Linux作为内核的操作系统。因此,在Linux上的一些操作,在Android上同样适用,而由于在Android中所有进程和系统组件的生命周期受ActivityManagerService(活动管理服务)的统一管理,并且,通过Linux的fork机制创建的进程为纯Linux进程,其生命周期不受Android的管理,因此可以通过使用Linux的fork机制来达到唤醒本应用的目的。
概括而言,本发明实施例为应用程序的进程(一般是指应用程序的主进程)创建文件锁。由于Android中的应用程序都运行于虚拟机之上,应用层的文件锁与底层的文件锁是不同的,要实现该功能需要封装Linux层的文件锁供应用层调用。而这种方式是被动的监听应用程序是否被杀,因此不存在任何耗电量,只要在应用程序被杀的情况下,该判断才会开始进行。
S101:为应用程序的进程创建文件锁,使得文件锁可在应用程序的进程中被执行。
具体的,为应用程序的进程创建文件锁包括:获取应用程序的进程标识;根据进程标识,获取应用程序的进程的当前文件锁状态;根据Linux操作命令,对应用程序的进程执行文件锁操作。
下面以一个示例进行说明。
例如,封装使用c语言来实现,通过Linux自带的文件锁来给文件加锁,并返回文件锁的状态值,成功为0,失败为-1,-2,-3。
首先会获取应用程序的进程号(PID)作为判断的对象,首先会判断该进程操作的文件是否存在,判断只需要将进程ID传入即可,如果不存在,则判断该进程无效,返回-1,如果存在则继续执行。
其次,由于需要使用flock(锁)命令来锁文件,因此进程使用flock尝试锁文件时,如果文件已经被其他进程锁住,进程会被阻塞直到锁被释放掉,或 者在调用flock时,采用LOCKNB参数,在尝试锁住该文件的时候,发现已经被其他服务锁住,会返回错误,此时文件锁状态值为-1。例如,使用linux的open命令,将进程号传入,可以得到int型的返回值,根据上述判断,只要等于-1时,则判断该文件已经被锁。因此,只要返回-1则返回错误码-2给App层,如果不等于-1,则开始进行操作。在执行完操作后,需要执行close关闭。
最后,进行文件锁操作。通过之前的判断,已经完成了文件锁的前期相关的判断,最后这一步就是开始加文件锁,使用linux的flock来添加文件锁,同样也是得到返回值,如果返回的值为-1,则判定添加文件锁失败,返回-3,如果返回值不是-1,则判定文件锁添加成功,返回0。
经过上述操作,可以使应用程序的进程使用文件锁,并在后续监听应用程序的进程当前是否存在(步骤S102),因为如果文件锁存在,并可以执行文件锁,则通过返回值为0断定该进程已经存在。如果出现其中文件锁状态值为-1或-2,则判定进程不存在,当返回值为-3时,则判断之前已经执行过文件锁。
S102:为应用程序创建监听程序,通过运行监听程序监听文件锁的状态。
在步骤S101完成后,需要调用文件锁到应用层。概括而言,是在框架层定义监听程序,并在应用层通过调用该监听程序获取文件锁状态,从而达到调用文件锁到应用层的目的。
例如,在框架层使用C语言,创建一个监听程序,该监听程序就是不断的监听文件锁的状态,来达到判断应用程序的进程是否存在的目的。由于监听程序是一个单独的程序,因此它不影响其应用程序的进程(主进程)的运行。例如,将上述监听程序的代码放到一个单独监听程序中执行,作为观察者来查看应用程序的进程是否存在。
S103:通过监听到的文件锁的状态,判断文件锁是否被执行。
具体的,获取监听到的文件锁的状态值,通过状态值预先定义的含义,判断文件锁是否被执行。
例如,当监听到返回的文件锁状态值为0,-2时,则确定应用程序正在正常执行,不作处理,依旧正常循环执行。当判断返回值为-1,-3时,则断定应用程序可能已经被杀,这时就需要唤醒应用程序的进程。
S104:当文件锁没有被执行时,确定应用程序的进程不存在,则启动唤醒应用程序的操作。
例如,唤醒的方法是通过Native进程拉活应用程序的进程,即通过am命令进行拉活。通过指定“-include-stopped-packages”参数来拉活进程处于forestop状态。
一个示例如下为:通过c语言的execlp来执行上述命令,执行格式如下:
int ret=execlp(“am”,”am”,”startservice”,”--user”,mSerial,”-n”,pkg,”-include-stopped-packages”,”NULL”);
上述命令会将该应用程序的包名传入,该包名为应用程序的唯一标示符。通过上述命令,在监听到应用程序的进程被杀后将可以重新启动进程,保证进程的活跃。
在一个优选的实施例中,需要保证监听程序的唯一性。由于监听程序需要不断调用应用程序以确定是否存在,因此,监听程序只能有一个,而从可扩展性和进程唯一等多方面考虑,将监听程序与主进程设计成C/S结构模式,主进程与监听程序通过Localsocket进行通信。在监听程序中利用Localsocket保证监听程序的唯一性,不至于出现创建多个监听程序以及监听程序变成无效进程等问题。实现方式是使用一个计数器来记录本地开启的数量,如果数量大于或者等于1,则不执行,如果小于1,则开启监听程序。
在另一个优选的实施例中,在框架层定义可供应用层调用监听程序的监听程序调用接口;应用层通过调用监听程序调用接口读取监听程序,从而获取到监听程序监听到的文件锁的状态。例如,使用Android提供的NDK编程,将C语言文件编译成so(shared object)文件,该目的是为了使Android应用程序可以调用已经编好的监听程序。
将C语言程序变成应用层可以执行的程序,其实现步骤示例为:
1)在Java中声明native()方法,然后编译,编译使用上述的NDK进行;
2)用javah产生一个.h文件;
3)定义一个.cpp文件实现native导出方法,其中需要包含第二步产生的.h文件(注意其中又包含了JDK带的jni.h文件);
4)将第3步的.cpp文件编译成动态链接库文件;
5)在Java中用System.loadLibrary()方法加载第4步产生的动态链接库文件,这个native()方法就可以在Java中被访问了。
在执行完上述的编译后,在应用程序每次启动时,将同时调用已经编译生成的监听程序。这样,每次应用程序启动时,就会开始执行监听程序,由于启动的监听程序是native的独立进程,因此启动后将与应用程序本身无关,当应用程序被杀后,启动的独立监听程序就可以检测到,从而重新开始启动应用程序,由此保证应用程序在被杀后将可以重新被唤醒。
与上述方法实施例相对应,本发明还提供一种对终端的应用程序进行唤醒的装置,该装置可以是终端本身,也可以是终端内的功能模块,可以通过硬件、软件或软硬件结合的方式实现。本发明实施例中提到的终端包括手机、PC机、 PAD等终端。
该装置包括:
文件锁创建单元201,用于为所述应用程序的进程创建文件锁,使得所述文件锁可在所述应用程序的进程中被执行;
监听程序创建单元202,用于为所述应用程序创建监听程序,通过运行所述监听程序监听所述文件锁的状态;
监听结果判断单元203,用于通过监听到的文件锁的状态,判断所述文件锁是否被执行;
唤醒执行单元204,用于当所述文件锁没有被执行时,确定所述应用程序的进程不存在,则启动唤醒所述应用程序的操作。
优选的,所述文件锁创建单元201具体用于:获取所述应用程序的进程标识;根据所述进程标识,获取所述应用程序的进程的当前文件锁状态;以及,根据Linux操作命令,对所述应用程序的进程执行文件锁操作。
优选的,所述监听结果判断单元203具体用于:获取监听到的文件锁的状态值,通过所述状态值预先定义的含义,判断所述文件锁是否被执行。
优选的,所述装置还包括:监听程序唯一控制单元205,用于通过一个计数器计算开启的监听程序的数量,从而确保开启的监听程序是唯一的。
优选的,所述终端的操作系统包括底层、框架层和应用层,在所述框架层为所述应用程序创建所述监听程序,所述装置还包括:监听程序调用接口设置单元206,用于在所述框架层定义可供所述应用层调用所述监听程序的监听程序调用接口;其中,所述应用层通过调用所述监听程序调用接口读取所述监听程序,从而获取到所述监听程序监听到的所述文件锁的状态。
在此提供的算法和显示不与任何特定计算机、虚拟系统或者其它设备固有相关。各种通用系统也可以与基于在此的示教一起使用。根据上面的描述,构造这类系统所要求的结构是显而易见的。此外,本发明也不针对任何特定编程语言。应当明白,可以利用各种编程语言实现在此描述的本发明的内容,并且上面对特定语言所做的描述是为了披露本发明的最佳实施方式。
本发明的各个部件实施例可以以硬件实现,或者以在一个或者多个处理器上运行的软件模块实现,或者以它们的组合实现。本领域的技术人员应当理解,可以在实践中使用微处理器或者数字信号处理器(DSP)来实现根据本发明实施例的用户变身控制的系统中的一些或者全部部件的一些或者全部功能。本发明还可以实现为用于执行这里所描述的方法的一部分或者全部的设备或者装置程序(例如,计算机程序和计算机程序产品)。这样的实现本发明的程序可以存储在计算机可读介质上,或者可以具有一个或者多个信号的形式。这样的 信号可以从因特网网站上下载得到,或者在载体信号上提供,或者以任何其他形式提供。
应该注意的是上述实施例对本发明进行说明而不是对本发明进行限制,并且本领域技术人员在不脱离所附权利要求的范围的情况下可设计出替换实施例。在权利要求中,不应将位于括号之间的任何参考符号构造成对权利要求的限制。单词“包含”不排除存在未列在权利要求中的元件或步骤。位于元件之前的单词“一”或“一个”不排除存在多个这样的元件。本发明可以借助于包括有若干不同元件的硬件以及借助于适当编程的计算机来实现。在列举了若干装置的单元权利要求中,这些装置中的若干个可以是通过同一个硬件项来具体体现。单词第一、第二、以及第三等的使用不表示任何顺序。可将这些单词解释为名称。

Claims (10)

  1. 一种对终端的应用程序进行唤醒的方法,其特征在于,包括:
    为所述应用程序的进程创建文件锁,使得所述文件锁可在所述应用程序的进程中被执行;
    为所述应用程序创建监听程序,通过运行所述监听程序监听所述文件锁的状态;
    通过监听到的文件锁的状态,判断所述文件锁是否被执行;
    当所述文件锁没有被执行时,确定所述应用程序的进程不存在,则启动唤醒所述应用程序的操作。
  2. 如权利要求1所述的方法,其特征在于,所述为所述应用程序的进程创建文件锁包括:
    获取所述应用程序的进程标识;
    根据所述进程标识,获取所述应用程序的进程的当前文件锁状态;
    根据Linux操作命令,对所述应用程序的进程执行文件锁操作。
  3. 如权利要求1所述的方法,其特征在于,所述通过监听到的文件锁的状态,判断所述文件锁是否被执行,包括:
    获取监听到的文件锁的状态值,
    通过所述状态值预先定义的含义,判断所述文件锁是否被执行。
  4. 如权利要求1、2或3所述的方法,其特征在于,所述方法还包括:
    通过计数器计算开启的监听程序的数量,从而确保开启的监听程序是唯一的。
  5. 如权利要求4所述的方法,其特征在于,所述终端的操作系统包括底层、框架层和应用层,在所述框架层为所述应用程序创建所述监听程序,所述方法还包括:
    在所述框架层定义供所述应用层调用所述监听程序的监听程序调用接口;
    所述应用层通过调用所述监听程序调用接口读取所述监听程序,从而获取到所述监听程序监听到的所述文件锁的状态。
  6. 一种对终端的应用程序进行唤醒的装置,其特征在于,包括:
    文件锁创建单元,用于为所述应用程序的进程创建文件锁,使得所述文件锁可在所述应用程序的进程中被执行;
    监听程序创建单元,用于为所述应用程序创建监听程序,通过运行所述监听程序监听所述文件锁的状态;
    监听结果判断单元,用于通过监听到的文件锁的状态,判断所述文件锁是否被执行;
    唤醒执行单元,用于当所述文件锁没有被执行时,确定所述应用程序的进程不存在,则启动唤醒所述应用程序的操作。
  7. 如权利要求6所述的装置,其特征在于,所述文件锁创建单元具体用于:获取所述应用程序的进程标识;根据所述进程标识,获取所述应用程序的进程的当前文件锁状态;以及,根据Linux操作命令,对所述应用程序的进程执行文件锁操作。
  8. 如权利要求6所述的装置,其特征在于,所述监听结果判断单元具体用于:获取监听到的文件锁的状态值,通过所述状态值预先定义的含义,判断所述文件锁是否被执行。
  9. 如权利要求6、7或8所述的装置,其特征在于,所述装置还包括:
    监听程序唯一控制单元,用于通过计数器计算开启的监听程序的数量,从而确保开启的监听程序是唯一的。
  10. 如权利要求9所述的装置,其特征在于,所述终端的操作系统包括底层、框架层和应用层,在所述框架层为所述应用程序创建所述监听程序,所述装置还包括:
    监听程序调用接口设置单元,用于在所述框架层定义供所述应用层调用所述监听程序的监听程序调用接口;其中,所述应用层通过调用所述监听程序调用接口读取所述监听程序,从而获取到所述监听程序监听到的所述文件锁的状态。
PCT/CN2017/075722 2016-11-24 2017-03-06 对终端的应用程序进行唤醒的方法及装置 WO2018094908A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201611058671.9A CN106775652A (zh) 2016-11-24 2016-11-24 对终端的应用程序进行唤醒的方法及装置
CN201611058671.9 2016-11-24

Publications (1)

Publication Number Publication Date
WO2018094908A1 true WO2018094908A1 (zh) 2018-05-31

Family

ID=58912652

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2017/075722 WO2018094908A1 (zh) 2016-11-24 2017-03-06 对终端的应用程序进行唤醒的方法及装置

Country Status (2)

Country Link
CN (1) CN106775652A (zh)
WO (1) WO2018094908A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113406696A (zh) * 2021-06-01 2021-09-17 成都高新减灾研究所 实现移动设备地震监测的方法及设备

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108459901B (zh) * 2018-01-24 2019-04-23 深圳市普威技术有限公司 一种进程锁的处理方法、装置及系统
CN108845875B (zh) * 2018-07-09 2021-02-02 北京顺丰同城科技有限公司 一种常驻进程保活系统以及方法
CN109189562B (zh) * 2018-08-09 2021-08-20 麒麟合盛网络技术股份有限公司 控制进程运行的方法和装置
CN113760492A (zh) * 2020-11-04 2021-12-07 北京沃东天骏信息技术有限公司 一种程序进程保活方法、系统、装置、设备以及存储介质

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103092691A (zh) * 2013-01-23 2013-05-08 广东欧珀移动通信有限公司 一种安卓系统的进程管理方法和管理单元
CN105159823A (zh) * 2015-08-07 2015-12-16 北京元心科技有限公司 应用程序的存活状态管理方法以及智能终端
CN105335171A (zh) * 2014-06-24 2016-02-17 北京奇虎科技有限公司 应用程序常驻操作系统后台的方法及装置
CN105893066A (zh) * 2014-12-19 2016-08-24 上海涌杰信息科技有限公司 一种基于安卓系统的移动终端恢复的控制方法

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7661115B2 (en) * 2006-01-30 2010-02-09 International Business Machines Corporation Method, apparatus and program storage device for preserving locked pages in memory when in user mode

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103092691A (zh) * 2013-01-23 2013-05-08 广东欧珀移动通信有限公司 一种安卓系统的进程管理方法和管理单元
CN105335171A (zh) * 2014-06-24 2016-02-17 北京奇虎科技有限公司 应用程序常驻操作系统后台的方法及装置
CN105893066A (zh) * 2014-12-19 2016-08-24 上海涌杰信息科技有限公司 一种基于安卓系统的移动终端恢复的控制方法
CN105159823A (zh) * 2015-08-07 2015-12-16 北京元心科技有限公司 应用程序的存活状态管理方法以及智能终端

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
"The Wheels of Chance, various ways to keep android process alive (non-official translation)", 14 August 2016 (2016-08-14), Retrieved from the Internet <URL:http://www.360doc.com/content/16/0814/10/11991_58311328.shtml> *
"Various ways to keep android alive 1 (non-official translation)", 30 August 2016 (2016-08-30), Retrieved from the Internet <URL:http://blog.csdn.net/zhangweiwtmdbf/article/details/52369276> *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113406696A (zh) * 2021-06-01 2021-09-17 成都高新减灾研究所 实现移动设备地震监测的方法及设备

Also Published As

Publication number Publication date
CN106775652A (zh) 2017-05-31

Similar Documents

Publication Publication Date Title
WO2018094908A1 (zh) 对终端的应用程序进行唤醒的方法及装置
US10402239B2 (en) Method of hosting a first application in a second application
TWI587219B (zh) 持續及有彈性之工作處理
CN106648863B (zh) 一种安卓应用安装包、应用目标进程保活方法及系统
US8893222B2 (en) Security system and method for the android operating system
CN106648855B (zh) 对终端的应用程序进行控制的方法及装置
CN102866903B (zh) 将后台工作和前台工作解耦合
CN107678782B (zh) 一种进程保护方法、装置、设备以及计算机可读存储介质
JP2013543627A (ja) オペレーティングシステム(os)不在サービス環境においてファームウェアをプロビジョニングする方法
EP3516850B1 (en) Systems and methods for sharing application data between isolated applications executing on one or more application platforms
US8539506B2 (en) Dynamic injection of code into running process
CN109716736B (zh) 应用数据共享和决策服务平台
US8453013B1 (en) System-hang recovery mechanisms for distributed systems
KR20140127341A (ko) 휴대용 컴퓨팅 디바이스에서 요청들을 스케쥴링하기 위한 방법 및 시스템
CN110750315B (zh) Android系统中的类加载方法、装置、设备和存储介质
US9652223B2 (en) Method and apparatus for executing integrated application program
JP6088531B2 (ja) ローカルサーバーを通じたローカルクライアントアプリケーションのためのイベントサービス
CN101794243A (zh) 一种利用操作系统结构化异常处理加固java应用程序的方法
US20180061361A1 (en) Managing display setting based on motion sensor activity for universal platform applications
Feitosa et al. Patterns and Energy Consumption: Design, Implementation, Studies, and Stories
CN115509531A (zh) 基于前端技术的微前端实现方法、装置、终端及存储介质
CN106445595B (zh) 插件的Application对象的构建方法及装置
CN110704247B (zh) 应用内存异常的处理方法、装置、电子设备及装置
WO2024037553A1 (zh) 一种生命周期调度的方法、装置及电子设备
US11983190B2 (en) System and method for configurable and automated data extraction, formatting and distribution

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 17873927

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 17873927

Country of ref document: EP

Kind code of ref document: A1