Home | History | Annotate | Download | only in compat
      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.LauncherActivityInfo;
     24 import android.graphics.Rect;
     25 import android.os.Bundle;
     26 import android.os.UserHandle;
     27 import android.support.annotation.Nullable;
     28 import com.android.launcher3.Utilities;
     29 import com.android.launcher3.shortcuts.ShortcutInfoCompat;
     30 import com.android.launcher3.util.PackageUserKey;
     31 import java.util.List;
     32 
     33 public abstract class LauncherAppsCompat {
     34 
     35     public interface OnAppsChangedCallbackCompat {
     36         void onPackageRemoved(String packageName, UserHandle user);
     37         void onPackageAdded(String packageName, UserHandle user);
     38         void onPackageChanged(String packageName, UserHandle user);
     39         void onPackagesAvailable(String[] packageNames, UserHandle user, boolean replacing);
     40         void onPackagesUnavailable(String[] packageNames, UserHandle user, boolean replacing);
     41         void onPackagesSuspended(String[] packageNames, UserHandle user);
     42         void onPackagesUnsuspended(String[] packageNames, UserHandle user);
     43         void onShortcutsChanged(String packageName, List<ShortcutInfoCompat> shortcuts,
     44                 UserHandle user);
     45     }
     46 
     47     protected LauncherAppsCompat() {
     48     }
     49 
     50     private static LauncherAppsCompat sInstance;
     51     private static final Object sInstanceLock = new Object();
     52 
     53     public static LauncherAppsCompat getInstance(Context context) {
     54         synchronized (sInstanceLock) {
     55             if (sInstance == null) {
     56                 if (Utilities.ATLEAST_OREO) {
     57                     sInstance = new LauncherAppsCompatVO(context.getApplicationContext());
     58                 } else {
     59                     sInstance = new LauncherAppsCompatVL(context.getApplicationContext());
     60                 }
     61             }
     62             return sInstance;
     63         }
     64     }
     65 
     66     public abstract List<LauncherActivityInfo> getActivityList(String packageName,
     67             UserHandle user);
     68     public abstract LauncherActivityInfo resolveActivity(Intent intent,
     69             UserHandle user);
     70     public abstract void startActivityForProfile(ComponentName component, UserHandle user,
     71             Rect sourceBounds, Bundle opts);
     72     public abstract ApplicationInfo getApplicationInfo(
     73             String packageName, int flags, UserHandle user);
     74     public abstract void showAppDetailsForProfile(ComponentName component, UserHandle user,
     75             Rect sourceBounds, Bundle opts);
     76     public abstract void addOnAppsChangedCallback(OnAppsChangedCallbackCompat listener);
     77     public abstract void removeOnAppsChangedCallback(OnAppsChangedCallbackCompat listener);
     78     public abstract boolean isPackageEnabledForProfile(String packageName, UserHandle user);
     79     public abstract boolean isActivityEnabledForProfile(ComponentName component,
     80             UserHandle user);
     81     public abstract List<ShortcutConfigActivityInfo> getCustomShortcutActivityList(
     82             @Nullable PackageUserKey packageUser);
     83 
     84     public void showAppDetailsForProfile(ComponentName component, UserHandle user) {
     85         showAppDetailsForProfile(component, user, null, null);
     86     }
     87 }
     88