Merge "Add caller check to com.android.credentials.RESET"

This commit is contained in:
TreeHugger Robot
2022-01-06 03:07:42 +00:00
committed by Android (Google) Code Review

View File

@@ -86,7 +86,7 @@ public final class CredentialStorage extends FragmentActivity {
final String action = intent.getAction(); final String action = intent.getAction();
final UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE); final UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
if (!userManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_CREDENTIALS)) { if (!userManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_CREDENTIALS)) {
if (ACTION_RESET.equals(action)) { if (ACTION_RESET.equals(action) && checkCallerIsSelf()) {
new ResetDialog(); new ResetDialog();
} else { } else {
if (ACTION_INSTALL.equals(action) && checkCallerIsCertInstallerOrSelfInProfile()) { if (ACTION_INSTALL.equals(action) && checkCallerIsCertInstallerOrSelfInProfile()) {
@@ -318,6 +318,19 @@ public final class CredentialStorage extends FragmentActivity {
finish(); finish();
} }
/**
* Check that the caller is Settings.
*/
private boolean checkCallerIsSelf() {
try {
return Process.myUid() == android.app.ActivityManager.getService()
.getLaunchedFromUid(getActivityToken());
} catch (RemoteException re) {
// Error talking to ActivityManager, just give up
return false;
}
}
/** /**
* Check that the caller is either certinstaller or Settings running in a profile of this user. * Check that the caller is either certinstaller or Settings running in a profile of this user.
*/ */