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

Commit 4c8fbb9c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Adding implementation of InstantAppResolver for quickstep" into ub-launcher3-master

parents f386e49c 61e08460
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -102,6 +102,11 @@
    public <init>(...);
}

# InstantAppResolver
-keep class com.android.quickstep.InstantAppResolverImpl {
    public <init>(...);
}

-keep interface com.android.launcher3.userevent.nano.LauncherLogProto.** {
  *;
}
+2 −0
Original line number Diff line number Diff line
@@ -16,5 +16,7 @@

<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
  <string name="app_transition_manager_class" translatable="false">com.android.launcher3.LauncherAppTransitionManagerImpl</string>

  <string name="instant_app_resolver_class" translatable="false">com.android.quickstep.InstantAppResolverImpl</string>
</resources>
+77 −0
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.content.ComponentName;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.InstantAppInfo;
import android.content.pm.PackageManager;
import android.util.Log;

import com.android.launcher3.AppInfo;
import com.android.launcher3.util.InstantAppResolver;

import java.util.ArrayList;
import java.util.List;

/**
 * Implementation of InstantAppResolver using platform APIs
 */
@SuppressWarnings("unused")
public class InstantAppResolverImpl extends InstantAppResolver {

    private static final String TAG = "InstantAppResolverImpl";
    public static final String COMPONENT_CLASS_MARKER = "@instantapp";

    private final PackageManager mPM;

    public InstantAppResolverImpl(Context context)
            throws NoSuchMethodException, ClassNotFoundException {
        mPM = context.getPackageManager();
    }

    @Override
    public boolean isInstantApp(ApplicationInfo info) {
        return info.isInstantApp();
    }

    @Override
    public boolean isInstantApp(AppInfo info) {
        ComponentName cn = info.getTargetComponent();
        return cn != null && cn.getClassName().equals(COMPONENT_CLASS_MARKER);
    }

    @Override
    public List<ApplicationInfo> getInstantApps() {
        try {
            List<ApplicationInfo> result = new ArrayList<>();
            for (InstantAppInfo iai : mPM.getInstantApps()) {
                ApplicationInfo info = iai.getApplicationInfo();
                if (info != null) {
                    result.add(info);
                }
            }
            return result;
        } catch (SecurityException se) {
            Log.w(TAG, "getInstantApps failed. Launcher may not be the default home app.", se);
        } catch (Exception e) {
            Log.e(TAG, "Error calling API: getInstantApps", e);
        }
        return super.getInstantApps();
    }
}
+14 −7
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.util.SparseArray;

import com.android.launcher3.FastBitmapDrawable;
import com.android.launcher3.graphics.BitmapInfo;
import com.android.launcher3.graphics.DrawableFactory;
import com.android.launcher3.graphics.LauncherIcons;
import com.android.systemui.shared.recents.model.IconLoader;
import com.android.systemui.shared.recents.model.TaskKeyLruCache;
@@ -40,11 +41,13 @@ import com.android.systemui.shared.recents.model.TaskKeyLruCache;
public class NormalizedIconLoader extends IconLoader {

    private final SparseArray<BitmapInfo> mDefaultIcons = new SparseArray<>();
    private final DrawableFactory mDrawableFactory;
    private LauncherIcons mLauncherIcons;

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

    @Override
@@ -53,7 +56,7 @@ public class NormalizedIconLoader extends IconLoader {
            BitmapInfo info = mDefaultIcons.get(userId);
            if (info == null) {
                info = getBitmapInfo(Resources.getSystem()
                        .getDrawable(android.R.drawable.sym_def_app_icon), userId);
                        .getDrawable(android.R.drawable.sym_def_app_icon), userId, false);
                mDefaultIcons.put(userId, info);
            }

@@ -63,22 +66,26 @@ public class NormalizedIconLoader extends IconLoader {

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

    private synchronized BitmapInfo getBitmapInfo(Drawable drawable, int userId) {
    private synchronized BitmapInfo getBitmapInfo(Drawable drawable, int userId,
            boolean isInstantApp) {
        if (mLauncherIcons == null) {
            mLauncherIcons = LauncherIcons.obtain(mContext);
        }

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

    @Override
    protected Drawable getBadgedActivityIcon(ActivityInfo activityInfo, int userId) {
        return createBadgedDrawable(
                activityInfo.loadUnbadgedIcon(mContext.getPackageManager()), userId);
    protected synchronized Drawable getBadgedActivityIcon(ActivityInfo activityInfo, int userId) {
        BitmapInfo bitmapInfo = getBitmapInfo(
                activityInfo.loadUnbadgedIcon(mContext.getPackageManager()),
                userId,
                activityInfo.applicationInfo.isInstantApp());
        return mDrawableFactory.newIcon(bitmapInfo, activityInfo);
    }
}
+4 −5
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ public class FastBitmapDrawable extends Drawable {
    private static final ColorMatrix sTempFilterMatrix = new ColorMatrix();

    protected final Paint mPaint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);
    private final Bitmap mBitmap;
    protected Bitmap mBitmap;
    protected final int mIconColor;

    private boolean mIsPressed;
@@ -324,10 +324,9 @@ public class FastBitmapDrawable extends Drawable {
        return new MyConstantState(mBitmap, mIconColor);
    }

    private static class MyConstantState extends ConstantState {
        private final Bitmap mBitmap;
        private final int mIconColor;

    protected static class MyConstantState extends ConstantState {
        protected final Bitmap mBitmap;
        protected final int mIconColor;

        public MyConstantState(Bitmap bitmap, int color) {
            mBitmap = bitmap;
Loading