Merge "Do not kill backup apps during restore for POST_NOTIFICATIONS" into tm-dev am: ae05ae1479

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18284930

Change-Id: I3ea2a4c64c36d4516eb682f28dd008b177641636
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Nate Myren
2022-05-12 15:25:03 +00:00
committed by Automerger Merge Worker

View File

@@ -42,6 +42,7 @@ import static android.content.pm.PackageManager.FLAG_PERMISSION_WHITELIST_SYSTEM
import static android.content.pm.PackageManager.FLAG_PERMISSION_WHITELIST_UPGRADE;
import static android.content.pm.PackageManager.MASK_PERMISSION_FLAGS_ALL;
import static android.content.pm.PackageManager.MATCH_DEBUG_TRIAGED_MISSING;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.os.Process.INVALID_UID;
import static android.os.Trace.TRACE_TAG_PACKAGE_MANAGER;
import static android.permission.PermissionManager.KILL_APP_REASON_GIDS_CHANGED;
@@ -97,6 +98,7 @@ import android.os.storage.StorageManager;
import android.permission.IOnPermissionsChangeListener;
import android.permission.PermissionControllerManager;
import android.permission.PermissionManager;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
@@ -333,7 +335,8 @@ public class PermissionManagerServiceImpl implements PermissionManagerServiceInt
mPackageManagerInt.writeSettings(true);
}
@Override
public void onPermissionRevoked(int uid, int userId, String reason, boolean overrideKill) {
public void onPermissionRevoked(int uid, int userId, String reason, boolean overrideKill,
@Nullable String permissionName) {
mOnPermissionChangeListeners.onPermissionsChanged(uid);
// Critical; after this call the application should never have the permission
@@ -342,13 +345,41 @@ public class PermissionManagerServiceImpl implements PermissionManagerServiceInt
return;
}
final int appId = UserHandle.getAppId(uid);
if (reason == null) {
mHandler.post(() -> killUid(appId, userId, KILL_APP_REASON_PERMISSIONS_REVOKED));
} else {
mHandler.post(() -> killUid(appId, userId, reason));
mHandler.post(() -> {
if (POST_NOTIFICATIONS.equals(permissionName)
&& isAppBackupAndRestoreRunning(uid)) {
return;
}
final int appId = UserHandle.getAppId(uid);
if (reason == null) {
killUid(appId, userId, KILL_APP_REASON_PERMISSIONS_REVOKED);
} else {
killUid(appId, userId, reason);
}
});
}
private boolean isAppBackupAndRestoreRunning(int uid) {
if (checkUidPermission(uid, Manifest.permission.BACKUP) != PERMISSION_GRANTED) {
return false;
}
try {
int userId = UserHandle.getUserId(uid);
boolean isInSetup = Settings.Secure.getIntForUser(mContext.getContentResolver(),
Settings.Secure.USER_SETUP_COMPLETE, userId) == 0;
boolean isInDeferredSetup = Settings.Secure.getIntForUser(
mContext.getContentResolver(),
Settings.Secure.USER_SETUP_PERSONALIZATION_STATE, userId)
== Settings.Secure.USER_SETUP_PERSONALIZATION_STARTED;
return isInSetup || isInDeferredSetup;
} catch (Settings.SettingNotFoundException e) {
Slog.w(LOG_TAG, "Failed to check if the user is in restore: " + e);
return false;
}
}
@Override
public void onInstallPermissionRevoked() {
mPackageManagerInt.writeSettings(true);
@@ -1600,7 +1631,7 @@ public class PermissionManagerServiceImpl implements PermissionManagerServiceInt
if (callback != null) {
if (isRuntimePermission) {
callback.onPermissionRevoked(UserHandle.getUid(userId, pkg.getUid()), userId,
reason, overrideKill);
reason, overrideKill, permName);
} else {
mDefaultPermissionCallback.onInstallPermissionRevoked();
}
@@ -5246,7 +5277,11 @@ public class PermissionManagerServiceImpl implements PermissionManagerServiceInt
onPermissionRevoked(uid, userId, reason, false);
}
public void onPermissionRevoked(int uid, @UserIdInt int userId, String reason,
boolean overrideKill) {}
boolean overrideKill) {
onPermissionRevoked(uid, userId, reason, false, null);
}
public void onPermissionRevoked(int uid, @UserIdInt int userId, String reason,
boolean overrideKill, @Nullable String permissionName) {}
public void onInstallPermissionRevoked() {}
public void onPermissionUpdated(@UserIdInt int[] updatedUserIds, boolean sync) {}
public void onPermissionUpdatedNotifyListener(@UserIdInt int[] updatedUserIds, boolean sync,