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

Commit 9f975ed0 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Merging task icon cache with content description cache

> Removing activity info cache as icon and description are loaded at the same time
> Invalidating icon if task cache is old

Bug: 38268585
Bug: 138944598
Change-Id: I28ae61a089556198534d48fcdb3aae6109748dff
parent efefa59f
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -72,7 +72,6 @@ import com.android.quickstep.BaseActivityInterface.AnimationFactory;
import com.android.quickstep.BaseActivityInterface.AnimationFactory.ShelfAnimState;
import com.android.quickstep.BaseActivityInterface.HomeAnimationFactory;
import com.android.quickstep.GestureState.GestureEndTarget;
import com.android.quickstep.SysUINavigationMode.Mode;
import com.android.quickstep.inputconsumers.OverviewInputConsumer;
import com.android.quickstep.util.ActiveGestureLog;
import com.android.quickstep.util.AppWindowAnimationHelper.TargetAlphaProvider;
@@ -1192,8 +1191,7 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity>
        }
        mRecentsView.onSwipeUpAnimationSuccess();

        RecentsModel.INSTANCE.get(mContext).onOverviewShown(false, TAG);

        SystemUiProxy.INSTANCE.get(mContext).onOverviewShown(false, TAG);
        doLogGesture(RECENTS);
        reset();
    }
+2 −2
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ import com.android.launcher3.touch.AbstractStateChangeTouchController;
import com.android.launcher3.touch.SingleAxisSwipeDetector;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction;
import com.android.quickstep.RecentsModel;
import com.android.quickstep.SystemUiProxy;

/**
 * Touch controller for handling edge swipes in landscape/seascape UI
@@ -73,7 +73,7 @@ public class LandscapeEdgeSwipeController extends AbstractStateChangeTouchContro
    protected void onSwipeInteractionCompleted(LauncherState targetState, int logAction) {
        super.onSwipeInteractionCompleted(targetState, logAction);
        if (mStartState == NORMAL && targetState == OVERVIEW) {
            RecentsModel.INSTANCE.get(mLauncher).onOverviewShown(true, TAG);
            SystemUiProxy.INSTANCE.get(mLauncher).onOverviewShown(true, TAG);
        }
    }
}
+1 −2
Original line number Diff line number Diff line
@@ -47,7 +47,6 @@ import com.android.launcher3.touch.SingleAxisSwipeDetector;
import com.android.launcher3.uioverrides.states.OverviewState;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.quickstep.RecentsModel;
import com.android.quickstep.SystemUiProxy;
import com.android.quickstep.TouchInteractionService;
import com.android.quickstep.util.LayoutUtils;
@@ -300,7 +299,7 @@ public class PortraitStatesTouchController extends AbstractStateChangeTouchContr
    protected void onSwipeInteractionCompleted(LauncherState targetState, int logAction) {
        super.onSwipeInteractionCompleted(targetState, logAction);
        if (mStartState == NORMAL && targetState == OVERVIEW) {
            RecentsModel.INSTANCE.get(mLauncher).onOverviewShown(true, TAG);
            SystemUiProxy.INSTANCE.get(mLauncher).onOverviewShown(true, TAG);
        }
    }

+0 −99
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.quickstep;

import android.annotation.TargetApi;
import android.app.ActivityManager.TaskDescription;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.UserHandle;
import android.util.LruCache;
import android.util.SparseArray;

import com.android.launcher3.FastBitmapDrawable;
import com.android.launcher3.icons.BitmapInfo;
import com.android.launcher3.graphics.DrawableFactory;
import com.android.launcher3.icons.LauncherIcons;
import com.android.systemui.shared.recents.model.IconLoader;
import com.android.systemui.shared.recents.model.TaskKeyLruCache;

/**
 * Extension of {@link IconLoader} with icon normalization support
 */
@TargetApi(Build.VERSION_CODES.O)
public class NormalizedIconLoader extends IconLoader {

    private final SparseArray<BitmapInfo> mDefaultIcons = new SparseArray<>();
    private final DrawableFactory mDrawableFactory;
    private final boolean mDisableColorExtraction;

    public NormalizedIconLoader(Context context, TaskKeyLruCache<Drawable> iconCache,
            LruCache<ComponentName, ActivityInfo> activityInfoCache,
            boolean disableColorExtraction) {
        super(context, iconCache, activityInfoCache);
        mDrawableFactory = DrawableFactory.INSTANCE.get(context);
        mDisableColorExtraction = disableColorExtraction;
    }

    @Override
    public Drawable getDefaultIcon(int userId) {
        synchronized (mDefaultIcons) {
            BitmapInfo info = mDefaultIcons.get(userId);
            if (info == null) {
                info = getBitmapInfo(Resources.getSystem()
                        .getDrawable(android.R.drawable.sym_def_app_icon), userId, 0, false);
                mDefaultIcons.put(userId, info);
            }

            return new FastBitmapDrawable(info);
        }
    }

    @Override
    protected Drawable createBadgedDrawable(Drawable drawable, int userId, TaskDescription desc) {
        return new FastBitmapDrawable(getBitmapInfo(drawable, userId, desc.getPrimaryColor(),
                false));
    }

    private BitmapInfo getBitmapInfo(Drawable drawable, int userId,
            int primaryColor, boolean isInstantApp) {
        try (LauncherIcons la = LauncherIcons.obtain(mContext)) {
            if (mDisableColorExtraction) {
                la.disableColorExtraction();
            }
            la.setWrapperBackgroundColor(primaryColor);

            // User version code O, so that the icon is always wrapped in an adaptive icon container
            return la.createBadgedIconBitmap(drawable, UserHandle.of(userId),
                    Build.VERSION_CODES.O, isInstantApp);
        }
    }

    @Override
    protected Drawable getBadgedActivityIcon(ActivityInfo activityInfo, int userId,
            TaskDescription desc) {
        BitmapInfo bitmapInfo = getBitmapInfo(
                activityInfo.loadUnbadgedIcon(mContext.getPackageManager()),
                userId,
                desc.getPrimaryColor(),
                activityInfo.applicationInfo.isInstantApp());
        return mDrawableFactory.newIcon(mContext, bitmapInfo, activityInfo);
    }
}
+0 −34
Original line number Diff line number Diff line
@@ -25,11 +25,9 @@ import android.annotation.TargetApi;
import android.app.ActivityManager;
import android.content.ComponentCallbacks2;
import android.content.Context;
import android.content.pm.LauncherApps;
import android.os.Build;
import android.os.Looper;
import android.os.Process;
import android.os.UserHandle;

import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.systemui.shared.recents.model.Task;
@@ -48,8 +46,6 @@ import java.util.function.Consumer;
@TargetApi(Build.VERSION_CODES.O)
public class RecentsModel extends TaskStackChangeListener {

    private static final String TAG = "RecentsModel";

    // We do not need any synchronization for this variable as its only written on UI thread.
    public static final MainThreadInitializedObject<RecentsModel> INSTANCE =
            new MainThreadInitializedObject<>(RecentsModel::new);
@@ -70,7 +66,6 @@ public class RecentsModel extends TaskStackChangeListener {
        mIconCache = new TaskIconCache(context, looper);
        mThumbnailCache = new TaskThumbnailCache(context, looper);
        ActivityManagerWrapper.getInstance().registerTaskStackListener(this);
        setupPackageListener();
    }

    public TaskIconCache getIconCache() {
@@ -183,35 +178,6 @@ public class RecentsModel extends TaskStackChangeListener {
        }
    }

    public void onOverviewShown(boolean fromHome, String tag) {
        SystemUiProxy.INSTANCE.get(mContext).onOverviewShown(fromHome, tag);
    }

    private void setupPackageListener() {
        mContext.getSystemService(LauncherApps.class).registerCallback(new LauncherApps.Callback() {
            @Override
            public void onPackageRemoved(String packageName, UserHandle user) {
                mIconCache.invalidatePackage(packageName);
            }

            @Override
            public void onPackageChanged(String packageName, UserHandle user) {
                mIconCache.invalidatePackage(packageName);
            }

            @Override
            public void onPackageAdded(String packageName, UserHandle user) { }

            @Override
            public void onPackagesAvailable(
                    String[] packageNames, UserHandle user, boolean replacing) { }

            @Override
            public void onPackagesUnavailable(
                    String[] packageNames, UserHandle user, boolean replacing) { }
        });
    }

    public void addThumbnailChangeListener(TaskThumbnailChangeListener listener) {
        mThumbnailChangeListeners.add(listener);
    }
Loading