Skip to content
Browse files

Added LeakingActivity project.

  • Loading branch information...
1 parent 52bde9a commit ae5080ed4f8211f8ce34e90e11da09fdef8a3912 @inazaruk committed
View
8 LeakingActivity/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="gen"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+ <classpathentry kind="output" path="bin/classes"/>
+</classpath>
View
33 LeakingActivity/.project
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>LeakingActivity</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
23 LeakingActivity/AndroidManifest.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.inazaruk.leak"
+ android:versionCode="1"
+ android:versionName="1.0" >
+
+ <uses-sdk android:minSdkVersion="7" />
+
+ <application
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name" >
+ <activity
+ android:name=".LeakingActivity"
+ android:label="@string/app_name" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
View
40 LeakingActivity/proguard.cfg
@@ -0,0 +1,40 @@
+-optimizationpasses 5
+-dontusemixedcaseclassnames
+-dontskipnonpubliclibraryclasses
+-dontpreverify
+-verbose
+-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
+
+-keep public class * extends android.app.Activity
+-keep public class * extends android.app.Application
+-keep public class * extends android.app.Service
+-keep public class * extends android.content.BroadcastReceiver
+-keep public class * extends android.content.ContentProvider
+-keep public class * extends android.app.backup.BackupAgentHelper
+-keep public class * extends android.preference.Preference
+-keep public class com.android.vending.licensing.ILicensingService
+
+-keepclasseswithmembernames class * {
+ native <methods>;
+}
+
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet);
+}
+
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet, int);
+}
+
+-keepclassmembers class * extends android.app.Activity {
+ public void *(android.view.View);
+}
+
+-keepclassmembers enum * {
+ public static **[] values();
+ public static ** valueOf(java.lang.String);
+}
+
+-keep class * implements android.os.Parcelable {
+ public static final android.os.Parcelable$Creator *;
+}
View
11 LeakingActivity/project.properties
@@ -0,0 +1,11 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-7
View
BIN LeakingActivity/res/drawable-hdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN LeakingActivity/res/drawable-ldpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN LeakingActivity/res/drawable-mdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
34 LeakingActivity/res/layout/main.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent" >
+
+ <LinearLayout
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:padding="10dp">
+
+ <ProgressBar
+ android:id="@+id/progress"
+ style="@android:style/Widget.ProgressBar.Horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="10dp"
+ />
+
+ <Button
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:onClick="onGC"
+ android:text="Garbage Collector"
+ />
+
+ <TextView
+ android:id="@+id/status"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/hello" />
+
+ </LinearLayout>
+</ScrollView>
View
7 LeakingActivity/res/values/strings.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <string name="hello">Hello World, LeakingActivity!</string>
+ <string name="app_name">LeakingActivity</string>
+
+</resources>
View
125 LeakingActivity/src/com/inazaruk/leak/LeakingActivity.java
@@ -0,0 +1,125 @@
+package com.inazaruk.leak;
+
+import android.app.Activity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Process;
+import android.view.View;
+import android.widget.ProgressBar;
+import android.widget.TextView;
+
+import java.util.concurrent.ConcurrentHashMap;
+
+public class LeakingActivity extends Activity {
+
+ private static final long UPDATE_INTERVAL = 1000;
+ private static final String ACTION_THREAD_COUNT_CHANGED = "threadcount";
+
+ private static int sThreads = 0;
+ private static ConcurrentHashMap<Integer, Integer> sThreadTimeouts = new ConcurrentHashMap<Integer, Integer>();
+
+ private byte [] mData = new byte[5 * 1024 * 1024];
+ private TextView mStatus;
+ private ProgressBar mMemoryProgress;
+ private Handler mHandler;
+ private Leaker mLeaker;
+ private BroadcastReceiver mReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ update();
+ }
+ };
+ private Runnable mRunnable = new Runnable() {
+ @Override
+ public void run() {
+ update();
+ mHandler.postDelayed(mRunnable, UPDATE_INTERVAL);
+ }
+ };
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+ mStatus = (TextView)findViewById(R.id.status);
+ mMemoryProgress = (ProgressBar)findViewById(R.id.progress);
+ mHandler = new Handler();
+ mLeaker = new Leaker();
+ mLeaker.start();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ registerReceiver(mReceiver, new IntentFilter(ACTION_THREAD_COUNT_CHANGED));
+ mRunnable.run();
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ unregisterReceiver(mReceiver);
+ mHandler.removeCallbacks(mRunnable);
+ }
+
+ public void onGC(View v) {
+ System.gc();
+ }
+
+ public void update() {
+ StringBuilder builder = new StringBuilder();
+
+ Runtime rt = Runtime.getRuntime();
+ mMemoryProgress.setMax((int)rt.maxMemory());
+ mMemoryProgress.setSecondaryProgress((int)rt.totalMemory());
+ mMemoryProgress.setProgress((int)(rt.totalMemory() - rt.freeMemory()));
+
+ float maxMem = rt.maxMemory() * 1f / 1024 / 1024;
+ float totalMem = rt.totalMemory() * 1f / 1024 / 1024;
+ float freeMem = rt.freeMemory() * 1f / 1024 / 1024;
+
+ String mem = String.format("MAX=%.2f Mb\nTOTAL=%.2f Mb\nFREE=%.2f Mb\n", maxMem, totalMem, freeMem);
+ builder.append(mem);
+
+ synchronized (LeakingActivity.class) {
+ builder.append("\n");
+ builder.append("Threads: " + sThreads + "\n");
+ builder.append("\n");
+
+ for(Integer id : sThreadTimeouts.keySet()) {
+ builder.append("thread " + id +" - " + sThreadTimeouts.get(id) + "ms\n");
+ }
+ }
+ mStatus.setText(builder.toString());
+ }
+
+ private class Leaker extends Thread {
+
+ @Override
+ public void run() {
+ synchronized (LeakingActivity.class) {
+ sThreads++;
+ }
+ int timeout = 30;
+ try {
+ for(int i = timeout; i > 0; i--) {
+ synchronized (LeakingActivity.class) {
+ sThreadTimeouts.put(Process.myTid(), i);
+ }
+ Thread.sleep(1000);
+ }
+ } catch (InterruptedException e) {
+ //ignore
+ }
+ synchronized (LeakingActivity.class) {
+ sThreadTimeouts.remove(Process.myTid());
+ sThreads--;
+ }
+ }
+ }
+}

0 comments on commit ae5080e

Please sign in to comment.
Something went wrong with that request. Please try again.