frameworks/base
修订版 | 6a89d1107b56327580292bad227b3aeaa65dbb8b (tree) |
---|---|
时间 | 2020-04-29 03:45:07 |
作者 | Anis Assi <anisassi@goog...> |
Commiter | Anis Assi |
Revert "DO NOT MERGE - Kill apps outright for API contract violations"
This reverts commit c6fd63a7a80f06a89b34aa1894694922c3af9f20.
@@ -266,8 +266,7 @@ interface IActivityManager { | ||
266 | 266 | boolean isImmersive(in IBinder token); |
267 | 267 | void setImmersive(in IBinder token, boolean immersive); |
268 | 268 | boolean isTopActivityImmersive(); |
269 | - void crashApplication(int uid, int initialPid, in String packageName, int userId, | |
270 | - in String message, boolean force); | |
269 | + void crashApplication(int uid, int initialPid, in String packageName, int userId, in String message); | |
271 | 270 | String getProviderMimeType(in Uri uri, int userId); |
272 | 271 | IBinder newUriPermissionOwner(in String name); |
273 | 272 | void grantUriPermissionFromOwner(in IBinder owner, int fromUid, in String targetPkg, |
@@ -653,15 +653,6 @@ public final class ActiveServices { | ||
653 | 653 | } |
654 | 654 | } |
655 | 655 | |
656 | - void killMisbehavingService(ServiceRecord r, | |
657 | - int appUid, int appPid, String localPackageName) { | |
658 | - synchronized (mAm) { | |
659 | - stopServiceLocked(r); | |
660 | - mAm.crashApplication(appUid, appPid, localPackageName, -1, | |
661 | - "Bad notification for startForeground", true /*force*/); | |
662 | - } | |
663 | - } | |
664 | - | |
665 | 656 | IBinder peekServiceLocked(Intent service, String resolvedType, String callingPackage) { |
666 | 657 | ServiceLookupResult r = retrieveServiceLocked(service, resolvedType, callingPackage, |
667 | 658 | Binder.getCallingPid(), Binder.getCallingUid(), |
@@ -3400,8 +3391,7 @@ public final class ActiveServices { | ||
3400 | 3391 | |
3401 | 3392 | void serviceForegroundCrash(ProcessRecord app) { |
3402 | 3393 | mAm.crashApplication(app.uid, app.pid, app.info.packageName, app.userId, |
3403 | - "Context.startForegroundService() did not then call Service.startForeground()", | |
3404 | - false /*force*/); | |
3394 | + "Context.startForegroundService() did not then call Service.startForeground()"); | |
3405 | 3395 | } |
3406 | 3396 | |
3407 | 3397 | void scheduleServiceTimeoutLocked(ProcessRecord proc) { |
@@ -5141,7 +5141,7 @@ public class ActivityManagerService extends IActivityManager.Stub | ||
5141 | 5141 | |
5142 | 5142 | @Override |
5143 | 5143 | public void crashApplication(int uid, int initialPid, String packageName, int userId, |
5144 | - String message, boolean force) { | |
5144 | + String message) { | |
5145 | 5145 | if (checkCallingPermission(android.Manifest.permission.FORCE_STOP_PACKAGES) |
5146 | 5146 | != PackageManager.PERMISSION_GRANTED) { |
5147 | 5147 | String msg = "Permission Denial: crashApplication() from pid=" |
@@ -5153,8 +5153,7 @@ public class ActivityManagerService extends IActivityManager.Stub | ||
5153 | 5153 | } |
5154 | 5154 | |
5155 | 5155 | synchronized(this) { |
5156 | - mAppErrors.scheduleAppCrashLocked(uid, initialPid, packageName, userId, | |
5157 | - message, force); | |
5156 | + mAppErrors.scheduleAppCrashLocked(uid, initialPid, packageName, userId, message); | |
5158 | 5157 | } |
5159 | 5158 | } |
5160 | 5159 |
@@ -921,7 +921,7 @@ final class ActivityManagerShellCommand extends ShellCommand { | ||
921 | 921 | } catch (NumberFormatException e) { |
922 | 922 | packageName = arg; |
923 | 923 | } |
924 | - mInterface.crashApplication(-1, pid, packageName, userId, "shell-induced crash", false); | |
924 | + mInterface.crashApplication(-1, pid, packageName, userId, "shell-induced crash"); | |
925 | 925 | return 0; |
926 | 926 | } |
927 | 927 |
@@ -243,24 +243,20 @@ class AppErrors { | ||
243 | 243 | } |
244 | 244 | |
245 | 245 | void killAppAtUserRequestLocked(ProcessRecord app, Dialog fromDialog) { |
246 | + app.crashing = false; | |
247 | + app.crashingReport = null; | |
248 | + app.notResponding = false; | |
249 | + app.notRespondingReport = null; | |
246 | 250 | if (app.anrDialog == fromDialog) { |
247 | 251 | app.anrDialog = null; |
248 | 252 | } |
249 | 253 | if (app.waitDialog == fromDialog) { |
250 | 254 | app.waitDialog = null; |
251 | 255 | } |
252 | - killAppImmediateLocked(app, "user-terminated", "user request after error"); | |
253 | - } | |
254 | - | |
255 | - private void killAppImmediateLocked(ProcessRecord app, String reason, String killReason) { | |
256 | - app.crashing = false; | |
257 | - app.crashingReport = null; | |
258 | - app.notResponding = false; | |
259 | - app.notRespondingReport = null; | |
260 | 256 | if (app.pid > 0 && app.pid != MY_PID) { |
261 | - handleAppCrashLocked(app, reason, | |
257 | + handleAppCrashLocked(app, "user-terminated" /*reason*/, | |
262 | 258 | null /*shortMsg*/, null /*longMsg*/, null /*stackTrace*/, null /*data*/); |
263 | - app.kill(killReason, true); | |
259 | + app.kill("user request after error", true); | |
264 | 260 | } |
265 | 261 | } |
266 | 262 |
@@ -274,7 +270,7 @@ class AppErrors { | ||
274 | 270 | * @param message |
275 | 271 | */ |
276 | 272 | void scheduleAppCrashLocked(int uid, int initialPid, String packageName, int userId, |
277 | - String message, boolean force) { | |
273 | + String message) { | |
278 | 274 | ProcessRecord proc = null; |
279 | 275 | |
280 | 276 | // Figure out which process to kill. We don't trust that initialPid |
@@ -307,14 +303,6 @@ class AppErrors { | ||
307 | 303 | } |
308 | 304 | |
309 | 305 | proc.scheduleCrash(message); |
310 | - if (force) { | |
311 | - // If the app is responsive, the scheduled crash will happen as expected | |
312 | - // and then the delayed summary kill will be a no-op. | |
313 | - final ProcessRecord p = proc; | |
314 | - mService.mHandler.postDelayed( | |
315 | - () -> killAppImmediateLocked(p, "forced", "killed for invalid state"), | |
316 | - 5000L); | |
317 | - } | |
318 | 306 | } |
319 | 307 | |
320 | 308 | /** |
@@ -453,7 +453,6 @@ final class ServiceRecord extends Binder { | ||
453 | 453 | final String localPackageName = packageName; |
454 | 454 | final int localForegroundId = foregroundId; |
455 | 455 | final Notification _foregroundNoti = foregroundNoti; |
456 | - final ServiceRecord record = this; | |
457 | 456 | ams.mHandler.post(new Runnable() { |
458 | 457 | public void run() { |
459 | 458 | NotificationManagerInternal nm = LocalServices.getService( |
@@ -552,8 +551,10 @@ final class ServiceRecord extends Binder { | ||
552 | 551 | Slog.w(TAG, "Error showing notification for service", e); |
553 | 552 | // If it gave us a garbage notification, it doesn't |
554 | 553 | // get to be foreground. |
555 | - ams.mServices.killMisbehavingService(record, | |
556 | - appUid, appPid, localPackageName); | |
554 | + ams.setServiceForeground(name, ServiceRecord.this, | |
555 | + 0, null, 0); | |
556 | + ams.crashApplication(appUid, appPid, localPackageName, -1, | |
557 | + "Bad notification for startForeground: " + e); | |
557 | 558 | } |
558 | 559 | } |
559 | 560 | }); |
@@ -714,23 +714,18 @@ public class NotificationManagerService extends SystemService { | ||
714 | 714 | @Override |
715 | 715 | public void onNotificationError(int callingUid, int callingPid, String pkg, String tag, int id, |
716 | 716 | int uid, int initialPid, String message, int userId) { |
717 | - final boolean fgService; | |
718 | - synchronized (mNotificationLock) { | |
719 | - NotificationRecord r = findNotificationLocked(pkg, tag, id, userId); | |
720 | - fgService = r != null | |
721 | - && (r.getNotification().flags&Notification.FLAG_FOREGROUND_SERVICE) != 0; | |
722 | - } | |
717 | + Slog.d(TAG, "onNotification error pkg=" + pkg + " tag=" + tag + " id=" + id | |
718 | + + "; will crashApplication(uid=" + uid + ", pid=" + initialPid + ")"); | |
723 | 719 | cancelNotification(callingUid, callingPid, pkg, tag, id, 0, 0, false, userId, |
724 | 720 | REASON_ERROR, null); |
725 | - if (fgService) { | |
726 | - // Still crash for foreground services, preventing the not-crash behaviour abused | |
727 | - // by apps to give us a garbage notification and silently start a fg service. | |
728 | - Binder.withCleanCallingIdentity( | |
729 | - () -> mAm.crashApplication(uid, initialPid, pkg, -1, | |
730 | - "Bad notification(tag=" + tag + ", id=" + id + ") posted from package " | |
731 | - + pkg + ", crashing app(uid=" + uid + ", pid=" + initialPid + "): " | |
732 | - + message, true /* force */)); | |
721 | + long ident = Binder.clearCallingIdentity(); | |
722 | + try { | |
723 | + ActivityManager.getService().crashApplication(uid, initialPid, pkg, -1, | |
724 | + "Bad notification posted from package " + pkg | |
725 | + + ": " + message); | |
726 | + } catch (RemoteException e) { | |
733 | 727 | } |
728 | + Binder.restoreCallingIdentity(ident); | |
734 | 729 | } |
735 | 730 | |
736 | 731 | @Override |