“This is the first day of my participation in the Gwen Challenge in November. Check out the details: The last Gwen Challenge in 2021”

1. Start an Activity with one pixel

It is said that this is the hand Q process alive scheme, the basic idea, the system is generally not kill the foreground process. So to make the process permanent, we just need to start an Activity in the process when the screen is locked. In order to deceive the user, let the Activity size be 1 pixel, and transparent without switching animation, when the screen is opened, the Activity is closed, so this needs to listen to the system lock screen broadcast

2, The front desk service

This scheme actually exploits a vulnerability in Android foreground services. If API level < 18: call startForeground(ID, new Notification()) and send empty Notification, the icon will not be displayed. For API level >= 18: Start an InnerService whose priority needs to be improved, and both services are startForeground, and bound with the same ID. Stop the InnerService so that the notification bar icon is removed.

Below API 18, send Notification directly and bring it to the foreground

startForeground(NOTIFICATION_ID, new Notification());

// Start InnerService after sending Notification and putting it in the foreground above API 18

Notification.Builder builder = new Notification.Builder(this);

builder.setSmallIcon(R.mipmap.ic_launcher);

startForeground(NOTIFICATION_ID, builder.build());

startService(new Intent(this, InnerService.class))

// Send the Notification with the same ID as in KeepLiveService, then cancel it and cancel its own foreground display

Notification.Builder builder = new Notification.Builder(this);

builder.setSmallIcon(R.mipmap.ic_launcher);

startForeground(NOTIFICATION_ID, builder.build());

 

3. Wake each other up

Mutual awakening means that if you have Alipay, Taobao, Tmall, UC and other Alibaba apps in your mobile phone, you may wake up other Alibaba apps after opening any One of them. It’s entirely possible. The app can also be woken up by system-generated announcements during startup, network switching, photo taking, and video shooting, but Android N has removed all three announcements.

4, JobSheduler

JobSheduler is a means of process resurrection after death. The biggest disadvantage of native process is that it consumes electricity. The reason why native process consumes electricity is that there are two ways to realize the perception of whether the main process is alive. Pull when the main process is not alive. Second, 5.0 or higher systems do not support it. But JobSheduler can replace native processes on Android5.0 and above, which can be pulled up even if the user forces them to shut down

5, Sticky services & bundled with system services

The onStartCommand method must have an integer return value that tells the system what to do if the service is killed after it has started. This option works, but it may fail in some cases or on some custom ROMs.