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