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

Commit daef80fd authored by Michal Karpinski's avatar Michal Karpinski
Browse files

Allow apps that are currently instrumenting with background activity

starts privileges to start activities from background

Test: atest WmTests:ActivityStarterTests
Test: atest google/perf/jank/SystemUI/UbSystemUIJankTests
Test: atest LightBarTests
Test: atest CtsActivityManagerDeviceTestCases
Bug: 123434182
Bug: 110956953
Bug: 122760822
Change-Id: I66dc700bcb4713838528094a35337bcb3770d229
parent 3fce7487
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -49,6 +49,9 @@ class ActiveInstrumentation {
    // Connection to use the UI introspection APIs.
    IUiAutomationConnection mUiAutomationConnection;

    // Whether the caller holds START_ACTIVITIES_FROM_BACKGROUND permission
    boolean mHasBackgroundActivityStartsPermission;

    // As given to us
    Bundle mArguments;

@@ -117,6 +120,8 @@ class ActiveInstrumentation {
            pw.print(prefix); pw.print("mUiAutomationConnection=");
            pw.println(mUiAutomationConnection);
        }
        pw.print("mHasBackgroundActivityStartsPermission=");
        pw.println(mHasBackgroundActivityStartsPermission);
        pw.print(prefix); pw.print("mArguments=");
        pw.println(mArguments);
    }
+7 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.Manifest.permission.FILTER_EVENTS;
import static android.Manifest.permission.INTERACT_ACROSS_USERS;
import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL;
import static android.Manifest.permission.REMOVE_TASKS;
import static android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND;
import static android.app.ActivityManager.INSTR_FLAG_DISABLE_HIDDEN_API_CHECKS;
import static android.app.ActivityManager.INSTR_FLAG_MOUNT_EXTERNAL_STORAGE_FULL;
import static android.app.ActivityManager.PROCESS_STATE_LAST_ACTIVITY;
@@ -15194,7 +15195,9 @@ public class ActivityManagerService extends IActivityManager.Stub
            IInstrumentationWatcher watcher, IUiAutomationConnection uiAutomationConnection,
            int userId, String abiOverride) {
        enforceNotIsolatedCaller("startInstrumentation");
        userId = mUserController.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(),
        final int callingUid = Binder.getCallingUid();
        final int callingPid = Binder.getCallingPid();
        userId = mUserController.handleIncomingUser(callingPid, callingUid,
                userId, false, ALLOW_FULL_ONLY, "startInstrumentation", null);
        // Refuse possible leaked file descriptors
        if (arguments != null && arguments.hasFileDescriptors()) {
@@ -15259,6 +15262,9 @@ public class ActivityManagerService extends IActivityManager.Stub
            activeInstr.mWatcher = watcher;
            activeInstr.mUiAutomationConnection = uiAutomationConnection;
            activeInstr.mResultClass = className;
            activeInstr.mHasBackgroundActivityStartsPermission = checkPermission(
                    START_ACTIVITIES_FROM_BACKGROUND, callingPid, callingUid)
                            == PackageManager.PERMISSION_GRANTED;
            boolean disableHiddenApiChecks = ai.usesNonSdkApi()
                    || (flags & INSTR_FLAG_DISABLE_HIDDEN_API_CHECKS) != 0;
+2 −0
Original line number Diff line number Diff line
@@ -1157,6 +1157,8 @@ final class ProcessRecord implements WindowProcessListener {
    void setActiveInstrumentation(ActiveInstrumentation instr) {
        mInstr = instr;
        mWindowProcessController.setInstrumenting(instr != null);
        mWindowProcessController.setInstrumentingWithBackgroundActivityStartPrivileges(instr != null
                && instr.mHasBackgroundActivityStartsPermission);
    }

    ActiveInstrumentation getActiveInstrumentation() {
+4 −0
Original line number Diff line number Diff line
@@ -926,6 +926,10 @@ class ActivityStarter {
        if (callerApp != null && callerApp.hasForegroundActivities()) {
            return false;
        }
        // don't abort if the callerApp is instrumenting with background activity starts privileges
        if (callerApp != null && callerApp.isInstrumentingWithBackgroundActivityStartPrivileges()) {
            return false;
        }
        // don't abort if the callingUid is in the foreground or is a persistent system process
        final int callingUidProcState = mService.getUidStateLocked(callingUid);
        final boolean callingUidHasAnyVisibleWindow =
+19 −0
Original line number Diff line number Diff line
@@ -138,6 +138,8 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
    private volatile boolean mDebugging;
    // Active instrumentation running in process?
    private volatile boolean mInstrumenting;
    // Active instrumentation with background activity starts privilege running in process?
    private volatile boolean mInstrumentingWithBackgroundActivityStartPrivileges;
    // This process it perceptible by the user.
    private volatile boolean mPerceptible;
    // Set to true when process was launched with a wrapper attached
@@ -370,6 +372,23 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
        return mInstrumenting;
    }

    /**
     * {@see isInstrumentingWithBackgroundActivityStartPrivileges}
     */
    public void setInstrumentingWithBackgroundActivityStartPrivileges(
            boolean instrumentingWithBackgroundActivityStartPrivileges) {
        mInstrumentingWithBackgroundActivityStartPrivileges =
                instrumentingWithBackgroundActivityStartPrivileges;
    }

    /**
     * @return true if the instrumentation was started by a holder of
     * START_ACTIVITIES_FROM_BACKGROUND permission
     */
    boolean isInstrumentingWithBackgroundActivityStartPrivileges() {
        return mInstrumentingWithBackgroundActivityStartPrivileges;
    }

    public void setPerceptible(boolean perceptible) {
        mPerceptible = perceptible;
    }
Loading