1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.launcher3.compat; 18 19 import android.content.ComponentName; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.content.pm.ApplicationInfo; 23 import android.content.pm.LauncherActivityInfo; 24 import android.content.pm.PackageInstaller; 25 import android.content.pm.PackageInstaller.SessionCallback; 26 import android.content.pm.ShortcutInfo; 27 import android.graphics.Rect; 28 import android.os.Bundle; 29 import android.os.UserHandle; 30 31 import androidx.annotation.Nullable; 32 33 import com.android.launcher3.Utilities; 34 import com.android.launcher3.util.LooperExecutor; 35 import com.android.launcher3.util.PackageUserKey; 36 37 import java.util.List; 38 39 public abstract class LauncherAppsCompat { 40 41 public interface OnAppsChangedCallbackCompat { onPackageRemoved(String packageName, UserHandle user)42 default void onPackageRemoved(String packageName, UserHandle user) { } onPackageAdded(String packageName, UserHandle user)43 default void onPackageAdded(String packageName, UserHandle user) { } onPackageChanged(String packageName, UserHandle user)44 default void onPackageChanged(String packageName, UserHandle user) { } onPackagesAvailable(String[] packageNames, UserHandle user, boolean replacing)45 default void onPackagesAvailable(String[] packageNames, UserHandle user, 46 boolean replacing) { } onPackagesUnavailable(String[] packageNames, UserHandle user, boolean replacing)47 default void onPackagesUnavailable(String[] packageNames, UserHandle user, 48 boolean replacing) { } onPackagesSuspended(String[] packageNames, UserHandle user)49 default void onPackagesSuspended(String[] packageNames, UserHandle user) { } onPackagesUnsuspended(String[] packageNames, UserHandle user)50 default void onPackagesUnsuspended(String[] packageNames, UserHandle user) { } onShortcutsChanged(String packageName, List<ShortcutInfo> shortcuts, UserHandle user)51 default void onShortcutsChanged(String packageName, List<ShortcutInfo> shortcuts, 52 UserHandle user) { } 53 } 54 LauncherAppsCompat()55 protected LauncherAppsCompat() { 56 } 57 58 private static LauncherAppsCompat sInstance; 59 private static final Object sInstanceLock = new Object(); 60 getInstance(Context context)61 public static LauncherAppsCompat getInstance(Context context) { 62 synchronized (sInstanceLock) { 63 if (sInstance == null) { 64 if (Utilities.ATLEAST_Q) { 65 sInstance = new LauncherAppsCompatVQ(context.getApplicationContext()); 66 } else if (Utilities.ATLEAST_OREO) { 67 sInstance = new LauncherAppsCompatVO(context.getApplicationContext()); 68 } else { 69 sInstance = new LauncherAppsCompatVL(context.getApplicationContext()); 70 } 71 } 72 return sInstance; 73 } 74 } 75 getActivityList(String packageName, UserHandle user)76 public abstract List<LauncherActivityInfo> getActivityList(String packageName, 77 UserHandle user); resolveActivity(Intent intent, UserHandle user)78 public abstract LauncherActivityInfo resolveActivity(Intent intent, 79 UserHandle user); startActivityForProfile(ComponentName component, UserHandle user, Rect sourceBounds, Bundle opts)80 public abstract void startActivityForProfile(ComponentName component, UserHandle user, 81 Rect sourceBounds, Bundle opts); getApplicationInfo( String packageName, int flags, UserHandle user)82 public abstract ApplicationInfo getApplicationInfo( 83 String packageName, int flags, UserHandle user); showAppDetailsForProfile(ComponentName component, UserHandle user, Rect sourceBounds, Bundle opts)84 public abstract void showAppDetailsForProfile(ComponentName component, UserHandle user, 85 Rect sourceBounds, Bundle opts); addOnAppsChangedCallback(OnAppsChangedCallbackCompat listener)86 public abstract void addOnAppsChangedCallback(OnAppsChangedCallbackCompat listener); removeOnAppsChangedCallback(OnAppsChangedCallbackCompat listener)87 public abstract void removeOnAppsChangedCallback(OnAppsChangedCallbackCompat listener); isPackageEnabledForProfile(String packageName, UserHandle user)88 public abstract boolean isPackageEnabledForProfile(String packageName, UserHandle user); isActivityEnabledForProfile(ComponentName component, UserHandle user)89 public abstract boolean isActivityEnabledForProfile(ComponentName component, 90 UserHandle user); getCustomShortcutActivityList( @ullable PackageUserKey packageUser)91 public abstract List<ShortcutConfigActivityInfo> getCustomShortcutActivityList( 92 @Nullable PackageUserKey packageUser); 93 getAllPackageInstallerSessions()94 public abstract List<PackageInstaller.SessionInfo> getAllPackageInstallerSessions(); 95 registerSessionCallback(LooperExecutor executor, SessionCallback sessionCallback)96 public abstract void registerSessionCallback(LooperExecutor executor, 97 SessionCallback sessionCallback); unregisterSessionCallback(SessionCallback sessionCallback)98 public abstract void unregisterSessionCallback(SessionCallback sessionCallback); 99 } 100