blob: 987588759ae84eff613382e4b275ec5c94bc14e4 [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
Jacek Surazskif5b9c722009-05-18 12:09:59 +020019import android.content.ActivityNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.content.Context;
Jacek Surazskif5b9c722009-05-18 12:09:59 +020021import android.content.DialogInterface;
22import android.content.Intent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.content.res.Resources;
Adrian Roosa85a2c62016-01-26 09:14:22 -080024import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.os.Handler;
26import android.os.Message;
Joe Onorato8a9b2202010-02-26 18:56:32 -080027import android.util.Slog;
Adrian Roosa85a2c62016-01-26 09:14:22 -080028import android.view.LayoutInflater;
29import android.view.View;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070030import android.view.WindowManager;
Adrian Roosa85a2c62016-01-26 09:14:22 -080031import android.widget.FrameLayout;
32import android.widget.TextView;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033
Adrian Roosa85a2c62016-01-26 09:14:22 -080034import static com.android.server.am.ActivityManagerService.IS_USER_BUILD;
35
36final class AppNotRespondingDialog extends BaseErrorDialog implements View.OnClickListener {
Jacek Surazskif5b9c722009-05-18 12:09:59 +020037 private static final String TAG = "AppNotRespondingDialog";
38
39 // Event 'what' codes
40 static final int FORCE_CLOSE = 1;
41 static final int WAIT = 2;
42 static final int WAIT_AND_REPORT = 3;
43
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044 private final ActivityManagerService mService;
45 private final ProcessRecord mProc;
Adrian Roosa85a2c62016-01-26 09:14:22 -080046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047 public AppNotRespondingDialog(ActivityManagerService service, Context context,
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070048 ProcessRecord app, ActivityRecord activity, boolean aboveSystem) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049 super(context);
Adrian Roosa85a2c62016-01-26 09:14:22 -080050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051 mService = service;
52 mProc = app;
53 Resources res = context.getResources();
Adrian Roosa85a2c62016-01-26 09:14:22 -080054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 setCancelable(false);
56
57 int resid;
58 CharSequence name1 = activity != null
59 ? activity.info.loadLabel(context.getPackageManager())
60 : null;
61 CharSequence name2 = null;
62 if ((app.pkgList.size() == 1) &&
63 (name2=context.getPackageManager().getApplicationLabel(app.info)) != null) {
64 if (name1 != null) {
65 resid = com.android.internal.R.string.anr_activity_application;
66 } else {
67 name1 = name2;
68 name2 = app.processName;
69 resid = com.android.internal.R.string.anr_application_process;
70 }
71 } else {
72 if (name1 != null) {
73 name2 = app.processName;
74 resid = com.android.internal.R.string.anr_activity_process;
75 } else {
76 name1 = app.processName;
77 resid = com.android.internal.R.string.anr_process;
78 }
79 }
80
Adrian Roosa85a2c62016-01-26 09:14:22 -080081 setTitle(name2 != null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 ? res.getString(resid, name1.toString(), name2.toString())
83 : res.getString(resid, name1.toString()));
84
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070085 if (aboveSystem) {
86 getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
87 }
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070088 WindowManager.LayoutParams attrs = getWindow().getAttributes();
89 attrs.setTitle("Application Not Responding: " + app.info.processName);
Adam Lesinski95c42972013-10-02 10:13:27 -070090 attrs.privateFlags = WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_ERROR |
91 WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -070092 getWindow().setAttributes(attrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 }
94
Adrian Roosa85a2c62016-01-26 09:14:22 -080095 @Override
96 protected void onCreate(Bundle savedInstanceState) {
97 super.onCreate(savedInstanceState);
98 final FrameLayout frame = (FrameLayout) findViewById(android.R.id.custom);
99 final Context context = getContext();
100 LayoutInflater.from(context).inflate(
101 com.android.internal.R.layout.app_anr_dialog, frame, true);
102
103 final TextView report = (TextView) findViewById(com.android.internal.R.id.aerr_report);
104 report.setOnClickListener(this);
105 final boolean hasReceiver = mProc.errorReportReceiver != null;
106 report.setVisibility(hasReceiver ? View.VISIBLE : View.GONE);
107 final TextView close = (TextView) findViewById(com.android.internal.R.id.aerr_close);
108 close.setOnClickListener(this);
109 final TextView wait = (TextView) findViewById(com.android.internal.R.id.aerr_wait);
110 wait.setOnClickListener(this);
111
112 findViewById(com.android.internal.R.id.customPanel).setVisibility(View.VISIBLE);
113 }
114
115 @Override
116 public void onClick(View v) {
117 switch (v.getId()) {
118 case com.android.internal.R.id.aerr_report:
119 mHandler.obtainMessage(WAIT_AND_REPORT).sendToTarget();
120 break;
121 case com.android.internal.R.id.aerr_close:
122 mHandler.obtainMessage(FORCE_CLOSE).sendToTarget();
123 break;
124 case com.android.internal.R.id.aerr_wait:
125 mHandler.obtainMessage(WAIT).sendToTarget();
126 break;
127 default:
128 break;
129 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 }
131
132 private final Handler mHandler = new Handler() {
133 public void handleMessage(Message msg) {
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200134 Intent appErrorIntent = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 switch (msg.what) {
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200136 case FORCE_CLOSE:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 // Kill the application.
Dan Egnor42471dd2010-01-07 17:25:22 -0800138 mService.killAppAtUsersRequest(mProc, AppNotRespondingDialog.this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 break;
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200140 case WAIT_AND_REPORT:
141 case WAIT:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 // Continue waiting for the application.
143 synchronized (mService) {
144 ProcessRecord app = mProc;
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200145
146 if (msg.what == WAIT_AND_REPORT) {
Adrian Roos20d7df32016-01-12 18:59:43 +0100147 appErrorIntent = mService.mAppErrors.createAppErrorIntentLocked(app,
Jacek Surazski41a9fd52010-01-27 16:37:21 -0800148 System.currentTimeMillis(), null);
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200149 }
150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 app.notResponding = false;
152 app.notRespondingReport = null;
153 if (app.anrDialog == AppNotRespondingDialog.this) {
154 app.anrDialog = null;
155 }
Dianne Hackborn2be00932013-09-22 16:46:00 -0700156 mService.mServices.scheduleServiceTimeoutLocked(app);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 }
158 break;
159 }
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200160
161 if (appErrorIntent != null) {
162 try {
163 getContext().startActivity(appErrorIntent);
164 } catch (ActivityNotFoundException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800165 Slog.w(TAG, "bug report receiver dissappeared", e);
Jacek Surazskif5b9c722009-05-18 12:09:59 +0200166 }
167 }
Adrian Roosa85a2c62016-01-26 09:14:22 -0800168
169 dismiss();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 }
171 };
172}