LauncherAppsCompat.java revision 7bc272a11b701a32d2ed91277341c382cbd84aeb
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 static final String ACTION_MANAGED_PROFILE_ADDED = 38 "android.intent.action.MANAGED_PROFILE_ADDED"; 39 public static final String ACTION_MANAGED_PROFILE_REMOVED = 40 "android.intent.action.MANAGED_PROFILE_REMOVED"; 41 42 public interface OnAppsChangedListenerCompat { 43 void onPackageRemoved(UserHandleCompat user, String packageName); 44 void onPackageAdded(UserHandleCompat user, String packageName); 45 void onPackageChanged(UserHandleCompat user, String packageName); 46 void onPackagesAvailable(UserHandleCompat user, String[] packageNames, boolean replacing); 47 void onPackagesUnavailable(UserHandleCompat user, String[] packageNames, boolean replacing); 48 } 49 50 protected LauncherAppsCompat() { 51 } 52 53 public static LauncherAppsCompat getInstance(Context context) { 54 // TODO change this to use api version once L gets an API number. 55 if ("L".equals(Build.VERSION.CODENAME)) { 56 Object launcherApps = context.getSystemService("launcherapps"); 57 if (launcherApps != null) { 58 LauncherAppsCompatVL compat = LauncherAppsCompatVL.build(context, launcherApps); 59 if (compat != null) { 60 return compat; 61 } 62 } 63 } 64 // Pre L or lunacher apps service not running, or reflection failed to find something. 65 return new LauncherAppsCompatV16(context); 66 } 67 68 public abstract List<LauncherActivityInfoCompat> getActivityList(String packageName, 69 UserHandleCompat user); 70 public abstract LauncherActivityInfoCompat resolveActivity(Intent intent, 71 UserHandleCompat user); 72 public abstract void startActivityForProfile(ComponentName component, Rect sourceBounds, 73 Bundle opts, UserHandleCompat user); 74 public abstract void addOnAppsChangedListener(OnAppsChangedListenerCompat listener); 75 public abstract void removeOnAppsChangedListener(OnAppsChangedListenerCompat listener); 76 public abstract boolean isPackageEnabledForProfile(String packageName, UserHandleCompat user); 77 public abstract boolean isActivityEnabledForProfile(ComponentName component, 78 UserHandleCompat user); 79}