OSDN Git Service

Moving a few testing classes to a separate package
authorSunny Goyal <sunnygoyal@google.com>
Fri, 26 Jun 2015 02:35:49 +0000 (19:35 -0700)
committerGabriele M <moto.falcon.git@gmail.com>
Sun, 26 Mar 2017 16:40:27 +0000 (18:40 +0200)
Change-Id: Ied1c063de3e938695493e4937f554686e0719dad

14 files changed:
AndroidManifest.xml
res/layout/zzz_dummy_widget.xml [moved from res/layout/dummy_widget.xml with 100% similarity]
res/layout/zzz_weight_watcher.xml [new file with mode: 0644]
res/values/config.xml
res/values/strings.xml
src/com/android/launcher3/Launcher.java
src/com/android/launcher3/LauncherAppState.java
src/com/android/launcher3/ToggleWeightWatcher.java [deleted file]
src/com/android/launcher3/testing/DummyWidget.java [moved from src/com/android/launcher3/DummyWidget.java with 82% similarity]
src/com/android/launcher3/testing/MemoryDumpActivity.java [moved from src/com/android/launcher3/MemoryDumpActivity.java with 94% similarity]
src/com/android/launcher3/testing/MemoryTracker.java [moved from src/com/android/launcher3/MemoryTracker.java with 93% similarity]
src/com/android/launcher3/testing/ToggleWeightWatcher.java [new file with mode: 0644]
src/com/android/launcher3/testing/WeightWatcher.java [moved from src/com/android/launcher3/WeightWatcher.java with 98% similarity]
src/com/android/launcher3/util/TestingUtils.java [new file with mode: 0644]

index f0c7444..a7038ba 100644 (file)
             </intent-filter>
         </activity>
 
-        <!-- ENABLE_FOR_TESTING
-
-        <activity
-            android:name="com.android.launcher3.testing.LauncherExtension"
-            android:launchMode="singleTask"
-            android:clearTaskOnLaunch="true"
-            android:stateNotNeeded="true"
-            android:theme="@style/Theme"
-            android:windowSoftInputMode="adjustPan"
-            android:screenOrientation="nosensor"
-            android:enabled="false">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.HOME" />
-                <category android:name="android.intent.category.DEFAULT" />
-                <category android:name="android.intent.category.MONKEY"/>
-            </intent-filter>
-        </activity>
-
-        -->
-
-        <activity
-            android:name="com.android.launcher3.ToggleWeightWatcher"
-            android:label="@string/toggle_weight_watcher"
-            android:enabled="@bool/debug_memory_enabled"
-            android:icon="@mipmap/ic_launcher_home">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.DEFAULT" />
-                <category android:name="android.intent.category.LAUNCHER" />
-            </intent-filter>
-        </activity>
-
         <activity
             android:name="com.android.launcher3.WallpaperPickerActivity"
             android:theme="@style/Theme.WallpaperPicker"
             </intent-filter>
         </activity>
 
-        <!-- Debugging tools -->
-        <activity
-            android:name="com.android.launcher3.MemoryDumpActivity"
-            android:theme="@android:style/Theme.NoDisplay"
-            android:label="@string/debug_memory_activity"
-            android:enabled="@bool/debug_memory_enabled"
-            android:excludeFromRecents="true"
-            android:icon="@mipmap/ic_launcher_home"
-            >
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.DEFAULT" />
-                <category android:name="android.intent.category.LAUNCHER" />
-            </intent-filter>
-        </activity>
-
-        <service android:name="com.android.launcher3.MemoryTracker"
-            android:enabled="@bool/debug_memory_enabled"
-            >
-        </service>
-
         <receiver
             android:name="com.android.launcher3.WallpaperChangedReceiver">
             <intent-filter>
 
         <meta-data android:name="android.nfc.disable_beam_default"
                        android:value="true" />
+
+        <!-- ENABLE_FOR_TESTING
+
+        <activity
+            android:name="com.android.launcher3.testing.LauncherExtension"
+            android:launchMode="singleTask"
+            android:clearTaskOnLaunch="true"
+            android:stateNotNeeded="true"
+            android:theme="@style/Theme"
+            android:windowSoftInputMode="adjustPan"
+            android:screenOrientation="nosensor"
+            >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.HOME" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <category android:name="android.intent.category.MONKEY"/>
+            </intent-filter>
+        </activity>
+
+        <activity
+            android:name="com.android.launcher3.testing.MemoryDumpActivity"
+            android:theme="@android:style/Theme.NoDisplay"
+            android:label="* HPROF"
+            android:excludeFromRecents="true"
+            android:icon="@mipmap/ic_launcher_home"
+            >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+
+        <activity
+            android:name="com.android.launcher3.testing.ToggleWeightWatcher"
+            android:label="Show Mem"
+            android:icon="@mipmap/ic_launcher_home">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+
+        <service android:name="com.android.launcher3.testing.MemoryTracker" />
+
+        -->
+
     </application>
 </manifest>
diff --git a/res/layout/zzz_weight_watcher.xml b/res/layout/zzz_weight_watcher.xml
new file mode 100644 (file)
index 0000000..07fd39e
--- /dev/null
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<com.android.launcher3.testing.WeightWatcher xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent" />
index 4d3f011..27b85a6 100644 (file)
@@ -66,9 +66,6 @@
 <!-- Hotseat -->
     <bool name="hotseat_transpose_layout_with_orientation">true</bool>
 
-    <!-- Memory debugging, including a memory dump icon -->
-    <bool name="debug_memory_enabled">false</bool>
-
     <!-- Name of a subclass of com.android.launcher3.AppFilter used to
          filter the activities shown in the launcher. Can be empty. -->
     <string name="app_filter_class" translatable="false"></string>
index b544788..80195ae 100644 (file)
@@ -45,8 +45,6 @@
     <!-- SafeMode widget error string -->
     <string name="safemode_widget_error">Widgets disabled in Safe mode</string>
 
-    <string name="toggle_weight_watcher">Show Mem</string>
-
     <!-- Widgets -->
     <!-- Message to tell the user to press and hold on a widget to add it [CHAR_LIMIT=50] -->
     <string name="long_press_widget_to_add">Touch &amp; hold to pick up a widget.</string>
     <!-- Folder name format -->
     <string name="folder_name_format">Folder: <xliff:g id="name" example="Games">%1$s</xliff:g></string>
 
-    <!-- Debug-only activity name. [DO NOT TRANSLATE] -->
-    <string name="debug_memory_activity">* HPROF</string>
-
     <!-- Strings for the customization mode -->
     <!-- Text for widget add button -->
     <string name="widget_button_text">Widgets</string>
index b3c61ca..575ba48 100644 (file)
@@ -81,7 +81,6 @@ import android.text.TextUtils;
 import android.text.method.TextKeyListener;
 import android.util.Log;
 import android.view.Display;
-import android.view.Gravity;
 import android.view.HapticFeedbackConstants;
 import android.view.KeyEvent;
 import android.view.LayoutInflater;
@@ -100,7 +99,6 @@ import android.view.accessibility.AccessibilityEvent;
 import android.view.animation.OvershootInterpolator;
 import android.view.inputmethod.InputMethodManager;
 import android.widget.Advanceable;
-import android.widget.FrameLayout;
 import android.widget.ImageView;
 import android.widget.TextView;
 import android.widget.Toast;
@@ -119,6 +117,7 @@ import com.android.launcher3.settings.SettingsProvider;
 import com.android.launcher3.stats.LauncherStats;
 import com.android.launcher3.util.ComponentKey;
 import com.android.launcher3.util.LongArrayMap;
+import com.android.launcher3.util.TestingUtils;
 import com.android.launcher3.util.Thunk;
 import com.android.launcher3.widget.PendingAddWidgetInfo;
 import com.android.launcher3.widget.WidgetHostViewLoader;
@@ -229,9 +228,6 @@ public class Launcher extends Activity
     static final String ACTION_FIRST_LOAD_COMPLETE =
             "com.android.launcher3.action.FIRST_LOAD_COMPLETE";
 
-    public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
-    public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
-
     private static final String QSB_WIDGET_ID = "qsb_widget_id";
     private static final String QSB_WIDGET_PROVIDER = "qsb_widget_provider";
     private static final String PROPERTY_SHOW_TREB_HIDDEN =
@@ -278,10 +274,11 @@ public class Launcher extends Activity
     private View mPageIndicators;
     @Thunk DragLayer mDragLayer;
     private DragController mDragController;
-    private View mWeightWatcher;
     private DynamicGridSizeFragment mDynamicGridSizeFragment;
     private boolean mIsHiddenMenuOptionEnabled;
 
+    public View mWeightWatcher;
+
     protected static RemoteFolderManager sRemoteFolderManager;
 
     private AppWidgetManagerCompat mAppWidgetManager;
@@ -451,10 +448,9 @@ public class Launcher extends Activity
     protected static HashMap<String, CustomAppWidget> sCustomAppWidgets =
             new HashMap<String, CustomAppWidget>();
 
-    private static final boolean ENABLE_CUSTOM_WIDGET_TEST = false;
     static {
-        if (ENABLE_CUSTOM_WIDGET_TEST) {
-            sCustomAppWidgets.put(DummyWidget.class.getName(), new DummyWidget());
+        if (TestingUtils.ENABLE_CUSTOM_WIDGET_TEST) {
+            TestingUtils.addDummyWidget(sCustomAppWidgets);
         }
     }
 
@@ -1770,19 +1766,8 @@ public class Launcher extends Activity
             mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
         }
 
-        if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
-            Log.v(TAG, "adding WeightWatcher");
-            mWeightWatcher = new WeightWatcher(this);
-            mWeightWatcher.setAlpha(0.5f);
-            ((FrameLayout) mLauncherView).addView(mWeightWatcher,
-                    new FrameLayout.LayoutParams(
-                            FrameLayout.LayoutParams.MATCH_PARENT,
-                            FrameLayout.LayoutParams.WRAP_CONTENT,
-                            Gravity.BOTTOM)
-            );
-
-            boolean show = shouldShowWeightWatcher();
-            mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
+        if (TestingUtils.MEMORY_DUMP_ENABLED) {
+            TestingUtils.addWeightWatcher(this);
         }
 
         sRemoteFolderManager.onSetupViews();
@@ -3165,21 +3150,6 @@ public class Launcher extends Activity
             return;
         }
 
-        final Intent intent = shortcut.intent;
-
-        // Check for special shortcuts
-        if (intent.getComponent() != null) {
-            final String shortcutClass = intent.getComponent().getClassName();
-
-            if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
-                MemoryDumpActivity.startDump(this);
-                return;
-            } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
-                toggleShowWeightWatcher();
-                return;
-            }
-        }
-
         // Check for abandoned promise
         if ((v instanceof BubbleTextView)
                 && shortcut.isPromise()
@@ -4324,30 +4294,6 @@ public class Launcher extends Activity
         }
     }
 
-    private boolean shouldShowWeightWatcher() {
-        String spKey = LauncherAppState.getSharedPreferencesKey();
-        SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
-        boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
-
-        return show;
-    }
-
-    private void toggleShowWeightWatcher() {
-        String spKey = LauncherAppState.getSharedPreferencesKey();
-        SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
-        boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
-
-        show = !show;
-
-        SharedPreferences.Editor editor = sp.edit();
-        editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
-        editor.commit();
-
-        if (mWeightWatcher != null) {
-            mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
-        }
-    }
-
     public void bindAppsAdded(final ArrayList<Long> newScreens,
                               final ArrayList<ItemInfo> addNotAnimated,
                               final ArrayList<ItemInfo> addAnimated,
index d2a9b26..73e17a2 100644 (file)
@@ -27,6 +27,7 @@ import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
 import com.android.launcher3.compat.LauncherAppsCompat;
 import com.android.launcher3.compat.PackageInstallerCompat;
 import com.android.launcher3.compat.UserManagerCompat;
+import com.android.launcher3.util.TestingUtils;
 import com.android.launcher3.util.Thunk;
 
 import java.lang.ref.WeakReference;
@@ -79,8 +80,8 @@ public class LauncherAppState {
 
         Log.v(Launcher.TAG, "LauncherAppState inited");
 
-        if (sContext.getResources().getBoolean(R.bool.debug_memory_enabled)) {
-            MemoryTracker.startTrackingMe(sContext, "L");
+        if (TestingUtils.MEMORY_DUMP_ENABLED) {
+            TestingUtils.startTrackingMemory(sContext);
         }
 
         mInvariantDeviceProfile = new InvariantDeviceProfile(sContext);
diff --git a/src/com/android/launcher3/ToggleWeightWatcher.java b/src/com/android/launcher3/ToggleWeightWatcher.java
deleted file mode 100644 (file)
index 33701a2..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.android.launcher3;
-
-import android.app.Activity;
-
-public class ToggleWeightWatcher extends Activity {
-
-}
@@ -1,7 +1,10 @@
-package com.android.launcher3;
+package com.android.launcher3.testing;
 
 import android.appwidget.AppWidgetProviderInfo;
 
+import com.android.launcher3.CustomAppWidget;
+import com.android.launcher3.R;
+
 public class DummyWidget implements CustomAppWidget {
     @Override
     public String getLabel() {
@@ -20,7 +23,7 @@ public class DummyWidget implements CustomAppWidget {
 
     @Override
     public int getWidgetLayout() {
-        return R.layout.dummy_widget;
+        return R.layout.zzz_dummy_widget;
     }
 
     @Override
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.launcher3;
+package com.android.launcher3.testing;
 
 import android.app.Activity;
 import android.content.ComponentName;
@@ -23,10 +23,20 @@ import android.content.Intent;
 import android.content.ServiceConnection;
 import android.content.pm.PackageManager;
 import android.net.Uri;
-import android.os.*;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Environment;
+import android.os.IBinder;
 import android.util.Log;
 
-import java.io.*;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.zip.ZipEntry;
  * limitations under the License.
  */
 
-package com.android.launcher3;
+package com.android.launcher3.testing;
 
 import android.app.ActivityManager;
 import android.app.Service;
 import android.content.Context;
 import android.content.Intent;
-import android.os.*;
+import android.os.Binder;
+import android.os.Debug;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Message;
+import android.os.SystemClock;
 import android.util.Log;
 import android.util.LongSparseArray;
 
+import com.android.launcher3.util.TestingUtils;
+
 import java.util.ArrayList;
 import java.util.List;
 
 public class MemoryTracker extends Service {
     public static final String TAG = MemoryTracker.class.getSimpleName();
-    public static final String ACTION_START_TRACKING = "com.android.launcher3.action.START_TRACKING";
 
     private static final long UPDATE_RATE = 5000;
 
@@ -83,14 +89,6 @@ public class MemoryTracker extends Service {
 
     ActivityManager mAm;
 
-    public static void startTrackingMe(Context context, String name) {
-        context.startService(new Intent(context, MemoryTracker.class)
-                .setAction(MemoryTracker.ACTION_START_TRACKING)
-                .putExtra("pid", android.os.Process.myPid())
-                .putExtra("name", name)
-        );
-    }
-
     public ProcessMemInfo getMemInfo(int pid) {
         return mData.get(pid);
     }
@@ -190,7 +188,7 @@ public class MemoryTracker extends Service {
         Log.v(TAG, "Received start id " + startId + ": " + intent);
 
         if (intent != null) {
-            if (ACTION_START_TRACKING.equals(intent.getAction())) {
+            if (TestingUtils.ACTION_START_TRACKING.equals(intent.getAction())) {
                 final int pid = intent.getIntExtra("pid", -1);
                 final String name = intent.getStringExtra("name");
                 final long start = intent.getLongExtra("start", System.currentTimeMillis());
diff --git a/src/com/android/launcher3/testing/ToggleWeightWatcher.java b/src/com/android/launcher3/testing/ToggleWeightWatcher.java
new file mode 100644 (file)
index 0000000..15e55ee
--- /dev/null
@@ -0,0 +1,32 @@
+package com.android.launcher3.testing;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.view.View;
+
+import com.android.launcher3.Launcher;
+import com.android.launcher3.LauncherAppState;
+import com.android.launcher3.util.TestingUtils;
+
+public class ToggleWeightWatcher extends Activity {
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        String spKey = LauncherAppState.getSharedPreferencesKey();
+        SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
+        boolean show = sp.getBoolean(TestingUtils.SHOW_WEIGHT_WATCHER, true);
+
+        show = !show;
+        sp.edit().putBoolean(TestingUtils.SHOW_WEIGHT_WATCHER, show).apply();
+
+        Launcher launcher = (Launcher) LauncherAppState.getInstance().getModel().getCallback();
+        if (launcher != null && launcher.mWeightWatcher != null) {
+            launcher.mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
+        }
+        finish();
+    }
+}
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.launcher3;
+package com.android.launcher3.testing;
 
 import android.content.ComponentName;
 import android.content.Context;
@@ -116,10 +116,6 @@ public class WeightWatcher extends LinearLayout {
         }
     }
 
-    public WeightWatcher(Context context) {
-        this(context, null);
-    }
-
     @Override
     public void onAttachedToWindow() {
         super.onAttachedToWindow();
diff --git a/src/com/android/launcher3/util/TestingUtils.java b/src/com/android/launcher3/util/TestingUtils.java
new file mode 100644 (file)
index 0000000..39b8046
--- /dev/null
@@ -0,0 +1,73 @@
+package com.android.launcher3.util;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.util.Log;
+import android.view.Gravity;
+import android.view.View;
+import android.widget.FrameLayout;
+
+import com.android.launcher3.CustomAppWidget;
+import com.android.launcher3.Launcher;
+import com.android.launcher3.LauncherAppState;
+import com.android.launcher3.R;
+
+import java.util.HashMap;
+
+public class TestingUtils {
+
+    public static final String MEMORY_TRACKER = "com.android.launcher3.testing.MemoryTracker";
+    public static final String ACTION_START_TRACKING = "com.android.launcher3.action.START_TRACKING";
+
+    public static final boolean MEMORY_DUMP_ENABLED = false;
+    public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
+
+    public static final boolean ENABLE_CUSTOM_WIDGET_TEST = false;
+    public static final String DUMMY_WIDGET = "com.android.launcher3.testing.DummyWidget";
+
+    public static void startTrackingMemory(Context context) {
+        if (MEMORY_DUMP_ENABLED) {
+            context.startService(new Intent()
+                .setComponent(new ComponentName(context.getPackageName(), MEMORY_TRACKER))
+                .setAction(ACTION_START_TRACKING)
+                .putExtra("pid", android.os.Process.myPid())
+                .putExtra("name", "L"));
+        }
+    }
+
+    public static void addWeightWatcher(Launcher launcher) {
+        if (MEMORY_DUMP_ENABLED) {
+            String spKey = LauncherAppState.getSharedPreferencesKey();
+            SharedPreferences sp = launcher.getSharedPreferences(spKey, Context.MODE_PRIVATE);
+            boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
+
+            int id = launcher.getResources().getIdentifier("zzz_weight_watcher", "layout",
+                    launcher.getPackageName());
+            View watcher = launcher.getLayoutInflater().inflate(id, null);
+            watcher.setAlpha(0.5f);
+            ((FrameLayout) launcher.findViewById(R.id.launcher)).addView(watcher,
+                    new FrameLayout.LayoutParams(
+                            FrameLayout.LayoutParams.MATCH_PARENT,
+                            FrameLayout.LayoutParams.WRAP_CONTENT,
+                            Gravity.BOTTOM)
+            );
+
+            watcher.setVisibility(show ? View.VISIBLE : View.GONE);
+            launcher.mWeightWatcher = watcher;
+        }
+    }
+
+    public static void addDummyWidget(HashMap<String, CustomAppWidget> set) {
+        if (ENABLE_CUSTOM_WIDGET_TEST) {
+            try {
+                Class<?> clazz = Class.forName(DUMMY_WIDGET);
+                CustomAppWidget widget = (CustomAppWidget) clazz.newInstance();
+                set.put(widget.getClass().getName(), widget);
+            } catch (Exception e) {
+                Log.e("TestingUtils", "Error adding dummy widget", e);
+            }
+        }
+    }
+}