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