public File dumpHeap() { if (!LeakCanaryInternals.isExternalStorageWritable()) { Log.d(TAG, "Could not dump heap, external storage not mounted."); } File heapDumpFile = getHeapDumpFile(); if (heapDumpFile.exists()) { Log.d(TAG, "Could not dump heap, previous analysis still is in progress."); return NO_DUMP; } FutureResult<Toast> waitingForToast = new FutureResult(); showToast(waitingForToast); if (waitingForToast.wait(5, TimeUnit.SECONDS)) { Toast toast = (Toast) waitingForToast.get(); try { Debug.dumpHprofData(heapDumpFile.getAbsolutePath()); cancelToast(toast); return heapDumpFile; } catch (IOException e) { cleanup(); Log.e(TAG, "Could not perform heap dump", e); return NO_DUMP; } } Log.d(TAG, "Did not dump heap, too much time waiting for Toast."); return NO_DUMP; }
public void cleanup() { LeakCanaryInternals.executeOnFileIoThread(new Runnable() { public void run() { if (LeakCanaryInternals.isExternalStorageWritable()) { Log.d(AndroidHeapDumper.TAG, "Could not attempt cleanup, external storage not" + " mounted."); } File heapDumpFile = AndroidHeapDumper.this.getHeapDumpFile(); if (heapDumpFile.exists()) { Log.d(AndroidHeapDumper.TAG, "Previous analysis did not complete correctly, " + "cleaning: " + heapDumpFile); heapDumpFile.delete(); } } }); }
/** * Call this on app startup to clean up all heap dump files that had not been handled yet when * the app process was killed. */ public void cleanup() { LeakCanaryInternals.executeOnFileIoThread(new Runnable() { @Override public void run() { if (!leakDirectoryProvider.isLeakStorageWritable()) { CanaryLog.d("Could not attempt cleanup, leak storage not writable."); return; } File heapDumpFile = getHeapDumpFile(); if (heapDumpFile.exists()) { CanaryLog.d("Previous analysis did not complete correctly, cleaning: %s", heapDumpFile); boolean success = heapDumpFile.delete(); if (!success) { CanaryLog.d("Could not delete file %s", heapDumpFile.getPath()); } } } }); }
public ServiceHeapDumpListener(Context context, Class<? extends AbstractAnalysisResultService> listenerServiceClass) { LeakCanaryInternals.setEnabled(context, listenerServiceClass, true); LeakCanaryInternals.setEnabled(context, HeapAnalyzerService.class, true); this.listenerServiceClass = (Class) Preconditions.checkNotNull(listenerServiceClass, "listenerServiceClass"); this.context = ((Context) Preconditions.checkNotNull(context, "context")) .getApplicationContext(); }
public static void setIconBadge(Context context, int count) { try { if (!Build.MANUFACTURER.equalsIgnoreCase(MiBandHelper.KEY_DATA_SOURCE)) { if (Build.MANUFACTURER.equalsIgnoreCase(LeakCanaryInternals.SAMSUNG)) { setToSamsumg(context, count); } else if (Build.MANUFACTURER.toLowerCase().contains("sony")) { setToSony(context, count); } } } catch (Exception e) { e.printStackTrace(); } }
public static void enableDisplayLeakActivity(Context context) { LeakCanaryInternals.setEnabled(context, DisplayLeakActivity.class, true); }
public static boolean isInAnalyzerProcess(Context context) { return LeakCanaryInternals.isInServiceProcess(context, HeapAnalyzerService.class); }
private File getHeapDumpFile() { return new File(LeakCanaryInternals.storageDirectory(), "suspected_leak_heapdump.hprof"); }