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