A multi-process foreground and background detection method based on an Android system

By creating a remote service (Service) in the Android system and collecting page counts of processes in real time, the problem of inaccurate detection of multiple foreground and background processes in existing technologies is solved, and privacy-compliant detection of multiple foreground and background processes is achieved.

CN115454777BActive Publication Date: 2025-12-09SICHUAN XW BANK CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211164680.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-23
Publication Date
2025-12-09
Estimated Expiration
2042-09-23

AI Technical Summary

Technical Problem

In existing technologies, obtaining a process list through ActivityManager cannot meet privacy compliance requirements, and it cannot accurately detect the foreground and background status in a multi-process environment, especially the foreground and background status of a single process.

Method used

Create a remote service to collect page counts of the process, and collect the number of displayed and hidden pages of the process in real time by showing and hiding page count objects. Bind the process to the remote service and synchronize the count values ​​for foreground and background detection.

Benefits of technology

It enables foreground and background detection of multiple processes in the Android system, meets privacy compliance requirements, does not require scanning all processes, avoids permission requests, and provides stable and latency-free detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115454777B_ABST
    Figure CN115454777B_ABST
Patent Text Reader

Abstract

The application discloses a multi-process foreground and background detection method based on an Android system, which is used for detecting the foreground and background of processes in the Android system and comprises the following steps: creating a remote service Service, the remote service Service is used for collecting the page count of the processes; when the processes are created, the processes are bound with the remote service Service, and each process has a corresponding page count in the remote service Service; the display page count cumulative value and the hidden page count cumulative value of the processes are synchronized to the page count of the remote service Service, and the foreground and background of each process are detected according to the page count, so that the foreground and background detection of the multi-processes is completed. The application realizes the foreground and background detection of the multi-processes, does not need to scan all the processes, and does not need to apply for permission, so that the problem that the system cannot be detected due to the unopened permission is avoided, and the privacy compliance is met.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application belongs to the field of data processing, and particularly relates to a multi-process foreground and background detection method based on an Android system. BACKGROUND

[0002] In the prior art, an ActivityManager is often used to obtain a running process list, and then it is judged whether a process package name is running in the foreground. This method cannot meet privacy compliance because it needs to scan all processes in the system, and it cannot perfectly detect the foreground and background when there are multiple processes, for example, when an application has multiple processes, the method can only detect whether the application is in the foreground, but cannot detect whether an individual process is in the foreground. SUMMARY

[0003] The application aims to provide a multi-process foreground and background detection method based on an Android system, and solves the problem that the prior art needs to scan all processes and cannot detect multiple processes.

[0004] The application is achieved through the following counting scheme:

[0005] A multi-process foreground and background detection method based on an Android system is used to detect the foreground and background of a process in the Android system, and comprises the following steps:

[0006] A remote service Service is created, and the remote service Service is used to collect the page count of a process;

[0007] When a process is created, the process is bound to the remote service Service, and each process has a corresponding page count in the remote service Service;

[0008] The display page count cumulative value and the hidden page count cumulative value of the process are synchronized to the page count of the remote service Service, and the foreground and background of each process are detected according to the page count, so that the foreground and background of multiple processes are detected.

[0009] In a possible implementation, the remote service Service is created, and comprises the following steps:

[0010] The remote service Service is created to contain a display page count object onActivityStarted and a hidden page count object onActivityStopped, the display page count object onActivityStarted is used to collect the display page count cumulative value of a process, and the hidden page count object onActivityStopped is used to collect the hidden page count cumulative value of the process.

[0011] In a possible implementation, the page count of the process is initialized as 0;

[0012] When the display page count object onActivityStarted collects the cumulative value of the display page count of the process, the count value of the page count is added to the cumulative value of the display page count to obtain a first addition result, and the first addition result is taken as a new page count;

[0013] When the hidden page count object onActivityStopped collects the cumulative value of the hidden page count of the process, the count value of the page count is added to the cumulative value of the hidden page count to obtain a second addition result, and the second addition result is taken as a new page count.

[0014] In a possible implementation, when the process is created, the process is bound to the remote service Service, including:

[0015] When the process is created, the communication between the process and the remote service Service is established, and the corresponding display page count object onActivityStarted, the hidden page count object onActivityStopped and the page count of the process are created through the remote service Service, so as to complete the binding of the process to the remote service Service.

[0016] In a possible implementation, the communication between the process and the remote service Service is established, including:

[0017] The Stub class between the process and the remote service Service is created through the binder object, so as to realize the communication between the process and the remote service Service.

[0018] In a possible implementation, before the process is bound to the remote service Service, further including:

[0019] A local page lifecycle statistics class ActivityLifecycleCallbacks is created;

[0020] Before the process is not bound to the remote service Service, the page lifecycle statistics class ActivityLifecycleCallbacks collects the cumulative value of the display page count of the process and collects the cumulative value of the hidden page count of the process;

[0021] When the process is bound to the remote service Service, the display page count cumulative value of the process in the page lifecycle statistics class ActivityLifecycleCallbacks and the hidden page count cumulative value of the process are synchronized to the remote service Service.

[0022] In a possible implementation, synchronizing the display page count cumulative value and the hidden page count cumulative value of the process to the page count of the remote service Service includes:

[0023] The display page count object onActivityStarted and the hidden page count object onActivityStopped in the remote service Service are called by the process.

[0024] The display page count cumulative value of the process is collected in real time by the display page count object onActivityStarted, and the hidden page count cumulative value of the process is collected in real time by the hidden page count object onActivityStopped.

[0025] The page count of the remote service Service is synchronized according to the display page count cumulative value and the hidden page count cumulative value collected in real time.

[0026] In a possible implementation, synchronizing the page count of the remote service Service according to the display page count cumulative value and the hidden page count cumulative value collected in real time includes:

[0027] The page count is added to the display page count cumulative value collected in real time and subtracted from the hidden page count cumulative value collected in real time to obtain a subtraction result, and the subtraction result is taken as a new page count.

[0028] In a possible implementation, the foreground and background of each process are detected according to the page count, including:

[0029] The foreground and background of each process are detected according to the page count and a foreground and background determination condition.

[0030] In a possible implementation, the foreground and background determination condition includes: when the page count is 1, it is determined that the corresponding process is in the foreground; and when the page count is 0, it is determined that the corresponding process is in the background.

[0031] The application embodiment provides a multi-process foreground and background detection method based on an Android system. BRIEF DESCRIPTION OF DRAWINGS

[0032] In order to more clearly illustrate the technical solutions of the exemplary embodiments of the present application, the drawings needed in the embodiments will be briefly introduced as follows, and it should be understood that the following drawings only show some embodiments of the present application, and therefore should not be regarded as a limitation on the scope, and for those skilled in the art, other related drawings can also be obtained without creative labor on the basis of these drawings. In the drawings:

[0033] Figure 1 The flow chart of the multi-process foreground and background detection method based on the Android system provided by the application embodiment.

[0034] Figure 2 The structural schematic diagram of the multi-process foreground and background detection device based on the Android system provided by the application embodiment.

[0035] Figure 3 The structural schematic diagram of the multi-process foreground and background detection device based on the Android system provided by the application embodiment.

[0036] Markings in the drawings and corresponding component names:

[0037] 21-counting module, 22-communication connection module, 23-foreground and background detection module, 31-memory, 32-processor, 33-bus. DETAILED DESCRIPTION

[0038] In order to make the purpose, technical solutions and advantages of the present application more clear and obvious, the present application will be further described in detail below in combination with the embodiments and drawings, and the exemplary embodiments of the present application and their descriptions are only used to explain the present application, and not as a limitation on the present application.

[0039] Embodiment 1

[0040] As shown in the Figure 1 application provides a multi-process foreground and background detection method based on an Android system, which is used for detecting the foreground and background of processes in the Android system, and includes:

[0041] S11, a remote service Service is created, and the remote service Service is used to collect the page count of a process.

[0042] The remote service Service is essentially a resident process that has been running, and the remote service Service is used to collect the page notification of the process or the sub-process corresponding to other APPs, so as to realize the collection of the page count of the process. For example, the display page count cumulative value and the hidden page count cumulative value of the process can be collected through the remote service Service, and then the page count is obtained according to the display page count cumulative value and the hidden page count cumulative value, so as to obtain the count data of the foreground and background detection.

[0043] S12, when the process is created, the process is bound to the remote service Service, and each process has a corresponding page count in the remote service Service.

[0044] The process can be bound to the remote service Service by establishing the communication between the remote service Service and the process, so that the remote service Service can collect the display page count cumulative value and the hidden page count cumulative value of the process. For example, the aidl file IForegroundDetectService.aidl of the foreground and background detection can be created, and the aidl file includes the display page count object onActivityStarted and the hidden page count object onActivityStopped.

[0045] The display page count object onActivityStarted can collect the display page count cumulative value of the current process without sending the notification, and the hidden page count object onActivityStopped can collect the hidden page count cumulative value of the current process without sending the notification.

[0046] S13, the display page count cumulative value and the hidden page count cumulative value of the process are synchronized to the page count of the remote service Service, and the foreground and background detection of each process is performed according to the page count, so as to complete the foreground and background detection of the multiple processes.

[0047] The multiple process foreground and background detection method based on the Android system provided by the embodiment of the application realizes the foreground and background detection of the multiple processes by constructing the remote service specially detecting the foreground and background of the process, and configuring the corresponding page count for each process, and detecting the foreground and background of the process according to the page technology, and does not need to scan all the processes and does not need to apply for the permission, so as to avoid the problem that the system cannot be detected due to the unopened permission, and meet the privacy compliance.

[0048] In a possible implementation, the remote service Service is created, including: creating the remote service Service including a display page count object onActivityStarted and a hidden page count object onActivityStopped, the display page count object onActivityStarted is used to collect the cumulative value of the display page number of the process, and the hidden page count object onActivityStopped is used to collect the cumulative value of the hidden page number of the process.

[0049] In a possible implementation, the page count of the process is initialized to 0; after the display page count object onActivityStarted collects the cumulative value of the display page number of the process, the count value of the page count is added to the cumulative value of the display page number to obtain a first addition result, and the first addition result is taken as a new page count; after the hidden page count object onActivityStopped collects the cumulative value of the hidden page number of the process, the count value of the page count is added to the cumulative value of the hidden page number to obtain a second addition result, and the second addition result is taken as a new page count.

[0050] The ForegroundDetectService is created to inherit the remote service Service of the system, and a page count count is maintained in the service to collect the total number of the currently displayed pages of each process. Then, an internal class is created to implement the Stub class produced by the system, and the display page count object onActivityStarted is implemented, that is, the page display number c1 called by each process needs to be updated, the current page count count is 0, and the callback is entered, which indicates that the application returns to the foreground, and the statistical count Count of the corresponding number c1 is increased. Similarly, the hidden page count object onActivityStopped is used to collect the value of the hidden page number c2, and only the corresponding c2 value is subtracted. If the page count count is reduced to 0, it is proved that the process returns to the background.

[0051] In a possible implementation, when the process is created, the process is bound to the remote service Service, including: when the process is created, the communication between the process and the remote service Service is established, and the corresponding display page count object onActivityStarted, hidden page count object onActivityStopped and page count of the process are created through the remote service Service, and the process is bound to the remote service Service.

[0052] In a possible implementation, the communication between the process and the remote service Service is established, including:

[0053] The Stub class between the process and the remote service Service is created through the binder object to realize the communication between the process and the remote service Service.

[0054] In a possible implementation, before the process is bound with the remote service Service, the method further includes: creating a local page lifecycle statistics class ActivityLifecycleCallbacks; collecting the cumulative value of the display page number of the process and collecting the cumulative value of the hidden page number of the process by the page lifecycle statistics class ActivityLifecycleCallbacks before the process is not bound with the remote service Service; and synchronizing the cumulative value of the display page number of the process and the cumulative value of the hidden page number of the process in the page lifecycle statistics class ActivityLifecycleCallbacks to the remote service Service after the process is bound with the remote service Service.

[0055] Before the communication between the process and the remote service Service is established, the cumulative value of the display page number of the process and the cumulative value of the hidden page number of the process can be collected by the local page lifecycle statistics class ActivityLifecycleCallbacks corresponding to the process, and after the communication is established, the data in the local page lifecycle statistics class ActivityLifecycleCallbacks is synchronized to the remote service Service, so as to ensure the accuracy of the page count.

[0056] If the process and the remote service Service have completed the binding, the display page count object onActivityStarted and the hidden page count object onActivityStopped are directly called to collect the cumulative value of the display page number of the process and the cumulative value of the hidden page number of the process, which is real-time response at this time. If the process and the remote service Service have not completed the binding, the display page count object onActivityStarted and the hidden page count object onActivityStopped are first used to maintain the cumulative value of the display page number of the process and the cumulative value of the hidden page number of the process to the count count2 in the local, and when the service binding is completed, if the count count2 is greater than 0, the display page count object onActivityStarted is called, the count count2 is synchronized to the remote service Service, and then the count count2 is set to 0; if the count count2 is less than or equal to 0, the hidden page count object onActivityStopped is called, the count count2 is synchronized to the remote service Service, and then the count count2 is set to 0.

[0057] In a possible implementation, synchronizing the display page count cumulative value and the hidden page count cumulative value of the process to the page count of the remote service Service includes:

[0058] The display page count object onActivityStarted and the hidden page count object onActivityStopped in the remote service Service are called by the process;

[0059] The display page count cumulative value of the process is collected in real time by the display page count object onActivityStarted, and the hidden page count cumulative value of the process is collected in real time by the hidden page count object onActivityStopped;

[0060] The page count of the remote service Service is synchronized according to the display page count cumulative value and the hidden page count cumulative value collected in real time.

[0061] In a possible implementation, the page count of the remote service Service is synchronized according to the display page count cumulative value and the hidden page count cumulative value collected in real time, including:

[0062] The page count is added to the display page count cumulative value collected in real time, and is subtracted from the hidden page count cumulative value collected in real time, to obtain a subtraction result, and the subtraction result is taken as a new page count.

[0063] In a possible implementation, the foreground and background of each process are detected according to the page count, including:

[0064] The foreground and background of each process are detected according to the page count and a foreground and background determination condition.

[0065] In a possible implementation, the foreground and background determination condition includes: when the page count is 1, it is determined that the corresponding process is in the foreground; and when the page count is 0, it is determined that the corresponding process is in the background.

[0066] In the App, the Application class of the system is implemented and is registered. In the onCreate callback of the Application, the bindService method of the system is called to bind the independent collection end process Service.

[0067] The application meets the privacy compliance requirements and multi-process foreground and background detection without permission, and has no requirement for system version, and almost no delay by using AIDL. At the same time, in order to avoid the page visible, the page process collects the count before the Service of foreground and background detection is bound, and updates when the Service of foreground and background detection is bound, so as to ensure the stable detection.

[0068] Embodiment 2

[0069] As shown in Figure 2 The application provides a multi-process foreground and background detection device based on an Android system, which is used for detecting the foreground and background of a process in the Android system, and includes a remote service creation module 21, a binding module 22 and a foreground and background detection module 23.

[0070] The remote service creation module 21 is used for creating a remote service Service, and the remote service Service is used for collecting the page count of the process.

[0071] The binding module 22 is used for binding the process with the remote service Service when the process is created, and each process has a corresponding page count in the remote service Service.

[0072] The foreground and background detection module 23 is used for synchronizing the display page count cumulative value and the hidden page count cumulative value of the process to the page count of the remote service Service, and performing foreground and background detection on each process according to the page count, so as to complete the foreground and background detection of the multi-process.

[0073] The multi-process foreground and background detection device based on the Android system provided in the embodiment can execute the method technical solution as described in Embodiment 1, and has similar principles and beneficial effects, which will not be repeated here.

[0074] Embodiment 3

[0075] As shown in Figure 3 The embodiment provides a multi-process foreground and background detection device based on an Android system, which includes a memory 31 and a processor 32, and the memory 31 and the processor 32 are connected with each other through a bus 33.

[0076] The memory 31 stores computer execution instructions.

[0077] The processor 32 executes the computer execution instructions stored in the memory, so that the processor executes the multi-process foreground and background detection method based on the Android system as described in Embodiment 1.

[0078] For example, the memory can include, but is not limited to, random access memory (RAM), read only memory (ROM), Flash memory, first input first output (FIFO) memory, first in last out (FILO) memory, and the like; specifically, the processor can include one or more processing cores, such as a 4-core processor, an 8-core processor, and the like. The processor can be implemented in at least one of a hardware form of a DSP (Digital Signal Processing), an FPGA (Field-Programmable Gate Array), a PLA (Programmable Logic Array), and the like, and the processor can also include a main processor and a co-processor. The main processor is a processor for processing data in an awake state, also known as a CPU (Central Processing Unit); the co-processor is a low-power processor for processing data in a standby state.

[0079] In some embodiments, the processor can be integrated with a GPU (Graphics Processing Unit) for rendering and drawing the content required to be displayed on the display screen. For example, the processor can be, but is not limited to, a microprocessor of the STM32F105 series, a RISC (reduced instruction set computer) microprocessor, an X86 architecture processor, or a processor integrated with an embedded neural network processing unit (NPU); the transceiver can be, but is not limited to, a WIFI wireless transceiver, a Bluetooth wireless transceiver, a GPRS (General Packet Radio Service) wireless transceiver, a ZigBee wireless transceiver, a 3G transceiver, a 4G transceiver, and / or a 5G transceiver, and the like. In addition, the device can also include, but is not limited to, a power module, a display screen, and other necessary components.

[0080] Embodiment 4

[0081] The embodiment provides a computer readable storage medium, and the computer readable storage medium stores computer execution instructions, which are used for realizing the multi-process foreground and background detection method based on an Android system when the computer execution instructions are executed by a processor.

[0082] Embodiment 5

[0083] The embodiment of the application can also provide a computer program product, comprising a computer program, which realizes the multi-process foreground and background detection method based on an Android system when the computer program is executed by a processor.

[0084] The above detailed description is further used for explaining the purpose, technical scheme and beneficial effects of the application, and it should be understood that the above description is only the specific embodiment of the application and is not used for limiting the protection scope of the application, and any modification, equivalent replacement, improvement and the like within the spirit and principle of the application should be included in the protection scope of the application.

Claims

1.A method for detecting foreground and background of processes in an Android system based on a multi-process Android system, for detecting foreground and background of processes in the Android system, characterized in that, The application comprises: a remote service Service including a display page count object onActivityStarted for collecting the cumulative value of the display page number of a process and a hidden page count object onActivityStopped for collecting the cumulative value of the hidden page number of the process; binding the process with the remote service Service when the process is created, and each process has a corresponding page count in the remote service Service; synchronizing the cumulative value of the display page number and the cumulative value of the hidden page number of the process to the page count of the remote service Service, and detecting the foreground and background of each process according to the page count, thereby completing the foreground and background detection of the multi-process. 2.The Android system-based multi-process foreground and background detection method of claim 1, wherein, The page count of the process is initialized as 0; after the display page count object onActivityStarted collects the cumulative value of the display page number of the process, adding the count value of the page count to the cumulative value of the display page number to obtain a first addition result, and taking the first addition result as the new page count; after the hidden page count object onActivityStopped collects the cumulative value of the hidden page number of the process, adding the count value of the page count to the cumulative value of the hidden page number to obtain a second addition result, and taking the second addition result as the new page count. 3.The method of claim 1, wherein, binding the process with the remote service Service when the process is created, comprising: establishing the communication between the process and the remote service Service when the process is created, and creating the corresponding display page count object onActivityStarted, hidden page count object onActivityStopped and page count for the process through the remote service Service, thereby completing the binding of the process with the remote service Service. 4.The method of claim 3, wherein, establishing the communication between the process and the remote service Service, comprising: creating the Stub class between the process and the remote service Service through the binder object to realize the communication between the process and the remote service Service. 5.The method of claim 1, wherein, before binding the process with the remote service Service, further comprising: creating a local page lifecycle statistics class ActivityLifecycleCallbacks; before the process is not bound with the remote service Service, the page lifecycle statistics class ActivityLifecycleCallbacks collecting the cumulative value of the display page number of the process and the cumulative value of the hidden page number of the process; after the process is bound with the remote service Service, synchronizing the cumulative value of the display page number of the process and the cumulative value of the hidden page number of the process in the page lifecycle statistics class ActivityLifecycleCallbacks to the remote service Service. 6.The Android system-based multi-process foreground and background detection method of claim 2, wherein, Synchronizing the display page count cumulative value and the hidden page count cumulative value of the process to the page count of the remote service Service, comprising: Calling the display page count object onActivityStarted and the hidden page count object onActivityStopped in the remote service Service through the process; Collecting the display page count cumulative value of the process in real time through the display page count object onActivityStarted and collecting the hidden page count cumulative value of the process in real time through the hidden page count object onActivityStopped; Synchronizing the page count of the remote service Service according to the display page count cumulative value and the hidden page count cumulative value collected in real time. 7.The method of claim 6, wherein, Synchronizing the page count of the remote service Service according to the display page count cumulative value and the hidden page count cumulative value collected in real time, comprising: Adding the page count to the display page count cumulative value collected in real time and subtracting the hidden page count cumulative value collected in real time to obtain a subtraction result, and taking the subtraction result as a new page count. 8.The method of claim 7, wherein, Detecting the foreground and background of each process according to the page count, comprising: Detecting the foreground and background of each process according to the page count by using a foreground and background determination condition. 9.The method of claim 8, wherein, The foreground and background determination condition comprises: when the page count is 1, it is determined that the corresponding process is in the foreground; and when the page count is 0, it is determined that the corresponding process is in the background.

Citation Information

Patent Citations

  • Universal method for monitoring Android foreground and Android background

    CN108153646A

  • Judgment method and device for foreground and background states of application program, and electronic equipment

    CN111382025A