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