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 | |
| 19 | import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR; |
| 20 | |
| 21 | import android.content.Context; |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 22 | import android.content.DialogInterface; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import android.content.res.Resources; |
| 24 | import android.os.Handler; |
| 25 | import android.os.Message; |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 26 | import android.view.WindowManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
| 28 | class AppErrorDialog extends BaseErrorDialog { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 29 | private final ActivityManagerService mService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | private final AppErrorResult mResult; |
| 31 | private final ProcessRecord mProc; |
| 32 | |
| 33 | // Event 'what' codes |
| 34 | static final int FORCE_QUIT = 0; |
Dan Egnor | b7f0367 | 2009-12-09 16:22:32 -0800 | [diff] [blame] | 35 | static final int FORCE_QUIT_AND_REPORT = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | |
| 37 | // 5-minute timeout, then we automatically dismiss the crash dialog |
| 38 | static final long DISMISS_TIMEOUT = 1000 * 60 * 5; |
| 39 | |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 40 | public AppErrorDialog(Context context, ActivityManagerService service, |
| 41 | AppErrorResult result, ProcessRecord app) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | super(context); |
| 43 | |
| 44 | Resources res = context.getResources(); |
| 45 | |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 46 | mService = service; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | mProc = app; |
| 48 | mResult = result; |
| 49 | CharSequence name; |
| 50 | if ((app.pkgList.size() == 1) && |
| 51 | (name=context.getPackageManager().getApplicationLabel(app.info)) != null) { |
| 52 | setMessage(res.getString( |
| 53 | com.android.internal.R.string.aerr_application, |
| 54 | name.toString(), app.info.processName)); |
| 55 | } else { |
| 56 | name = app.processName; |
| 57 | setMessage(res.getString( |
| 58 | com.android.internal.R.string.aerr_process, |
| 59 | name.toString())); |
| 60 | } |
| 61 | |
| 62 | setCancelable(false); |
| 63 | |
Adam Powell | 40a9784 | 2011-08-14 17:12:10 -0700 | [diff] [blame] | 64 | setButton(DialogInterface.BUTTON_POSITIVE, |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 65 | res.getText(com.android.internal.R.string.force_close), |
| 66 | mHandler.obtainMessage(FORCE_QUIT)); |
| 67 | |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 68 | if (app.errorReportReceiver != null) { |
Adam Powell | 40a9784 | 2011-08-14 17:12:10 -0700 | [diff] [blame] | 69 | setButton(DialogInterface.BUTTON_NEGATIVE, |
Jacek Surazski | f5b9c72 | 2009-05-18 12:09:59 +0200 | [diff] [blame] | 70 | res.getText(com.android.internal.R.string.report), |
| 71 | mHandler.obtainMessage(FORCE_QUIT_AND_REPORT)); |
| 72 | } |
| 73 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | setTitle(res.getText(com.android.internal.R.string.aerr_title)); |
| 75 | getWindow().addFlags(FLAG_SYSTEM_ERROR); |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 76 | WindowManager.LayoutParams attrs = getWindow().getAttributes(); |
| 77 | attrs.setTitle("Application Error: " + app.info.processName); |
Amith Yamasani | 64442c1 | 2012-10-07 08:17:46 -0700 | [diff] [blame] | 78 | attrs.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 79 | getWindow().setAttributes(attrs); |
Dianne Hackborn | 38cc896 | 2011-10-13 11:33:55 -0700 | [diff] [blame] | 80 | if (app.persistent) { |
| 81 | getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR); |
| 82 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | |
| 84 | // After the timeout, pretend the user clicked the quit button |
| 85 | mHandler.sendMessageDelayed( |
| 86 | mHandler.obtainMessage(FORCE_QUIT), |
| 87 | DISMISS_TIMEOUT); |
| 88 | } |
Dan Egnor | b7f0367 | 2009-12-09 16:22:32 -0800 | [diff] [blame] | 89 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | private final Handler mHandler = new Handler() { |
| 91 | public void handleMessage(Message msg) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 92 | synchronized (mService) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | if (mProc != null && mProc.crashDialog == AppErrorDialog.this) { |
| 94 | mProc.crashDialog = null; |
| 95 | } |
| 96 | } |
| 97 | mResult.set(msg.what); |
| 98 | |
| 99 | // If this is a timeout we won't be automatically closed, so go |
| 100 | // ahead and explicitly dismiss ourselves just in case. |
| 101 | dismiss(); |
| 102 | } |
| 103 | }; |
| 104 | } |