Home | History | Annotate | Download | only in am
      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.Slog;
     27 
     28 class StrictModeViolationDialog extends BaseErrorDialog {
     29     private final static String TAG = "StrictModeViolationDialog";
     30 
     31     private final ActivityManagerService mService;
     32     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 
     43     public StrictModeViolationDialog(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.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 
     87     private final Handler mHandler = new Handler() {
     88         public void handleMessage(Message msg) {
     89             synchronized (mService) {
     90                 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 }
    102