blob: d9c6a3023903c40560e5fb92b9c317a491851531 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package com.android.server.am;
18
Adrian Roos90462222016-02-17 15:45:09 -080019import com.android.internal.logging.MetricsLogger;
Tamas Berghammer383db5eb2016-06-22 15:21:38 +010020import com.android.internal.logging.nano.MetricsProto;
Adrian Roos90462222016-02-17 15:45:09 -080021
Jacek Surazskif5b9c722009-05-18 12:09:59 +020022import android.content.ActivityNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.content.Context;
Jacek Surazskif5b9c722009-05-18 12:09:59 +020024import android.content.DialogInterface;
25import android.content.Intent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.content.res.Resources;
Adrian Roosa85a2c62016-01-26 09:14:22 -080027import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.os.Handler;
29import android.os.Message;
Adrian Roos890f1f32016-03-03 16:23:30 -080030import android.text.BidiFormatter;
Joe Onorato8a9b2202010-02-26 18:56:32 -080031import android.util.Slog;
Adrian Roosa85a2c62016-01-26 09:14:22 -080032import android.view.LayoutInflater;
33import android.view.View;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070034import android.view.WindowManager;
Adrian Roosa85a2c62016-01-26 09:14:22 -080035import android.widget.FrameLayout;
36import android.widget.TextView;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037
Adrian Roosa85a2c62016-01-26 09:14:22 -080038final class AppNotRespondingDialog extends BaseErrorDialog implements View.OnClickListener {
Jacek Surazskif5b9c722009-05-18 12:09:59 +020039 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 Roos90462222016-02-17 15:45:09 -080046 public static final int CANT_SHOW = -1;
47 public static final int ALREADY_SHOWING = -2;
48
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049 private final ActivityManagerService mService;
50 private final ProcessRecord mProc;
Adrian Roosa85a2c62016-01-26 09:14:22 -080051
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052 public AppNotRespondingDialog(ActivityManagerService service, Context context,
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070053 ProcessRecord app, ActivityRecord activity, boolean aboveSystem) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054 super(context);
Adrian Roosa85a2c62016-01-26 09:14:22 -080055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056 mService = service;
57 mProc = app;
58 Resources res = context.getResources();
Adrian Roosa85a2c62016-01-26 09:14:22 -080059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060 setCancelable(false);
61
62 int resid;
63 CharSequence name1 = activity != null
64 ? activity.info.loadLabel(context.getPackageManager())
65 : null;
66 CharSequence name2 = null;
67 if ((app.pkgList.size() == 1) &&
68 (name2=context.getPackageManager().getApplicationLabel(app.info)) != null) {
69 if (name1 != null) {
70 resid = com.android.internal.R.string.anr_activity_application;
71 } else {
72 name1 = name2;
73 name2 = app.processName;
74 resid = com.android.internal.R.string.anr_application_process;
75 }
76 } else {
77 if (name1 != null) {
78 name2 = app.processName;
79 resid = com.android.internal.R.string.anr_activity_process;
80 } else {
81 name1 = app.processName;
82 resid = com.android.internal.R.string.anr_process;
83 }
84 }
85
Adrian Roos890f1f32016-03-03 16:23:30 -080086 BidiFormatter bidi = BidiFormatter.getInstance();
87
Adrian Roosa85a2c62016-01-26 09:14:22 -080088 setTitle(name2 != null
Adrian Roos890f1f32016-03-03 16:23:30 -080089 ? res.getString(resid, bidi.unicodeWrap(name1.toString()), bidi.unicodeWrap(name2.toString()))
90 : res.getString(resid, bidi.unicodeWrap(name1.toString())));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070092 if (aboveSystem) {
93 getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
94 }
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070095 WindowManager.LayoutParams attrs = getWindow().getAttributes();
96 attrs.setTitle("Application Not Responding: " + app.info.processName);
Adam Lesinski95c42972013-10-02 10:13:27 -070097 attrs.privateFlags = WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_ERROR |
98 WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070099 getWindow().setAttributes(attrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 }
101
Adrian Roosa85a2c62016-01-26 09:14:22 -0800102 @Override
103 protected void onCreate(Bundle savedInstanceState) {
104 super.onCreate(savedInstanceState);
Alan Viverette51efddb2017-04-05 10:00:01 -0400105 final FrameLayout frame = findViewById(android.R.id.custom);
Adrian Roosa85a2c62016-01-26 09:14:22 -0800106 final Context context = getContext();
107 LayoutInflater.from(context).inflate(
108 com.android.internal.R.layout.app_anr_dialog, frame, true);
109
Alan Viverette51efddb2017-04-05 10:00:01 -0400110 final TextView report = findViewById(com.android.internal.R.id.aerr_report);
Adrian Roosa85a2c62016-01-26 09:14:22 -0800111 report.setOnClickListener(this);
112 final boolean hasReceiver = mProc.errorReportReceiver != null;
113 report.setVisibility(hasReceiver ? View.VISIBLE : View.GONE);
Alan Viverette51efddb2017-04-05 10:00:01 -0400114 final TextView close = findViewById(com.android.internal.R.id.aerr_close);
Adrian Roosa85a2c62016-01-26 09:14:22 -0800115 close.setOnClickListener(this);
Alan Viverette51efddb2017-04-05 10:00:01 -0400116 final TextView wait = findViewById(com.android.internal.R.id.aerr_wait);
Adrian Roosa85a2c62016-01-26 09:14:22 -0800117 wait.setOnClickListener(this);
118
119 findViewById(com.android.internal.R.id.customPanel).setVisibility(View.VISIBLE);
120 }
121
122 @Override
123 public void onClick(View v) {
124 switch (v.getId()) {
125 case com.android.internal.R.id.aerr_report:
126 mHandler.obtainMessage(WAIT_AND_REPORT).sendToTarget();
127 break;
128 case com.android.internal.R.id.aerr_close:
129 mHandler.obtainMessage(FORCE_CLOSE).sendToTarget();
130 break;
131 case com.android.internal.R.id.aerr_wait:
132 mHandler.obtainMessage(WAIT).sendToTarget();
133 break;
134 default:
135 break;
136 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 }
138
139 private final Handler mHandler = new Handler() {
140 public void handleMessage(Message msg) {
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200141 Intent appErrorIntent = null;
Adrian Roos90462222016-02-17 15:45:09 -0800142
143 MetricsLogger.action(getContext(), MetricsProto.MetricsEvent.ACTION_APP_ANR,
144 msg.what);
145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 switch (msg.what) {
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200147 case FORCE_CLOSE:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 // Kill the application.
Dan Egnor42471dd2010-01-07 17:25:22 -0800149 mService.killAppAtUsersRequest(mProc, AppNotRespondingDialog.this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 break;
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200151 case WAIT_AND_REPORT:
152 case WAIT:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 // Continue waiting for the application.
154 synchronized (mService) {
155 ProcessRecord app = mProc;
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200156
157 if (msg.what == WAIT_AND_REPORT) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100158 appErrorIntent = mService.mAppErrors.createAppErrorIntentLocked(app,
Jacek Surazski41a9fd52010-01-27 16:37:21 -0800159 System.currentTimeMillis(), null);
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200160 }
161
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 app.notResponding = false;
163 app.notRespondingReport = null;
164 if (app.anrDialog == AppNotRespondingDialog.this) {
165 app.anrDialog = null;
166 }
Dianne Hackborn2be00932013-09-22 16:46:00 -0700167 mService.mServices.scheduleServiceTimeoutLocked(app);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 }
169 break;
170 }
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200171
172 if (appErrorIntent != null) {
173 try {
174 getContext().startActivity(appErrorIntent);
175 } catch (ActivityNotFoundException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800176 Slog.w(TAG, "bug report receiver dissappeared", e);
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200177 }
178 }
Adrian Roosa85a2c62016-01-26 09:14:22 -0800179
180 dismiss();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 }
182 };
183}