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

Commit ea32bc4e authored by Benjamin Franz's avatar Benjamin Franz Committed by android-build-merger
Browse files

Merge "Expose hidden API to check whether a given package is state protected" into pi-dev

am: 3ff20e22

Change-Id: I797fd24aff1afa3e37e6b5f4dbd93042b19ac369
parents 669ceda1 3ff20e22
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -2855,4 +2855,13 @@ public class ApplicationPackageManager extends PackageManager {
            throw e.rethrowAsRuntimeException();
        }
    }

    @Override
    public boolean isPackageStateProtected(String packageName, int userId) {
        try {
            return mPM.isPackageStateProtected(packageName, userId);
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -674,4 +674,6 @@ interface IPackageManager {
    boolean hasUidSigningCertificate(int uid, in byte[] signingCertificate, int flags);

    String getSystemTextClassifierPackageName();

    boolean isPackageStateProtected(String packageName, int userId);
}
+12 −0
Original line number Diff line number Diff line
@@ -6140,4 +6140,16 @@ public abstract class PackageManager {
        throw new UnsupportedOperationException(
                "getSystemTextClassifierPackageName not implemented in subclass");
    }

    /**
     * @return whether a given package's state is protected, e.g. package cannot be disabled,
     *         suspended, hidden or force stopped.
     *
     * @hide
     */
    public boolean isPackageStateProtected(String packageName, int userId) {
        throw new UnsupportedOperationException(
            "isPackageStateProtected not implemented in subclass");
    }

}
+19 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.pm;
import static android.Manifest.permission.DELETE_PACKAGES;
import static android.Manifest.permission.MANAGE_DEVICE_ADMINS;
import static android.Manifest.permission.SET_HARMFUL_APP_WARNINGS;
import static android.Manifest.permission.INSTALL_PACKAGES;
import static android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS;
@@ -115,6 +116,7 @@ import android.Manifest;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.app.ActivityManager;
import android.app.ActivityManagerInternal;
import android.app.AppOpsManager;
@@ -24326,6 +24328,23 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
            return mSettings.getHarmfulAppWarningLPr(packageName, userId);
        }
    }
    @Override
    public boolean isPackageStateProtected(@NonNull String packageName, @UserIdInt int userId) {
        final int callingUid = Binder.getCallingUid();
        final int callingAppId = UserHandle.getAppId(callingUid);
        mPermissionManager.enforceCrossUserPermission(callingUid, userId,
                false /*requireFullPermission*/, true /*checkShell*/, "isPackageStateProtected");
        if (callingAppId != Process.SYSTEM_UID && callingAppId != Process.ROOT_UID
                && checkUidPermission(MANAGE_DEVICE_ADMINS, callingUid) != PERMISSION_GRANTED) {
            throw new SecurityException("Caller must have the "
                    + MANAGE_DEVICE_ADMINS + " permission.");
        }
        return mProtectedPackages.isPackageStateProtected(userId, packageName);
    }
}
interface PackageSender {