diff options
author | Anis Assi <anisassi@google.com> | 2020-04-28 12:41:11 -0700 |
---|---|---|
committer | Anis Assi <anisassi@google.com> | 2020-04-28 12:41:11 -0700 |
commit | 219090580807891b83d167c06d941feba45edf1f (patch) | |
tree | 730dc3397712cd15505e8ebe6c61d72693e5ad9f | |
parent | 7fc95f204527ee079c5891d56c969668f0b35a0b (diff) | |
download | base-219090580807891b83d167c06d941feba45edf1f.tar.gz |
Revert "DO NOT MERGE - Kill apps outright for API contract violations"
This reverts commit ca006a7de870f58587dbd9054aa98b3ea21157f6.
7 files changed, 16 insertions, 52 deletions
diff --git a/core/java/android/app/IActivityManager.aidl b/core/java/android/app/IActivityManager.aidl index 1bee7ce1ff0e..569c2bd37b6a 100644 --- a/core/java/android/app/IActivityManager.aidl +++ b/core/java/android/app/IActivityManager.aidl @@ -278,8 +278,7 @@ interface IActivityManager { boolean isImmersive(in IBinder token); void setImmersive(in IBinder token, boolean immersive); boolean isTopActivityImmersive(); - void crashApplication(int uid, int initialPid, in String packageName, int userId, - in String message, boolean force); + void crashApplication(int uid, int initialPid, in String packageName, int userId, in String message); String getProviderMimeType(in Uri uri, int userId); IBinder newUriPermissionOwner(in String name); void grantUriPermissionFromOwner(in IBinder owner, int fromUid, in String targetPkg, diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java index b49d07f3e46c..ca715b51a328 100644 --- a/services/core/java/com/android/server/am/ActiveServices.java +++ b/services/core/java/com/android/server/am/ActiveServices.java @@ -787,15 +787,6 @@ public final class ActiveServices { } } - void killMisbehavingService(ServiceRecord r, - int appUid, int appPid, String localPackageName) { - synchronized (mAm) { - stopServiceLocked(r); - mAm.crashApplication(appUid, appPid, localPackageName, -1, - "Bad notification for startForeground", true /*force*/); - } - } - IBinder peekServiceLocked(Intent service, String resolvedType, String callingPackage) { ServiceLookupResult r = retrieveServiceLocked(service, resolvedType, callingPackage, Binder.getCallingPid(), Binder.getCallingUid(), @@ -3664,7 +3655,7 @@ public final class ActiveServices { void serviceForegroundCrash(ProcessRecord app, CharSequence serviceRecord) { mAm.crashApplication(app.uid, app.pid, app.info.packageName, app.userId, "Context.startForegroundService() did not then call Service.startForeground(): " - + serviceRecord, false /*force*/); + + serviceRecord); } void scheduleServiceTimeoutLocked(ProcessRecord proc) { diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index a2ea8e0dac29..18f99945f169 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -5763,7 +5763,7 @@ public class ActivityManagerService extends IActivityManager.Stub @Override public void crashApplication(int uid, int initialPid, String packageName, int userId, - String message, boolean force) { + String message) { if (checkCallingPermission(android.Manifest.permission.FORCE_STOP_PACKAGES) != PackageManager.PERMISSION_GRANTED) { String msg = "Permission Denial: crashApplication() from pid=" @@ -5775,8 +5775,7 @@ public class ActivityManagerService extends IActivityManager.Stub } synchronized(this) { - mAppErrors.scheduleAppCrashLocked(uid, initialPid, packageName, userId, - message, force); + mAppErrors.scheduleAppCrashLocked(uid, initialPid, packageName, userId, message); } } diff --git a/services/core/java/com/android/server/am/ActivityManagerShellCommand.java b/services/core/java/com/android/server/am/ActivityManagerShellCommand.java index c105a33d5c6b..dc9a5adb5a0c 100644 --- a/services/core/java/com/android/server/am/ActivityManagerShellCommand.java +++ b/services/core/java/com/android/server/am/ActivityManagerShellCommand.java @@ -990,7 +990,7 @@ final class ActivityManagerShellCommand extends ShellCommand { } catch (NumberFormatException e) { packageName = arg; } - mInterface.crashApplication(-1, pid, packageName, userId, "shell-induced crash", false); + mInterface.crashApplication(-1, pid, packageName, userId, "shell-induced crash"); return 0; } diff --git a/services/core/java/com/android/server/am/AppErrors.java b/services/core/java/com/android/server/am/AppErrors.java index e6a170478b82..a6dafbb1db36 100644 --- a/services/core/java/com/android/server/am/AppErrors.java +++ b/services/core/java/com/android/server/am/AppErrors.java @@ -314,24 +314,20 @@ class AppErrors { } void killAppAtUserRequestLocked(ProcessRecord app, Dialog fromDialog) { + app.crashing = false; + app.crashingReport = null; + app.notResponding = false; + app.notRespondingReport = null; if (app.anrDialog == fromDialog) { app.anrDialog = null; } if (app.waitDialog == fromDialog) { app.waitDialog = null; } - killAppImmediateLocked(app, "user-terminated", "user request after error"); - } - - private void killAppImmediateLocked(ProcessRecord app, String reason, String killReason) { - app.crashing = false; - app.crashingReport = null; - app.notResponding = false; - app.notRespondingReport = null; if (app.pid > 0 && app.pid != MY_PID) { - handleAppCrashLocked(app, reason, + handleAppCrashLocked(app, "user-terminated" /*reason*/, null /*shortMsg*/, null /*longMsg*/, null /*stackTrace*/, null /*data*/); - app.kill(killReason, true); + app.kill("user request after error", true); } } @@ -345,7 +341,7 @@ class AppErrors { * @param message */ void scheduleAppCrashLocked(int uid, int initialPid, String packageName, int userId, - String message, boolean force) { + String message) { ProcessRecord proc = null; // Figure out which process to kill. We don't trust that initialPid @@ -378,14 +374,6 @@ class AppErrors { } proc.scheduleCrash(message); - if (force) { - // If the app is responsive, the scheduled crash will happen as expected - // and then the delayed summary kill will be a no-op. - final ProcessRecord p = proc; - mService.mHandler.postDelayed( - () -> killAppImmediateLocked(p, "forced", "killed for invalid state"), - 5000L); - } } /** diff --git a/services/core/java/com/android/server/am/ServiceRecord.java b/services/core/java/com/android/server/am/ServiceRecord.java index 925a4d97fa32..4d89d015b669 100644 --- a/services/core/java/com/android/server/am/ServiceRecord.java +++ b/services/core/java/com/android/server/am/ServiceRecord.java @@ -584,7 +584,6 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN final String localPackageName = packageName; final int localForegroundId = foregroundId; final Notification _foregroundNoti = foregroundNoti; - final ServiceRecord record = this; ams.mHandler.post(new Runnable() { public void run() { NotificationManagerInternal nm = LocalServices.getService( @@ -683,8 +682,10 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN Slog.w(TAG, "Error showing notification for service", e); // If it gave us a garbage notification, it doesn't // get to be foreground. - ams.mServices.killMisbehavingService(record, - appUid, appPid, localPackageName); + ams.setServiceForeground(name, ServiceRecord.this, + 0, null, 0); + ams.crashApplication(appUid, appPid, localPackageName, -1, + "Bad notification for startForeground: " + e); } } }); diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index c422f5e092bc..78204acd6626 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -792,22 +792,8 @@ public class NotificationManagerService extends SystemService { @Override public void onNotificationError(int callingUid, int callingPid, String pkg, String tag, int id, int uid, int initialPid, String message, int userId) { - final boolean fgService; - synchronized (mNotificationLock) { - NotificationRecord r = findNotificationLocked(pkg, tag, id, userId); - fgService = r != null && (r.getNotification().flags & FLAG_FOREGROUND_SERVICE) != 0; - } cancelNotification(callingUid, callingPid, pkg, tag, id, 0, 0, false, userId, REASON_ERROR, null); - if (fgService) { - // Still crash for foreground services, preventing the not-crash behaviour abused - // by apps to give us a garbage notification and silently start a fg service. - Binder.withCleanCallingIdentity( - () -> mAm.crashApplication(uid, initialPid, pkg, -1, - "Bad notification(tag=" + tag + ", id=" + id + ") posted from package " - + pkg + ", crashing app(uid=" + uid + ", pid=" + initialPid + "): " - + message, true /* force */)); - } } @Override |