DumpHeapActivity.java revision b9a5e4ad30c9add140fd13491419ae66e947809d
1/* 2 * Copyright (C) 2015 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.internal.app; 18 19import android.app.Activity; 20import android.app.AlertDialog; 21import android.content.ClipData; 22import android.content.DialogInterface; 23import android.content.Intent; 24import android.net.Uri; 25import android.os.Bundle; 26import android.util.DebugUtils; 27 28/** 29 * This activity is displayed when the system has collected a heap dump from 30 * a large process and the user has selected to share it. 31 */ 32public class DumpHeapActivity extends Activity { 33 /** The process we are reporting */ 34 public static final String KEY_PROCESS = "process"; 35 /** The size limit the process reached */ 36 public static final String KEY_SIZE = "size"; 37 38 // Broadcast action to determine when to delete the current dump heap data. 39 public static final String ACTION_DELETE_DUMPHEAP = "com.android.server.am.DELETE_DUMPHEAP"; 40 41 // Extra for above: delay delete of data, since the user is in the process of sharing it. 42 public static final String EXTRA_DELAY_DELETE = "delay_delete"; 43 44 static final public Uri JAVA_URI = Uri.parse("content://com.android.server.heapdump/java"); 45 46 String mProcess; 47 long mSize; 48 AlertDialog mDialog; 49 boolean mHandled = false; 50 51 @Override 52 protected void onCreate(Bundle savedInstanceState) { 53 super.onCreate(savedInstanceState); 54 55 mProcess = getIntent().getStringExtra(KEY_PROCESS); 56 mSize = getIntent().getLongExtra(KEY_SIZE, 0); 57 AlertDialog.Builder b = new AlertDialog.Builder(this, 58 android.R.style.Theme_Material_Light_Dialog_Alert); 59 b.setTitle(com.android.internal.R.string.dump_heap_title); 60 b.setMessage(getString(com.android.internal.R.string.dump_heap_text, 61 mProcess, DebugUtils.sizeValueToString(mSize, null))); 62 b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { 63 @Override 64 public void onClick(DialogInterface dialog, int which) { 65 mHandled = true; 66 sendBroadcast(new Intent(ACTION_DELETE_DUMPHEAP)); 67 finish(); 68 } 69 }); 70 b.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { 71 @Override 72 public void onClick(DialogInterface dialog, int which) { 73 mHandled = true; 74 Intent broadcast = new Intent(ACTION_DELETE_DUMPHEAP); 75 broadcast.putExtra(EXTRA_DELAY_DELETE, true); 76 sendBroadcast(broadcast); 77 Intent intent = new Intent(Intent.ACTION_SEND); 78 ClipData clip = ClipData.newUri(getContentResolver(), "Heap Dump", JAVA_URI); 79 intent.setClipData(clip); 80 intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 81 intent.setType(clip.getDescription().getMimeType(0)); 82 intent.putExtra(Intent.EXTRA_STREAM, JAVA_URI); 83 startActivity(Intent.createChooser(intent, 84 getText(com.android.internal.R.string.dump_heap_title))); 85 finish(); 86 } 87 }); 88 mDialog = b.show(); 89 } 90 91 @Override 92 protected void onStop() { 93 super.onStop(); 94 if (!isChangingConfigurations()) { 95 if (!mHandled) { 96 sendBroadcast(new Intent(ACTION_DELETE_DUMPHEAP)); 97 } 98 } 99 } 100 101 @Override 102 protected void onDestroy() { 103 super.onDestroy(); 104 mDialog.dismiss(); 105 } 106} 107