Merge "Expose hidden API to check whether a given package is state protected" into pi-dev
am: 3ff20e2257
Change-Id: I797fd24aff1afa3e37e6b5f4dbd93042b19ac369
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -674,4 +674,6 @@ interface IPackageManager {
|
||||
boolean hasUidSigningCertificate(int uid, in byte[] signingCertificate, int flags);
|
||||
|
||||
String getSystemTextClassifierPackageName();
|
||||
|
||||
boolean isPackageStateProtected(String packageName, int userId);
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user