The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.am; |
| 18 | |
| 19 | import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR; |
| 20 | |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 21 | import android.content.ActivityNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.content.Context; |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 23 | import android.content.DialogInterface; |
| 24 | import android.content.Intent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import android.content.res.Resources; |
| 26 | import android.os.Handler; |
| 27 | import android.os.Message; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 28 | import android.util.Slog; |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 29 | import android.view.WindowManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | |
Dianne Hackborn | be4e6aa | 2013-06-07 13:25:29 -0700 | [diff] [blame] | 31 | final class AppNotRespondingDialog extends BaseErrorDialog { |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 32 | private static final String TAG = "AppNotRespondingDialog"; |
| 33 | |
| 34 | // Event 'what' codes |
| 35 | static final int FORCE_CLOSE = 1; |
| 36 | static final int WAIT = 2; |
| 37 | static final int WAIT_AND_REPORT = 3; |
| 38 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | private final ActivityManagerService mService; |
| 40 | private final ProcessRecord mProc; |
| 41 | |
| 42 | public AppNotRespondingDialog(ActivityManagerService service, Context context, |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 43 | ProcessRecord app, ActivityRecord activity, boolean aboveSystem) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | super(context); |
| 45 | |
| 46 | mService = service; |
| 47 | mProc = app; |
| 48 | Resources res = context.getResources(); |
| 49 | |
| 50 | setCancelable(false); |
| 51 | |
| 52 | int resid; |
| 53 | CharSequence name1 = activity != null |
| 54 | ? activity.info.loadLabel(context.getPackageManager()) |
| 55 | : null; |
| 56 | CharSequence name2 = null; |
| 57 | if ((app.pkgList.size() == 1) && |
| 58 | (name2=context.getPackageManager().getApplicationLabel(app.info)) != null) { |
| 59 | if (name1 != null) { |
| 60 | resid = com.android.internal.R.string.anr_activity_application; |
| 61 | } else { |
| 62 | name1 = name2; |
| 63 | name2 = app.processName; |
| 64 | resid = com.android.internal.R.string.anr_application_process; |
| 65 | } |
| 66 | } else { |
| 67 | if (name1 != null) { |
| 68 | name2 = app.processName; |
| 69 | resid = com.android.internal.R.string.anr_activity_process; |
| 70 | } else { |
| 71 | name1 = app.processName; |
| 72 | resid = com.android.internal.R.string.anr_process; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | setMessage(name2 != null |
| 77 | ? res.getString(resid, name1.toString(), name2.toString()) |
| 78 | : res.getString(resid, name1.toString())); |
| 79 | |
Adam Powell | 40a9784 | 2011-08-14 17:12:10 -0700 | [diff] [blame] | 80 | setButton(DialogInterface.BUTTON_POSITIVE, |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 81 | res.getText(com.android.internal.R.string.force_close), |
| 82 | mHandler.obtainMessage(FORCE_CLOSE)); |
Adam Powell | 40a9784 | 2011-08-14 17:12:10 -0700 | [diff] [blame] | 83 | setButton(DialogInterface.BUTTON_NEGATIVE, |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 84 | res.getText(com.android.internal.R.string.wait), |
| 85 | mHandler.obtainMessage(WAIT)); |
| 86 | |
| 87 | if (app.errorReportReceiver != null) { |
Adam Powell | 40a9784 | 2011-08-14 17:12:10 -0700 | [diff] [blame] | 88 | setButton(DialogInterface.BUTTON_NEUTRAL, |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 89 | res.getText(com.android.internal.R.string.report), |
| 90 | mHandler.obtainMessage(WAIT_AND_REPORT)); |
| 91 | } |
| 92 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | setTitle(res.getText(com.android.internal.R.string.anr_title)); |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 94 | if (aboveSystem) { |
| 95 | getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR); |
| 96 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | getWindow().addFlags(FLAG_SYSTEM_ERROR); |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 98 | WindowManager.LayoutParams attrs = getWindow().getAttributes(); |
| 99 | attrs.setTitle("Application Not Responding: " + app.info.processName); |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 100 | attrs.privateFlags = WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 101 | getWindow().setAttributes(attrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | public void onStop() { |
| 105 | } |
| 106 | |
| 107 | private final Handler mHandler = new Handler() { |
| 108 | public void handleMessage(Message msg) { |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 109 | Intent appErrorIntent = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | switch (msg.what) { |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 111 | case FORCE_CLOSE: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | // Kill the application. |
Dan Egnor | 42471dd | 2010-01-07 17:25:22 -0800 | [diff] [blame] | 113 | mService.killAppAtUsersRequest(mProc, AppNotRespondingDialog.this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | break; |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 115 | case WAIT_AND_REPORT: |
| 116 | case WAIT: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | // Continue waiting for the application. |
| 118 | synchronized (mService) { |
| 119 | ProcessRecord app = mProc; |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 120 | |
| 121 | if (msg.what == WAIT_AND_REPORT) { |
Jacek Surazski | 41a9fd5 | 2010-01-27 16:37:21 -0800 | [diff] [blame] | 122 | appErrorIntent = mService.createAppErrorIntentLocked(app, |
| 123 | System.currentTimeMillis(), null); |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 124 | } |
| 125 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | app.notResponding = false; |
| 127 | app.notRespondingReport = null; |
| 128 | if (app.anrDialog == AppNotRespondingDialog.this) { |
| 129 | app.anrDialog = null; |
| 130 | } |
| 131 | } |
| 132 | break; |
| 133 | } |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 134 | |
| 135 | if (appErrorIntent != null) { |
| 136 | try { |
| 137 | getContext().startActivity(appErrorIntent); |
| 138 | } catch (ActivityNotFoundException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 139 | Slog.w(TAG, "bug report receiver dissappeared", e); |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 140 | } |
| 141 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | } |
| 143 | }; |
| 144 | } |