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

Commit e7b00128 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Removing static instance of LauncherAppsCompat and unnecessary wrapper classes

Bug: 141376165
Change-Id: I8c1f1ab7d83ec50fe9c7bf39960ef9c360025ec7
parent a0db584e
Loading
Loading
Loading
Loading
+23 −14
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ 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;
@@ -32,8 +33,6 @@ import android.os.RemoteException;
import android.os.UserHandle;
import android.util.Log;

import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.LauncherAppsCompat.OnAppsChangedCallbackCompat;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.systemui.shared.recents.ISystemUiProxy;
import com.android.systemui.shared.recents.model.Task;
@@ -211,8 +210,7 @@ public class RecentsModel extends TaskStackChangeListener {
    }

    private void setupPackageListener() {
        LauncherAppsCompat.getInstance(mContext)
                .addOnAppsChangedCallback(new OnAppsChangedCallbackCompat() {
        mContext.getSystemService(LauncherApps.class).registerCallback(new LauncherApps.Callback() {
            @Override
            public void onPackageRemoved(String packageName, UserHandle user) {
                mIconCache.invalidatePackage(packageName);
@@ -222,6 +220,17 @@ public class RecentsModel extends TaskStackChangeListener {
            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) { }
        });
    }

+4 −5
Original line number Diff line number Diff line
@@ -23,9 +23,9 @@ import android.content.pm.PackageManager;
import android.os.UserHandle;
import android.util.Log;

import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.systemui.shared.recents.model.Task;
import com.android.systemui.shared.system.RemoteAnimationTargetCompat;

@@ -44,15 +44,14 @@ public final class TaskUtils {
     * TODO: remove this once we switch to getting the icon and label from IconCache.
     */
    public static CharSequence getTitle(Context context, Task task) {
        LauncherAppsCompat launcherAppsCompat = LauncherAppsCompat.getInstance(context);
        PackageManager packageManager = context.getPackageManager();
        UserHandle user = UserHandle.of(task.key.userId);
        ApplicationInfo applicationInfo = launcherAppsCompat.getApplicationInfo(
            task.getTopComponent().getPackageName(), 0, user);
        ApplicationInfo applicationInfo = new PackageManagerHelper(context)
                .getApplicationInfo(task.getTopComponent().getPackageName(), user, 0);
        if (applicationInfo == null) {
            Log.e(TAG, "Failed to get title for task " + task);
            return "";
        }
        PackageManager packageManager = context.getPackageManager();
        return packageManager.getUserBadgedLabel(
            applicationInfo.loadLabel(packageManager), user);
    }
+2 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.app.prediction.AppTarget;
import android.app.prediction.AppTargetId;
import android.content.ComponentName;
import android.content.pm.LauncherActivityInfo;
import android.content.pm.LauncherApps;
import android.os.Process;
import android.view.View;

@@ -35,7 +36,6 @@ import com.android.launcher3.Launcher;
import com.android.launcher3.appprediction.PredictionRowView;
import com.android.launcher3.appprediction.PredictionUiStateManager;
import com.android.launcher3.appprediction.PredictionUiStateManager.Client;
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.model.AppLaunchTracker;

import org.junit.After;
@@ -60,7 +60,7 @@ public class AppPredictionsUITests extends AbstractQuickStepTest {
    public void setUp() throws Exception {
        super.setUp();

        List<LauncherActivityInfo> activities = LauncherAppsCompat.getInstance(mTargetContext)
        List<LauncherActivityInfo> activities = mTargetContext.getSystemService(LauncherApps.class)
                .getActivityList(null, Process.myUserHandle());
        mSampleApp1 = activities.get(0);
        mSampleApp2 = activities.get(1);
+2 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.launcher3;
import android.app.ActivityOptions;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.pm.LauncherApps;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.os.Bundle;
@@ -33,7 +34,6 @@ import android.widget.Toast;
import androidx.annotation.Nullable;

import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.model.AppLaunchTracker;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.uioverrides.DejankBinderTracker;
@@ -168,7 +168,7 @@ public abstract class BaseDraggingActivity extends BaseActivity
                AppLaunchTracker.INSTANCE.get(this).onStartApp(intent.getComponent(),
                        Process.myUserHandle(), sourceContainer);
            } else {
                LauncherAppsCompat.getInstance(this).startActivityForProfile(
                getSystemService(LauncherApps.class).startMainActivity(
                        intent.getComponent(), user, intent.getSourceBounds(), optsBundle);
                AppLaunchTracker.INSTANCE.get(this).onStartApp(intent.getComponent(), user,
                        sourceContainer);
+5 −5
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.pm.LauncherActivityInfo;
import android.content.pm.LauncherApps;
import android.content.pm.PackageManager;
import android.content.pm.ShortcutInfo;
import android.graphics.Bitmap;
@@ -40,7 +41,6 @@ import android.util.Pair;

import androidx.annotation.WorkerThread;

import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.icons.BitmapInfo;
import com.android.launcher3.icons.GraphicsUtils;
@@ -124,7 +124,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
            return;
        }

        LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context);
        LauncherApps launcherApps = context.getSystemService(LauncherApps.class);
        for (String encoded : strings) {
            PendingInstallShortcutInfo info = decode(encoded, context);
            if (info == null) {
@@ -133,7 +133,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {

            String pkg = getIntentPackage(info.launchIntent);
            if (!TextUtils.isEmpty(pkg)
                    && !launcherApps.isPackageEnabledForProfile(pkg, info.user)
                    && !launcherApps.isPackageEnabled(pkg, info.user)
                    && !info.isActivity) {
                if (DBG) {
                    Log.d(TAG, "Ignoring shortcut for absent package: " + info.launchIntent);
@@ -520,7 +520,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
        try {
            Decoder decoder = new Decoder(encoded, context);
            if (decoder.optBoolean(APP_SHORTCUT_TYPE_KEY)) {
                LauncherActivityInfo info = LauncherAppsCompat.getInstance(context)
                LauncherActivityInfo info = context.getSystemService(LauncherApps.class)
                        .resolveActivity(decoder.launcherIntent, decoder.user);
                if (info != null) {
                    return new PendingInstallShortcutInfo(info, context);
@@ -610,7 +610,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
            return original;
        }

        LauncherActivityInfo info = LauncherAppsCompat.getInstance(original.mContext)
        LauncherActivityInfo info = original.mContext.getSystemService(LauncherApps.class)
                .resolveActivity(original.launchIntent, original.user);
        if (info == null) {
            return original;
Loading