The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 | |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 19 | import android.app.ActivityManager; |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 20 | import android.appwidget.AppWidgetProviderInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | import android.content.BroadcastReceiver; |
| 22 | import android.content.ComponentName; |
| 23 | import android.content.Context; |
| 24 | import android.content.Intent; |
| 25 | import android.content.IntentFilter; |
Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 26 | import android.content.pm.PackageManager; |
Amith Yamasani | 8fd96ec | 2012-09-21 17:48:49 -0700 | [diff] [blame] | 27 | import android.os.Binder; |
Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 28 | import android.os.Bundle; |
Adam Cohen | a1a2f96 | 2012-11-01 14:06:16 -0700 | [diff] [blame] | 29 | import android.os.Handler; |
| 30 | import android.os.HandlerThread; |
Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 31 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.os.RemoteException; |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 33 | import android.os.UserHandle; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 34 | import android.util.Slog; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 35 | import android.util.SparseArray; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.widget.RemoteViews; |
| 37 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 38 | import com.android.internal.appwidget.IAppWidgetHost; |
Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 39 | import com.android.internal.appwidget.IAppWidgetService; |
Amith Yamasani | 8320de8 | 2012-10-05 16:10:38 -0700 | [diff] [blame] | 40 | import com.android.internal.util.IndentingPrintWriter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | |
Adam Cohen | 9730031 | 2011-10-12 15:48:13 -0700 | [diff] [blame] | 42 | import java.io.FileDescriptor; |
Adam Cohen | 9730031 | 2011-10-12 15:48:13 -0700 | [diff] [blame] | 43 | import java.io.PrintWriter; |
Adam Cohen | 9730031 | 2011-10-12 15:48:13 -0700 | [diff] [blame] | 44 | import java.util.List; |
| 45 | import java.util.Locale; |
| 46 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 47 | |
| 48 | /** |
| 49 | * Redirects calls to this service to the instance of the service for the appropriate user. |
| 50 | */ |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 51 | class AppWidgetService extends IAppWidgetService.Stub |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 53 | private static final String TAG = "AppWidgetService"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | Context mContext; |
Eric Fischer | 63c2d9e | 2009-10-22 15:22:50 -0700 | [diff] [blame] | 56 | Locale mLocale; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | PackageManager mPackageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | boolean mSafeMode; |
Adam Cohen | a1a2f96 | 2012-11-01 14:06:16 -0700 | [diff] [blame] | 59 | private final Handler mSaveStateHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 61 | private final SparseArray<AppWidgetServiceImpl> mAppWidgetServices; |
Adam Cohen | 7bb9883 | 2011-10-05 18:10:13 -0700 | [diff] [blame] | 62 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 63 | AppWidgetService(Context context) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | mContext = context; |
Adam Cohen | a1a2f96 | 2012-11-01 14:06:16 -0700 | [diff] [blame] | 65 | |
| 66 | HandlerThread handlerThread = new HandlerThread("AppWidgetService -- Save state"); |
| 67 | handlerThread.start(); |
| 68 | mSaveStateHandler = new Handler(handlerThread.getLooper()); |
| 69 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 70 | mAppWidgetServices = new SparseArray<AppWidgetServiceImpl>(5); |
Adam Cohen | a1a2f96 | 2012-11-01 14:06:16 -0700 | [diff] [blame] | 71 | AppWidgetServiceImpl primary = new AppWidgetServiceImpl(context, 0, mSaveStateHandler); |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 72 | mAppWidgetServices.append(0, primary); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | public void systemReady(boolean safeMode) { |
| 76 | mSafeMode = safeMode; |
| 77 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 78 | mAppWidgetServices.get(0).systemReady(safeMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | |
| 80 | // Register for the boot completed broadcast, so we can send the |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 81 | // ENABLE broacasts. If we try to send them now, they time out, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | // because the system isn't ready to handle them yet. |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 83 | mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | new IntentFilter(Intent.ACTION_BOOT_COMPLETED), null, null); |
| 85 | |
Eric Fischer | 63c2d9e | 2009-10-22 15:22:50 -0700 | [diff] [blame] | 86 | // Register for configuration changes so we can update the names |
| 87 | // of the widgets when the locale changes. |
Dianne Hackborn | fd8bf5c | 2012-09-04 18:48:37 -0700 | [diff] [blame] | 88 | mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, |
| 89 | new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED), null, null); |
Eric Fischer | 63c2d9e | 2009-10-22 15:22:50 -0700 | [diff] [blame] | 90 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | // Register for broadcasts about package install, etc., so we can |
| 92 | // update the provider list. |
| 93 | IntentFilter filter = new IntentFilter(); |
| 94 | filter.addAction(Intent.ACTION_PACKAGE_ADDED); |
Joe Onorato | d070e89 | 2011-01-07 20:50:37 -0800 | [diff] [blame] | 95 | filter.addAction(Intent.ACTION_PACKAGE_CHANGED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | filter.addAction(Intent.ACTION_PACKAGE_REMOVED); |
| 97 | filter.addDataScheme("package"); |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 98 | mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, |
| 99 | filter, null, null); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 100 | // Register for events related to sdcard installation. |
| 101 | IntentFilter sdFilter = new IntentFilter(); |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 102 | sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE); |
| 103 | sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE); |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 104 | mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, |
| 105 | sdFilter, null, null); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 106 | |
| 107 | IntentFilter userFilter = new IntentFilter(); |
| 108 | userFilter.addAction(Intent.ACTION_USER_REMOVED); |
Amith Yamasani | 756901d | 2012-10-12 12:30:07 -0700 | [diff] [blame] | 109 | userFilter.addAction(Intent.ACTION_USER_STOPPING); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 110 | mContext.registerReceiver(new BroadcastReceiver() { |
| 111 | @Override |
| 112 | public void onReceive(Context context, Intent intent) { |
Amith Yamasani | 756901d | 2012-10-12 12:30:07 -0700 | [diff] [blame] | 113 | if (Intent.ACTION_USER_REMOVED.equals(intent.getAction())) { |
| 114 | onUserRemoved(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, |
| 115 | UserHandle.USER_NULL)); |
| 116 | } else if (Intent.ACTION_USER_STOPPING.equals(intent.getAction())) { |
| 117 | onUserStopping(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, |
| 118 | UserHandle.USER_NULL)); |
| 119 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 120 | } |
| 121 | }, userFilter); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | } |
| 123 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 124 | @Override |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 125 | public int allocateAppWidgetId(String packageName, int hostId, int userId) |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 126 | throws RemoteException { |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 127 | return getImplForUser(userId).allocateAppWidgetId(packageName, hostId); |
| 128 | } |
| 129 | |
| 130 | @Override |
| 131 | public int[] getAppWidgetIdsForHost(int hostId, int userId) throws RemoteException { |
| 132 | return getImplForUser(userId).getAppWidgetIdsForHost(hostId); |
| 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public void deleteAppWidgetId(int appWidgetId, int userId) throws RemoteException { |
| 137 | getImplForUser(userId).deleteAppWidgetId(appWidgetId); |
| 138 | } |
| 139 | |
| 140 | @Override |
| 141 | public void deleteHost(int hostId, int userId) throws RemoteException { |
| 142 | getImplForUser(userId).deleteHost(hostId); |
| 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public void deleteAllHosts(int userId) throws RemoteException { |
| 147 | getImplForUser(userId).deleteAllHosts(); |
| 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public void bindAppWidgetId(int appWidgetId, ComponentName provider, Bundle options, int userId) |
| 152 | throws RemoteException { |
| 153 | getImplForUser(userId).bindAppWidgetId(appWidgetId, provider, options); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | } |
| 155 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 156 | @Override |
Michael Jurka | 61a5b01 | 2012-04-13 10:39:45 -0700 | [diff] [blame] | 157 | public boolean bindAppWidgetIdIfAllowed( |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 158 | String packageName, int appWidgetId, ComponentName provider, Bundle options, int userId) |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 159 | throws RemoteException { |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 160 | return getImplForUser(userId).bindAppWidgetIdIfAllowed( |
Adam Cohen | 0aa2d42 | 2012-09-07 17:37:26 -0700 | [diff] [blame] | 161 | packageName, appWidgetId, provider, options); |
Michael Jurka | 61a5b01 | 2012-04-13 10:39:45 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | @Override |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 165 | public boolean hasBindAppWidgetPermission(String packageName, int userId) |
| 166 | throws RemoteException { |
| 167 | return getImplForUser(userId).hasBindAppWidgetPermission(packageName); |
Michael Jurka | 61a5b01 | 2012-04-13 10:39:45 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | @Override |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 171 | public void setBindAppWidgetPermission(String packageName, boolean permission, int userId) |
Michael Jurka | 61a5b01 | 2012-04-13 10:39:45 -0700 | [diff] [blame] | 172 | throws RemoteException { |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 173 | getImplForUser(userId).setBindAppWidgetPermission(packageName, permission); |
Michael Jurka | 61a5b01 | 2012-04-13 10:39:45 -0700 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | @Override |
Amith Yamasani | c566b43 | 2012-11-30 15:26:21 -0800 | [diff] [blame] | 177 | public void bindRemoteViewsService(int appWidgetId, Intent intent, IBinder connection, |
| 178 | int userId) throws RemoteException { |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 179 | getImplForUser(userId).bindRemoteViewsService(appWidgetId, intent, connection); |
Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 180 | } |
| 181 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 182 | @Override |
| 183 | public int[] startListening(IAppWidgetHost host, String packageName, int hostId, |
Amith Yamasani | c566b43 | 2012-11-30 15:26:21 -0800 | [diff] [blame] | 184 | List<RemoteViews> updatedViews, int userId) throws RemoteException { |
Amith Yamasani | c566b43 | 2012-11-30 15:26:21 -0800 | [diff] [blame] | 185 | return getImplForUser(userId).startListening(host, packageName, hostId, updatedViews); |
| 186 | } |
| 187 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 188 | public void onUserRemoved(int userId) { |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 189 | if (userId < 1) return; |
Amith Yamasani | 8320de8 | 2012-10-05 16:10:38 -0700 | [diff] [blame] | 190 | synchronized (mAppWidgetServices) { |
| 191 | AppWidgetServiceImpl impl = mAppWidgetServices.get(userId); |
| 192 | mAppWidgetServices.remove(userId); |
Amith Yamasani | 756901d | 2012-10-12 12:30:07 -0700 | [diff] [blame] | 193 | |
Amith Yamasani | 8320de8 | 2012-10-05 16:10:38 -0700 | [diff] [blame] | 194 | if (impl == null) { |
| 195 | AppWidgetServiceImpl.getSettingsFile(userId).delete(); |
| 196 | } else { |
| 197 | impl.onUserRemoved(); |
| 198 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 199 | } |
Winson Chung | 84bbb02 | 2011-02-21 13:57:45 -0800 | [diff] [blame] | 200 | } |
| 201 | |
Amith Yamasani | 756901d | 2012-10-12 12:30:07 -0700 | [diff] [blame] | 202 | public void onUserStopping(int userId) { |
| 203 | if (userId < 1) return; |
| 204 | synchronized (mAppWidgetServices) { |
| 205 | AppWidgetServiceImpl impl = mAppWidgetServices.get(userId); |
| 206 | if (impl != null) { |
| 207 | mAppWidgetServices.remove(userId); |
| 208 | impl.onUserStopping(); |
| 209 | } |
| 210 | } |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 213 | private void checkPermission(int userId) { |
| 214 | int realUserId = ActivityManager.handleIncomingUser( |
| 215 | Binder.getCallingPid(), |
| 216 | Binder.getCallingUid(), |
| 217 | userId, |
| 218 | false, /* allowAll */ |
| 219 | true, /* requireFull */ |
| 220 | this.getClass().getSimpleName(), |
| 221 | this.getClass().getPackage().getName()); |
| 222 | } |
| 223 | |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 224 | private AppWidgetServiceImpl getImplForUser(int userId) { |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 225 | checkPermission(userId); |
Amith Yamasani | 8320de8 | 2012-10-05 16:10:38 -0700 | [diff] [blame] | 226 | boolean sendInitial = false; |
| 227 | AppWidgetServiceImpl service; |
| 228 | synchronized (mAppWidgetServices) { |
| 229 | service = mAppWidgetServices.get(userId); |
| 230 | if (service == null) { |
| 231 | Slog.i(TAG, "Unable to find AppWidgetServiceImpl for user " + userId + ", adding"); |
| 232 | // TODO: Verify that it's a valid user |
Adam Cohen | a1a2f96 | 2012-11-01 14:06:16 -0700 | [diff] [blame] | 233 | service = new AppWidgetServiceImpl(mContext, userId, mSaveStateHandler); |
Amith Yamasani | 8320de8 | 2012-10-05 16:10:38 -0700 | [diff] [blame] | 234 | service.systemReady(mSafeMode); |
| 235 | // Assume that BOOT_COMPLETED was received, as this is a non-primary user. |
| 236 | mAppWidgetServices.append(userId, service); |
| 237 | sendInitial = true; |
| 238 | } |
Winson Chung | 84bbb02 | 2011-02-21 13:57:45 -0800 | [diff] [blame] | 239 | } |
Amith Yamasani | 8320de8 | 2012-10-05 16:10:38 -0700 | [diff] [blame] | 240 | if (sendInitial) { |
| 241 | service.sendInitialBroadcasts(); |
| 242 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 243 | return service; |
Winson Chung | 84bbb02 | 2011-02-21 13:57:45 -0800 | [diff] [blame] | 244 | } |
| 245 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 246 | @Override |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 247 | public int[] getAppWidgetIds(ComponentName provider, int userId) throws RemoteException { |
| 248 | return getImplForUser(userId).getAppWidgetIds(provider); |
Winson Chung | 84bbb02 | 2011-02-21 13:57:45 -0800 | [diff] [blame] | 249 | } |
| 250 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 251 | @Override |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 252 | public AppWidgetProviderInfo getAppWidgetInfo(int appWidgetId, int userId) |
Adam Cohen | d9e5af3 | 2012-11-28 16:34:57 -0800 | [diff] [blame] | 253 | throws RemoteException { |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 254 | return getImplForUser(userId).getAppWidgetInfo(appWidgetId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | } |
| 256 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 257 | @Override |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 258 | public RemoteViews getAppWidgetViews(int appWidgetId, int userId) throws RemoteException { |
| 259 | return getImplForUser(userId).getAppWidgetViews(appWidgetId); |
| 260 | } |
| 261 | |
| 262 | @Override |
| 263 | public void updateAppWidgetOptions(int appWidgetId, Bundle options, int userId) { |
| 264 | getImplForUser(userId).updateAppWidgetOptions(appWidgetId, options); |
| 265 | } |
| 266 | |
| 267 | @Override |
| 268 | public Bundle getAppWidgetOptions(int appWidgetId, int userId) { |
| 269 | return getImplForUser(userId).getAppWidgetOptions(appWidgetId); |
| 270 | } |
| 271 | |
| 272 | @Override |
| 273 | public List<AppWidgetProviderInfo> getInstalledProviders(int categoryFilter, int userId) |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 274 | throws RemoteException { |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 275 | return getImplForUser(userId).getInstalledProviders(categoryFilter); |
| 276 | } |
| 277 | |
| 278 | @Override |
| 279 | public void notifyAppWidgetViewDataChanged(int[] appWidgetIds, int viewId, int userId) |
| 280 | throws RemoteException { |
| 281 | getImplForUser(userId).notifyAppWidgetViewDataChanged( |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 282 | appWidgetIds, viewId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | } |
| 284 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 285 | @Override |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 286 | public void partiallyUpdateAppWidgetIds(int[] appWidgetIds, RemoteViews views, int userId) |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 287 | throws RemoteException { |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 288 | getImplForUser(userId).partiallyUpdateAppWidgetIds( |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 289 | appWidgetIds, views); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 290 | } |
| 291 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 292 | @Override |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 293 | public void stopListening(int hostId, int userId) throws RemoteException { |
Amith Yamasani | c566b43 | 2012-11-30 15:26:21 -0800 | [diff] [blame] | 294 | getImplForUser(userId).stopListening(hostId); |
| 295 | } |
| 296 | |
| 297 | @Override |
| 298 | public void unbindRemoteViewsService(int appWidgetId, Intent intent, int userId) |
| 299 | throws RemoteException { |
Amith Yamasani | c566b43 | 2012-11-30 15:26:21 -0800 | [diff] [blame] | 300 | getImplForUser(userId).unbindRemoteViewsService( |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 301 | appWidgetId, intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 302 | } |
| 303 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 304 | @Override |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 305 | public void updateAppWidgetIds(int[] appWidgetIds, RemoteViews views, int userId) |
| 306 | throws RemoteException { |
| 307 | getImplForUser(userId).updateAppWidgetIds(appWidgetIds, views); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 308 | } |
Adam Cohen | 9730031 | 2011-10-12 15:48:13 -0700 | [diff] [blame] | 309 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 310 | @Override |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 311 | public void updateAppWidgetProvider(ComponentName provider, RemoteViews views, int userId) |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 312 | throws RemoteException { |
Jim Miller | a75a883 | 2013-02-07 16:53:32 -0800 | [diff] [blame] | 313 | getImplForUser(userId).updateAppWidgetProvider(provider, views); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | } |
| 315 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 316 | @Override |
| 317 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Jeff Sharkey | 52801aa | 2012-10-12 16:06:16 -0700 | [diff] [blame] | 318 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG); |
| 319 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 320 | // Dump the state of all the app widget providers |
Amith Yamasani | 8320de8 | 2012-10-05 16:10:38 -0700 | [diff] [blame] | 321 | synchronized (mAppWidgetServices) { |
| 322 | IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); |
| 323 | for (int i = 0; i < mAppWidgetServices.size(); i++) { |
| 324 | pw.println("User: " + mAppWidgetServices.keyAt(i)); |
| 325 | ipw.increaseIndent(); |
| 326 | AppWidgetServiceImpl service = mAppWidgetServices.valueAt(i); |
| 327 | service.dump(fd, ipw, args); |
| 328 | ipw.decreaseIndent(); |
| 329 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 330 | } |
| 331 | } |
| 332 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 334 | public void onReceive(Context context, Intent intent) { |
| 335 | String action = intent.getAction(); |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 336 | // Slog.d(TAG, "received " + action); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | if (Intent.ACTION_BOOT_COMPLETED.equals(action)) { |
Amith Yamasani | 756901d | 2012-10-12 12:30:07 -0700 | [diff] [blame] | 338 | int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL); |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 339 | if (userId >= 0) { |
| 340 | getImplForUser(userId).sendInitialBroadcasts(); |
| 341 | } else { |
Amith Yamasani | 756901d | 2012-10-12 12:30:07 -0700 | [diff] [blame] | 342 | Slog.w(TAG, "Incorrect user handle supplied in " + intent); |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 343 | } |
Eric Fischer | 63c2d9e | 2009-10-22 15:22:50 -0700 | [diff] [blame] | 344 | } else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) { |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 345 | for (int i = 0; i < mAppWidgetServices.size(); i++) { |
| 346 | AppWidgetServiceImpl service = mAppWidgetServices.valueAt(i); |
| 347 | service.onConfigurationChanged(); |
Eric Fischer | 63c2d9e | 2009-10-22 15:22:50 -0700 | [diff] [blame] | 348 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 349 | } else { |
Dianne Hackborn | 20e8098 | 2012-08-31 19:00:44 -0700 | [diff] [blame] | 350 | int sendingUser = getSendingUserId(); |
| 351 | if (sendingUser == UserHandle.USER_ALL) { |
| 352 | for (int i = 0; i < mAppWidgetServices.size(); i++) { |
| 353 | AppWidgetServiceImpl service = mAppWidgetServices.valueAt(i); |
| 354 | service.onBroadcastReceived(intent); |
| 355 | } |
| 356 | } else { |
| 357 | AppWidgetServiceImpl service = mAppWidgetServices.get(sendingUser); |
| 358 | if (service != null) { |
| 359 | service.onBroadcastReceived(intent); |
| 360 | } |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 361 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 365 | } |