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

Commit 4d7b092a authored by Winson Chung's avatar Winson Chung
Browse files

Fixing memory leaks related to Tasks holding onto their callbacks.

- Switching to SwipeHelper
parent e13cf570
Loading
Loading
Loading
Loading
+69 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.recents;


import android.content.ComponentCallbacks2;
import android.content.Context;
import android.util.Log;
import android.view.MotionEvent;
@@ -36,20 +37,20 @@ public class Console {

    /** Logs a key */
    public static void log(String key) {
        Console.log(true, key, "", AnsiReset);
        log(true, key, "", AnsiReset);
    }

    /** Logs a conditioned key */
    public static void log(boolean condition, String key) {
        if (condition) {
            Console.log(condition, key, "", AnsiReset);
            log(condition, key, "", AnsiReset);
        }
    }

    /** Logs a key in a specific color */
    public static void log(boolean condition, String key, Object data) {
        if (condition) {
            Console.log(condition, key, data, AnsiReset);
            log(condition, key, data, AnsiReset);
        }
    }

@@ -74,6 +75,50 @@ public class Console {
        }
    }

    /** Logs a stack trace */
    public static void logStackTrace() {
        logStackTrace("", 99);
    }

    /** Logs a stack trace to a certain depth */
    public static void logStackTrace(int depth) {
        logStackTrace("", depth);
    }

    /** Logs a stack trace to a certain depth with a key */
    public static void logStackTrace(String key, int depth) {
        int offset = 0;
        StackTraceElement[] callStack = Thread.currentThread().getStackTrace();
        String tinyStackTrace = "";
        // Skip over the known stack trace classes
        for (int i = 0; i < callStack.length; i++) {
            StackTraceElement el = callStack[i];
            String className = el.getClassName();
            if (className.indexOf("dalvik.system.VMStack") == -1 &&
                className.indexOf("java.lang.Thread") == -1 &&
                className.indexOf("recents.Console") == -1) {
                break;
            } else {
                offset++;
            }
        }
        // Build the pretty stack trace
        int start = Math.min(offset + depth, callStack.length);
        int end = offset;
        String indent = "";
        for (int i = start - 1; i >= end; i--) {
            StackTraceElement el = callStack[i];
            tinyStackTrace += indent + " -> " + el.getClassName() +
                    "[" + el.getLineNumber() + "]." + el.getMethodName();
            if (i > end) {
                tinyStackTrace += "\n";
                indent += "  ";
            }
        }
        log(true, key, tinyStackTrace, AnsiRed);
    }


    /** Returns the stringified MotionEvent action */
    public static String motionEventActionToString(int action) {
        switch (action) {
@@ -93,4 +138,25 @@ public class Console {
                return "" + action;
        }
    }

    public static String trimMemoryLevelToString(int level) {
        switch (level) {
            case ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN:
                return "UI Hidden";
            case ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE:
                return "Running Moderate";
            case ComponentCallbacks2.TRIM_MEMORY_BACKGROUND:
                return "Background";
            case ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW:
                return "Running Low";
            case ComponentCallbacks2.TRIM_MEMORY_MODERATE:
                return "Moderate";
            case ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL:
                return "Critical";
            case ComponentCallbacks2.TRIM_MEMORY_COMPLETE:
                return "Complete";
            default:
                return "" + level;
        }
    }
}
+6 −1
Original line number Diff line number Diff line
@@ -30,9 +30,11 @@ public class Constants {
            public static final boolean EnableTaskStackClipping = false;
            public static final boolean EnableBackgroundTaskLoading = true;
            public static final boolean ForceDisableBackgroundCache = false;

            public static final boolean TaskDataLoader = false;
            public static final boolean SystemUIHandshake = false;
            public static final boolean TimeSystemCalls = false;
            public static final boolean Memory = false;
        }

        public static class UI {
@@ -41,7 +43,7 @@ public class Constants {
            public static final boolean TouchEvents = false;
            public static final boolean MeasureAndLayout = false;
            public static final boolean Clipping = false;
            public static final boolean HwLayers = true;
            public static final boolean HwLayers = false;
        }

        public static class TaskStack {
@@ -55,13 +57,16 @@ public class Constants {

    public static class Values {
        public static class Window {
            // The dark background dim is set behind the empty recents view
            public static final float DarkBackgroundDim = 0.5f;
            // The background dim is set behind the card stack
            public static final float BackgroundDim = 0.35f;
        }

        public static class RecentsTaskLoader {
            // XXX: This should be calculated on the first load
            public static final int PreloadFirstTasksCount = 5;
            // For debugging, this allows us to multiply the number of cards for each task
            public static final int TaskEntryMultiplier = 1;
        }

+9 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.FrameLayout;
import com.android.systemui.recent.RecentTasksLoader;
import com.android.systemui.recents.model.SpaceNode;
import com.android.systemui.recents.model.TaskStack;
import com.android.systemui.recents.views.RecentsView;
@@ -167,6 +168,14 @@ public class RecentsActivity extends Activity {
        mVisible = false;
    }

    @Override
    public void onTrimMemory(int level) {
        RecentsTaskLoader loader = RecentsTaskLoader.getInstance();
        if (loader != null) {
            loader.onTrimMemory(level);
        }
    }

    @Override
    public void onBackPressed() {
        if (!mRecentsView.unfilterFilteredStacks()) {
+0 −2
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ public class RecentsConfiguration {

    DisplayMetrics mDisplayMetrics;

    public boolean layoutVerticalStack;
    public Rect systemInsets = new Rect();

    /** Private constructor */
@@ -56,7 +55,6 @@ public class RecentsConfiguration {

        boolean isPortrait = context.getResources().getConfiguration().orientation ==
                Configuration.ORIENTATION_PORTRAIT;
        layoutVerticalStack = isPortrait || Constants.LANDSCAPE_LAYOUT_VERTICAL_STACK;
    }

    public void updateSystemInsets(Rect insets) {
+10 −1
Original line number Diff line number Diff line
@@ -57,8 +57,9 @@ public class RecentsService extends Service {
                    tsv.computeRects(windowRect.width(), windowRect.height() - systemInsets.top);
                    tsv.boundScroll();
                    TaskViewTransform transform = tsv.getStackTransform(0);
                    Rect taskRect = new Rect(transform.rect);

                    data.putParcelable("taskRect", transform.rect);
                    data.putParcelable("taskRect", taskRect);
                    Message reply = Message.obtain(null, MSG_UPDATE_RECENTS_FOR_CONFIGURATION, 0, 0);
                    reply.setData(data);
                    msg.replyTo.send(reply);
@@ -100,4 +101,12 @@ public class RecentsService extends Service {
        Console.log(Constants.DebugFlags.App.SystemUIHandshake, "[RecentsService|onDestroy]");
        super.onDestroy();
    }

    @Override
    public void onTrimMemory(int level) {
        RecentsTaskLoader loader = RecentsTaskLoader.getInstance();
        if (loader != null) {
            loader.onTrimMemory(level);
        }
    }
}
Loading