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; |
| 22 | import android.content.res.Resources; |
| 23 | import android.os.Handler; |
| 24 | import android.os.Message; |
| 25 | import android.os.Process; |
| 26 | import android.util.Log; |
| 27 | |
| 28 | class AppNotRespondingDialog extends BaseErrorDialog { |
| 29 | private final ActivityManagerService mService; |
| 30 | private final ProcessRecord mProc; |
| 31 | |
| 32 | public AppNotRespondingDialog(ActivityManagerService service, Context context, |
| 33 | ProcessRecord app, HistoryRecord activity) { |
| 34 | super(context); |
| 35 | |
| 36 | mService = service; |
| 37 | mProc = app; |
| 38 | Resources res = context.getResources(); |
| 39 | |
| 40 | setCancelable(false); |
| 41 | |
| 42 | int resid; |
| 43 | CharSequence name1 = activity != null |
| 44 | ? activity.info.loadLabel(context.getPackageManager()) |
| 45 | : null; |
| 46 | CharSequence name2 = null; |
| 47 | if ((app.pkgList.size() == 1) && |
| 48 | (name2=context.getPackageManager().getApplicationLabel(app.info)) != null) { |
| 49 | if (name1 != null) { |
| 50 | resid = com.android.internal.R.string.anr_activity_application; |
| 51 | } else { |
| 52 | name1 = name2; |
| 53 | name2 = app.processName; |
| 54 | resid = com.android.internal.R.string.anr_application_process; |
| 55 | } |
| 56 | } else { |
| 57 | if (name1 != null) { |
| 58 | name2 = app.processName; |
| 59 | resid = com.android.internal.R.string.anr_activity_process; |
| 60 | } else { |
| 61 | name1 = app.processName; |
| 62 | resid = com.android.internal.R.string.anr_process; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | setMessage(name2 != null |
| 67 | ? res.getString(resid, name1.toString(), name2.toString()) |
| 68 | : res.getString(resid, name1.toString())); |
| 69 | |
| 70 | setButton(res.getText(com.android.internal.R.string.force_close), |
| 71 | mHandler.obtainMessage(1)); |
| 72 | setButton2(res.getText(com.android.internal.R.string.wait), |
| 73 | mHandler.obtainMessage(2)); |
| 74 | setTitle(res.getText(com.android.internal.R.string.anr_title)); |
| 75 | getWindow().addFlags(FLAG_SYSTEM_ERROR); |
| 76 | getWindow().setTitle("Application Not Responding: " + app.info.processName); |
| 77 | } |
| 78 | |
| 79 | public void onStop() { |
| 80 | } |
| 81 | |
| 82 | private final Handler mHandler = new Handler() { |
| 83 | public void handleMessage(Message msg) { |
| 84 | switch (msg.what) { |
| 85 | case 1: |
| 86 | // Kill the application. |
| 87 | mService.killAppAtUsersRequest(mProc, |
| 88 | AppNotRespondingDialog.this, true); |
| 89 | break; |
| 90 | case 2: |
| 91 | // Continue waiting for the application. |
| 92 | synchronized (mService) { |
| 93 | ProcessRecord app = mProc; |
| 94 | app.notResponding = false; |
| 95 | app.notRespondingReport = null; |
| 96 | if (app.anrDialog == AppNotRespondingDialog.this) { |
| 97 | app.anrDialog = null; |
| 98 | } |
| 99 | } |
| 100 | break; |
| 101 | } |
| 102 | } |
| 103 | }; |
| 104 | } |