/services/java/com/android/server/am/AppErrorDialog.java

https://github.com/aizuzi/platform_frameworks_base · Java · 102 lines · 67 code · 15 blank · 20 comment · 11 complexity · fd51f5f3afa87a74acbf7429eeca509c MD5 · raw file

  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. package com.android.server.am;
  17. import android.content.Context;
  18. import android.content.DialogInterface;
  19. import android.content.res.Resources;
  20. import android.os.Handler;
  21. import android.os.Message;
  22. import android.view.WindowManager;
  23. final class AppErrorDialog extends BaseErrorDialog {
  24. private final ActivityManagerService mService;
  25. private final AppErrorResult mResult;
  26. private final ProcessRecord mProc;
  27. // Event 'what' codes
  28. static final int FORCE_QUIT = 0;
  29. static final int FORCE_QUIT_AND_REPORT = 1;
  30. // 5-minute timeout, then we automatically dismiss the crash dialog
  31. static final long DISMISS_TIMEOUT = 1000 * 60 * 5;
  32. public AppErrorDialog(Context context, ActivityManagerService service,
  33. AppErrorResult result, ProcessRecord app) {
  34. super(context);
  35. Resources res = context.getResources();
  36. mService = service;
  37. mProc = app;
  38. mResult = result;
  39. CharSequence name;
  40. if ((app.pkgList.size() == 1) &&
  41. (name=context.getPackageManager().getApplicationLabel(app.info)) != null) {
  42. setMessage(res.getString(
  43. com.android.internal.R.string.aerr_application,
  44. name.toString(), app.info.processName));
  45. } else {
  46. name = app.processName;
  47. setMessage(res.getString(
  48. com.android.internal.R.string.aerr_process,
  49. name.toString()));
  50. }
  51. setCancelable(false);
  52. setButton(DialogInterface.BUTTON_POSITIVE,
  53. res.getText(com.android.internal.R.string.force_close),
  54. mHandler.obtainMessage(FORCE_QUIT));
  55. if (app.errorReportReceiver != null) {
  56. setButton(DialogInterface.BUTTON_NEGATIVE,
  57. res.getText(com.android.internal.R.string.report),
  58. mHandler.obtainMessage(FORCE_QUIT_AND_REPORT));
  59. }
  60. setTitle(res.getText(com.android.internal.R.string.aerr_title));
  61. WindowManager.LayoutParams attrs = getWindow().getAttributes();
  62. attrs.setTitle("Application Error: " + app.info.processName);
  63. attrs.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_ERROR
  64. | WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
  65. getWindow().setAttributes(attrs);
  66. if (app.persistent) {
  67. getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
  68. }
  69. // After the timeout, pretend the user clicked the quit button
  70. mHandler.sendMessageDelayed(
  71. mHandler.obtainMessage(FORCE_QUIT),
  72. DISMISS_TIMEOUT);
  73. }
  74. private final Handler mHandler = new Handler() {
  75. public void handleMessage(Message msg) {
  76. synchronized (mService) {
  77. if (mProc != null && mProc.crashDialog == AppErrorDialog.this) {
  78. mProc.crashDialog = null;
  79. }
  80. }
  81. mResult.set(msg.what);
  82. // If this is a timeout we won't be automatically closed, so go
  83. // ahead and explicitly dismiss ourselves just in case.
  84. dismiss();
  85. }
  86. };
  87. }