blob: 385681ec66d099eb03c400e5fc34ee1ca2a52937 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package com.android.server;
18
19import android.app.AlarmManager;
20import android.app.PendingIntent;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070021import android.appwidget.AppWidgetManager;
22import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.content.BroadcastReceiver;
24import android.content.ComponentName;
25import android.content.Context;
26import android.content.Intent;
27import android.content.IntentFilter;
Winson Chung81f39eb2011-01-11 18:05:01 -080028import android.content.ServiceConnection;
Winson Chung81f39eb2011-01-11 18:05:01 -080029import android.content.pm.PackageManager;
Adam Cohene8724c82012-04-19 17:11:40 -070030import android.os.Bundle;
Winson Chung81f39eb2011-01-11 18:05:01 -080031import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.os.RemoteException;
Dianne Hackborn41203752012-08-31 14:05:51 -070033import android.os.UserHandle;
Winson Chung81f39eb2011-01-11 18:05:01 -080034import android.util.Pair;
Joe Onorato8a9b2202010-02-26 18:56:32 -080035import android.util.Slog;
Amith Yamasani742a6712011-05-04 14:49:28 -070036import android.util.SparseArray;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.widget.RemoteViews;
38
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070039import com.android.internal.appwidget.IAppWidgetHost;
Winson Chung81f39eb2011-01-11 18:05:01 -080040import com.android.internal.appwidget.IAppWidgetService;
Winson Chung81f39eb2011-01-11 18:05:01 -080041import com.android.internal.widget.IRemoteViewsAdapterConnection;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042
Adam Cohen97300312011-10-12 15:48:13 -070043import java.io.FileDescriptor;
Adam Cohen97300312011-10-12 15:48:13 -070044import java.io.PrintWriter;
45import java.util.ArrayList;
Adam Cohen97300312011-10-12 15:48:13 -070046import java.util.List;
47import java.util.Locale;
48
Amith Yamasani742a6712011-05-04 14:49:28 -070049
50/**
51 * Redirects calls to this service to the instance of the service for the appropriate user.
52 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070053class AppWidgetService extends IAppWidgetService.Stub
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054{
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070055 private static final String TAG = "AppWidgetService";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057 /*
58 * When identifying a Host or Provider based on the calling process, use the uid field.
59 * When identifying a Host or Provider based on a package manager broadcast, use the
60 * package given.
61 */
62
63 static class Provider {
64 int uid;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070065 AppWidgetProviderInfo info;
Romain Guya5475592009-07-01 17:20:08 -070066 ArrayList<AppWidgetId> instances = new ArrayList<AppWidgetId>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067 PendingIntent broadcast;
68 boolean zombie; // if we're in safe mode, don't prune this just because nobody references it
69
70 int tag; // for use while saving state (the index)
71 }
72
73 static class Host {
74 int uid;
75 int hostId;
76 String packageName;
Romain Guya5475592009-07-01 17:20:08 -070077 ArrayList<AppWidgetId> instances = new ArrayList<AppWidgetId>();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070078 IAppWidgetHost callbacks;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079 boolean zombie; // if we're in safe mode, don't prune this just because nobody references it
80
81 int tag; // for use while saving state (the index)
82 }
83
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070084 static class AppWidgetId {
85 int appWidgetId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 Provider provider;
87 RemoteViews views;
88 Host host;
89 }
90
Winson Chung81f39eb2011-01-11 18:05:01 -080091 /**
92 * Acts as a proxy between the ServiceConnection and the RemoteViewsAdapterConnection.
93 * This needs to be a static inner class since a reference to the ServiceConnection is held
94 * globally and may lead us to leak AppWidgetService instances (if there were more than one).
95 */
96 static class ServiceConnectionProxy implements ServiceConnection {
Winson Chung81f39eb2011-01-11 18:05:01 -080097 private final IBinder mConnectionCb;
98
Winson Chung16c8d8a2011-01-20 16:19:33 -080099 ServiceConnectionProxy(Pair<Integer, Intent.FilterComparison> key, IBinder connectionCb) {
Winson Chung81f39eb2011-01-11 18:05:01 -0800100 mConnectionCb = connectionCb;
101 }
102 public void onServiceConnected(ComponentName name, IBinder service) {
Winson Chung16c8d8a2011-01-20 16:19:33 -0800103 final IRemoteViewsAdapterConnection cb =
Winson Chung81f39eb2011-01-11 18:05:01 -0800104 IRemoteViewsAdapterConnection.Stub.asInterface(mConnectionCb);
105 try {
106 cb.onServiceConnected(service);
Adam Cohenc2be22c2011-03-16 16:33:53 -0700107 } catch (Exception e) {
Winson Chung81f39eb2011-01-11 18:05:01 -0800108 e.printStackTrace();
109 }
110 }
111 public void onServiceDisconnected(ComponentName name) {
Winson Chung16c8d8a2011-01-20 16:19:33 -0800112 disconnect();
113 }
114 public void disconnect() {
115 final IRemoteViewsAdapterConnection cb =
Winson Chung81f39eb2011-01-11 18:05:01 -0800116 IRemoteViewsAdapterConnection.Stub.asInterface(mConnectionCb);
117 try {
118 cb.onServiceDisconnected();
Adam Cohenc2be22c2011-03-16 16:33:53 -0700119 } catch (Exception e) {
Winson Chung81f39eb2011-01-11 18:05:01 -0800120 e.printStackTrace();
121 }
122 }
123 }
124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 Context mContext;
Eric Fischer63c2d9e2009-10-22 15:22:50 -0700126 Locale mLocale;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127 PackageManager mPackageManager;
128 AlarmManager mAlarmManager;
Romain Guya5475592009-07-01 17:20:08 -0700129 ArrayList<Provider> mInstalledProviders = new ArrayList<Provider>();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700130 int mNextAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID + 1;
Romain Guya5475592009-07-01 17:20:08 -0700131 final ArrayList<AppWidgetId> mAppWidgetIds = new ArrayList<AppWidgetId>();
132 ArrayList<Host> mHosts = new ArrayList<Host>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 boolean mSafeMode;
134
Amith Yamasani742a6712011-05-04 14:49:28 -0700135
136 private final SparseArray<AppWidgetServiceImpl> mAppWidgetServices;
Adam Cohen7bb98832011-10-05 18:10:13 -0700137
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700138 AppWidgetService(Context context) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 mContext = context;
Amith Yamasani742a6712011-05-04 14:49:28 -0700140 mAppWidgetServices = new SparseArray<AppWidgetServiceImpl>(5);
141 AppWidgetServiceImpl primary = new AppWidgetServiceImpl(context, 0);
142 mAppWidgetServices.append(0, primary);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 }
144
145 public void systemReady(boolean safeMode) {
146 mSafeMode = safeMode;
147
Amith Yamasani742a6712011-05-04 14:49:28 -0700148 mAppWidgetServices.get(0).systemReady(safeMode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149
150 // Register for the boot completed broadcast, so we can send the
Amith Yamasani742a6712011-05-04 14:49:28 -0700151 // ENABLE broacasts. If we try to send them now, they time out,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 // because the system isn't ready to handle them yet.
Dianne Hackborn20e80982012-08-31 19:00:44 -0700153 mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 new IntentFilter(Intent.ACTION_BOOT_COMPLETED), null, null);
155
Eric Fischer63c2d9e2009-10-22 15:22:50 -0700156 // Register for configuration changes so we can update the names
157 // of the widgets when the locale changes.
Dianne Hackbornfd8bf5c2012-09-04 18:48:37 -0700158 mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL,
159 new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED), null, null);
Eric Fischer63c2d9e2009-10-22 15:22:50 -0700160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 // Register for broadcasts about package install, etc., so we can
162 // update the provider list.
163 IntentFilter filter = new IntentFilter();
164 filter.addAction(Intent.ACTION_PACKAGE_ADDED);
Joe Onoratod070e892011-01-07 20:50:37 -0800165 filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
167 filter.addDataScheme("package");
Dianne Hackborn20e80982012-08-31 19:00:44 -0700168 mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL,
169 filter, null, null);
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800170 // Register for events related to sdcard installation.
171 IntentFilter sdFilter = new IntentFilter();
Suchi Amalapurapub56ae202010-02-04 22:51:07 -0800172 sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
173 sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
Dianne Hackborn20e80982012-08-31 19:00:44 -0700174 mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL,
175 sdFilter, null, null);
Amith Yamasani13593602012-03-22 16:16:17 -0700176
177 IntentFilter userFilter = new IntentFilter();
178 userFilter.addAction(Intent.ACTION_USER_REMOVED);
179 mContext.registerReceiver(new BroadcastReceiver() {
180 @Override
181 public void onReceive(Context context, Intent intent) {
Amith Yamasani2a003292012-08-14 18:25:45 -0700182 onUserRemoved(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1));
Amith Yamasani13593602012-03-22 16:16:17 -0700183 }
184 }, userFilter);
Dianne Hackborn20e80982012-08-31 19:00:44 -0700185
186 IntentFilter userStopFilter = new IntentFilter();
187 userStopFilter.addAction(Intent.ACTION_USER_STOPPED);
188 mContext.registerReceiverAsUser(new BroadcastReceiver() {
189 @Override
190 public void onReceive(Context context, Intent intent) {
191 onUserStopped(getSendingUserId());
192 }
193 }, UserHandle.ALL, userFilter, null, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 }
195
Amith Yamasani742a6712011-05-04 14:49:28 -0700196 @Override
197 public int allocateAppWidgetId(String packageName, int hostId) throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700198 return getImplForUser(UserHandle.getCallingUserId()).allocateAppWidgetId(
199 packageName, hostId);
Jeff Sharkey15d161f2011-09-01 21:30:56 -0700200 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700201
202 @Override
203 public void deleteAppWidgetId(int appWidgetId) throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700204 getImplForUser(UserHandle.getCallingUserId()).deleteAppWidgetId(appWidgetId);
Adam Cohen7bb98832011-10-05 18:10:13 -0700205 }
206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 @Override
Amith Yamasani742a6712011-05-04 14:49:28 -0700208 public void deleteHost(int hostId) throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700209 getImplForUser(UserHandle.getCallingUserId()).deleteHost(hostId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 }
211
Amith Yamasani742a6712011-05-04 14:49:28 -0700212 @Override
213 public void deleteAllHosts() throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700214 getImplForUser(UserHandle.getCallingUserId()).deleteAllHosts();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215 }
216
Amith Yamasani742a6712011-05-04 14:49:28 -0700217 @Override
Adam Cohen0aa2d422012-09-07 17:37:26 -0700218 public void bindAppWidgetId(int appWidgetId, ComponentName provider, Bundle options)
219 throws RemoteException {
220 getImplForUser(UserHandle.getCallingUserId()).bindAppWidgetId(appWidgetId, provider,
221 options);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 }
223
Amith Yamasani742a6712011-05-04 14:49:28 -0700224 @Override
Michael Jurka61a5b012012-04-13 10:39:45 -0700225 public boolean bindAppWidgetIdIfAllowed(
Adam Cohen0aa2d422012-09-07 17:37:26 -0700226 String packageName, int appWidgetId, ComponentName provider, Bundle options)
227 throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700228 return getImplForUser(UserHandle.getCallingUserId()).bindAppWidgetIdIfAllowed(
Adam Cohen0aa2d422012-09-07 17:37:26 -0700229 packageName, appWidgetId, provider, options);
Michael Jurka61a5b012012-04-13 10:39:45 -0700230 }
231
232 @Override
233 public boolean hasBindAppWidgetPermission(String packageName) throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700234 return getImplForUser(UserHandle.getCallingUserId()).hasBindAppWidgetPermission(
235 packageName);
Michael Jurka61a5b012012-04-13 10:39:45 -0700236 }
237
238 @Override
239 public void setBindAppWidgetPermission(String packageName, boolean permission)
240 throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700241 getImplForUser(UserHandle.getCallingUserId()).setBindAppWidgetPermission(
242 packageName, permission);
Michael Jurka61a5b012012-04-13 10:39:45 -0700243 }
244
245 @Override
Amith Yamasani742a6712011-05-04 14:49:28 -0700246 public void bindRemoteViewsService(int appWidgetId, Intent intent, IBinder connection)
247 throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700248 getImplForUser(UserHandle.getCallingUserId()).bindRemoteViewsService(
249 appWidgetId, intent, connection);
Winson Chung81f39eb2011-01-11 18:05:01 -0800250 }
251
Amith Yamasani742a6712011-05-04 14:49:28 -0700252 @Override
253 public int[] startListening(IAppWidgetHost host, String packageName, int hostId,
254 List<RemoteViews> updatedViews) throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700255 return getImplForUser(UserHandle.getCallingUserId()).startListening(host,
256 packageName, hostId, updatedViews);
Winson Chung81f39eb2011-01-11 18:05:01 -0800257 }
258
Amith Yamasani13593602012-03-22 16:16:17 -0700259 public void onUserRemoved(int userId) {
260 AppWidgetServiceImpl impl = mAppWidgetServices.get(userId);
261 if (userId < 1) return;
262
263 if (impl == null) {
264 AppWidgetServiceImpl.getSettingsFile(userId).delete();
265 } else {
266 impl.onUserRemoved();
267 }
Winson Chung84bbb022011-02-21 13:57:45 -0800268 }
269
Dianne Hackborn20e80982012-08-31 19:00:44 -0700270 public void onUserStopped(int userId) {
271 }
272
Dianne Hackborn41203752012-08-31 14:05:51 -0700273 private AppWidgetServiceImpl getImplForUser(int userId) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700274 AppWidgetServiceImpl service = mAppWidgetServices.get(userId);
275 if (service == null) {
276 Slog.e(TAG, "Unable to find AppWidgetServiceImpl for the current user");
277 // TODO: Verify that it's a valid user
278 service = new AppWidgetServiceImpl(mContext, userId);
279 service.systemReady(mSafeMode);
280 // Assume that BOOT_COMPLETED was received, as this is a non-primary user.
281 service.sendInitialBroadcasts();
282 mAppWidgetServices.append(userId, service);
Winson Chung84bbb022011-02-21 13:57:45 -0800283 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700284
285 return service;
Winson Chung84bbb022011-02-21 13:57:45 -0800286 }
287
Amith Yamasani742a6712011-05-04 14:49:28 -0700288 @Override
289 public int[] getAppWidgetIds(ComponentName provider) throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700290 return getImplForUser(UserHandle.getCallingUserId()).getAppWidgetIds(provider);
Winson Chung84bbb022011-02-21 13:57:45 -0800291 }
292
Amith Yamasani742a6712011-05-04 14:49:28 -0700293 @Override
294 public AppWidgetProviderInfo getAppWidgetInfo(int appWidgetId) throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700295 return getImplForUser(UserHandle.getCallingUserId()).getAppWidgetInfo(appWidgetId);
Winson Chung81f39eb2011-01-11 18:05:01 -0800296 }
297
Amith Yamasani742a6712011-05-04 14:49:28 -0700298 @Override
299 public RemoteViews getAppWidgetViews(int appWidgetId) throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700300 return getImplForUser(UserHandle.getCallingUserId()).getAppWidgetViews(appWidgetId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301 }
302
Adam Cohene8724c82012-04-19 17:11:40 -0700303 @Override
Adam Cohend2097eb2012-05-01 18:10:28 -0700304 public void updateAppWidgetOptions(int appWidgetId, Bundle options) {
Dianne Hackborn41203752012-08-31 14:05:51 -0700305 getImplForUser(UserHandle.getCallingUserId()).updateAppWidgetOptions(appWidgetId, options);
Adam Cohene8724c82012-04-19 17:11:40 -0700306 }
307
308 @Override
Adam Cohend2097eb2012-05-01 18:10:28 -0700309 public Bundle getAppWidgetOptions(int appWidgetId) {
Dianne Hackborn41203752012-08-31 14:05:51 -0700310 return getImplForUser(UserHandle.getCallingUserId()).getAppWidgetOptions(appWidgetId);
Adam Cohene8724c82012-04-19 17:11:40 -0700311 }
312
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700313 static int[] getAppWidgetIds(Provider p) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800314 int instancesSize = p.instances.size();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700315 int appWidgetIds[] = new int[instancesSize];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316 for (int i=0; i<instancesSize; i++) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700317 appWidgetIds[i] = p.instances.get(i).appWidgetId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800318 }
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700319 return appWidgetIds;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700321
322 @Override
323 public List<AppWidgetProviderInfo> getInstalledProviders() throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700324 return getImplForUser(UserHandle.getCallingUserId()).getInstalledProviders();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325 }
326
Amith Yamasani742a6712011-05-04 14:49:28 -0700327 @Override
328 public void notifyAppWidgetViewDataChanged(int[] appWidgetIds, int viewId)
329 throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700330 getImplForUser(UserHandle.getCallingUserId()).notifyAppWidgetViewDataChanged(
331 appWidgetIds, viewId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332 }
333
Amith Yamasani742a6712011-05-04 14:49:28 -0700334 @Override
335 public void partiallyUpdateAppWidgetIds(int[] appWidgetIds, RemoteViews views)
336 throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700337 getImplForUser(UserHandle.getCallingUserId()).partiallyUpdateAppWidgetIds(
338 appWidgetIds, views);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339 }
340
Amith Yamasani742a6712011-05-04 14:49:28 -0700341 @Override
342 public void stopListening(int hostId) throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700343 getImplForUser(UserHandle.getCallingUserId()).stopListening(hostId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344 }
345
Amith Yamasani742a6712011-05-04 14:49:28 -0700346 @Override
347 public void unbindRemoteViewsService(int appWidgetId, Intent intent) throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700348 getImplForUser(UserHandle.getCallingUserId()).unbindRemoteViewsService(
349 appWidgetId, intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800350 }
351
Amith Yamasani742a6712011-05-04 14:49:28 -0700352 @Override
353 public void updateAppWidgetIds(int[] appWidgetIds, RemoteViews views) throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700354 getImplForUser(UserHandle.getCallingUserId()).updateAppWidgetIds(appWidgetIds, views);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 }
Adam Cohen97300312011-10-12 15:48:13 -0700356
Amith Yamasani742a6712011-05-04 14:49:28 -0700357 @Override
358 public void updateAppWidgetProvider(ComponentName provider, RemoteViews views)
359 throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700360 getImplForUser(UserHandle.getCallingUserId()).updateAppWidgetProvider(provider, views);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361 }
362
Amith Yamasani742a6712011-05-04 14:49:28 -0700363 @Override
364 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
365 // Dump the state of all the app widget providers
366 for (int i = 0; i < mAppWidgetServices.size(); i++) {
367 AppWidgetServiceImpl service = mAppWidgetServices.valueAt(i);
368 service.dump(fd, pw, args);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800369 }
370 }
371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
373 public void onReceive(Context context, Intent intent) {
374 String action = intent.getAction();
Amith Yamasani742a6712011-05-04 14:49:28 -0700375 // Slog.d(TAG, "received " + action);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
Dianne Hackborn41203752012-08-31 14:05:51 -0700377 int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
378 if (userId >= 0) {
379 getImplForUser(userId).sendInitialBroadcasts();
380 } else {
381 Slog.w(TAG, "Not user handle supplied in " + intent);
382 }
Eric Fischer63c2d9e2009-10-22 15:22:50 -0700383 } else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700384 for (int i = 0; i < mAppWidgetServices.size(); i++) {
385 AppWidgetServiceImpl service = mAppWidgetServices.valueAt(i);
386 service.onConfigurationChanged();
Eric Fischer63c2d9e2009-10-22 15:22:50 -0700387 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 } else {
Dianne Hackborn20e80982012-08-31 19:00:44 -0700389 int sendingUser = getSendingUserId();
390 if (sendingUser == UserHandle.USER_ALL) {
391 for (int i = 0; i < mAppWidgetServices.size(); i++) {
392 AppWidgetServiceImpl service = mAppWidgetServices.valueAt(i);
393 service.onBroadcastReceived(intent);
394 }
395 } else {
396 AppWidgetServiceImpl service = mAppWidgetServices.get(sendingUser);
397 if (service != null) {
398 service.onBroadcastReceived(intent);
399 }
Amith Yamasani483f3b02012-03-13 16:08:00 -0700400 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800401 }
402 }
403 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404}