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