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

Commit 2ef69945 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Internalize setPackageStoppedState() call.

Several places across the OS internals were invoking this method
via AppGlobals, which is a poor strategy for testing.  Moving the
call to PackageManagerInternal supports easier mocking.

Bug: 243656033
Test: atest CtsContentTestCases:BroadcastReceiverTest
Test: atest FrameworksMockingServicesTests:BroadcastQueueTest
Change-Id: Ie29f60ac379eac8137af1301ac5cded4c9f37fc8
parent eee6a6bb
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1305,4 +1305,7 @@ public abstract class PackageManagerInternal {
     * {@link android.Manifest.permission#INTERACT_ACROSS_USERS}.
     */
    public abstract @SignatureResult int checkUidSignaturesForAllUsers(int uid1, int uid2);

    public abstract void setPackageStoppedState(@NonNull String packageName, boolean stopped,
            @UserIdInt int userId);
}
+1 −2
Original line number Diff line number Diff line
@@ -4236,9 +4236,8 @@ public final class ActiveServices {

        // Service is now being launched, its package can't be stopped.
        try {
            AppGlobals.getPackageManager().setPackageStoppedState(
            mAm.mPackageManagerInt.setPackageStoppedState(
                    r.packageName, false, r.userId);
        } catch (RemoteException e) {
        } catch (IllegalArgumentException e) {
            Slog.w(TAG, "Failed trying to unstop package "
                    + r.packageName + ": " + e);
+2 −9
Original line number Diff line number Diff line
@@ -2998,11 +2998,6 @@ public class ActivityManagerService extends IActivityManager.Stub
        mActivityTaskManager.setPackageScreenCompatMode(packageName, mode);
    }
    public void setPackageStoppedState(String packageName, boolean stopped, int userId)
            throws RemoteException {
        AppGlobals.getPackageManager().setPackageStoppedState(packageName, stopped, userId);
    }
    private boolean hasUsageStatsPermission(String callingPackage, int callingUid, int callingPid) {
        final int mode = mAppOpsService.noteOperation(AppOpsManager.OP_GET_USAGE_STATS,
                callingUid, callingPackage, null, false, "", false).getOpMode();
@@ -6742,9 +6737,8 @@ public class ActivityManagerService extends IActivityManager.Stub
        // TODO: how set package stopped state should work for sdk sandboxes?
        if (!isSdkSandbox) {
            try {
                AppGlobals.getPackageManager().setPackageStoppedState(
                mPackageManagerInt.setPackageStoppedState(
                        info.packageName, false, UserHandle.getUserId(app.uid));
            } catch (RemoteException e) {
            } catch (IllegalArgumentException e) {
                Slog.w(TAG, "Failed trying to unstop package "
                        + info.packageName + ": " + e);
@@ -12860,9 +12854,8 @@ public class ActivityManagerService extends IActivityManager.Stub
            // !!! TODO: currently no check here that we're already bound
            // Backup agent is now in use, its package can't be stopped.
            try {
                AppGlobals.getPackageManager().setPackageStoppedState(
                mPackageManagerInt.setPackageStoppedState(
                        app.packageName, false, UserHandle.getUserId(app.uid));
            } catch (RemoteException e) {
            } catch (IllegalArgumentException e) {
                Slog.w(TAG, "Failed trying to unstop package "
                        + app.packageName + ": " + e);
+1 −2
Original line number Diff line number Diff line
@@ -1378,9 +1378,8 @@ public class BroadcastQueueImpl extends BroadcastQueue {

        // Broadcast is being executed, its package can't be stopped.
        try {
            mService.setPackageStoppedState(
            mService.mPackageManagerInt.setPackageStoppedState(
                    r.curComponent.getPackageName(), false, r.userId);
        } catch (RemoteException e) {
        } catch (IllegalArgumentException e) {
            Slog.w(TAG, "Failed trying to unstop package "
                    + r.curComponent.getPackageName() + ": " + e);
+1 −2
Original line number Diff line number Diff line
@@ -464,10 +464,9 @@ public class ContentProviderHelper {
                        try {
                            checkTime(startTime,
                                    "getContentProviderImpl: before set stopped state");
                            AppGlobals.getPackageManager().setPackageStoppedState(
                            mService.mPackageManagerInt.setPackageStoppedState(
                                    cpr.appInfo.packageName, false, userId);
                            checkTime(startTime, "getContentProviderImpl: after set stopped state");
                        } catch (RemoteException e) {
                        } catch (IllegalArgumentException e) {
                            Slog.w(TAG, "Failed trying to unstop package "
                                    + cpr.appInfo.packageName + ": " + e);
Loading