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 | |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 19 | import android.content.pm.ApplicationInfo; |
Adrian Roos | 9046222 | 2016-02-17 15:45:09 -0800 | [diff] [blame] | 20 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 21 | import com.android.internal.logging.nano.MetricsProto; |
Adrian Roos | 9046222 | 2016-02-17 15:45:09 -0800 | [diff] [blame] | 22 | |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 23 | import android.content.ActivityNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.content.Context; |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 25 | import android.content.Intent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.content.res.Resources; |
Adrian Roos | a85a2c6 | 2016-01-26 09:14:22 -0800 | [diff] [blame] | 27 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import android.os.Handler; |
| 29 | import android.os.Message; |
Adrian Roos | 890f1f3 | 2016-03-03 16:23:30 -0800 | [diff] [blame] | 30 | import android.text.BidiFormatter; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 31 | import android.util.Slog; |
Adrian Roos | a85a2c6 | 2016-01-26 09:14:22 -0800 | [diff] [blame] | 32 | import android.view.LayoutInflater; |
| 33 | import android.view.View; |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 34 | import android.view.WindowManager; |
Adrian Roos | a85a2c6 | 2016-01-26 09:14:22 -0800 | [diff] [blame] | 35 | import android.widget.FrameLayout; |
| 36 | import android.widget.TextView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | |
Adrian Roos | a85a2c6 | 2016-01-26 09:14:22 -0800 | [diff] [blame] | 38 | final class AppNotRespondingDialog extends BaseErrorDialog implements View.OnClickListener { |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 39 | private static final String TAG = "AppNotRespondingDialog"; |
| 40 | |
| 41 | // Event 'what' codes |
| 42 | static final int FORCE_CLOSE = 1; |
| 43 | static final int WAIT = 2; |
| 44 | static final int WAIT_AND_REPORT = 3; |
| 45 | |
Adrian Roos | 9046222 | 2016-02-17 15:45:09 -0800 | [diff] [blame] | 46 | public static final int CANT_SHOW = -1; |
| 47 | public static final int ALREADY_SHOWING = -2; |
| 48 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | private final ActivityManagerService mService; |
| 50 | private final ProcessRecord mProc; |
Adrian Roos | a85a2c6 | 2016-01-26 09:14:22 -0800 | [diff] [blame] | 51 | |
Adrian Roos | c3a06e5 | 2018-02-16 18:33:17 +0100 | [diff] [blame] | 52 | public AppNotRespondingDialog(ActivityManagerService service, Context context, Data data) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | super(context); |
Adrian Roos | a85a2c6 | 2016-01-26 09:14:22 -0800 | [diff] [blame] | 54 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | mService = service; |
Adrian Roos | c3a06e5 | 2018-02-16 18:33:17 +0100 | [diff] [blame] | 56 | mProc = data.proc; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | Resources res = context.getResources(); |
Adrian Roos | a85a2c6 | 2016-01-26 09:14:22 -0800 | [diff] [blame] | 58 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | setCancelable(false); |
| 60 | |
| 61 | int resid; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 62 | CharSequence name1 = data.aInfo != null |
| 63 | ? data.aInfo.loadLabel(context.getPackageManager()) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | : null; |
| 65 | CharSequence name2 = null; |
Adrian Roos | c3a06e5 | 2018-02-16 18:33:17 +0100 | [diff] [blame] | 66 | if ((mProc.pkgList.size() == 1) && |
| 67 | (name2=context.getPackageManager().getApplicationLabel(mProc.info)) != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | if (name1 != null) { |
| 69 | resid = com.android.internal.R.string.anr_activity_application; |
| 70 | } else { |
| 71 | name1 = name2; |
Adrian Roos | c3a06e5 | 2018-02-16 18:33:17 +0100 | [diff] [blame] | 72 | name2 = mProc.processName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | resid = com.android.internal.R.string.anr_application_process; |
| 74 | } |
| 75 | } else { |
| 76 | if (name1 != null) { |
Adrian Roos | c3a06e5 | 2018-02-16 18:33:17 +0100 | [diff] [blame] | 77 | name2 = mProc.processName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | resid = com.android.internal.R.string.anr_activity_process; |
| 79 | } else { |
Adrian Roos | c3a06e5 | 2018-02-16 18:33:17 +0100 | [diff] [blame] | 80 | name1 = mProc.processName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | resid = com.android.internal.R.string.anr_process; |
| 82 | } |
| 83 | } |
| 84 | |
Adrian Roos | 890f1f3 | 2016-03-03 16:23:30 -0800 | [diff] [blame] | 85 | BidiFormatter bidi = BidiFormatter.getInstance(); |
| 86 | |
Adrian Roos | a85a2c6 | 2016-01-26 09:14:22 -0800 | [diff] [blame] | 87 | setTitle(name2 != null |
Adrian Roos | 890f1f3 | 2016-03-03 16:23:30 -0800 | [diff] [blame] | 88 | ? res.getString(resid, bidi.unicodeWrap(name1.toString()), bidi.unicodeWrap(name2.toString())) |
| 89 | : res.getString(resid, bidi.unicodeWrap(name1.toString()))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | |
Adrian Roos | c3a06e5 | 2018-02-16 18:33:17 +0100 | [diff] [blame] | 91 | if (data.aboveSystem) { |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 92 | getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR); |
| 93 | } |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 94 | WindowManager.LayoutParams attrs = getWindow().getAttributes(); |
Adrian Roos | c3a06e5 | 2018-02-16 18:33:17 +0100 | [diff] [blame] | 95 | attrs.setTitle("Application Not Responding: " + mProc.info.processName); |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 96 | attrs.privateFlags = WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_ERROR | |
| 97 | WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 98 | getWindow().setAttributes(attrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | } |
| 100 | |
Adrian Roos | a85a2c6 | 2016-01-26 09:14:22 -0800 | [diff] [blame] | 101 | @Override |
| 102 | protected void onCreate(Bundle savedInstanceState) { |
| 103 | super.onCreate(savedInstanceState); |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 104 | final FrameLayout frame = findViewById(android.R.id.custom); |
Adrian Roos | a85a2c6 | 2016-01-26 09:14:22 -0800 | [diff] [blame] | 105 | final Context context = getContext(); |
| 106 | LayoutInflater.from(context).inflate( |
| 107 | com.android.internal.R.layout.app_anr_dialog, frame, true); |
| 108 | |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 109 | final TextView report = findViewById(com.android.internal.R.id.aerr_report); |
Adrian Roos | a85a2c6 | 2016-01-26 09:14:22 -0800 | [diff] [blame] | 110 | report.setOnClickListener(this); |
| 111 | final boolean hasReceiver = mProc.errorReportReceiver != null; |
| 112 | report.setVisibility(hasReceiver ? View.VISIBLE : View.GONE); |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 113 | final TextView close = findViewById(com.android.internal.R.id.aerr_close); |
Adrian Roos | a85a2c6 | 2016-01-26 09:14:22 -0800 | [diff] [blame] | 114 | close.setOnClickListener(this); |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 115 | final TextView wait = findViewById(com.android.internal.R.id.aerr_wait); |
Adrian Roos | a85a2c6 | 2016-01-26 09:14:22 -0800 | [diff] [blame] | 116 | wait.setOnClickListener(this); |
| 117 | |
| 118 | findViewById(com.android.internal.R.id.customPanel).setVisibility(View.VISIBLE); |
| 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public void onClick(View v) { |
| 123 | switch (v.getId()) { |
| 124 | case com.android.internal.R.id.aerr_report: |
| 125 | mHandler.obtainMessage(WAIT_AND_REPORT).sendToTarget(); |
| 126 | break; |
| 127 | case com.android.internal.R.id.aerr_close: |
| 128 | mHandler.obtainMessage(FORCE_CLOSE).sendToTarget(); |
| 129 | break; |
| 130 | case com.android.internal.R.id.aerr_wait: |
| 131 | mHandler.obtainMessage(WAIT).sendToTarget(); |
| 132 | break; |
| 133 | default: |
| 134 | break; |
| 135 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | private final Handler mHandler = new Handler() { |
| 139 | public void handleMessage(Message msg) { |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 140 | Intent appErrorIntent = null; |
Adrian Roos | 9046222 | 2016-02-17 15:45:09 -0800 | [diff] [blame] | 141 | |
| 142 | MetricsLogger.action(getContext(), MetricsProto.MetricsEvent.ACTION_APP_ANR, |
| 143 | msg.what); |
| 144 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | switch (msg.what) { |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 146 | case FORCE_CLOSE: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | // Kill the application. |
Dan Egnor | 42471dd | 2010-01-07 17:25:22 -0800 | [diff] [blame] | 148 | mService.killAppAtUsersRequest(mProc, AppNotRespondingDialog.this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | break; |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 150 | case WAIT_AND_REPORT: |
| 151 | case WAIT: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | // Continue waiting for the application. |
| 153 | synchronized (mService) { |
| 154 | ProcessRecord app = mProc; |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 155 | |
| 156 | if (msg.what == WAIT_AND_REPORT) { |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 157 | appErrorIntent = mService.mAppErrors.createAppErrorIntentLocked(app, |
Jacek Surazski | 41a9fd5 | 2010-01-27 16:37:21 -0800 | [diff] [blame] | 158 | System.currentTimeMillis(), null); |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 159 | } |
| 160 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 161 | app.setNotResponding(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | app.notRespondingReport = null; |
| 163 | if (app.anrDialog == AppNotRespondingDialog.this) { |
| 164 | app.anrDialog = null; |
| 165 | } |
Dianne Hackborn | 2be0093 | 2013-09-22 16:46:00 -0700 | [diff] [blame] | 166 | mService.mServices.scheduleServiceTimeoutLocked(app); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | } |
| 168 | break; |
| 169 | } |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 170 | |
| 171 | if (appErrorIntent != null) { |
| 172 | try { |
| 173 | getContext().startActivity(appErrorIntent); |
| 174 | } catch (ActivityNotFoundException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 175 | Slog.w(TAG, "bug report receiver dissappeared", e); |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 176 | } |
| 177 | } |
Adrian Roos | a85a2c6 | 2016-01-26 09:14:22 -0800 | [diff] [blame] | 178 | |
| 179 | dismiss(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | } |
| 181 | }; |
Adrian Roos | c3a06e5 | 2018-02-16 18:33:17 +0100 | [diff] [blame] | 182 | |
| 183 | static class Data { |
| 184 | final ProcessRecord proc; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 185 | final ApplicationInfo aInfo; |
Adrian Roos | c3a06e5 | 2018-02-16 18:33:17 +0100 | [diff] [blame] | 186 | final boolean aboveSystem; |
| 187 | |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 188 | Data(ProcessRecord proc, ApplicationInfo aInfo, boolean aboveSystem) { |
Adrian Roos | c3a06e5 | 2018-02-16 18:33:17 +0100 | [diff] [blame] | 189 | this.proc = proc; |
Wale Ogunwale | 51cc98a | 2018-10-15 10:41:05 -0700 | [diff] [blame] | 190 | this.aInfo = aInfo; |
Adrian Roos | c3a06e5 | 2018-02-16 18:33:17 +0100 | [diff] [blame] | 191 | this.aboveSystem = aboveSystem; |
| 192 | } |
| 193 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | } |