Merge "Enforce guards against crash command via shell" into tm-dev am: 4d2ea02b88 am: 496c0968a8

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

Change-Id: I7309b46d27e9a2fd8b3e78d4ac3991ca84ad3339
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Ayush Sharma
2022-04-29 18:35:15 +00:00
committed by Automerger Merge Worker
2 changed files with 24 additions and 2 deletions

View File

@@ -1200,8 +1200,19 @@ final class ActivityManagerShellCommand extends ShellCommand {
} catch (NumberFormatException e) {
packageName = arg;
}
mInterface.crashApplicationWithType(-1, pid, packageName, userId, "shell-induced crash",
false, CrashedByAdbException.TYPE_ID);
int[] userIds = (userId == UserHandle.USER_ALL) ? mInternal.mUserController.getUserIds()
: new int[]{userId};
for (int id : userIds) {
if (mInternal.mUserController.hasUserRestriction(
UserManager.DISALLOW_DEBUGGING_FEATURES, id)) {
getOutPrintWriter().println(
"Shell does not have permission to crash packages for user " + id);
continue;
}
mInterface.crashApplicationWithType(-1, pid, packageName, id, "shell-induced crash",
false, CrashedByAdbException.TYPE_ID);
}
return 0;
}

View File

@@ -33,6 +33,7 @@ import android.app.ActivityOptions;
import android.app.AnrController;
import android.app.ApplicationErrorReport;
import android.app.ApplicationExitInfo;
import android.app.RemoteServiceException.CrashedByAdbException;
import android.app.usage.UsageStatsManager;
import android.content.ActivityNotFoundException;
import android.content.Context;
@@ -523,6 +524,16 @@ class AppErrors {
return;
}
if (exceptionTypeId == CrashedByAdbException.TYPE_ID) {
String[] packages = proc.getPackageList();
for (int i = 0; i < packages.length; i++) {
if (mService.mPackageManagerInt.isPackageStateProtected(packages[i], proc.userId)) {
Slog.w(TAG, "crashApplication: Can not crash protected package " + packages[i]);
return;
}
}
}
proc.scheduleCrashLocked(message, exceptionTypeId, extras);
if (force) {
// If the app is responsive, the scheduled crash will happen as expected