• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.Log;
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 DEBUG = 1;
37     static final int FORCE_QUIT_AND_REPORT = 2;
38 
39     // 5-minute timeout, then we automatically dismiss the crash dialog
40     static final long DISMISS_TIMEOUT = 1000 * 60 * 5;
41 
AppErrorDialog(Context context, AppErrorResult result, ProcessRecord app, int flags, String shortMsg, String longMsg)42     public AppErrorDialog(Context context, AppErrorResult result,
43             ProcessRecord app, int flags,
44             String shortMsg, String longMsg) {
45         super(context);
46 
47         Resources res = context.getResources();
48 
49         mProc = app;
50         mResult = result;
51         CharSequence name;
52         if ((app.pkgList.size() == 1) &&
53                 (name=context.getPackageManager().getApplicationLabel(app.info)) != null) {
54             setMessage(res.getString(
55                     com.android.internal.R.string.aerr_application,
56                     name.toString(), app.info.processName));
57         } else {
58             name = app.processName;
59             setMessage(res.getString(
60                     com.android.internal.R.string.aerr_process,
61                     name.toString()));
62         }
63 
64         setCancelable(false);
65 
66         setButton(DialogInterface.BUTTON_POSITIVE,
67                 res.getText(com.android.internal.R.string.force_close),
68                 mHandler.obtainMessage(FORCE_QUIT));
69 
70         if ((flags&1) != 0) {
71             setButton(DialogInterface.BUTTON_NEUTRAL,
72                     res.getText(com.android.internal.R.string.debug),
73                     mHandler.obtainMessage(DEBUG));
74         }
75 
76         if (app.errorReportReceiver != null) {
77             setButton(DialogInterface.BUTTON_NEGATIVE,
78                     res.getText(com.android.internal.R.string.report),
79                     mHandler.obtainMessage(FORCE_QUIT_AND_REPORT));
80         }
81 
82         setTitle(res.getText(com.android.internal.R.string.aerr_title));
83         getWindow().addFlags(FLAG_SYSTEM_ERROR);
84         getWindow().setTitle("Application Error: " + app.info.processName);
85 
86         // After the timeout, pretend the user clicked the quit button
87         mHandler.sendMessageDelayed(
88                 mHandler.obtainMessage(FORCE_QUIT),
89                 DISMISS_TIMEOUT);
90     }
91 
onStop()92     public void onStop() {
93     }
94 
95     private final Handler mHandler = new Handler() {
96         public void handleMessage(Message msg) {
97             synchronized (mProc) {
98                 if (mProc != null && mProc.crashDialog == AppErrorDialog.this) {
99                     mProc.crashDialog = null;
100                 }
101             }
102             mResult.set(msg.what);
103 
104             // If this is a timeout we won't be automatically closed, so go
105             // ahead and explicitly dismiss ourselves just in case.
106             dismiss();
107         }
108     };
109 }
110