Method and system for monitoring use time of Android application equipment
By creating a system-level accessibility service in Android devices, listening to window state changes and combining it with screen-off and screen-on broadcasts, the problem of application usage time statistics when the system clock synchronization of Android terminal devices is inaccurate is solved, and more accurate user behavior analysis and visualization reports are achieved.
Patent Information
- Application Number
- CN202510866207.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-26
- Publication Date
- 2025-10-31
AI Technical Summary
In existing technologies, when the system clock of an Android terminal device is not synchronized in a timely manner, the application usage time data will be biased, making it impossible to effectively monitor the foreground application and count its usage time through the accessibility service in Android services.
By creating a system-level accessibility service, we can monitor window state changes, maintain package name and time variables, filter abnormal window events, and automatically record application usage time by combining screen-off and screen-on broadcasts, and store the data locally and in the cloud.
It improves statistical accuracy in complex scenarios, resolves errors in duration statistics during screen-off periods, and is suitable for user digital behavior analysis, generating visual reports.
Smart Images

Figure CN120872753A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of Android application development technology, specifically to a method and system for monitoring Android application device usage time. Background Technology
[0002] Administrators of some Android devices need to obtain data on the application usage time of the device. Developers usually collect and count data based on the system clock, but when the system clock is not synchronized in time, it will cause data deviation.
[0003] The technical problem that needs to be solved is how to monitor foreground applications and collect usage time data for each application through the accessibility service in Android services. Summary of the Invention
[0004] The technical objective of this invention is to address the above-mentioned shortcomings by providing a method and system for monitoring Android application device usage time, thereby solving the technical problem of how to monitor foreground applications and collect usage time data for each application through accessibility services in Android services.
[0005] In a first aspect, the present invention provides a method for monitoring application usage time on an Android device, comprising the following steps:
[0006] Service creation: Create a system-level accessibility service, register window listener events for listening to window state changes in the accessibility service configuration file, and maintain two member variables, one of which is a package name variable that records the current foreground application package name, and the other is a time variable that records the time of the most recent event trigger.
[0007] Window switching event handling: When the accessibility service detects a change in window state, extract the package name of the application to which the new window belongs. If the package name of the new window changes relative to the package name variable, calculate the continuous foreground runtime of the previous application, generate a data record as the application exit record, update the member variable, and generate a data record of the new package as the application startup record.
[0008] Multi-layer filtering: When a window switching event is triggered, the new window is filtered through a pre-configured multi-layer filtering mechanism. If the new window is blocked, no data record is generated. If the new window passes the filter, the window switching event processing flow continues.
[0009] Screen off and screen on broadcast monitoring: Listen for screen off and screen on broadcasts on Android devices. When an Android device enters screen off state, calculate the continuous usage time of the current foreground application and generate data records as application exit records. When an Android device enters screen on state, generate data records as application launch records.
[0010] Data recording and storage: Store the data records generated during window switching event handling and screen-off / screen-on broadcast listening to the local machine, and upload the locally stored data records to the cloud.
[0011] As a preferred option, the following steps should be performed when creating the service:
[0012] Create a new service class in your Android application project that inherits from the AccessibilityService class.
[0013] Register the window listener event TYPE_WINDOW_STATE_CHANGED in the accessibility service configuration file;
[0014] The service class maintains two member variables: one is the package name variable mForegroundPackageName, which records the package name of the current foreground application; the other is the time variable mRecordTime, which records the time of the most recent event trigger.
[0015] Correspondingly, window switching event handling includes the following operations:
[0016] In the onAccessibilityEvent() callback, when a window listener event is detected, the package name of the application to which the new window belongs is extracted;
[0017] Compare the package name in the new window with the package name variable; if there is a change, obtain the current system runtime.
[0018] Calculate the duration of the previous application's continuous foreground runtime, generate a data record as the application exit record; update the package name variable to the new window's package name, update the time variable to the current time, and generate a data record as the application startup record.
[0019] Preferably, the application exit record generated during the window switching event handling process includes a timestamp, package name, event type, and the duration of the previous application's continuous foreground runtime. The event type in the application exit record is "application exit". The application startup record generated during the window switching event handling process includes a timestamp, new package name, and event type. The event type in the application startup record is "application startup".
[0020] The application exit record generated during the screen-off and screen-on broadcast listening process includes a timestamp, package name, event type, and the duration of continuous use of the current foreground application. The event type in the application exit record is "application exit". The application startup record generated during the screen-off and screen-on broadcast listening process includes a timestamp, new package name, and event type. The event type in the application startup record is "application startup".
[0021] Preferably, the new window is filtered through a pre-configured multi-layer filtering mechanism, including the following operations:
[0022] Input method window filtering: Check if the package name or class name contains input method characteristic keywords. If it does, block the window switching event and do not perform further processing.
[0023] System pop-up filtering: Check if the class name contains system pop-up characteristic keywords; if so, intercept the window switching event.
[0024] Window size filtering: Check the size of the current window. If the window size is smaller than a preset threshold, it is considered a temporary window, and the window switching event is intercepted.
[0025] As a preferred method, when storing data records locally, once the amount of data stored reaches a certain unit of time or a predetermined amount, the locally stored data records are uploaded to the cloud. The cloud then aggregates and analyzes the data records according to a predetermined period to generate a visual report.
[0026] Secondly, the present invention provides an Android application device usage time monitoring system, including a service creation module, a window switching event handling module, a multi-layer filtering module, a screen-off and screen-on broadcast monitoring module, and a data recording and storage module.
[0027] The service creation module is used to perform the following: create a system-level accessibility service, register window listener events for listening to changes in window state in the accessibility service configuration file, and maintain two member variables, one of which is a package name variable that records the current foreground application package name, and the other is a time variable that records the time of the most recent event trigger.
[0028] The window switching event handling module is used to perform the following: when the accessibility service detects a change in the window state, it extracts the package name of the application to which the new window belongs. If the package name of the new window changes relative to the package name variable, it calculates the continuous foreground runtime of the previous application, generates a data record as the application exit record, updates the member variables, and generates a data record of the new package as the application startup record.
[0029] The multi-layer filtering module is used to perform the following: when a window switching event is triggered, the new window is filtered through a pre-configured multi-layer filtering mechanism. If the new window is blocked, no data record is generated. If the new window passes the filter, the window switching event processing flow continues.
[0030] The screen-off and screen-on broadcast monitoring module is used to perform the following: monitor the screen-off and screen-on broadcasts of Android devices; when the Android device enters the screen-off state, calculate the continuous usage time of the current foreground application and generate data records as application exit records; when the Android device enters the screen-on state, generate data records as application startup records.
[0031] The data recording and storage module is used to perform the following: store the data records generated during window switching event handling and screen-off / screen-on broadcast listening to the local machine, and upload the locally stored data records to the cloud.
[0032] Preferably, the service creation module is used to perform the following operations:
[0033] Create a new service class in your Android application project that inherits from AccessibilityService.
[0034] -e;
[0035] Register the window listener event TYPE_WINDOW_STATE_ in the accessibility service configuration file.
[0036] CHANGED;
[0037] The service class maintains two member variables: one is the package name variable mForegroundPackageName, which records the package name of the current foreground application; the other is the time variable mRecordTime, which records the time of the most recent event trigger.
[0038] Correspondingly, the window switching event handling module is used to perform the following operations:
[0039] In the onAccessibilityEvent() callback, when a window listener event is detected, the package name of the application to which the new window belongs is extracted;
[0040] Compare the package name in the new window with the package name variable; if there is a change, obtain the current system runtime.
[0041] Calculate the duration of the previous application's continuous foreground runtime, generate a data record as the application exit record; update the package name variable to the new window's package name, update the time variable to the current time, and generate a data record as the application startup record.
[0042] Preferably, the application exit record generated during the window switching event handling process includes a timestamp, package name, event type, and the duration of the previous application's continuous foreground runtime. The event type in the application exit record is "application exit". The application startup record generated during the window switching event handling process includes a timestamp, new package name, and event type. The event type in the application startup record is "application startup".
[0043] The application exit record generated during the screen-off and screen-on broadcast listening process includes a timestamp, package name, event type, and the duration of continuous use of the current foreground application. The event type in the application exit record is "application exit". The application startup record generated during the screen-off and screen-on broadcast listening process includes a timestamp, new package name, and event type. The event type in the application startup record is "application startup".
[0044] Preferably, when filtering a new window using a pre-configured multi-layer filtering mechanism, the multi-layer filtering processing module performs the following operations:
[0045] Input method window filtering: Check if the package name or class name contains input method characteristic keywords. If it does, block the window switching event and do not perform further processing.
[0046] System pop-up filtering: Check if the class name contains system pop-up characteristic keywords; if so, intercept the window switching event.
[0047] Window size filtering: Check the size of the current window. If the window size is smaller than a preset threshold, it is considered a temporary window, and the window switching event is intercepted.
[0048] As a preferred option, once the data records stored locally reach a certain amount of time or a predetermined amount of data, the data record storage module will upload the locally stored data records to the cloud. The cloud will then aggregate and analyze the data records according to a predetermined period to generate a visual report.
[0049] The Android application device usage time monitoring method and system of the present invention have the following advantages:
[0050] 1. Improved statistical accuracy in complex scenarios (pop-ups, screen-off), suitable for user digital behavior analysis systems;
[0051] 2. Automatically records application exits when listening to screen-off broadcasts and records new application launches when the screen is on, thus resolving the issue of incorrect duration statistics during screen-off periods;
[0052] 3. False positives were blocked through a multi-layered filtering mechanism. Attached Figure Description
[0053] To more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0054] The invention will be further described below with reference to the accompanying drawings.
[0055] Figure 1This is a flowchart of an Android device application usage time monitoring method according to Example 1. Detailed Implementation
[0056] The present invention will be further described below with reference to the accompanying drawings and specific embodiments, so that those skilled in the art can better understand and implement the present invention. However, the embodiments are not intended to limit the present invention. In the absence of conflict, the embodiments of the present invention and the technical features in the embodiments can be combined with each other.
[0057] This invention provides a method and system for monitoring Android application device usage time, which solves the technical problem of how to monitor foreground applications and collect usage time data for each application through accessibility services in Android services.
[0058] Example 1:
[0059] This invention discloses a method for monitoring application usage time on Android devices, comprising five steps: service creation, window switching event handling, multi-layer filtering, screen-off and screen-on broadcast monitoring, and data recording and storage.
[0060] Step S100 Service Creation: Create a system-level accessibility service, register window listener events for listening to changes in window state in the accessibility service configuration file, and maintain two member variables, one of which is a package name variable that records the current foreground application package name, and the other is a time variable that records the time of the most recent event trigger.
[0061] The specific implementation of service creation includes the following operations:
[0062] (1) Create a new service class in the Android application project, which inherits from the AccessibilityService;
[0063] (2) Register the window listener TYPE_WINDOW_STATE_CHANGED in the accessibility service configuration file;
[0064] (3) Maintain two member variables in the service class. One member variable is the package name variable mForegroundPackageName, which records the current foreground application package name, and the other member variable is the time variable mRecordTime, which records the time of the most recent event trigger.
[0065] Step S200 Window switching event handling: When the accessibility service detects a change in window state, extract the package name of the application to which the new window belongs. If the package name of the new window changes relative to the package name variable, calculate the continuous foreground runtime of the previous application, generate a data record as the application exit record, update the member variables, and generate a data record of the new package as the application startup record.
[0066] As a specific implementation of window switching event handling, this step includes the following operations:
[0067] (1) In the onAccessibilityEvent() callback, when a window listener event is detected, extract the package name of the application to which the new window belongs;
[0068] (2) Compare the package name of the new window with the package name variable. If there is a change, obtain the current system runtime.
[0069] (3) Calculate the continuous foreground runtime of the previous application, generate a data record as the application exit record; update the package name variable to the package name of the new window, update the time variable to the current time, and generate a data record as the application startup record.
[0070] The application exit record generated during the window switching event handling includes a timestamp, package name, event type, and the duration of the previous application's continuous foreground runtime. The event type in the application exit record is "application exit". The application startup record generated during the window switching event handling includes a timestamp, new package name, and event type. The event type in the application startup record is "application startup".
[0071] Step S300 Multi-layer filtering process: When a window switching event is triggered, the new window is filtered through a pre-configured multi-layer filtering mechanism. If the new window is blocked, no data record is generated. If the new window passes the filter, the window switching event processing flow continues.
[0072] As a specific implementation of multi-layer filtering, the new window is filtered through a pre-configured multi-layer filtering mechanism, including the following operations:
[0073] (1) Input method window filtering: Check whether the package name or class name contains input method characteristic keywords. If it does, intercept the window switching event and do not perform subsequent processing.
[0074] (2) System pop-up filtering: Check if the class name contains system pop-up characteristic keywords. If it does, intercept the window switching event.
[0075] (3) Window size filtering: Check the size of the current window. If the window size is smaller than the preset threshold, it is considered a temporary window and the window switching event is intercepted.
[0076] Step S400 Screen Off and Screen On Broadcast Listening: Listen for screen off and screen on broadcasts on Android devices. When the Android device enters the screen off state, calculate the continuous usage time of the current foreground application and generate a data record as an application exit record. When the Android device enters the screen on state, generate a data record as an application launch record.
[0077] The application exit record generated during the screen-off and screen-on broadcast listening process includes a timestamp, package name, event type, and the duration of continuous use of the current foreground application. The event type in the application exit record is "application exit". The application startup record generated during the screen-off and screen-on broadcast listening process includes a timestamp, new package name, and event type. The event type in the application startup record is "application startup".
[0078] Step S500 Data Recording and Storage: Store the data records generated during window switching event handling and screen-off / screen-on broadcast listening to the local machine, and upload the locally stored data records to the cloud.
[0079] When data records are stored locally, once the amount of data stored reaches a certain unit of time or a predetermined amount, the locally stored data records are uploaded to the cloud. The cloud then aggregates and analyzes the data records according to a predetermined period to generate a visual report.
[0080] The method in this embodiment is applied to Android devices, using the Accessibility Service to listen for foreground application window switching events. This permission is typically required for the application to be system-level. A new service class is created in the system-level application's project, inheriting from AccessibilityService. In the configuration file, `typeWindowStateChanged` is added to `android:accessibilityEventTypes`, indicating that the service is allowed to listen for events related to window state changes. This service class maintains two member variables: `mForegroundPackageName` and `mRecordTime`, which record the package name and system runtime at the time the foreground application change was most recently detected, respectively.
[0081] When the `onAccessibilityEvent()` callback function is triggered, it first filters for foreground application window switching events named `TYPE_WINDOW_STATE_CHANGED` and records the package name of the application to which the window belongs after the switch. It compares the current package name with the package name in the member variable; if there is a change, it obtains the current system runtime, calculates the duration the foreground application has been running in the foreground, and generates a "Application Exited" data record locally, including the package name and duration. It then updates the package name and runtime maintained in the member variable and finally generates a "Application Started" data record locally.
[0082] When a user uses an application, system-level pop-ups (such as input method or notification bar pop-ups) briefly gain focus, causing the original application to be mistakenly identified as being in the background and the pop-up as a new application, generating a large number of millisecond-level fragmented records. To address this issue, multiple layers of filtering can be added when the window switching event is triggered, based on package name, class name, and size. First, package names or class names containing keywords characteristic of input methods, such as Keyboard and InputMethod, will be directly blocked. Second, filtering can be added for standard Android pop-up classes such as system permission pop-ups, for example, class names containing keywords such as permission. Finally, the size of the current window can be limited to filter out temporary windows within a specified size.
[0083] If the device enters a screen-off state, the window switching event will not be triggered, and the user is not actually continuing to use the device. In this case, the usage time cannot be counted. Therefore, when the screen-off broadcast "SCREEN_OFF" is heard, the continuous usage time is calculated and an "application exit" data is generated. When the screen-on broadcast "SCREEN_ON" is heard, an "application launch" data is generated.
[0084] The collected data undergoes statistical processing. The data is collected in the format of timestamp, application package name, event type (entry or exit), and duration of use. A certain amount of raw data is temporarily stored in memory. After a certain period of time or when a threshold is reached, the raw data is uploaded to the cloud data center. The data is then cleaned and aggregated locally on the device, and statistics are presented to the user by usage period (hour, day, week).
[0085] Example 2:
[0086] This invention discloses an Android application device usage time monitoring system, comprising a service creation module, a window switching event handling module, a multi-layer filtering module, a screen-off and screen-on broadcast monitoring module, and a data recording and storage module.
[0087] The service creation module is used to perform the following: create a system-level accessibility service, register window listener events for listening to changes in window state in the accessibility service configuration file, and maintain two member variables, one of which is a package name variable that records the current foreground application package name, and the other is a time variable that records the time of the most recent event trigger.
[0088] As a specific implementation of the service creation module, this module is used to perform the following operations:
[0089] (1) Create a new service class in the Android application project, which inherits from the AccessibilityService;
[0090] (2) Register the window listener TYPE_WINDOW_STATE_CHANGED in the accessibility service configuration file;
[0091] (3) Maintain two member variables in the service class. One member variable is the package name variable mForegroundPackageName, which records the current foreground application package name, and the other member variable is the time variable mRecordTime, which records the time of the most recent event trigger.
[0092] The window switching event handling module is used to perform the following: when the accessibility service detects a change in the window state, it extracts the package name of the application to which the new window belongs. If the package name of the new window changes relative to the package name variable, it calculates the continuous foreground runtime of the previous application, generates a data record as the application exit record, updates the member variables, and generates a data record of the new package as the application startup record.
[0093] As a specific implementation of the window switching event handling module, this module is used to perform the following operations:
[0094] (1) In the onAccessibilityEvent() callback, when a window listener event is detected, extract the package name of the application to which the new window belongs;
[0095] (2) Compare the package name of the new window with the package name variable. If there is a change, obtain the current system runtime.
[0096] (3) Calculate the continuous foreground runtime of the previous application, generate a data record as the application exit record; update the package name variable to the package name of the new window, update the time variable to the current time, and generate a data record as the application startup record.
[0097] The application exit record generated during the window switching event handling includes a timestamp, package name, event type, and the duration of the previous application's continuous foreground runtime. The event type in the application exit record is "application exit". The application startup record generated during the window switching event handling includes a timestamp, new package name, and event type. The event type in the application startup record is "application startup".
[0098] The multi-layer filtering module is used to perform the following: when a window switching event is triggered, the new window is filtered through a pre-configured multi-layer filtering mechanism. If the new window is blocked, no data record is generated. If the new window passes the filter, the window switching event processing flow continues.
[0099] As a specific implementation of the multi-layer filtering module, when filtering new windows through a pre-configured multi-layer filtering mechanism, this module performs the following operations:
[0100] (1) Input method window filtering: Check whether the package name or class name contains input method characteristic keywords. If it does, intercept the window switching event and do not perform subsequent processing.
[0101] (2) System pop-up filtering: Check if the class name contains system pop-up characteristic keywords. If it does, intercept the window switching event.
[0102] (3) Window size filtering: Check the size of the current window. If the window size is smaller than the preset threshold, it is considered a temporary window and the window switching event is intercepted.
[0103] The screen-off and screen-on broadcast monitoring module is used to perform the following: listen for screen-off and screen-on broadcasts of Android devices. When the Android device enters the screen-off state, calculate the continuous usage time of the current foreground application and generate data records as application exit records. When the Android device enters the screen-on state, generate data records as application startup records.
[0104] The application exit record generated during the screen-off and screen-on broadcast listening process includes a timestamp, package name, event type, and the duration of continuous use of the current foreground application. The event type in the application exit record is "application exit". The application startup record generated during the screen-off and screen-on broadcast listening process includes a timestamp, new package name, and event type. The event type in the application startup record is "application startup".
[0105] The data recording and storage module is used to perform the following: store the data records generated during window switching event handling and screen-off / screen-on broadcast listening to the local machine, and upload the locally stored data records to the cloud.
[0106] When data records are stored locally, once the amount of data stored reaches a certain unit of time or a predetermined amount, the locally stored data records are uploaded to the cloud. The cloud then aggregates and analyzes the data records according to a predetermined period to generate a visual report.
[0107] The system in this embodiment can execute the method disclosed in Embodiment 1 to monitor the usage time of Android device applications.
[0108] The above provides a detailed description of the Android device application usage time monitoring method and system provided by the present invention. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A method for monitoring application usage time on Android devices, characterized in that, Includes the following steps: Service creation: Create a system-level accessibility service, register window listener events for listening to window state changes in the accessibility service configuration file, and maintain two member variables, one of which is a package name variable that records the current foreground application package name, and the other is a time variable that records the time of the most recent event trigger. Window switching event handling: When the accessibility service detects a change in window state, extract the package name of the application to which the new window belongs. If the package name of the new window changes relative to the package name variable, calculate the continuous foreground runtime of the previous application, generate a data record as the application exit record, update the member variable, and generate a data record of the new package as the application startup record. Multi-layer filtering: When a window switching event is triggered, the new window is filtered through a pre-configured multi-layer filtering mechanism. If the new window is blocked, no data record is generated. If the new window passes the filter, the window switching event processing flow continues. Screen off and screen on broadcast monitoring: Listen for screen off and screen on broadcasts on Android devices. When an Android device enters screen off state, calculate the continuous usage time of the current foreground application and generate data records as application exit records. When an Android device enters screen on state, generate data records as application launch records. Data recording and storage: Store the data records generated during window switching event handling and screen-off / screen-on broadcast listening to the local machine, and upload the locally stored data records to the cloud.
2. The method for monitoring application usage time on Android devices according to claim 1, characterized in that, When creating a service, perform the following operations: Create a new service class in your Android application project that inherits from the AccessibilityService class. Register the window listener event TYPE_WINDOW_STATE_CHANGED in the accessibility service configuration file; The service class maintains two member variables: one is the package name variable mForegroundPackageName, which records the package name of the current foreground application; the other is the time variable mRecordTime, which records the time of the most recent event trigger. Correspondingly, window switching event handling includes the following operations: In the onAccessibilityEvent() callback, when a window listener event is detected, the package name of the application to which the new window belongs is extracted; Compare the package name in the new window with the package name variable; if there is a change, obtain the current system runtime. Calculate the duration of the previous application's continuous foreground runtime and generate a data record as the application exit record; Update the package name variable to the package name of the new window, update the time variable to the current time, and generate a data record as the application startup record.
3. The method for monitoring Android device application usage time according to claim 1 or 2, characterized in that, The application exit record generated during the window switching event handling includes a timestamp, package name, event type, and the duration of the previous application's continuous foreground runtime. The event type in the application exit record is "application exit". The application startup record generated during the window switching event handling includes a timestamp, new package name, and event type. The event type in the application startup record is "application startup". The application exit record generated during the screen-off and screen-on broadcast listening process includes a timestamp, package name, event type, and the duration of continuous use of the current foreground application. The event type in the application exit record is "application exit". The application startup record generated during the screen-off and screen-on broadcast listening process includes a timestamp, new package name, and event type. The event type in the application startup record is "application startup".
4. The method for monitoring application usage time on Android devices according to claim 1 or 2, characterized in that, The new window is filtered using a pre-configured multi-layered filtering mechanism, including the following operations: Input method window filtering: Check if the package name or class name contains input method characteristic keywords. If it does, block the window switching event and do not perform further processing. System pop-up filtering: Check if the class name contains system pop-up characteristic keywords; if so, intercept the window switching event. Window size filtering: Check the size of the current window. If the window size is smaller than a preset threshold, it is considered a temporary window, and the window switching event is intercepted.
5. The method for monitoring application usage time on Android devices according to claim 1, characterized in that, When data records are stored locally, once the amount of data stored reaches a certain unit of time or a predetermined amount, the locally stored data records are uploaded to the cloud. The cloud then aggregates and analyzes the data records according to a predetermined period to generate a visual report.
6. An Android application device usage time monitoring system, characterized in that, It includes a service creation module, a window switching event handling module, a multi-layer filtering module, a screen-off / screen-on broadcast monitoring module, and a data recording and storage module; The service creation module is used to perform the following: create a system-level accessibility service, register window listener events for listening to changes in window state in the accessibility service configuration file, and maintain two member variables, one of which is a package name variable that records the current foreground application package name, and the other is a time variable that records the time of the most recent event trigger. The window switching event handling module is used to perform the following: when the accessibility service detects a change in the window state, it extracts the package name of the application to which the new window belongs. If the package name of the new window changes relative to the package name variable, it calculates the continuous foreground runtime of the previous application, generates a data record as the application exit record, updates the member variables, and generates a data record of the new package as the application startup record. The multi-layer filtering module is used to perform the following: when a window switching event is triggered, the new window is filtered through a pre-configured multi-layer filtering mechanism. If the new window is blocked, no data record is generated. If the new window passes the filter, the window switching event processing flow continues. The screen-off and screen-on broadcast monitoring module is used to perform the following: monitor the screen-off and screen-on broadcasts of Android devices; when the Android device enters the screen-off state, calculate the continuous usage time of the current foreground application and generate data records as application exit records; when the Android device enters the screen-on state, generate data records as application startup records. The data recording and storage module is used to perform the following: store the data records generated during window switching event handling and screen-off / screen-on broadcast listening to the local machine, and upload the locally stored data records to the cloud.
7. The Android application device usage time monitoring system according to claim 6, characterized in that, The service creation module is used to perform the following operations: Create a new service class in your Android application project that inherits from the AccessibilityService class. Register the window listener event TYPE_WINDOW_STATE_CHANGED in the accessibility service configuration file; The service class maintains two member variables: one is the package name variable mForegroundPackageName, which records the package name of the current foreground application; the other is the time variable mRecordTime, which records the time of the most recent event trigger. Correspondingly, the window switching event handling module is used to perform the following operations: In the onAccessibilityEvent() callback, when a window listener event is detected, the package name of the application to which the new window belongs is extracted; Compare the package name in the new window with the package name variable; if there is a change, obtain the current system runtime. Calculate the duration of the previous application's continuous foreground runtime and generate a data record as the application exit record; Update the package name variable to the package name of the new window, update the time variable to the current time, and generate a data record as the application startup record.
8. The Android application device usage time monitoring system according to claim 6 or 7, characterized in that, The application exit record generated during the window switching event handling includes a timestamp, package name, event type, and the duration of the previous application's continuous foreground runtime. The event type in the application exit record is "application exit". The application startup record generated during the window switching event handling includes a timestamp, new package name, and event type. The event type in the application startup record is "application startup". The application exit record generated during the screen-off and screen-on broadcast listening process includes a timestamp, package name, event type, and the duration of continuous use of the current foreground application. The event type in the application exit record is "application exit". The application startup record generated during the screen-off and screen-on broadcast listening process includes a timestamp, new package name, and event type. The event type in the application startup record is "application startup".
9. The Android application device usage time monitoring system according to claim 6 or 7, characterized in that, When filtering a new window using a pre-configured multi-layer filtering mechanism, the multi-layer filtering processing module performs the following operations: Input method window filtering: Check if the package name or class name contains input method characteristic keywords. If it does, block the window switching event and do not perform further processing. System pop-up filtering: Check if the class name contains system pop-up characteristic keywords; if so, intercept the window switching event. Window size filtering: Check the size of the current window. If the window size is smaller than a preset threshold, it is considered a temporary window, and the window switching event is intercepted.
10. The Android application device usage time monitoring system according to claim 6, characterized in that, Once the data records stored locally reach a certain time or a predetermined amount, the data record storage module will upload the locally stored data records to the cloud. The cloud will then aggregate and analyze the data records according to a predetermined period to generate a visual report.