Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 44f11f6e authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Use ApplicationInfo to track the notLaunched flag

Use it instead of relying on PackageManager calls because the
PackageManager state gets updated before the ProcessRecord is
created, causing a difference between the ApplicationInfo and
package state.

This fixes the problem with force-stopped state being incorrect
when correlating FLAG_STOPPED and notLaunched state.

Bug: 362516211
Bug: 362198191
Bug: 353651949
Test: atest CtsAppTestCases:ForceStopTest
Flag: android.app.use_app_info_not_launched
Change-Id: I4d0138071a15a07ae41aaa1779919799da998ede
parent 38618c52
Loading
Loading
Loading
Loading
+11 −0
Original line number Original line Diff line number Diff line
@@ -104,6 +104,17 @@ flag {
     }
     }
}
}


flag {
     namespace: "backstage_power"
     name: "use_app_info_not_launched"
     description: "Use the notLaunched state from ApplicationInfo instead of current value"
     is_fixed_read_only: true
     bug: "362516211"
     metadata {
         purpose: PURPOSE_BUGFIX
     }
}

flag {
flag {
     namespace: "backstage_power"
     namespace: "backstage_power"
     name: "cache_get_current_user_id"
     name: "cache_get_current_user_id"
+23 −0
Original line number Original line Diff line number Diff line
@@ -849,6 +849,12 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
     */
     */
    public static final int PRIVATE_FLAG_EXT_CPU_OVERRIDE = 1 << 5;
    public static final int PRIVATE_FLAG_EXT_CPU_OVERRIDE = 1 << 5;


    /**
     * Whether the app has been previously not launched
     * @hide
     */
    public static final int PRIVATE_FLAG_EXT_NOT_LAUNCHED = 1 << 6;

    /** @hide */
    /** @hide */
    @IntDef(flag = true, prefix = { "PRIVATE_FLAG_EXT_" }, value = {
    @IntDef(flag = true, prefix = { "PRIVATE_FLAG_EXT_" }, value = {
            PRIVATE_FLAG_EXT_PROFILEABLE,
            PRIVATE_FLAG_EXT_PROFILEABLE,
@@ -857,6 +863,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
            PRIVATE_FLAG_EXT_ENABLE_ON_BACK_INVOKED_CALLBACK,
            PRIVATE_FLAG_EXT_ENABLE_ON_BACK_INVOKED_CALLBACK,
            PRIVATE_FLAG_EXT_ALLOWLISTED_FOR_HIDDEN_APIS,
            PRIVATE_FLAG_EXT_ALLOWLISTED_FOR_HIDDEN_APIS,
            PRIVATE_FLAG_EXT_CPU_OVERRIDE,
            PRIVATE_FLAG_EXT_CPU_OVERRIDE,
            PRIVATE_FLAG_EXT_NOT_LAUNCHED,
    })
    })
    @Retention(RetentionPolicy.SOURCE)
    @Retention(RetentionPolicy.SOURCE)
    public @interface ApplicationInfoPrivateFlagsExt {}
    public @interface ApplicationInfoPrivateFlagsExt {}
@@ -2663,6 +2670,22 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
        return (privateFlags & ApplicationInfo.PRIVATE_FLAG_IS_RESOURCE_OVERLAY) != 0;
        return (privateFlags & ApplicationInfo.PRIVATE_FLAG_IS_RESOURCE_OVERLAY) != 0;
    }
    }


    /**
     * Returns whether the app in the STOPPED state.
     * @hide
     */
    public boolean isStopped() {
        return (flags & ApplicationInfo.FLAG_STOPPED) != 0;
    }

    /**
     * Returns whether the app was never launched (any process started) before.
     * @hide
     */
    public boolean isNotLaunched() {
        return (privateFlagsExt & ApplicationInfo.PRIVATE_FLAG_EXT_NOT_LAUNCHED) != 0;
    }

    /**
    /**
     * Checks if a changeId is enabled for the current user
     * Checks if a changeId is enabled for the current user
     * @param changeId The changeId to verify
     * @param changeId The changeId to verify
+4 −10
Original line number Original line Diff line number Diff line
@@ -1516,9 +1516,8 @@ public final class ActiveServices {
                serviceName, FrameworkStatsLog.SERVICE_STATE_CHANGED__STATE__START);
                serviceName, FrameworkStatsLog.SERVICE_STATE_CHANGED__STATE__START);
        mAm.mBatteryStatsService.noteServiceStartRunning(uid, packageName, serviceName);
        mAm.mBatteryStatsService.noteServiceStartRunning(uid, packageName, serviceName);
        final ProcessRecord hostApp = r.app;
        final ProcessRecord hostApp = r.app;
        final boolean wasStopped = hostApp == null ? wasStopped(r) : false;
        final boolean wasStopped = hostApp == null ? r.appInfo.isStopped() : false;
        final boolean firstLaunch =
        final boolean firstLaunch = hostApp == null ? r.appInfo.isNotLaunched() : false;
                hostApp == null ? !mAm.wasPackageEverLaunched(r.packageName, r.userId) : false;


        String error = bringUpServiceLocked(r, service.getFlags(), callerFg,
        String error = bringUpServiceLocked(r, service.getFlags(), callerFg,
                false /* whileRestarting */,
                false /* whileRestarting */,
@@ -4308,9 +4307,8 @@ public final class ActiveServices {
                        true, UNKNOWN_ADJ);
                        true, UNKNOWN_ADJ);
            }
            }


            final boolean wasStopped = hostApp == null ? wasStopped(s) : false;
            final boolean wasStopped = hostApp == null ? s.appInfo.isStopped() : false;
            final boolean firstLaunch =
            final boolean firstLaunch = hostApp == null ? s.appInfo.isNotLaunched() : false;
                    hostApp == null ? !mAm.wasPackageEverLaunched(s.packageName, s.userId) : false;


            boolean needOomAdj = false;
            boolean needOomAdj = false;
            if (c.hasFlag(Context.BIND_AUTO_CREATE)) {
            if (c.hasFlag(Context.BIND_AUTO_CREATE)) {
@@ -9350,8 +9348,4 @@ public final class ActiveServices {
        return mCachedDeviceProvisioningPackage != null
        return mCachedDeviceProvisioningPackage != null
                && mCachedDeviceProvisioningPackage.equals(packageName);
                && mCachedDeviceProvisioningPackage.equals(packageName);
    }
    }

    private boolean wasStopped(ServiceRecord serviceRecord) {
        return (serviceRecord.appInfo.flags & ApplicationInfo.FLAG_STOPPED) != 0;
    }
}
}
+5 −0
Original line number Original line Diff line number Diff line
@@ -33,6 +33,7 @@ import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.icu.text.SimpleDateFormat;
import android.icu.text.SimpleDateFormat;
import android.os.Binder;
import android.os.Binder;
import android.os.Debug;
import android.os.FileUtils;
import android.os.FileUtils;
import android.os.Handler;
import android.os.Handler;
import android.os.IBinder.DeathRecipient;
import android.os.IBinder.DeathRecipient;
@@ -495,6 +496,10 @@ public final class AppStartInfoTracker {


    private void addBaseFieldsFromProcessRecord(ApplicationStartInfo start, ProcessRecord app) {
    private void addBaseFieldsFromProcessRecord(ApplicationStartInfo start, ProcessRecord app) {
        if (app == null) {
        if (app == null) {
            if (DEBUG) {
                Slog.w(TAG,
                        "app is null in addBaseFieldsFromProcessRecord: " + Debug.getCallers(4));
            }
            return;
            return;
        }
        }
        final int definingUid = app.getHostingRecord() != null
        final int definingUid = app.getHostingRecord() != null
+3 −6
Original line number Original line Diff line number Diff line
@@ -1005,13 +1005,10 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
        final ApplicationInfo info = ((ResolveInfo) receiver).activityInfo.applicationInfo;
        final ApplicationInfo info = ((ResolveInfo) receiver).activityInfo.applicationInfo;
        final ComponentName component = ((ResolveInfo) receiver).activityInfo.getComponentName();
        final ComponentName component = ((ResolveInfo) receiver).activityInfo.getComponentName();


        if ((info.flags & ApplicationInfo.FLAG_STOPPED) != 0) {
        queue.setActiveWasStopped(info.isStopped());
            queue.setActiveWasStopped(true);
        queue.setActiveFirstLaunch(info.isNotLaunched());
        }
        final int intentFlags = r.intent.getFlags() | Intent.FLAG_FROM_BACKGROUND;
        final boolean firstLaunch = !mService.wasPackageEverLaunched(info.packageName, r.userId);
        queue.setActiveFirstLaunch(firstLaunch);


        final int intentFlags = r.intent.getFlags() | Intent.FLAG_FROM_BACKGROUND;
        final HostingRecord hostingRecord = new HostingRecord(HostingRecord.HOSTING_TYPE_BROADCAST,
        final HostingRecord hostingRecord = new HostingRecord(HostingRecord.HOSTING_TYPE_BROADCAST,
                component, r.intent.getAction(), r.getHostingRecordTriggerType());
                component, r.intent.getAction(), r.getHostingRecordTriggerType());
        final boolean isActivityCapable = (r.options != null
        final boolean isActivityCapable = (r.options != null
Loading