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