• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.appwidget.AppWidgetManager;
20 import android.appwidget.AppWidgetProviderInfo;
21 import android.content.ComponentName;
22 import android.content.Context;
23 import android.os.Bundle;
24 import android.os.UserHandle;
25 import android.support.annotation.Nullable;
26 
27 import com.android.launcher3.LauncherAppWidgetProviderInfo;
28 import com.android.launcher3.Utilities;
29 import com.android.launcher3.util.ComponentKey;
30 import com.android.launcher3.util.PackageUserKey;
31 
32 import java.util.HashMap;
33 import java.util.List;
34 
35 public abstract class AppWidgetManagerCompat {
36 
37     private static final Object sInstanceLock = new Object();
38     private static AppWidgetManagerCompat sInstance;
39 
getInstance(Context context)40     public static AppWidgetManagerCompat getInstance(Context context) {
41         synchronized (sInstanceLock) {
42             if (sInstance == null) {
43                 if (Utilities.ATLEAST_OREO) {
44                     sInstance = new AppWidgetManagerCompatVO(context.getApplicationContext());
45                 } else {
46                     sInstance = new AppWidgetManagerCompatVL(context.getApplicationContext());
47                 }
48             }
49             return sInstance;
50         }
51     }
52 
53     final AppWidgetManager mAppWidgetManager;
54     final Context mContext;
55 
AppWidgetManagerCompat(Context context)56     AppWidgetManagerCompat(Context context) {
57         mContext = context;
58         mAppWidgetManager = AppWidgetManager.getInstance(context);
59     }
60 
getAppWidgetInfo(int appWidgetId)61     public AppWidgetProviderInfo getAppWidgetInfo(int appWidgetId) {
62         return mAppWidgetManager.getAppWidgetInfo(appWidgetId);
63     }
64 
getLauncherAppWidgetInfo(int appWidgetId)65     public LauncherAppWidgetProviderInfo getLauncherAppWidgetInfo(int appWidgetId) {
66         AppWidgetProviderInfo info = getAppWidgetInfo(appWidgetId);
67         return info == null ? null : LauncherAppWidgetProviderInfo.fromProviderInfo(mContext, info);
68     }
69 
getAllProviders( @ullable PackageUserKey packageUser)70     public abstract List<AppWidgetProviderInfo> getAllProviders(
71             @Nullable PackageUserKey packageUser);
72 
bindAppWidgetIdIfAllowed( int appWidgetId, AppWidgetProviderInfo info, Bundle options)73     public abstract boolean bindAppWidgetIdIfAllowed(
74             int appWidgetId, AppWidgetProviderInfo info, Bundle options);
75 
findProvider( ComponentName provider, UserHandle user)76     public abstract LauncherAppWidgetProviderInfo findProvider(
77             ComponentName provider, UserHandle user);
78 
getAllProvidersMap()79     public abstract HashMap<ComponentKey, AppWidgetProviderInfo> getAllProvidersMap();
80 }
81