blob: 35d50a16be099bc3cb368e9e58df0b59894f846a [file] [log] [blame]
Brad Fitzpatrick438d0592010-06-10 12:19:19 -07001/*
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;
27
28class StrictModeViolationDialog extends BaseErrorDialog {
29 private final static String TAG = "StrictModeViolationDialog";
30
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -070031 private final ActivityManagerService mService;
Brad Fitzpatrick438d0592010-06-10 12:19:19 -070032 private final AppErrorResult mResult;
33 private final ProcessRecord mProc;
34
35 // Event 'what' codes
36 static final int ACTION_OK = 0;
37 static final int ACTION_OK_AND_REPORT = 1;
38
39 // 1-minute timeout, then we automatically dismiss the violation
40 // dialog
41 static final long DISMISS_TIMEOUT = 1000 * 60 * 1;
42
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -070043 public StrictModeViolationDialog(Context context, ActivityManagerService service,
44 AppErrorResult result, ProcessRecord app) {
Brad Fitzpatrick438d0592010-06-10 12:19:19 -070045 super(context);
46
47 Resources res = context.getResources();
48
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -070049 mService = service;
Brad Fitzpatrick438d0592010-06-10 12:19:19 -070050 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.smv_application,
57 name.toString(), app.info.processName));
58 } else {
59 name = app.processName;
60 setMessage(res.getString(
61 com.android.internal.R.string.smv_process,
62 name.toString()));
63 }
64
65 setCancelable(false);
66
67 setButton(DialogInterface.BUTTON_POSITIVE,
68 res.getText(com.android.internal.R.string.dlg_ok),
69 mHandler.obtainMessage(ACTION_OK));
70
71 if (app.errorReportReceiver != null) {
72 setButton(DialogInterface.BUTTON_NEGATIVE,
73 res.getText(com.android.internal.R.string.report),
74 mHandler.obtainMessage(ACTION_OK_AND_REPORT));
75 }
76
77 setTitle(res.getText(com.android.internal.R.string.aerr_title));
78 getWindow().addFlags(FLAG_SYSTEM_ERROR);
79 getWindow().setTitle("Strict Mode Violation: " + app.info.processName);
80
81 // After the timeout, pretend the user clicked the quit button
82 mHandler.sendMessageDelayed(
83 mHandler.obtainMessage(ACTION_OK),
84 DISMISS_TIMEOUT);
85 }
86
Brad Fitzpatrick438d0592010-06-10 12:19:19 -070087 private final Handler mHandler = new Handler() {
88 public void handleMessage(Message msg) {
Dianne Hackbornd4ac8d72012-09-27 23:20:10 -070089 synchronized (mService) {
Brad Fitzpatrick438d0592010-06-10 12:19:19 -070090 if (mProc != null && mProc.crashDialog == StrictModeViolationDialog.this) {
91 mProc.crashDialog = null;
92 }
93 }
94 mResult.set(msg.what);
95
96 // If this is a timeout we won't be automatically closed, so go
97 // ahead and explicitly dismiss ourselves just in case.
98 dismiss();
99 }
100 };
101}