1 /*
2  * Copyright (C) 2018 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.model;
18 
19 import android.content.ComponentName;
20 import android.content.Context;
21 import android.os.UserHandle;
22 
23 import androidx.annotation.Nullable;
24 
25 import com.android.launcher3.LauncherAppState;
26 import com.android.launcher3.icons.ComponentWithLabelAndIcon;
27 import com.android.launcher3.model.data.PackageItemInfo;
28 import com.android.launcher3.util.PackageUserKey;
29 import com.android.launcher3.widget.model.WidgetsListBaseEntry;
30 
31 import java.util.ArrayList;
32 import java.util.Collections;
33 import java.util.List;
34 import java.util.Map;
35 import java.util.Set;
36 
37 /**
38  * Widgets data model that is used by the adapters of the widget views and controllers.
39  *
40  * <p> The widgets and shortcuts are organized using package name as its index.
41  */
42 public class WidgetsModel {
43 
44     // True is the widget support is disabled.
45     public static final boolean GO_DISABLE_WIDGETS = true;
46     public static final boolean GO_DISABLE_NOTIFICATION_DOTS = true;
47 
48     private static final ArrayList<WidgetsListBaseEntry> EMPTY_WIDGET_LIST = new ArrayList<>();
49 
50     /**
51      * Returns a list of {@link WidgetsListBaseEntry}. All {@link WidgetItem} in a single row are
52      * sorted (based on label and user), but the overall list of {@link WidgetsListBaseEntry}s is
53      * not sorted. This list is sorted at the UI when using
54      * {@link com.android.launcher3.widget.picker.WidgetsDiffReporter}
55      *
56      * @see com.android.launcher3.widget.picker.WidgetsListAdapter#setWidgets(List)
57      */
getWidgetsListForPicker(Context context)58     public synchronized ArrayList<WidgetsListBaseEntry> getWidgetsListForPicker(Context context) {
59         return EMPTY_WIDGET_LIST;
60     }
61 
62     /** Returns a mapping of packages to their widgets without static shortcuts. */
getAllWidgetsWithoutShortcuts()63     public synchronized Map<PackageUserKey, List<WidgetItem>> getAllWidgetsWithoutShortcuts() {
64         return Map.of();
65     }
66 
67     /**
68      * @param packageUser If null, all widgets and shortcuts are updated and returned, otherwise
69      *                    only widgets and shortcuts associated with the package/user are.
70      */
update(LauncherAppState app, @Nullable PackageUserKey packageUser)71     public List<ComponentWithLabelAndIcon> update(LauncherAppState app,
72             @Nullable PackageUserKey packageUser) {
73         return Collections.emptyList();
74     }
75 
76 
onPackageIconsUpdated(Set<String> packageNames, UserHandle user, LauncherAppState app)77     public void onPackageIconsUpdated(Set<String> packageNames, UserHandle user,
78             LauncherAppState app) {
79     }
80 
getWidgetProviderInfoByProviderName( ComponentName providerName, UserHandle user)81     public WidgetItem getWidgetProviderInfoByProviderName(
82             ComponentName providerName, UserHandle user) {
83         return null;
84     }
85 
86     /** Returns {@link PackageItemInfo} of a pending widget. */
newPendingItemInfo( Context context, ComponentName provider, UserHandle userHandle)87     public static PackageItemInfo newPendingItemInfo(
88             Context context, ComponentName provider, UserHandle userHandle) {
89         return new PackageItemInfo(provider.getPackageName(), userHandle);
90     }
91 }