blob: 68c63a2d595b6af8f735009de70090d8c13eeb79 [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 Roosad028c12016-05-17 14:30:42 -070019import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.content.Context;
Adrian Roosad028c12016-05-17 14:30:42 -070021import android.content.Intent;
22import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.content.res.Resources;
Jeff Sharkey5ab02432017-06-27 11:01:36 -060024import android.os.Build;
Filip Gruszczynskia925f182015-07-28 09:36:51 -070025import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.os.Handler;
27import android.os.Message;
Adrian Roosad028c12016-05-17 14:30:42 -070028import android.provider.Settings;
Adrian Roos890f1f32016-03-03 16:23:30 -080029import android.text.BidiFormatter;
Filip Gruszczynskia925f182015-07-28 09:36:51 -070030import android.view.LayoutInflater;
31import android.view.View;
Dianne Hackborn38cc8962011-10-13 11:33:55 -070032import android.view.WindowManager;
Filip Gruszczynskia925f182015-07-28 09:36:51 -070033import android.widget.FrameLayout;
34import android.widget.TextView;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035
Adrian Roos20d7df32016-01-12 18:59:43 +010036final class AppErrorDialog extends BaseErrorDialog implements View.OnClickListener {
Adrian Roos90462222016-02-17 15:45:09 -080037
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -070038 private final ActivityManagerService mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039 private final AppErrorResult mResult;
40 private final ProcessRecord mProc;
Adrian Roos805ea302016-07-27 12:25:54 -070041 private final boolean mIsRestartable;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042
Adrian Roos90462222016-02-17 15:45:09 -080043 static int CANT_SHOW = -1;
44 static int BACKGROUND_USER = -2;
45 static int ALREADY_SHOWING = -3;
46
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047 // Event 'what' codes
Adrian Roos20d7df32016-01-12 18:59:43 +010048 static final int FORCE_QUIT = 1;
49 static final int FORCE_QUIT_AND_REPORT = 2;
50 static final int RESTART = 3;
Adrian Roos20d7df32016-01-12 18:59:43 +010051 static final int MUTE = 5;
Adrian Roos90462222016-02-17 15:45:09 -080052 static final int TIMEOUT = 6;
Adrian Roosad028c12016-05-17 14:30:42 -070053 static final int CANCEL = 7;
Andrew Sapperstein5b679c42018-01-16 11:13:40 -080054 static final int APP_INFO = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055
56 // 5-minute timeout, then we automatically dismiss the crash dialog
57 static final long DISMISS_TIMEOUT = 1000 * 60 * 5;
Filip Gruszczynskia925f182015-07-28 09:36:51 -070058
Adrian Roos20d7df32016-01-12 18:59:43 +010059 public AppErrorDialog(Context context, ActivityManagerService service, Data data) {
60 super(context);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061 Resources res = context.getResources();
Filip Gruszczynskia925f182015-07-28 09:36:51 -070062
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -070063 mService = service;
Adrian Roos20d7df32016-01-12 18:59:43 +010064 mProc = data.proc;
65 mResult = data.result;
Andrew Sapperstein5b679c42018-01-16 11:13:40 -080066 mIsRestartable = (data.task != null || data.isRestartableForService)
67 && Settings.Global.getInt(context.getContentResolver(),
68 Settings.Global.SHOW_RESTART_IN_CRASH_DIALOG, 0) != 0;
Adrian Roos890f1f32016-03-03 16:23:30 -080069 BidiFormatter bidi = BidiFormatter.getInstance();
70
Andrew Sapperstein5b679c42018-01-16 11:13:40 -080071 CharSequence name;
Adrian Roos20d7df32016-01-12 18:59:43 +010072 if ((mProc.pkgList.size() == 1) &&
Andrew Sapperstein5b679c42018-01-16 11:13:40 -080073 (name = context.getPackageManager().getApplicationLabel(mProc.info)) != null) {
Adrian Roos20d7df32016-01-12 18:59:43 +010074 setTitle(res.getString(
Andrew Sapperstein5b679c42018-01-16 11:13:40 -080075 data.repeating ? com.android.internal.R.string.aerr_application_repeated
Adrian Roos20d7df32016-01-12 18:59:43 +010076 : com.android.internal.R.string.aerr_application,
Andrew Sapperstein5b679c42018-01-16 11:13:40 -080077 bidi.unicodeWrap(name.toString()),
Adrian Roos890f1f32016-03-03 16:23:30 -080078 bidi.unicodeWrap(mProc.info.processName)));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079 } else {
Andrew Sapperstein5b679c42018-01-16 11:13:40 -080080 name = mProc.processName;
Adrian Roos20d7df32016-01-12 18:59:43 +010081 setTitle(res.getString(
Andrew Sapperstein5b679c42018-01-16 11:13:40 -080082 data.repeating ? com.android.internal.R.string.aerr_process_repeated
Adrian Roos20d7df32016-01-12 18:59:43 +010083 : com.android.internal.R.string.aerr_process,
Andrew Sapperstein5b679c42018-01-16 11:13:40 -080084 bidi.unicodeWrap(name.toString())));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085 }
86
Adrian Roosad028c12016-05-17 14:30:42 -070087 setCancelable(true);
88 setCancelMessage(mHandler.obtainMessage(CANCEL));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070090 WindowManager.LayoutParams attrs = getWindow().getAttributes();
Adrian Roos20d7df32016-01-12 18:59:43 +010091 attrs.setTitle("Application Error: " + mProc.info.processName);
Adam Lesinski95c42972013-10-02 10:13:27 -070092 attrs.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_ERROR
93 | WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070094 getWindow().setAttributes(attrs);
Adrian Roos20d7df32016-01-12 18:59:43 +010095 if (mProc.persistent) {
Dianne Hackborn38cc8962011-10-13 11:33:55 -070096 getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
97 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098
99 // After the timeout, pretend the user clicked the quit button
100 mHandler.sendMessageDelayed(
Adrian Roos90462222016-02-17 15:45:09 -0800101 mHandler.obtainMessage(TIMEOUT),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 DISMISS_TIMEOUT);
103 }
Dan Egnorb7f03672009-12-09 16:22:32 -0800104
Filip Gruszczynskia925f182015-07-28 09:36:51 -0700105 @Override
106 protected void onCreate(Bundle savedInstanceState) {
107 super.onCreate(savedInstanceState);
Alan Viverette51efddb2017-04-05 10:00:01 -0400108 final FrameLayout frame = findViewById(android.R.id.custom);
Adrian Roos20d7df32016-01-12 18:59:43 +0100109 final Context context = getContext();
110 LayoutInflater.from(context).inflate(
111 com.android.internal.R.layout.app_error_dialog, frame, true);
112
Adrian Roosad028c12016-05-17 14:30:42 -0700113 final boolean hasReceiver = mProc.errorReportReceiver != null;
114
Alan Viverette51efddb2017-04-05 10:00:01 -0400115 final TextView restart = findViewById(com.android.internal.R.id.aerr_restart);
Adrian Roos20d7df32016-01-12 18:59:43 +0100116 restart.setOnClickListener(this);
Amith Yamasanib0c8a882017-08-28 09:36:42 -0700117 restart.setVisibility(mIsRestartable ? View.VISIBLE : View.GONE);
Alan Viverette51efddb2017-04-05 10:00:01 -0400118 final TextView report = findViewById(com.android.internal.R.id.aerr_report);
Adrian Roos20d7df32016-01-12 18:59:43 +0100119 report.setOnClickListener(this);
Adrian Roos20d7df32016-01-12 18:59:43 +0100120 report.setVisibility(hasReceiver ? View.VISIBLE : View.GONE);
Alan Viverette51efddb2017-04-05 10:00:01 -0400121 final TextView close = findViewById(com.android.internal.R.id.aerr_close);
Adrian Roos20d7df32016-01-12 18:59:43 +0100122 close.setOnClickListener(this);
Andrew Sapperstein5b679c42018-01-16 11:13:40 -0800123 final TextView appInfo = findViewById(com.android.internal.R.id.aerr_app_info);
124 appInfo.setOnClickListener(this);
Adrian Roosad028c12016-05-17 14:30:42 -0700125
Jeff Sharkey5ab02432017-06-27 11:01:36 -0600126 boolean showMute = !Build.IS_USER && Settings.Global.getInt(context.getContentResolver(),
Andrew Sapperstein5b679c42018-01-16 11:13:40 -0800127 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0
128 && Settings.Global.getInt(context.getContentResolver(),
129 Settings.Global.SHOW_MUTE_IN_CRASH_DIALOG, 0) != 0;
Alan Viverette51efddb2017-04-05 10:00:01 -0400130 final TextView mute = findViewById(com.android.internal.R.id.aerr_mute);
Adrian Roos20d7df32016-01-12 18:59:43 +0100131 mute.setOnClickListener(this);
Adrian Roosad028c12016-05-17 14:30:42 -0700132 mute.setVisibility(showMute ? View.VISIBLE : View.GONE);
Adrian Roos20d7df32016-01-12 18:59:43 +0100133
134 findViewById(com.android.internal.R.id.customPanel).setVisibility(View.VISIBLE);
Filip Gruszczynskia925f182015-07-28 09:36:51 -0700135 }
136
Adrian Roosad028c12016-05-17 14:30:42 -0700137 @Override
138 public void onStart() {
139 super.onStart();
140 getContext().registerReceiver(mReceiver,
141 new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
142 }
143
144 @Override
145 protected void onStop() {
146 super.onStop();
147 getContext().unregisterReceiver(mReceiver);
148 }
149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 private final Handler mHandler = new Handler() {
151 public void handleMessage(Message msg) {
Adrian Roos0da67d662017-04-17 14:50:22 -0700152 setResult(msg.what);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 dismiss();
154 }
155 };
Wale Ogunwale31dd3a72015-07-07 17:13:13 -0700156
157 @Override
158 public void dismiss() {
159 if (!mResult.mHasResult) {
160 // We are dismissing and the result has not been set...go ahead and set.
Adrian Roos0da67d662017-04-17 14:50:22 -0700161 setResult(FORCE_QUIT);
Wale Ogunwale31dd3a72015-07-07 17:13:13 -0700162 }
163 super.dismiss();
164 }
Adrian Roos20d7df32016-01-12 18:59:43 +0100165
Adrian Roos0da67d662017-04-17 14:50:22 -0700166 private void setResult(int result) {
167 synchronized (mService) {
168 if (mProc != null && mProc.crashDialog == AppErrorDialog.this) {
169 mProc.crashDialog = null;
170 }
171 }
172 mResult.set(result);
173
174 // Make sure we don't have time timeout still hanging around.
175 mHandler.removeMessages(TIMEOUT);
176 }
177
Adrian Roos20d7df32016-01-12 18:59:43 +0100178 @Override
179 public void onClick(View v) {
180 switch (v.getId()) {
181 case com.android.internal.R.id.aerr_restart:
182 mHandler.obtainMessage(RESTART).sendToTarget();
183 break;
Adrian Roos20d7df32016-01-12 18:59:43 +0100184 case com.android.internal.R.id.aerr_report:
185 mHandler.obtainMessage(FORCE_QUIT_AND_REPORT).sendToTarget();
186 break;
187 case com.android.internal.R.id.aerr_close:
188 mHandler.obtainMessage(FORCE_QUIT).sendToTarget();
189 break;
Andrew Sapperstein5b679c42018-01-16 11:13:40 -0800190 case com.android.internal.R.id.aerr_app_info:
191 mHandler.obtainMessage(APP_INFO).sendToTarget();
192 break;
Adrian Roos20d7df32016-01-12 18:59:43 +0100193 case com.android.internal.R.id.aerr_mute:
194 mHandler.obtainMessage(MUTE).sendToTarget();
195 break;
196 default:
197 break;
198 }
199 }
200
Adrian Roosad028c12016-05-17 14:30:42 -0700201 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
202 @Override
203 public void onReceive(Context context, Intent intent) {
204 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(intent.getAction())) {
205 cancel();
206 }
207 }
208 };
209
Adrian Roos20d7df32016-01-12 18:59:43 +0100210 static class Data {
211 AppErrorResult result;
212 TaskRecord task;
213 boolean repeating;
214 ProcessRecord proc;
Adrian Roos805ea302016-07-27 12:25:54 -0700215 boolean isRestartableForService;
Adrian Roos20d7df32016-01-12 18:59:43 +0100216 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217}