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.DialogInterface; 23 import android.content.res.Resources; 24 import android.os.Handler; 25 import android.os.Message; 26 import android.util.Slog; 27 28 class AppErrorDialog extends BaseErrorDialog { 29 private final static String TAG = "AppErrorDialog"; 30 31 private final AppErrorResult mResult; 32 private final ProcessRecord mProc; 33 34 // Event 'what' codes 35 static final int FORCE_QUIT = 0; 36 static final int FORCE_QUIT_AND_REPORT = 1; 37 38 // 5-minute timeout, then we automatically dismiss the crash dialog 39 static final long DISMISS_TIMEOUT = 1000 * 60 * 5; 40 41 public AppErrorDialog(Context context, AppErrorResult result, ProcessRecord app) { 42 super(context); 43 44 Resources res = context.getResources(); 45 46 mProc = app; 47 mResult = result; 48 CharSequence name; 49 if ((app.pkgList.size() == 1) && 50 (name=context.getPackageManager().getApplicationLabel(app.info)) != null) { 51 setMessage(res.getString( 52 com.android.internal.R.string.aerr_application, 53 name.toString(), app.info.processName)); 54 } else { 55 name = app.processName; 56 setMessage(res.getString( 57 com.android.internal.R.string.aerr_process, 58 name.toString())); 59 } 60 61 setCancelable(false); 62 63 setButton(DialogInterface.BUTTON_POSITIVE, 64 res.getText(com.android.internal.R.string.force_close), 65 mHandler.obtainMessage(FORCE_QUIT)); 66 67 if (app.errorReportReceiver != null) { 68 setButton(DialogInterface.BUTTON_NEGATIVE, 69 res.getText(com.android.internal.R.string.report), 70 mHandler.obtainMessage(FORCE_QUIT_AND_REPORT)); 71 } 72 73 setTitle(res.getText(com.android.internal.R.string.aerr_title)); 74 getWindow().addFlags(FLAG_SYSTEM_ERROR); 75 getWindow().setTitle("Application Error: " + app.info.processName); 76 77 // After the timeout, pretend the user clicked the quit button 78 mHandler.sendMessageDelayed( 79 mHandler.obtainMessage(FORCE_QUIT), 80 DISMISS_TIMEOUT); 81 } 82 83 private final Handler mHandler = new Handler() { 84 public void handleMessage(Message msg) { 85 synchronized (mProc) { 86 if (mProc != null && mProc.crashDialog == AppErrorDialog.this) { 87 mProc.crashDialog = null; 88 } 89 } 90 mResult.set(msg.what); 91 92 // If this is a timeout we won't be automatically closed, so go 93 // ahead and explicitly dismiss ourselves just in case. 94 dismiss(); 95 } 96 }; 97 } 98