2 * Copyright (C) 2006 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.server.am;
19 import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR;
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;
28 class StrictModeViolationDialog extends BaseErrorDialog {
29 private final static String TAG = "StrictModeViolationDialog";
31 private final AppErrorResult mResult;
32 private final ProcessRecord mProc;
35 static final int ACTION_OK = 0;
36 static final int ACTION_OK_AND_REPORT = 1;
38 // 1-minute timeout, then we automatically dismiss the violation
40 static final long DISMISS_TIMEOUT = 1000 * 60 * 1;
42 public StrictModeViolationDialog(Context context, AppErrorResult result, ProcessRecord app) {
45 Resources res = context.getResources();
50 if ((app.pkgList.size() == 1) &&
51 (name=context.getPackageManager().getApplicationLabel(app.info)) != null) {
52 setMessage(res.getString(
53 com.android.internal.R.string.smv_application,
54 name.toString(), app.info.processName));
56 name = app.processName;
57 setMessage(res.getString(
58 com.android.internal.R.string.smv_process,
64 setButton(DialogInterface.BUTTON_POSITIVE,
65 res.getText(com.android.internal.R.string.dlg_ok),
66 mHandler.obtainMessage(ACTION_OK));
68 if (app.errorReportReceiver != null) {
69 setButton(DialogInterface.BUTTON_NEGATIVE,
70 res.getText(com.android.internal.R.string.report),
71 mHandler.obtainMessage(ACTION_OK_AND_REPORT));
74 setTitle(res.getText(com.android.internal.R.string.aerr_title));
75 getWindow().addFlags(FLAG_SYSTEM_ERROR);
76 getWindow().setTitle("Strict Mode Violation: " + app.info.processName);
78 // After the timeout, pretend the user clicked the quit button
79 mHandler.sendMessageDelayed(
80 mHandler.obtainMessage(ACTION_OK),
84 private final Handler mHandler = new Handler() {
85 public void handleMessage(Message msg) {
86 synchronized (mProc) {
87 if (mProc != null && mProc.crashDialog == StrictModeViolationDialog.this) {
88 mProc.crashDialog = null;
91 mResult.set(msg.what);
93 // If this is a timeout we won't be automatically closed, so go
94 // ahead and explicitly dismiss ourselves just in case.