LauncherAppsCompat.java revision ed13187a745866483139e2878037e1f8427ce567
1ed13187a745866483139e2878037e1f8427ce567Kenny Guy/* 2ed13187a745866483139e2878037e1f8427ce567Kenny Guy * Copyright (C) 2014 The Android Open Source Project 3ed13187a745866483139e2878037e1f8427ce567Kenny Guy * 4ed13187a745866483139e2878037e1f8427ce567Kenny Guy * Licensed under the Apache License, Version 2.0 (the "License"); 5ed13187a745866483139e2878037e1f8427ce567Kenny Guy * you may not use this file except in compliance with the License. 6ed13187a745866483139e2878037e1f8427ce567Kenny Guy * You may obtain a copy of the License at 7ed13187a745866483139e2878037e1f8427ce567Kenny Guy * 8ed13187a745866483139e2878037e1f8427ce567Kenny Guy * http://www.apache.org/licenses/LICENSE-2.0 9ed13187a745866483139e2878037e1f8427ce567Kenny Guy * 10ed13187a745866483139e2878037e1f8427ce567Kenny Guy * Unless required by applicable law or agreed to in writing, software 11ed13187a745866483139e2878037e1f8427ce567Kenny Guy * distributed under the License is distributed on an "AS IS" BASIS, 12ed13187a745866483139e2878037e1f8427ce567Kenny Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13ed13187a745866483139e2878037e1f8427ce567Kenny Guy * See the License for the specific language governing permissions and 14ed13187a745866483139e2878037e1f8427ce567Kenny Guy * limitations under the License. 15ed13187a745866483139e2878037e1f8427ce567Kenny Guy */ 16ed13187a745866483139e2878037e1f8427ce567Kenny Guy 17ed13187a745866483139e2878037e1f8427ce567Kenny Guypackage com.android.launcher3.compat; 18ed13187a745866483139e2878037e1f8427ce567Kenny Guy 19ed13187a745866483139e2878037e1f8427ce567Kenny Guyimport android.content.ComponentName; 20ed13187a745866483139e2878037e1f8427ce567Kenny Guyimport android.content.Context; 21ed13187a745866483139e2878037e1f8427ce567Kenny Guyimport android.content.Intent; 22ed13187a745866483139e2878037e1f8427ce567Kenny Guyimport android.graphics.Rect; 23ed13187a745866483139e2878037e1f8427ce567Kenny Guyimport android.graphics.drawable.Drawable; 24ed13187a745866483139e2878037e1f8427ce567Kenny Guyimport android.os.Build; 25ed13187a745866483139e2878037e1f8427ce567Kenny Guyimport android.os.Bundle; 26ed13187a745866483139e2878037e1f8427ce567Kenny Guyimport android.os.UserHandle; 27ed13187a745866483139e2878037e1f8427ce567Kenny Guyimport android.os.UserManager; 28ed13187a745866483139e2878037e1f8427ce567Kenny Guy 29ed13187a745866483139e2878037e1f8427ce567Kenny Guyimport java.util.ArrayList; 30ed13187a745866483139e2878037e1f8427ce567Kenny Guyimport java.util.Collections; 31ed13187a745866483139e2878037e1f8427ce567Kenny Guyimport java.util.HashMap; 32ed13187a745866483139e2878037e1f8427ce567Kenny Guyimport java.util.List; 33ed13187a745866483139e2878037e1f8427ce567Kenny Guyimport java.util.Map; 34ed13187a745866483139e2878037e1f8427ce567Kenny Guy 35ed13187a745866483139e2878037e1f8427ce567Kenny Guypublic abstract class LauncherAppsCompat { 36ed13187a745866483139e2878037e1f8427ce567Kenny Guy 37ed13187a745866483139e2878037e1f8427ce567Kenny Guy public interface OnAppsChangedListenerCompat { 38ed13187a745866483139e2878037e1f8427ce567Kenny Guy void onPackageRemoved(UserHandleCompat user, String packageName); 39ed13187a745866483139e2878037e1f8427ce567Kenny Guy void onPackageAdded(UserHandleCompat user, String packageName); 40ed13187a745866483139e2878037e1f8427ce567Kenny Guy void onPackageChanged(UserHandleCompat user, String packageName); 41ed13187a745866483139e2878037e1f8427ce567Kenny Guy void onPackagesAvailable(UserHandleCompat user, String[] packageNames, boolean replacing); 42ed13187a745866483139e2878037e1f8427ce567Kenny Guy void onPackagesUnavailable(UserHandleCompat user, String[] packageNames, boolean replacing); 43ed13187a745866483139e2878037e1f8427ce567Kenny Guy } 44ed13187a745866483139e2878037e1f8427ce567Kenny Guy 45ed13187a745866483139e2878037e1f8427ce567Kenny Guy protected LauncherAppsCompat() { 46ed13187a745866483139e2878037e1f8427ce567Kenny Guy } 47ed13187a745866483139e2878037e1f8427ce567Kenny Guy 48ed13187a745866483139e2878037e1f8427ce567Kenny Guy public static LauncherAppsCompat getInstance(Context context) { 49ed13187a745866483139e2878037e1f8427ce567Kenny Guy // TODO change this to use api version once L gets an API number. 50ed13187a745866483139e2878037e1f8427ce567Kenny Guy if ("L".equals(Build.VERSION.CODENAME)) { 51ed13187a745866483139e2878037e1f8427ce567Kenny Guy Object launcherApps = context.getSystemService("launcherapps"); 52ed13187a745866483139e2878037e1f8427ce567Kenny Guy if (launcherApps != null) { 53ed13187a745866483139e2878037e1f8427ce567Kenny Guy LauncherAppsCompatVL compat = LauncherAppsCompatVL.build(context, launcherApps); 54ed13187a745866483139e2878037e1f8427ce567Kenny Guy if (compat != null) { 55ed13187a745866483139e2878037e1f8427ce567Kenny Guy return compat; 56ed13187a745866483139e2878037e1f8427ce567Kenny Guy } 57ed13187a745866483139e2878037e1f8427ce567Kenny Guy } 58ed13187a745866483139e2878037e1f8427ce567Kenny Guy } 59ed13187a745866483139e2878037e1f8427ce567Kenny Guy // Pre L or lunacher apps service not running, or reflection failed to find something. 60ed13187a745866483139e2878037e1f8427ce567Kenny Guy return new LauncherAppsCompatV16(context); 61ed13187a745866483139e2878037e1f8427ce567Kenny Guy } 62ed13187a745866483139e2878037e1f8427ce567Kenny Guy 63ed13187a745866483139e2878037e1f8427ce567Kenny Guy public abstract List<LauncherActivityInfoCompat> getActivityList(String packageName, 64ed13187a745866483139e2878037e1f8427ce567Kenny Guy UserHandleCompat user); 65ed13187a745866483139e2878037e1f8427ce567Kenny Guy public abstract LauncherActivityInfoCompat resolveActivity(Intent intent, 66ed13187a745866483139e2878037e1f8427ce567Kenny Guy UserHandleCompat user); 67ed13187a745866483139e2878037e1f8427ce567Kenny Guy public abstract void startActivityForProfile(ComponentName component, Rect sourceBounds, 68ed13187a745866483139e2878037e1f8427ce567Kenny Guy Bundle opts, UserHandleCompat user); 69ed13187a745866483139e2878037e1f8427ce567Kenny Guy public abstract void addOnAppsChangedListener(OnAppsChangedListenerCompat listener); 70ed13187a745866483139e2878037e1f8427ce567Kenny Guy public abstract void removeOnAppsChangedListener(OnAppsChangedListenerCompat listener); 71ed13187a745866483139e2878037e1f8427ce567Kenny Guy public abstract boolean isPackageEnabledForProfile(String packageName, UserHandleCompat user); 72ed13187a745866483139e2878037e1f8427ce567Kenny Guy public abstract boolean isActivityEnabledForProfile(ComponentName component, 73ed13187a745866483139e2878037e1f8427ce567Kenny Guy UserHandleCompat user); 74ed13187a745866483139e2878037e1f8427ce567Kenny Guy}