Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 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 | |
Adam Lesinski | 6a591f5 | 2013-10-01 18:11:17 -0700 | [diff] [blame] | 19 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_ERROR; |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 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; |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 26 | |
Dianne Hackborn | be4e6aa | 2013-06-07 13:25:29 -0700 | [diff] [blame] | 27 | final class StrictModeViolationDialog extends BaseErrorDialog { |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 28 | private final static String TAG = "StrictModeViolationDialog"; |
| 29 | |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 30 | private final ActivityManagerService mService; |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 31 | private final AppErrorResult mResult; |
| 32 | private final ProcessRecord mProc; |
| 33 | |
| 34 | // Event 'what' codes |
| 35 | static final int ACTION_OK = 0; |
| 36 | static final int ACTION_OK_AND_REPORT = 1; |
| 37 | |
| 38 | // 1-minute timeout, then we automatically dismiss the violation |
| 39 | // dialog |
| 40 | static final long DISMISS_TIMEOUT = 1000 * 60 * 1; |
| 41 | |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 42 | public StrictModeViolationDialog(Context context, ActivityManagerService service, |
| 43 | AppErrorResult result, ProcessRecord app) { |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 44 | super(context); |
| 45 | |
| 46 | Resources res = context.getResources(); |
| 47 | |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 48 | mService = service; |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 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.smv_application, |
| 56 | name.toString(), app.info.processName)); |
| 57 | } else { |
| 58 | name = app.processName; |
| 59 | setMessage(res.getString( |
| 60 | com.android.internal.R.string.smv_process, |
| 61 | name.toString())); |
| 62 | } |
| 63 | |
| 64 | setCancelable(false); |
| 65 | |
| 66 | setButton(DialogInterface.BUTTON_POSITIVE, |
| 67 | res.getText(com.android.internal.R.string.dlg_ok), |
| 68 | mHandler.obtainMessage(ACTION_OK)); |
| 69 | |
| 70 | if (app.errorReportReceiver != null) { |
| 71 | setButton(DialogInterface.BUTTON_NEGATIVE, |
| 72 | res.getText(com.android.internal.R.string.report), |
| 73 | mHandler.obtainMessage(ACTION_OK_AND_REPORT)); |
| 74 | } |
| 75 | |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 76 | getWindow().addPrivateFlags(PRIVATE_FLAG_SYSTEM_ERROR); |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 77 | getWindow().setTitle("Strict Mode Violation: " + app.info.processName); |
| 78 | |
| 79 | // After the timeout, pretend the user clicked the quit button |
| 80 | mHandler.sendMessageDelayed( |
| 81 | mHandler.obtainMessage(ACTION_OK), |
| 82 | DISMISS_TIMEOUT); |
| 83 | } |
| 84 | |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 85 | private final Handler mHandler = new Handler() { |
| 86 | public void handleMessage(Message msg) { |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 87 | synchronized (mService) { |
Brad Fitzpatrick | 438d059 | 2010-06-10 12:19:19 -0700 | [diff] [blame] | 88 | if (mProc != null && mProc.crashDialog == StrictModeViolationDialog.this) { |
| 89 | mProc.crashDialog = null; |
| 90 | } |
| 91 | } |
| 92 | mResult.set(msg.what); |
| 93 | |
| 94 | // If this is a timeout we won't be automatically closed, so go |
| 95 | // ahead and explicitly dismiss ourselves just in case. |
| 96 | dismiss(); |
| 97 | } |
| 98 | }; |
| 99 | } |