Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 88b4f153 authored by Romain Guy's avatar Romain Guy
Browse files

Code cleanup.

Change-Id: Ia6ea04b83832db2f39e3168ef2596c24273a7ef3
parent 51c07e71
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -49,8 +49,6 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.text.format.DateUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Pool;
+6 −186
Original line number Diff line number Diff line
@@ -91,21 +91,6 @@ public class ViewDebug {
     */
    public static final boolean TRACE_RECYCLER = false;

    /**
     * Enables or disables motion events tracing. Any invoker of
     * {@link #trace(View, MotionEvent, MotionEventTraceType)} should first check
     * that this value is set to true as not to affect performance.
     * 
     * @hide
     */
    public static final boolean TRACE_MOTION_EVENTS = false;

    /**
     * The system property of dynamic switch for capturing view information
     * when it is set, we dump interested fields and methods for the view on focus
     */
    static final String SYSTEM_PROPERTY_CAPTURE_VIEW = "debug.captureview";

    /**
     * The system property of dynamic switch for capturing event information
     * when it is set, we log key events, touch/motion and trackball events
@@ -170,12 +155,6 @@ public class ViewDebug {
    @Debug.DebugProperty
    public static boolean consistencyCheckEnabled = false;

    static {
        if (false) {        
	        Debug.setFieldsOn(ViewDebug.class, true);
	    }
    }

    /**
     * This annotation can be used to mark fields and methods to be dumped by
     * the view server. Only non-void methods with no arguments can be annotated
@@ -423,21 +402,6 @@ public class ViewDebug {
    private static List<RecyclerTrace> sRecyclerTraces;
    private static String sRecyclerTracePrefix;

    /**
     * Defines the type of motion events trace to output to the motion events traces file.
     * 
     * @hide
     */
    public enum MotionEventTraceType {
        DISPATCH,
        ON_INTERCEPT,
        ON_TOUCH
    }

    private static BufferedWriter sMotionEventTraces;
    private static ViewAncestor sMotionEventRoot;
    private static String sMotionEventTracePrefix;

    /**
     * Returns the number of instanciated Views.
     *
@@ -574,6 +538,7 @@ public class ViewDebug {
        recyclerDump = new File(recyclerDump, sRecyclerTracePrefix + ".traces");
        try {
            if (recyclerDump.exists()) {
                //noinspection ResultOfMethodCallIgnored
                recyclerDump.delete();
            }
            final FileOutputStream file = new FileOutputStream(recyclerDump);
@@ -732,146 +697,6 @@ public class ViewDebug {
        sHierarhcyRoot = null;
    }

    /**
     * Outputs a trace to the currently opened traces file. The trace contains the class name
     * and instance's hashcode of the specified view as well as the supplied trace type.
     *
     * @param view the view to trace
     * @param event the event of the trace
     * @param type the type of the trace
     * 
     * @hide
     */
    public static void trace(View view, MotionEvent event, MotionEventTraceType type) {
        if (sMotionEventTraces == null) {
            return;
        }

        try {
            sMotionEventTraces.write(type.name());
            sMotionEventTraces.write(' ');
            sMotionEventTraces.write(event.getAction());
            sMotionEventTraces.write(' ');
            sMotionEventTraces.write(view.getClass().getName());
            sMotionEventTraces.write('@');
            sMotionEventTraces.write(Integer.toHexString(view.hashCode()));
            sHierarchyTraces.newLine();
        } catch (IOException e) {
            Log.w("View", "Error while dumping trace of event " + event + " for view " + view);
        }
    }

    /**
     * Starts tracing the motion events for the hierarchy of the specificy view.
     * The trace is identified by a prefix, used to build the traces files names:
     * <code>/EXTERNAL/motion-events/PREFIX.traces</code> and
     * <code>/EXTERNAL/motion-events/PREFIX.tree</code>.
     *
     * Only one view hierarchy can be traced at the same time. After calling this method, any
     * other invocation will result in a <code>IllegalStateException</code> unless
     * {@link #stopMotionEventTracing()} is invoked before.
     *
     * Calling this method creates the file <code>/EXTERNAL/motion-events/PREFIX.traces</code>
     * containing all the traces (or method calls) relative to the specified view's hierarchy.
     *
     * This method will return immediately if TRACE_HIERARCHY is false.
     *
     * @param prefix the traces files name prefix
     * @param view the view whose hierarchy must be traced
     *
     * @see #stopMotionEventTracing()
     * @see #trace(View, MotionEvent, android.view.ViewDebug.MotionEventTraceType)
     * 
     * @hide 
     */
    public static void startMotionEventTracing(String prefix, View view) {
        //noinspection PointlessBooleanExpression,ConstantConditions
        if (!TRACE_MOTION_EVENTS) {
            return;
        }

        if (sMotionEventRoot != null) {
            throw new IllegalStateException("You must call stopMotionEventTracing() before running" +
                " a new trace!");
        }

        File hierarchyDump = new File(Environment.getExternalStorageDirectory(), "motion-events/");
        //noinspection ResultOfMethodCallIgnored
        hierarchyDump.mkdirs();

        hierarchyDump = new File(hierarchyDump, prefix + ".traces");
        sMotionEventTracePrefix = prefix;

        try {
            sMotionEventTraces = new BufferedWriter(new FileWriter(hierarchyDump), 32 * 1024);
        } catch (IOException e) {
            Log.e("View", "Could not dump view hierarchy");
            return;
        }

        sMotionEventRoot = (ViewAncestor) view.getRootView().getParent();
    }

    /**
     * Stops the current motion events tracing. This method closes the file
     * <code>/EXTERNAL/motion-events/PREFIX.traces</code>.
     *
     * Calling this method creates the file <code>/EXTERNAL/motion-events/PREFIX.tree</code>
     * containing the view hierarchy of the view supplied to
     * {@link #startMotionEventTracing(String, View)}.
     *
     * This method will return immediately if TRACE_HIERARCHY is false.
     *
     * @see #startMotionEventTracing(String, View) 
     * @see #trace(View, MotionEvent, android.view.ViewDebug.MotionEventTraceType) 
     * 
     * @hide
     */
    public static void stopMotionEventTracing() {
        //noinspection PointlessBooleanExpression,ConstantConditions
        if (!TRACE_MOTION_EVENTS) {
            return;
        }

        if (sMotionEventRoot == null || sMotionEventTraces == null) {
            throw new IllegalStateException("You must call startMotionEventTracing() before" +
                " stopMotionEventTracing()!");
        }

        try {
            sMotionEventTraces.close();
        } catch (IOException e) {
            Log.e("View", "Could not write view traces");
        }
        sMotionEventTraces = null;

        File hierarchyDump = new File(Environment.getExternalStorageDirectory(), "motion-events/");
        //noinspection ResultOfMethodCallIgnored
        hierarchyDump.mkdirs();
        hierarchyDump = new File(hierarchyDump, sMotionEventTracePrefix + ".tree");

        BufferedWriter out;
        try {
            out = new BufferedWriter(new FileWriter(hierarchyDump), 8 * 1024);
        } catch (IOException e) {
            Log.e("View", "Could not dump view hierarchy");
            return;
        }

        View view = sMotionEventRoot.getView();
        if (view instanceof ViewGroup) {
            ViewGroup group = (ViewGroup) view;
            dumpViewHierarchy(group, out, 0);
            try {
                out.close();
            } catch (IOException e) {
                Log.e("View", "Could not dump view hierarchy");
            }
        }

        sHierarhcyRoot = null;
    }

    static void dispatchCommand(View view, String command, String parameters,
            OutputStream clientStream) throws IOException {

@@ -1069,8 +894,10 @@ public class ViewDebug {
                try {
                    T[] data = operation.pre();
                    long start = Debug.threadCpuTimeNanos();
                    //noinspection unchecked
                    operation.run(data);
                    duration[0] = Debug.threadCpuTimeNanos() - start;
                    //noinspection unchecked
                    operation.post(data);
                } finally {
                    latch.countDown();
@@ -1201,12 +1028,7 @@ public class ViewDebug {
                        cache[0] = captureView.createSnapshot(
                                Bitmap.Config.ARGB_8888, 0, skpiChildren);
                    } catch (OutOfMemoryError e) {
                        try {
                            cache[0] = captureView.createSnapshot(
                                    Bitmap.Config.ARGB_4444, 0, skpiChildren);
                        } catch (OutOfMemoryError e2) {
                        Log.w("View", "Out of memory for bitmap");
                        }
                    } finally {
                        latch.countDown();
                    }
@@ -1316,7 +1138,6 @@ public class ViewDebug {
        }

        final HashMap<Class<?>, Field[]> map = sFieldsForClasses;
        final HashMap<AccessibleObject, ExportedProperty> annotations = sAnnotations;

        Field[] fields = map.get(klass);
        if (fields != null) {
@@ -1332,7 +1153,7 @@ public class ViewDebug {
            if (field.isAnnotationPresent(ExportedProperty.class)) {
                field.setAccessible(true);
                foundFields.add(field);
                annotations.put(field, field.getAnnotation(ExportedProperty.class));
                sAnnotations.put(field, field.getAnnotation(ExportedProperty.class));
            }
        }

@@ -1351,7 +1172,6 @@ public class ViewDebug {
        }

        final HashMap<Class<?>, Method[]> map = sMethodsForClasses;
        final HashMap<AccessibleObject, ExportedProperty> annotations = sAnnotations;

        Method[] methods = map.get(klass);
        if (methods != null) {
@@ -1369,7 +1189,7 @@ public class ViewDebug {
                    method.getReturnType() != Void.class) {
                method.setAccessible(true);
                foundMethods.add(method);
                annotations.put(method, method.getAnnotation(ExportedProperty.class));
                sAnnotations.put(method, method.getAnnotation(ExportedProperty.class));
            }
        }

+7 −18
Original line number Diff line number Diff line
@@ -72,19 +72,6 @@ class ViewServer implements Runnable {

    private ExecutorService mThreadPool;

    /**
     * Creates a new ViewServer associated with the specified window manager.
     * The server uses the default port {@link #VIEW_SERVER_DEFAULT_PORT}. The server
     * is not started by default.
     *
     * @param windowManager The window manager used to communicate with the views.
     *
     * @see #start()
     */
    ViewServer(WindowManagerService windowManager) {
        this(windowManager, VIEW_SERVER_DEFAULT_PORT);
    }

    /**
     * Creates a new ViewServer associated with the specified window manager on the
     * specified local port. The server is not started by default.
@@ -220,6 +207,7 @@ class ViewServer implements Runnable {
        private Socket mClient;
        private boolean mNeedWindowListUpdate;
        private boolean mNeedFocusedWindowUpdate;

        public ViewServerWorker(Socket client) {
            mClient = client;
            mNeedWindowListUpdate = false;
@@ -263,7 +251,7 @@ class ViewServer implements Runnable {
                }

                if (!result) {
                    Slog.w(LOG_TAG, "An error occured with the command: " + command);
                    Slog.w(LOG_TAG, "An error occurred with the command: " + command);
                }
            } catch(IOException e) {
                Slog.w(LOG_TAG, "Connection error: ", e);
@@ -337,6 +325,7 @@ class ViewServer implements Runnable {
                    try {
                        out.close();
                    } catch (IOException e) {
                        // Ignore
                    }
                }
                mWindowManager.removeWindowChangeListener(this);