blob: 5858bc8b9e5bac6df57ae6bce82f6e19a40f185e [file] [log] [blame]
Kenny Guyed131872014-04-30 03:02:21 +01001/*
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;
Sunny Goyal1a745e82014-10-02 15:58:31 -070022import android.content.pm.ApplicationInfo;
23import android.content.pm.PackageManager;
24import android.content.pm.PackageManager.NameNotFoundException;
Kenny Guyed131872014-04-30 03:02:21 +010025import android.graphics.Rect;
Kenny Guyed131872014-04-30 03:02:21 +010026import android.os.Bundle;
Kenny Guyed131872014-04-30 03:02:21 +010027
Kenny Guyd794a3f2014-09-16 15:17:58 +010028import com.android.launcher3.Utilities;
29
Kenny Guyed131872014-04-30 03:02:21 +010030import java.util.List;
Kenny Guyed131872014-04-30 03:02:21 +010031
32public abstract class LauncherAppsCompat {
33
Amith Yamasani6cc806d2014-05-02 13:47:11 -070034 public static final String ACTION_MANAGED_PROFILE_ADDED =
35 "android.intent.action.MANAGED_PROFILE_ADDED";
36 public static final String ACTION_MANAGED_PROFILE_REMOVED =
37 "android.intent.action.MANAGED_PROFILE_REMOVED";
38
Kenny Guyc2bd8102014-06-30 12:30:31 +010039 public interface OnAppsChangedCallbackCompat {
40 void onPackageRemoved(String packageName, UserHandleCompat user);
41 void onPackageAdded(String packageName, UserHandleCompat user);
42 void onPackageChanged(String packageName, UserHandleCompat user);
43 void onPackagesAvailable(String[] packageNames, UserHandleCompat user, boolean replacing);
44 void onPackagesUnavailable(String[] packageNames, UserHandleCompat user, boolean replacing);
Kenny Guyed131872014-04-30 03:02:21 +010045 }
46
47 protected LauncherAppsCompat() {
48 }
49
Kenny Guyc2bd8102014-06-30 12:30:31 +010050 private static LauncherAppsCompat sInstance;
51 private static Object sInstanceLock = new Object();
52
Kenny Guyed131872014-04-30 03:02:21 +010053 public static LauncherAppsCompat getInstance(Context context) {
Kenny Guyc2bd8102014-06-30 12:30:31 +010054 synchronized (sInstanceLock) {
Kenny Guyc2bd8102014-06-30 12:30:31 +010055 if (sInstance == null) {
Kenny Guyd794a3f2014-09-16 15:17:58 +010056 if (Utilities.isLmpOrAbove()) {
Sunny Goyalcf5d24b2014-09-15 11:35:00 -070057 sInstance = new LauncherAppsCompatVL(context.getApplicationContext());
Kenny Guyc2bd8102014-06-30 12:30:31 +010058 } else {
Sunny Goyalcf5d24b2014-09-15 11:35:00 -070059 sInstance = new LauncherAppsCompatV16(context.getApplicationContext());
Kenny Guyed131872014-04-30 03:02:21 +010060 }
61 }
Kenny Guyc2bd8102014-06-30 12:30:31 +010062 return sInstance;
Kenny Guyed131872014-04-30 03:02:21 +010063 }
Kenny Guyed131872014-04-30 03:02:21 +010064 }
65
66 public abstract List<LauncherActivityInfoCompat> getActivityList(String packageName,
67 UserHandleCompat user);
68 public abstract LauncherActivityInfoCompat resolveActivity(Intent intent,
69 UserHandleCompat user);
Kenny Guyc2bd8102014-06-30 12:30:31 +010070 public abstract void startActivityForProfile(ComponentName component, UserHandleCompat user,
71 Rect sourceBounds, Bundle opts);
Kenny Guyf07af7b2014-07-31 11:39:16 +010072 public abstract void showAppDetailsForProfile(ComponentName component, UserHandleCompat user);
Kenny Guyc2bd8102014-06-30 12:30:31 +010073 public abstract void addOnAppsChangedCallback(OnAppsChangedCallbackCompat listener);
74 public abstract void removeOnAppsChangedCallback(OnAppsChangedCallbackCompat listener);
Kenny Guyed131872014-04-30 03:02:21 +010075 public abstract boolean isPackageEnabledForProfile(String packageName, UserHandleCompat user);
76 public abstract boolean isActivityEnabledForProfile(ComponentName component,
77 UserHandleCompat user);
Sunny Goyal1a745e82014-10-02 15:58:31 -070078
79 public boolean isAppEnabled(PackageManager pm, String packageName, int flags) {
80 try {
81 ApplicationInfo info = pm.getApplicationInfo(packageName, flags);
82 return info != null && info.enabled;
83 } catch (NameNotFoundException e) {
84 return false;
85 }
86 }
Kenny Guyed131872014-04-30 03:02:21 +010087}