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.graphics.Rect; 23 import android.os.Bundle; 24 25 import com.android.launcher3.Utilities; 26 27 import java.util.List; 28 29 public abstract class LauncherAppsCompat { 30 31 public static final String ACTION_MANAGED_PROFILE_ADDED = 32 "android.intent.action.MANAGED_PROFILE_ADDED"; 33 public static final String ACTION_MANAGED_PROFILE_REMOVED = 34 "android.intent.action.MANAGED_PROFILE_REMOVED"; 35 public static final String ACTION_MANAGED_PROFILE_AVAILABLE = 36 "android.intent.action.MANAGED_PROFILE_AVAILABLE"; 37 public static final String ACTION_MANAGED_PROFILE_UNAVAILABLE = 38 "android.intent.action.MANAGED_PROFILE_UNAVAILABLE"; 39 40 public interface OnAppsChangedCallbackCompat { onPackageRemoved(String packageName, UserHandleCompat user)41 void onPackageRemoved(String packageName, UserHandleCompat user); onPackageAdded(String packageName, UserHandleCompat user)42 void onPackageAdded(String packageName, UserHandleCompat user); onPackageChanged(String packageName, UserHandleCompat user)43 void onPackageChanged(String packageName, UserHandleCompat user); onPackagesAvailable(String[] packageNames, UserHandleCompat user, boolean replacing)44 void onPackagesAvailable(String[] packageNames, UserHandleCompat user, boolean replacing); onPackagesUnavailable(String[] packageNames, UserHandleCompat user, boolean replacing)45 void onPackagesUnavailable(String[] packageNames, UserHandleCompat user, boolean replacing); onPackagesSuspended(String[] packageNames, UserHandleCompat user)46 void onPackagesSuspended(String[] packageNames, UserHandleCompat user); onPackagesUnsuspended(String[] packageNames, UserHandleCompat user)47 void onPackagesUnsuspended(String[] packageNames, UserHandleCompat user); 48 } 49 LauncherAppsCompat()50 protected LauncherAppsCompat() { 51 } 52 53 private static LauncherAppsCompat sInstance; 54 private static Object sInstanceLock = new Object(); 55 getInstance(Context context)56 public static LauncherAppsCompat getInstance(Context context) { 57 synchronized (sInstanceLock) { 58 if (sInstance == null) { 59 if (Utilities.ATLEAST_LOLLIPOP) { 60 sInstance = new LauncherAppsCompatVL(context.getApplicationContext()); 61 } else { 62 sInstance = new LauncherAppsCompatV16(context.getApplicationContext()); 63 } 64 } 65 return sInstance; 66 } 67 } 68 getActivityList(String packageName, UserHandleCompat user)69 public abstract List<LauncherActivityInfoCompat> getActivityList(String packageName, 70 UserHandleCompat user); resolveActivity(Intent intent, UserHandleCompat user)71 public abstract LauncherActivityInfoCompat resolveActivity(Intent intent, 72 UserHandleCompat user); startActivityForProfile(ComponentName component, UserHandleCompat user, Rect sourceBounds, Bundle opts)73 public abstract void startActivityForProfile(ComponentName component, UserHandleCompat user, 74 Rect sourceBounds, Bundle opts); showAppDetailsForProfile(ComponentName component, UserHandleCompat user)75 public abstract void showAppDetailsForProfile(ComponentName component, UserHandleCompat user); addOnAppsChangedCallback(OnAppsChangedCallbackCompat listener)76 public abstract void addOnAppsChangedCallback(OnAppsChangedCallbackCompat listener); removeOnAppsChangedCallback(OnAppsChangedCallbackCompat listener)77 public abstract void removeOnAppsChangedCallback(OnAppsChangedCallbackCompat listener); isPackageEnabledForProfile(String packageName, UserHandleCompat user)78 public abstract boolean isPackageEnabledForProfile(String packageName, UserHandleCompat user); isActivityEnabledForProfile(ComponentName component, UserHandleCompat user)79 public abstract boolean isActivityEnabledForProfile(ComponentName component, 80 UserHandleCompat user); isPackageSuspendedForProfile(String packageName, UserHandleCompat user)81 public abstract boolean isPackageSuspendedForProfile(String packageName, UserHandleCompat user); 82 } 83