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

Commit b0791173 authored by Winson Chung's avatar Winson Chung Committed by Android (Google) Code Review
Browse files

Merge "Add some flags to reduce memory usage on svelte devices." into lmp-mr1-dev

parents a8e6d6fd 96d70418
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -182,6 +182,8 @@
    <bool name="recents_has_transposed_search_bar">true</bool>
    <bool name="recents_has_transposed_search_bar">true</bool>
    <!-- Transposes the nav bar in landscape (only used for purposes of layout). -->
    <!-- Transposes the nav bar in landscape (only used for purposes of layout). -->
    <bool name="recents_has_transposed_nav_bar">true</bool>
    <bool name="recents_has_transposed_nav_bar">true</bool>
    <!-- Svelte specific logic, see RecentsConfiguration.SVELTE_* constants. -->
    <integer name="recents_svelte_level">0</integer>


    <!-- Whether to enable KeyguardService or not -->
    <!-- Whether to enable KeyguardService or not -->
    <bool name="config_enableKeyguardService">true</bool>
    <bool name="config_enableKeyguardService">true</bool>
+14 −0
Original line number Original line Diff line number Diff line
@@ -38,6 +38,18 @@ public class RecentsConfiguration {
    static RecentsConfiguration sInstance;
    static RecentsConfiguration sInstance;
    static int sPrevConfigurationHashCode;
    static int sPrevConfigurationHashCode;


    /** Levels of svelte in increasing severity/austerity. */
    // No svelting.
    public static final int SVELTE_NONE = 0;
    // Limit thumbnail cache to number of visible thumbnails when Recents was loaded, disable
    // caching thumbnails as you scroll.
    public static final int SVELTE_LIMIT_CACHE = 1;
    // Disable the thumbnail cache, load thumbnails asynchronously when the activity loads and
    // evict all thumbnails when hidden.
    public static final int SVELTE_DISABLE_CACHE = 2;
    // Disable all thumbnail loading.
    public static final int SVELTE_DISABLE_LOADING = 3;

    /** Animations */
    /** Animations */
    public float animationPxMovementPerSecond;
    public float animationPxMovementPerSecond;


@@ -128,6 +140,7 @@ public class RecentsConfiguration {
    public boolean lockToAppEnabled;
    public boolean lockToAppEnabled;
    public boolean developerOptionsEnabled;
    public boolean developerOptionsEnabled;
    public boolean debugModeEnabled;
    public boolean debugModeEnabled;
    public int svelteLevel;


    /** Private constructor */
    /** Private constructor */
    private RecentsConfiguration(Context context) {
    private RecentsConfiguration(Context context) {
@@ -277,6 +290,7 @@ public class RecentsConfiguration {
        useHardwareLayers = res.getBoolean(R.bool.config_recents_use_hardware_layers);
        useHardwareLayers = res.getBoolean(R.bool.config_recents_use_hardware_layers);
        altTabKeyDelay = res.getInteger(R.integer.recents_alt_tab_key_delay);
        altTabKeyDelay = res.getInteger(R.integer.recents_alt_tab_key_delay);
        fakeShadows = res.getBoolean(R.bool.config_recents_fake_shadows);
        fakeShadows = res.getBoolean(R.bool.config_recents_fake_shadows);
        svelteLevel = res.getInteger(R.integer.recents_svelte_level);
    }
    }


    /** Updates the system insets */
    /** Updates the system insets */
+8 −3
Original line number Original line Diff line number Diff line
@@ -155,7 +155,8 @@ public class RecentsTaskLoadPlan {
    /**
    /**
     * Called to apply the actual loading based on the specified conditions.
     * Called to apply the actual loading based on the specified conditions.
     */
     */
    synchronized void executePlan(Options opts, RecentsTaskLoader loader) {
    synchronized void executePlan(Options opts, RecentsTaskLoader loader,
            TaskResourceLoadQueue loadQueue) {
        if (DEBUG) Log.d(TAG, "executePlan, # tasks: " + opts.numVisibleTasks +
        if (DEBUG) Log.d(TAG, "executePlan, # tasks: " + opts.numVisibleTasks +
                ", # thumbnails: " + opts.numVisibleTaskThumbnails +
                ", # thumbnails: " + opts.numVisibleTaskThumbnails +
                ", running task id: " + opts.runningTaskId);
                ", running task id: " + opts.runningTaskId);
@@ -195,8 +196,12 @@ public class RecentsTaskLoadPlan {
            if (opts.loadThumbnails && (isRunningTask || isVisibleThumbnail)) {
            if (opts.loadThumbnails && (isRunningTask || isVisibleThumbnail)) {
                if (task.thumbnail == null) {
                if (task.thumbnail == null) {
                    if (DEBUG) Log.d(TAG, "\tLoading thumbnail: " + taskKey);
                    if (DEBUG) Log.d(TAG, "\tLoading thumbnail: " + taskKey);
                    if (mConfig.svelteLevel <= RecentsConfiguration.SVELTE_LIMIT_CACHE) {
                        task.thumbnail = loader.getAndUpdateThumbnail(taskKey, mSystemServicesProxy,
                        task.thumbnail = loader.getAndUpdateThumbnail(taskKey, mSystemServicesProxy,
                                true);
                                true);
                    } else if (mConfig.svelteLevel == RecentsConfiguration.SVELTE_DISABLE_CACHE) {
                        loadQueue.addTask(task);
                    }
                }
                }
            }
            }


+29 −6
Original line number Original line Diff line number Diff line
@@ -94,6 +94,9 @@ class TaskResourceLoadQueue {


/* Task resource loader */
/* Task resource loader */
class TaskResourceLoader implements Runnable {
class TaskResourceLoader implements Runnable {
    static String TAG = "TaskResourceLoader";
    static boolean DEBUG = false;

    Context mContext;
    Context mContext;
    HandlerThread mLoadThread;
    HandlerThread mLoadThread;
    Handler mLoadThreadHandler;
    Handler mLoadThreadHandler;
@@ -165,6 +168,7 @@ class TaskResourceLoader implements Runnable {
                    }
                    }
                }
                }
            } else {
            } else {
                RecentsConfiguration config = RecentsConfiguration.getInstance();
                SystemServicesProxy ssp = mSystemServicesProxy;
                SystemServicesProxy ssp = mSystemServicesProxy;
                // If we've stopped the loader, then fall thorugh to the above logic to wait on
                // If we've stopped the loader, then fall thorugh to the above logic to wait on
                // the load thread
                // the load thread
@@ -185,6 +189,7 @@ class TaskResourceLoader implements Runnable {
                            ActivityInfo info = ssp.getActivityInfo(t.key.baseIntent.getComponent(),
                            ActivityInfo info = ssp.getActivityInfo(t.key.baseIntent.getComponent(),
                                    t.key.userId);
                                    t.key.userId);
                            if (info != null) {
                            if (info != null) {
                                if (DEBUG) Log.d(TAG, "Loading icon: " + t.key);
                                cachedIcon = ssp.getActivityIcon(info, t.key.userId);
                                cachedIcon = ssp.getActivityIcon(info, t.key.userId);
                            }
                            }
                        }
                        }
@@ -199,12 +204,20 @@ class TaskResourceLoader implements Runnable {
                    }
                    }
                    // Load the thumbnail if it is stale or we haven't cached one yet
                    // Load the thumbnail if it is stale or we haven't cached one yet
                    if (cachedThumbnail == null) {
                    if (cachedThumbnail == null) {
                        if (config.svelteLevel < RecentsConfiguration.SVELTE_DISABLE_LOADING) {
                            if (DEBUG) Log.d(TAG, "Loading thumbnail: " + t.key);
                            cachedThumbnail = ssp.getTaskThumbnail(t.key.id);
                            cachedThumbnail = ssp.getTaskThumbnail(t.key.id);
                        }
                        if (cachedThumbnail == null) {
                        if (cachedThumbnail == null) {
                            cachedThumbnail = mDefaultThumbnail;
                            cachedThumbnail = mDefaultThumbnail;
                        }
                        }
                        // When svelte, we trim the memory to just the visible thumbnails when
                        // leaving, so don't thrash the cache as the user scrolls (just load them
                        // from scratch each time)
                        if (config.svelteLevel < RecentsConfiguration.SVELTE_LIMIT_CACHE) {
                            mThumbnailCache.put(t.key, cachedThumbnail);
                            mThumbnailCache.put(t.key, cachedThumbnail);
                        }
                        }
                    }
                    if (!mCancelled) {
                    if (!mCancelled) {
                        // Notify that the task data has changed
                        // Notify that the task data has changed
                        final Drawable newIcon = cachedIcon;
                        final Drawable newIcon = cachedIcon;
@@ -267,6 +280,7 @@ public class RecentsTaskLoader {
    int mMaxThumbnailCacheSize;
    int mMaxThumbnailCacheSize;
    int mMaxIconCacheSize;
    int mMaxIconCacheSize;
    int mNumVisibleTasksLoaded;
    int mNumVisibleTasksLoaded;
    int mNumVisibleThumbnailsLoaded;


    BitmapDrawable mDefaultApplicationIcon;
    BitmapDrawable mDefaultApplicationIcon;
    Bitmap mDefaultThumbnail;
    Bitmap mDefaultThumbnail;
@@ -392,7 +406,8 @@ public class RecentsTaskLoader {
            return thumbnail;
            return thumbnail;
        }
        }


        if (loadIfNotCached) {
        RecentsConfiguration config = RecentsConfiguration.getInstance();
        if (config.svelteLevel < RecentsConfiguration.SVELTE_DISABLE_LOADING && loadIfNotCached) {
            // Load the thumbnail from the system
            // Load the thumbnail from the system
            thumbnail = ssp.getTaskThumbnail(taskKey.id);
            thumbnail = ssp.getTaskThumbnail(taskKey.id);
            if (thumbnail != null) {
            if (thumbnail != null) {
@@ -441,9 +456,10 @@ public class RecentsTaskLoader {
        if (opts == null) {
        if (opts == null) {
            throw new RuntimeException("Requires load options");
            throw new RuntimeException("Requires load options");
        }
        }
        plan.executePlan(opts, this);
        plan.executePlan(opts, this, mLoadQueue);
        if (!opts.onlyLoadForCache) {
        if (!opts.onlyLoadForCache) {
            mNumVisibleTasksLoaded = opts.numVisibleTasks;
            mNumVisibleTasksLoaded = opts.numVisibleTasks;
            mNumVisibleThumbnailsLoaded = opts.numVisibleTaskThumbnails;


            // Start the loader
            // Start the loader
            mLoader.start(context);
            mLoader.start(context);
@@ -503,12 +519,19 @@ public class RecentsTaskLoader {
     * out of memory.
     * out of memory.
     */
     */
    public void onTrimMemory(int level) {
    public void onTrimMemory(int level) {
        RecentsConfiguration config = RecentsConfiguration.getInstance();
        switch (level) {
        switch (level) {
            case ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN:
            case ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN:
                // Stop the loader immediately when the UI is no longer visible
                // Stop the loader immediately when the UI is no longer visible
                stopLoader();
                stopLoader();
                if (config.svelteLevel == RecentsConfiguration.SVELTE_NONE) {
                    mThumbnailCache.trimToSize(Math.max(mNumVisibleTasksLoaded,
                    mThumbnailCache.trimToSize(Math.max(mNumVisibleTasksLoaded,
                            mMaxThumbnailCacheSize / 2));
                            mMaxThumbnailCacheSize / 2));
                } else if (config.svelteLevel == RecentsConfiguration.SVELTE_LIMIT_CACHE) {
                    mThumbnailCache.trimToSize(mNumVisibleThumbnailsLoaded);
                } else if (config.svelteLevel >= RecentsConfiguration.SVELTE_DISABLE_CACHE) {
                    mThumbnailCache.evictAll();
                }
                mApplicationIconCache.trimToSize(Math.max(mNumVisibleTasksLoaded,
                mApplicationIconCache.trimToSize(Math.max(mNumVisibleTasksLoaded,
                        mMaxIconCacheSize / 2));
                        mMaxIconCacheSize / 2));
                break;
                break;