LauncherAppsCompat.java revision ed13187a745866483139e2878037e1f8427ce567
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.graphics.Rect;
23import android.graphics.drawable.Drawable;
24import android.os.Build;
25import android.os.Bundle;
26import android.os.UserHandle;
27import android.os.UserManager;
28
29import java.util.ArrayList;
30import java.util.Collections;
31import java.util.HashMap;
32import java.util.List;
33import java.util.Map;
34
35public abstract class LauncherAppsCompat {
36
37    public interface OnAppsChangedListenerCompat {
38        void onPackageRemoved(UserHandleCompat user, String packageName);
39        void onPackageAdded(UserHandleCompat user, String packageName);
40        void onPackageChanged(UserHandleCompat user, String packageName);
41        void onPackagesAvailable(UserHandleCompat user, String[] packageNames, boolean replacing);
42        void onPackagesUnavailable(UserHandleCompat user, String[] packageNames, boolean replacing);
43    }
44
45    protected LauncherAppsCompat() {
46    }
47
48    public static LauncherAppsCompat getInstance(Context context) {
49        // TODO change this to use api version once L gets an API number.
50        if ("L".equals(Build.VERSION.CODENAME)) {
51            Object launcherApps = context.getSystemService("launcherapps");
52            if (launcherApps != null) {
53                LauncherAppsCompatVL compat = LauncherAppsCompatVL.build(context, launcherApps);
54                if (compat != null) {
55                    return compat;
56                }
57            }
58        }
59        // Pre L or lunacher apps service not running, or reflection failed to find something.
60        return new LauncherAppsCompatV16(context);
61    }
62
63    public abstract List<LauncherActivityInfoCompat> getActivityList(String packageName,
64            UserHandleCompat user);
65    public abstract LauncherActivityInfoCompat resolveActivity(Intent intent,
66            UserHandleCompat user);
67    public abstract void startActivityForProfile(ComponentName component, Rect sourceBounds,
68            Bundle opts, UserHandleCompat user);
69    public abstract void addOnAppsChangedListener(OnAppsChangedListenerCompat listener);
70    public abstract void removeOnAppsChangedListener(OnAppsChangedListenerCompat listener);
71    public abstract boolean isPackageEnabledForProfile(String packageName, UserHandleCompat user);
72    public abstract boolean isActivityEnabledForProfile(ComponentName component,
73            UserHandleCompat user);
74}