Android application lock monitoring application before and after the switch mode

Source: Internet
Author: User

Today in the technical summary, the way to share knowledge, personal advocating sharing.

Listen to whether the app's front and back switches have occurred in the following ways:

1. Android API 10–15

The Activitymanager Registeractivitywatcher method registers the Iactivitywatcher mode of monitoring.

2. Android API 16–20

Listen for changes in application switching by listening for changes in/dev/log/events file content.

Why this approach can be successfully monitored:

Because/dev/log/events is the kernel of the log output character device terminal file.

By looking at the Logger.h (Linux kernel log output System) Discovery defines:

Define/dev/log/events log output device files

by viewing Logcat.cpp Source We will find:

His readloglines (log_device_t * devices) function

The output of the kernel log is monitored through the select mode and then output to the screen terminal, so we can enter ADB locat in terminal to see the system log output as follows: I click the SMS app

Look at the Readloglines function in log_device_t creation:

Why use this way to listen:

Because the Android api16-20 uses the Iactivitcontorller or iprocessobserver instead of the iactivitywatcher, this approach only listens to its own activity switch, System permissions are required to listen to other applications.

3. Android API and above:

Listen for changes in application switching by listening for changes in Bg_non_interactive/tasks file content.

Why this way can be monitored successfully

This is, of course, a bug left in the design of the system, when the app occurs before and after the switch, his PID will be added or deleted in the Bg_non_interactive/tasks

Why use this way to listen:

Because/dev/log/events can not be in the user-state monitoring, see Logcat Source code did not choose to listen directly, or through the interface provided by the logger to listen to the kernel state

4. Other Auxiliary monitoring methods:

Listen to the corresponding/proc/pid/oom_adj is worth the change to monitor before and after switching

5. fallback mode:

Use polling to get app switching changes (power consumption, temporarily unused)

Android application lock monitoring application before and after the switch mode

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.