• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.ShortcutInfo;
26 import android.graphics.Rect;
27 import android.os.Bundle;
28 import android.os.UserHandle;
29 
30 import com.android.launcher3.Utilities;
31 import com.android.launcher3.util.PackageUserKey;
32 
33 import java.util.List;
34 
35 import androidx.annotation.Nullable;
36 
37 public abstract class LauncherAppsCompat {
38 
39     public interface OnAppsChangedCallbackCompat {
onPackageRemoved(String packageName, UserHandle user)40         void onPackageRemoved(String packageName, UserHandle user);
onPackageAdded(String packageName, UserHandle user)41         void onPackageAdded(String packageName, UserHandle user);
onPackageChanged(String packageName, UserHandle user)42         void onPackageChanged(String packageName, UserHandle user);
onPackagesAvailable(String[] packageNames, UserHandle user, boolean replacing)43         void onPackagesAvailable(String[] packageNames, UserHandle user, boolean replacing);
onPackagesUnavailable(String[] packageNames, UserHandle user, boolean replacing)44         void onPackagesUnavailable(String[] packageNames, UserHandle user, boolean replacing);
onPackagesSuspended(String[] packageNames, UserHandle user)45         void onPackagesSuspended(String[] packageNames, UserHandle user);
onPackagesUnsuspended(String[] packageNames, UserHandle user)46         void onPackagesUnsuspended(String[] packageNames, UserHandle user);
onShortcutsChanged(String packageName, List<ShortcutInfo> shortcuts, UserHandle user)47         void onShortcutsChanged(String packageName, List<ShortcutInfo> shortcuts,
48                 UserHandle user);
49     }
50 
LauncherAppsCompat()51     protected LauncherAppsCompat() {
52     }
53 
54     private static LauncherAppsCompat sInstance;
55     private static final Object sInstanceLock = new Object();
56 
getInstance(Context context)57     public static LauncherAppsCompat getInstance(Context context) {
58         synchronized (sInstanceLock) {
59             if (sInstance == null) {
60                 if (Utilities.ATLEAST_Q) {
61                     sInstance = new LauncherAppsCompatVQ(context.getApplicationContext());
62                 } else if (Utilities.ATLEAST_OREO) {
63                     sInstance = new LauncherAppsCompatVO(context.getApplicationContext());
64                 } else {
65                     sInstance = new LauncherAppsCompatVL(context.getApplicationContext());
66                 }
67             }
68             return sInstance;
69         }
70     }
71 
getActivityList(String packageName, UserHandle user)72     public abstract List<LauncherActivityInfo> getActivityList(String packageName,
73             UserHandle user);
resolveActivity(Intent intent, UserHandle user)74     public abstract LauncherActivityInfo resolveActivity(Intent intent,
75             UserHandle user);
startActivityForProfile(ComponentName component, UserHandle user, Rect sourceBounds, Bundle opts)76     public abstract void startActivityForProfile(ComponentName component, UserHandle user,
77             Rect sourceBounds, Bundle opts);
getApplicationInfo( String packageName, int flags, UserHandle user)78     public abstract ApplicationInfo getApplicationInfo(
79             String packageName, int flags, UserHandle user);
showAppDetailsForProfile(ComponentName component, UserHandle user, Rect sourceBounds, Bundle opts)80     public abstract void showAppDetailsForProfile(ComponentName component, UserHandle user,
81             Rect sourceBounds, Bundle opts);
addOnAppsChangedCallback(OnAppsChangedCallbackCompat listener)82     public abstract void addOnAppsChangedCallback(OnAppsChangedCallbackCompat listener);
removeOnAppsChangedCallback(OnAppsChangedCallbackCompat listener)83     public abstract void removeOnAppsChangedCallback(OnAppsChangedCallbackCompat listener);
isPackageEnabledForProfile(String packageName, UserHandle user)84     public abstract boolean isPackageEnabledForProfile(String packageName, UserHandle user);
isActivityEnabledForProfile(ComponentName component, UserHandle user)85     public abstract boolean isActivityEnabledForProfile(ComponentName component,
86             UserHandle user);
getCustomShortcutActivityList( @ullable PackageUserKey packageUser)87     public abstract List<ShortcutConfigActivityInfo> getCustomShortcutActivityList(
88             @Nullable PackageUserKey packageUser);
89 
getAllPackageInstallerSessions()90     public abstract List<PackageInstaller.SessionInfo> getAllPackageInstallerSessions();
91 }
92