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.server;
18 
19 import android.annotation.Nullable;
20 
21 import java.util.List;
22 
23 /**
24  * Runtime bridge between the Backup Manager Service and the App Widget Service,
25  * since those two modules are intentionally decoupled for modularity.
26  *
27  * @hide
28  */
29 public class AppWidgetBackupBridge {
30     private static WidgetBackupProvider sAppWidgetService;
31 
register(WidgetBackupProvider instance)32     public static void register(WidgetBackupProvider instance) {
33         sAppWidgetService = instance;
34     }
35 
getWidgetParticipants(int userId)36     public static List<String> getWidgetParticipants(int userId) {
37         return (sAppWidgetService != null)
38                 ? sAppWidgetService.getWidgetParticipants(userId)
39                 : null;
40     }
41 
42     /** Returns a byte array of widget data for the specified package or {@code null}. */
43     @Nullable
getWidgetState(String packageName, int userId)44     public static byte[] getWidgetState(String packageName, int userId) {
45         return (sAppWidgetService != null)
46                 ? sAppWidgetService.getWidgetState(packageName, userId)
47                 : null;
48     }
49 
restoreStarting(int userId)50     public static void restoreStarting(int userId) {
51         if (sAppWidgetService != null) {
52             sAppWidgetService.restoreStarting(userId);
53         }
54     }
55 
restoreWidgetState(String packageName, byte[] restoredState, int userId)56     public static void restoreWidgetState(String packageName, byte[] restoredState, int userId) {
57         if (sAppWidgetService != null) {
58             sAppWidgetService.restoreWidgetState(packageName, restoredState, userId);
59         }
60     }
61 
restoreFinished(int userId)62     public static void restoreFinished(int userId) {
63         if (sAppWidgetService != null) {
64             sAppWidgetService.restoreFinished(userId);
65         }
66     }
67 }
68