Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 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 | |
| 17 | package com.android.launcher3.compat; |
| 18 | |
| 19 | import android.content.ComponentName; |
| 20 | import android.content.Context; |
| 21 | import android.content.Intent; |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame^] | 22 | import android.content.pm.ApplicationInfo; |
| 23 | import android.content.pm.PackageManager; |
| 24 | import android.content.pm.PackageManager.NameNotFoundException; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 25 | import android.graphics.Rect; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 26 | import android.os.Bundle; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 27 | |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 28 | import com.android.launcher3.Utilities; |
| 29 | |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 30 | import java.util.List; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 31 | |
| 32 | public abstract class LauncherAppsCompat { |
| 33 | |
Amith Yamasani | 6cc806d | 2014-05-02 13:47:11 -0700 | [diff] [blame] | 34 | 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 Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 39 | 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 Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | protected LauncherAppsCompat() { |
| 48 | } |
| 49 | |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 50 | private static LauncherAppsCompat sInstance; |
| 51 | private static Object sInstanceLock = new Object(); |
| 52 | |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 53 | public static LauncherAppsCompat getInstance(Context context) { |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 54 | synchronized (sInstanceLock) { |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 55 | if (sInstance == null) { |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 56 | if (Utilities.isLmpOrAbove()) { |
Sunny Goyal | cf5d24b | 2014-09-15 11:35:00 -0700 | [diff] [blame] | 57 | sInstance = new LauncherAppsCompatVL(context.getApplicationContext()); |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 58 | } else { |
Sunny Goyal | cf5d24b | 2014-09-15 11:35:00 -0700 | [diff] [blame] | 59 | sInstance = new LauncherAppsCompatV16(context.getApplicationContext()); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 60 | } |
| 61 | } |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 62 | return sInstance; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 63 | } |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | public abstract List<LauncherActivityInfoCompat> getActivityList(String packageName, |
| 67 | UserHandleCompat user); |
| 68 | public abstract LauncherActivityInfoCompat resolveActivity(Intent intent, |
| 69 | UserHandleCompat user); |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 70 | public abstract void startActivityForProfile(ComponentName component, UserHandleCompat user, |
| 71 | Rect sourceBounds, Bundle opts); |
Kenny Guy | f07af7b | 2014-07-31 11:39:16 +0100 | [diff] [blame] | 72 | public abstract void showAppDetailsForProfile(ComponentName component, UserHandleCompat user); |
Kenny Guy | c2bd810 | 2014-06-30 12:30:31 +0100 | [diff] [blame] | 73 | public abstract void addOnAppsChangedCallback(OnAppsChangedCallbackCompat listener); |
| 74 | public abstract void removeOnAppsChangedCallback(OnAppsChangedCallbackCompat listener); |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 75 | public abstract boolean isPackageEnabledForProfile(String packageName, UserHandleCompat user); |
| 76 | public abstract boolean isActivityEnabledForProfile(ComponentName component, |
| 77 | UserHandleCompat user); |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame^] | 78 | |
| 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 Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 87 | } |