Say android:persistent="true" keep alive

Say android:persistent = "true" to keep alive

1. What kind of application configuration can realize this value to keep alive?

The pre installed application of the system is related to the pre installed location. See code for details

if ((flags&PARSE_IS_SYSTEM) != 0) {
    if (sa.getBoolean(
            com.android.internal.R.styleable.AndroidManifestApplication_persistent,
            false)) {
        ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
    }
}

Where parse? Is? System is passed in here

scanDirTracedLI(systemAppDir, mDefParseFlags
        | PackageParser.PARSE_IS_SYSTEM
        | PackageParser.PARSE_IS_SYSTEM_DIR, scanFlags, 0);

For different pre installed directories, different parseFlags will be configured, but only if parse is system is configured and Android is configured: persistent = "true", as follows:

<application android:name="XXXX" 
             android:persistent="true" >

This application can become a persistent application, which can keep alive. So for a system application after its self upgrade, it will no longer be a persistent application.

2. What problems will appear in the application of life preservation?

At present, because the application is always alive, the application will not exit in the process of self upgrading and data clearing, which leads to the application running abnormally even if the data is cleared. The code is as follows:

if (app.persistent && !evenPersistent) {
    // we don't kill persistent processes
    if (IS_ENG_BUILD || DEBUG_PROCESSES) {
        Slog.d(TAG, "ACT-killPackageProcessesLocked ignore persistent process " +
            app.persistent + " " + evenPersistent);
    }
    continue;
}

3. The start-up time of persistent application is very early, which is earlier than the start-up broadcast and desktop start-up.

public void systemReady(final Runnable goingCallback) 
{
    ...
    synchronized (this) {
        // Only start up encryption-aware persistent apps; once user is
        // unlocked we'll come back around and start unaware apps
        startPersistentApps(PackageManager.MATCH_DIRECT_BOOT_AWARE);
        ...
        if (skipHome == false) {
            //Boot desktop
            startHomeActivityLocked(currentUserId, "systemReady");
        }
        ...
        //Send finish? Booting? MSG here before starting to send power on broadcast
        postFinishBooting(false, true);
        ...
    }
    ....
}

Printing to start such a process is as follows:

Start proc 1308:XXXX/10003 for added application XXXX

For more information, please refer to Talk about the persistent property of Android Application

Keywords: Android

Added by cashflowtips on Sat, 04 Apr 2020 00:41:40 +0300