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; 22 import android.content.pm.ApplicationInfo; 23 import android.content.pm.PackageManager; 24 import android.content.pm.PackageManager.NameNotFoundException; 25 import android.graphics.Rect; 26 import android.os.Bundle; 27 28 import com.android.launcher3.Utilities; 29 30 import java.util.List; 31 32 public abstract class LauncherAppsCompat { 33 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 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); 45 } 46 47 protected LauncherAppsCompat() { 48 } 49 50 private static LauncherAppsCompat sInstance; 51 private static Object sInstanceLock = new Object(); 52 53 public static LauncherAppsCompat getInstance(Context context) { 54 synchronized (sInstanceLock) { 55 if (sInstance == null) { 56 if (Utilities.isLmpOrAbove()) { 57 sInstance = new LauncherAppsCompatVL(context.getApplicationContext()); 58 } else { 59 sInstance = new LauncherAppsCompatV16(context.getApplicationContext()); 60 } 61 } 62 return sInstance; 63 } 64 } 65 66 public abstract List<LauncherActivityInfoCompat> getActivityList(String packageName, 67 UserHandleCompat user); 68 public abstract LauncherActivityInfoCompat resolveActivity(Intent intent, 69 UserHandleCompat user); 70 public abstract void startActivityForProfile(ComponentName component, UserHandleCompat user, 71 Rect sourceBounds, Bundle opts); 72 public abstract void showAppDetailsForProfile(ComponentName component, UserHandleCompat user); 73 public abstract void addOnAppsChangedCallback(OnAppsChangedCallbackCompat listener); 74 public abstract void removeOnAppsChangedCallback(OnAppsChangedCallbackCompat listener); 75 public abstract boolean isPackageEnabledForProfile(String packageName, UserHandleCompat user); 76 public abstract boolean isActivityEnabledForProfile(ComponentName component, 77 UserHandleCompat user); 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 } 87 }