AppErrorDialog.java revision 20d7df3c3ff0000678a208b25fcf7ddf90c5abe4
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 17package com.android.server.am; 18 19import android.app.ActivityManagerInternal; 20import android.app.ActivityOptions; 21import android.content.Context; 22import android.content.pm.IPackageDataObserver; 23import android.content.pm.PackageManager; 24import android.content.res.Resources; 25import android.os.Bundle; 26import android.os.Handler; 27import android.os.Message; 28import android.util.Slog; 29import android.view.LayoutInflater; 30import android.view.View; 31import android.view.WindowManager; 32import android.widget.FrameLayout; 33import android.widget.TextView; 34 35import java.util.List; 36 37import static com.android.server.am.ActivityManagerService.IS_USER_BUILD; 38 39final class AppErrorDialog extends BaseErrorDialog implements View.OnClickListener { 40 private final ActivityManagerService mService; 41 private final AppErrorResult mResult; 42 private final ProcessRecord mProc; 43 private final boolean mRepeating; 44 45 private CharSequence mName; 46 47 // Event 'what' codes 48 static final int FORCE_QUIT = 1; 49 static final int FORCE_QUIT_AND_REPORT = 2; 50 static final int RESTART = 3; 51 static final int RESET = 4; 52 static final int MUTE = 5; 53 54 // 5-minute timeout, then we automatically dismiss the crash dialog 55 static final long DISMISS_TIMEOUT = 1000 * 60 * 5; 56 57 public AppErrorDialog(Context context, ActivityManagerService service, Data data) { 58 super(context); 59 Resources res = context.getResources(); 60 61 mService = service; 62 mProc = data.proc; 63 mResult = data.result; 64 mRepeating = data.repeating; 65 if ((mProc.pkgList.size() == 1) && 66 (mName = context.getPackageManager().getApplicationLabel(mProc.info)) != null) { 67 setTitle(res.getString( 68 mRepeating ? com.android.internal.R.string.aerr_application_repeated 69 : com.android.internal.R.string.aerr_application, 70 mName.toString(), mProc.info.processName)); 71 } else { 72 mName = mProc.processName; 73 setTitle(res.getString( 74 mRepeating ? com.android.internal.R.string.aerr_process_repeated 75 : com.android.internal.R.string.aerr_process, 76 mName.toString())); 77 } 78 79 setCancelable(false); 80 81 WindowManager.LayoutParams attrs = getWindow().getAttributes(); 82 attrs.setTitle("Application Error: " + mProc.info.processName); 83 attrs.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_ERROR 84 | WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; 85 getWindow().setAttributes(attrs); 86 if (mProc.persistent) { 87 getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR); 88 } 89 90 // After the timeout, pretend the user clicked the quit button 91 mHandler.sendMessageDelayed( 92 mHandler.obtainMessage(FORCE_QUIT), 93 DISMISS_TIMEOUT); 94 } 95 96 @Override 97 protected void onCreate(Bundle savedInstanceState) { 98 super.onCreate(savedInstanceState); 99 final FrameLayout frame = (FrameLayout) findViewById(android.R.id.custom); 100 final Context context = getContext(); 101 LayoutInflater.from(context).inflate( 102 com.android.internal.R.layout.app_error_dialog, frame, true); 103 104 final TextView restart = (TextView) findViewById(com.android.internal.R.id.aerr_restart); 105 restart.setOnClickListener(this); 106 restart.setVisibility(!mRepeating ? View.VISIBLE : View.GONE); 107 final TextView reset = (TextView) findViewById(com.android.internal.R.id.aerr_reset); 108 reset.setOnClickListener(this); 109 reset.setVisibility(mRepeating ? View.VISIBLE : View.GONE); 110 final TextView report = (TextView) findViewById(com.android.internal.R.id.aerr_report); 111 report.setOnClickListener(this); 112 final boolean hasReceiver = mProc.errorReportReceiver != null; 113 report.setVisibility(hasReceiver ? View.VISIBLE : View.GONE); 114 final TextView close = (TextView) findViewById(com.android.internal.R.id.aerr_close); 115 close.setOnClickListener(this); 116 final TextView mute = (TextView) findViewById(com.android.internal.R.id.aerr_mute); 117 mute.setOnClickListener(this); 118 mute.setVisibility(!IS_USER_BUILD ? View.VISIBLE : View.GONE); 119 120 findViewById(com.android.internal.R.id.customPanel).setVisibility(View.VISIBLE); 121 } 122 123 private final Handler mHandler = new Handler() { 124 public void handleMessage(Message msg) { 125 final int result = msg.what; 126 127 synchronized (mService) { 128 if (mProc != null && mProc.crashDialog == AppErrorDialog.this) { 129 mProc.crashDialog = null; 130 } 131 } 132 mResult.set(result); 133 134 // Make sure we don't have time timeout still hanging around. 135 removeMessages(FORCE_QUIT); 136 137 dismiss(); 138 } 139 }; 140 141 @Override 142 public void dismiss() { 143 if (!mResult.mHasResult) { 144 // We are dismissing and the result has not been set...go ahead and set. 145 mResult.set(FORCE_QUIT); 146 } 147 super.dismiss(); 148 } 149 150 @Override 151 public void onClick(View v) { 152 switch (v.getId()) { 153 case com.android.internal.R.id.aerr_restart: 154 mHandler.obtainMessage(RESTART).sendToTarget(); 155 break; 156 case com.android.internal.R.id.aerr_reset: 157 mHandler.obtainMessage(RESET).sendToTarget(); 158 break; 159 case com.android.internal.R.id.aerr_report: 160 mHandler.obtainMessage(FORCE_QUIT_AND_REPORT).sendToTarget(); 161 break; 162 case com.android.internal.R.id.aerr_close: 163 mHandler.obtainMessage(FORCE_QUIT).sendToTarget(); 164 break; 165 case com.android.internal.R.id.aerr_mute: 166 mHandler.obtainMessage(MUTE).sendToTarget(); 167 break; 168 default: 169 break; 170 } 171 } 172 173 static class Data { 174 AppErrorResult result; 175 TaskRecord task; 176 boolean repeating; 177 ProcessRecord proc; 178 } 179} 180