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