blob: b869abd6a9898d7a51305d12b663eaac303dbc2a [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;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.os.Binder;
Adam Cohene8724c82012-04-19 17:11:40 -070031import android.os.Bundle;
Winson Chung81f39eb2011-01-11 18:05:01 -080032import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.os.RemoteException;
Dianne Hackborn41203752012-08-31 14:05:51 -070034import android.os.UserHandle;
Winson Chung81f39eb2011-01-11 18:05:01 -080035import android.util.Pair;
Joe Onorato8a9b2202010-02-26 18:56:32 -080036import android.util.Slog;
Amith Yamasani742a6712011-05-04 14:49:28 -070037import android.util.SparseArray;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import android.widget.RemoteViews;
39
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070040import com.android.internal.appwidget.IAppWidgetHost;
Winson Chung81f39eb2011-01-11 18:05:01 -080041import com.android.internal.appwidget.IAppWidgetService;
Winson Chung81f39eb2011-01-11 18:05:01 -080042import com.android.internal.widget.IRemoteViewsAdapterConnection;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043
Adam Cohen97300312011-10-12 15:48:13 -070044import java.io.FileDescriptor;
Adam Cohen97300312011-10-12 15:48:13 -070045import java.io.PrintWriter;
46import java.util.ArrayList;
Adam Cohen97300312011-10-12 15:48:13 -070047import java.util.List;
48import java.util.Locale;
49
Amith Yamasani742a6712011-05-04 14:49:28 -070050
51/**
52 * Redirects calls to this service to the instance of the service for the appropriate user.
53 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070054class AppWidgetService extends IAppWidgetService.Stub
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055{
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070056 private static final String TAG = "AppWidgetService";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058 /*
59 * When identifying a Host or Provider based on the calling process, use the uid field.
60 * When identifying a Host or Provider based on a package manager broadcast, use the
61 * package given.
62 */
63
64 static class Provider {
65 int uid;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070066 AppWidgetProviderInfo info;
Romain Guya5475592009-07-01 17:20:08 -070067 ArrayList<AppWidgetId> instances = new ArrayList<AppWidgetId>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068 PendingIntent broadcast;
69 boolean zombie; // if we're in safe mode, don't prune this just because nobody references it
70
71 int tag; // for use while saving state (the index)
72 }
73
74 static class Host {
75 int uid;
76 int hostId;
77 String packageName;
Romain Guya5475592009-07-01 17:20:08 -070078 ArrayList<AppWidgetId> instances = new ArrayList<AppWidgetId>();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070079 IAppWidgetHost callbacks;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 boolean zombie; // if we're in safe mode, don't prune this just because nobody references it
81
82 int tag; // for use while saving state (the index)
83 }
84
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070085 static class AppWidgetId {
86 int appWidgetId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 Provider provider;
88 RemoteViews views;
89 Host host;
90 }
91
Winson Chung81f39eb2011-01-11 18:05:01 -080092 /**
93 * Acts as a proxy between the ServiceConnection and the RemoteViewsAdapterConnection.
94 * This needs to be a static inner class since a reference to the ServiceConnection is held
95 * globally and may lead us to leak AppWidgetService instances (if there were more than one).
96 */
97 static class ServiceConnectionProxy implements ServiceConnection {
Winson Chung81f39eb2011-01-11 18:05:01 -080098 private final IBinder mConnectionCb;
99
Winson Chung16c8d8a2011-01-20 16:19:33 -0800100 ServiceConnectionProxy(Pair<Integer, Intent.FilterComparison> key, IBinder connectionCb) {
Winson Chung81f39eb2011-01-11 18:05:01 -0800101 mConnectionCb = connectionCb;
102 }
103 public void onServiceConnected(ComponentName name, IBinder service) {
Winson Chung16c8d8a2011-01-20 16:19:33 -0800104 final IRemoteViewsAdapterConnection cb =
Winson Chung81f39eb2011-01-11 18:05:01 -0800105 IRemoteViewsAdapterConnection.Stub.asInterface(mConnectionCb);
106 try {
107 cb.onServiceConnected(service);
Adam Cohenc2be22c2011-03-16 16:33:53 -0700108 } catch (Exception e) {
Winson Chung81f39eb2011-01-11 18:05:01 -0800109 e.printStackTrace();
110 }
111 }
112 public void onServiceDisconnected(ComponentName name) {
Winson Chung16c8d8a2011-01-20 16:19:33 -0800113 disconnect();
114 }
115 public void disconnect() {
116 final IRemoteViewsAdapterConnection cb =
Winson Chung81f39eb2011-01-11 18:05:01 -0800117 IRemoteViewsAdapterConnection.Stub.asInterface(mConnectionCb);
118 try {
119 cb.onServiceDisconnected();
Adam Cohenc2be22c2011-03-16 16:33:53 -0700120 } catch (Exception e) {
Winson Chung81f39eb2011-01-11 18:05:01 -0800121 e.printStackTrace();
122 }
123 }
124 }
125
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 Context mContext;
Eric Fischer63c2d9e2009-10-22 15:22:50 -0700127 Locale mLocale;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 PackageManager mPackageManager;
129 AlarmManager mAlarmManager;
Romain Guya5475592009-07-01 17:20:08 -0700130 ArrayList<Provider> mInstalledProviders = new ArrayList<Provider>();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700131 int mNextAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID + 1;
Romain Guya5475592009-07-01 17:20:08 -0700132 final ArrayList<AppWidgetId> mAppWidgetIds = new ArrayList<AppWidgetId>();
133 ArrayList<Host> mHosts = new ArrayList<Host>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 boolean mSafeMode;
135
Amith Yamasani742a6712011-05-04 14:49:28 -0700136
137 private final SparseArray<AppWidgetServiceImpl> mAppWidgetServices;
Adam Cohen7bb98832011-10-05 18:10:13 -0700138
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700139 AppWidgetService(Context context) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 mContext = context;
Amith Yamasani742a6712011-05-04 14:49:28 -0700141 mAppWidgetServices = new SparseArray<AppWidgetServiceImpl>(5);
142 AppWidgetServiceImpl primary = new AppWidgetServiceImpl(context, 0);
143 mAppWidgetServices.append(0, primary);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 }
145
146 public void systemReady(boolean safeMode) {
147 mSafeMode = safeMode;
148
Amith Yamasani742a6712011-05-04 14:49:28 -0700149 mAppWidgetServices.get(0).systemReady(safeMode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150
151 // Register for the boot completed broadcast, so we can send the
Amith Yamasani742a6712011-05-04 14:49:28 -0700152 // ENABLE broacasts. If we try to send them now, they time out,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 // because the system isn't ready to handle them yet.
154 mContext.registerReceiver(mBroadcastReceiver,
155 new IntentFilter(Intent.ACTION_BOOT_COMPLETED), null, null);
156
Eric Fischer63c2d9e2009-10-22 15:22:50 -0700157 // Register for configuration changes so we can update the names
158 // of the widgets when the locale changes.
Amith Yamasani742a6712011-05-04 14:49:28 -0700159 mContext.registerReceiver(mBroadcastReceiver, new IntentFilter(
160 Intent.ACTION_CONFIGURATION_CHANGED), null, null);
Eric Fischer63c2d9e2009-10-22 15:22:50 -0700161
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 // Register for broadcasts about package install, etc., so we can
163 // update the provider list.
164 IntentFilter filter = new IntentFilter();
165 filter.addAction(Intent.ACTION_PACKAGE_ADDED);
Joe Onoratod070e892011-01-07 20:50:37 -0800166 filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
168 filter.addDataScheme("package");
169 mContext.registerReceiver(mBroadcastReceiver, filter);
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);
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800174 mContext.registerReceiver(mBroadcastReceiver, sdFilter);
Amith Yamasani13593602012-03-22 16:16:17 -0700175
176 IntentFilter userFilter = new IntentFilter();
177 userFilter.addAction(Intent.ACTION_USER_REMOVED);
178 mContext.registerReceiver(new BroadcastReceiver() {
179 @Override
180 public void onReceive(Context context, Intent intent) {
Amith Yamasani2a003292012-08-14 18:25:45 -0700181 onUserRemoved(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1));
Amith Yamasani13593602012-03-22 16:16:17 -0700182 }
183 }, userFilter);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184 }
185
Amith Yamasani742a6712011-05-04 14:49:28 -0700186 @Override
187 public int allocateAppWidgetId(String packageName, int hostId) throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700188 return getImplForUser(UserHandle.getCallingUserId()).allocateAppWidgetId(
189 packageName, hostId);
Jeff Sharkey15d161f2011-09-01 21:30:56 -0700190 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700191
192 @Override
193 public void deleteAppWidgetId(int appWidgetId) throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700194 getImplForUser(UserHandle.getCallingUserId()).deleteAppWidgetId(appWidgetId);
Adam Cohen7bb98832011-10-05 18:10:13 -0700195 }
196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 @Override
Amith Yamasani742a6712011-05-04 14:49:28 -0700198 public void deleteHost(int hostId) throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700199 getImplForUser(UserHandle.getCallingUserId()).deleteHost(hostId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200 }
201
Amith Yamasani742a6712011-05-04 14:49:28 -0700202 @Override
203 public void deleteAllHosts() throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700204 getImplForUser(UserHandle.getCallingUserId()).deleteAllHosts();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 }
206
Amith Yamasani742a6712011-05-04 14:49:28 -0700207 @Override
208 public void bindAppWidgetId(int appWidgetId, ComponentName provider) throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700209 getImplForUser(UserHandle.getCallingUserId()).bindAppWidgetId(appWidgetId, provider);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 }
211
Amith Yamasani742a6712011-05-04 14:49:28 -0700212 @Override
Michael Jurka61a5b012012-04-13 10:39:45 -0700213 public boolean bindAppWidgetIdIfAllowed(
214 String packageName, int appWidgetId, ComponentName provider) throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700215 return getImplForUser(UserHandle.getCallingUserId()).bindAppWidgetIdIfAllowed(
216 packageName, appWidgetId, provider);
Michael Jurka61a5b012012-04-13 10:39:45 -0700217 }
218
219 @Override
220 public boolean hasBindAppWidgetPermission(String packageName) throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700221 return getImplForUser(UserHandle.getCallingUserId()).hasBindAppWidgetPermission(
222 packageName);
Michael Jurka61a5b012012-04-13 10:39:45 -0700223 }
224
225 @Override
226 public void setBindAppWidgetPermission(String packageName, boolean permission)
227 throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700228 getImplForUser(UserHandle.getCallingUserId()).setBindAppWidgetPermission(
229 packageName, permission);
Michael Jurka61a5b012012-04-13 10:39:45 -0700230 }
231
232 @Override
Amith Yamasani742a6712011-05-04 14:49:28 -0700233 public void bindRemoteViewsService(int appWidgetId, Intent intent, IBinder connection)
234 throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700235 getImplForUser(UserHandle.getCallingUserId()).bindRemoteViewsService(
236 appWidgetId, intent, connection);
Winson Chung81f39eb2011-01-11 18:05:01 -0800237 }
238
Amith Yamasani742a6712011-05-04 14:49:28 -0700239 @Override
240 public int[] startListening(IAppWidgetHost host, String packageName, int hostId,
241 List<RemoteViews> updatedViews) throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700242 return getImplForUser(UserHandle.getCallingUserId()).startListening(host,
243 packageName, hostId, updatedViews);
Winson Chung81f39eb2011-01-11 18:05:01 -0800244 }
245
Amith Yamasani13593602012-03-22 16:16:17 -0700246 public void onUserRemoved(int userId) {
247 AppWidgetServiceImpl impl = mAppWidgetServices.get(userId);
248 if (userId < 1) return;
249
250 if (impl == null) {
251 AppWidgetServiceImpl.getSettingsFile(userId).delete();
252 } else {
253 impl.onUserRemoved();
254 }
Winson Chung84bbb022011-02-21 13:57:45 -0800255 }
256
Dianne Hackborn41203752012-08-31 14:05:51 -0700257 private AppWidgetServiceImpl getImplForUser(int userId) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700258 AppWidgetServiceImpl service = mAppWidgetServices.get(userId);
259 if (service == null) {
260 Slog.e(TAG, "Unable to find AppWidgetServiceImpl for the current user");
261 // TODO: Verify that it's a valid user
262 service = new AppWidgetServiceImpl(mContext, userId);
263 service.systemReady(mSafeMode);
264 // Assume that BOOT_COMPLETED was received, as this is a non-primary user.
265 service.sendInitialBroadcasts();
266 mAppWidgetServices.append(userId, service);
Winson Chung84bbb022011-02-21 13:57:45 -0800267 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700268
269 return service;
Winson Chung84bbb022011-02-21 13:57:45 -0800270 }
271
Amith Yamasani742a6712011-05-04 14:49:28 -0700272 @Override
273 public int[] getAppWidgetIds(ComponentName provider) throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700274 return getImplForUser(UserHandle.getCallingUserId()).getAppWidgetIds(provider);
Winson Chung84bbb022011-02-21 13:57:45 -0800275 }
276
Amith Yamasani742a6712011-05-04 14:49:28 -0700277 @Override
278 public AppWidgetProviderInfo getAppWidgetInfo(int appWidgetId) throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700279 return getImplForUser(UserHandle.getCallingUserId()).getAppWidgetInfo(appWidgetId);
Winson Chung81f39eb2011-01-11 18:05:01 -0800280 }
281
Amith Yamasani742a6712011-05-04 14:49:28 -0700282 @Override
283 public RemoteViews getAppWidgetViews(int appWidgetId) throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700284 return getImplForUser(UserHandle.getCallingUserId()).getAppWidgetViews(appWidgetId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 }
286
Adam Cohene8724c82012-04-19 17:11:40 -0700287 @Override
Adam Cohend2097eb2012-05-01 18:10:28 -0700288 public void updateAppWidgetOptions(int appWidgetId, Bundle options) {
Dianne Hackborn41203752012-08-31 14:05:51 -0700289 getImplForUser(UserHandle.getCallingUserId()).updateAppWidgetOptions(appWidgetId, options);
Adam Cohene8724c82012-04-19 17:11:40 -0700290 }
291
292 @Override
Adam Cohend2097eb2012-05-01 18:10:28 -0700293 public Bundle getAppWidgetOptions(int appWidgetId) {
Dianne Hackborn41203752012-08-31 14:05:51 -0700294 return getImplForUser(UserHandle.getCallingUserId()).getAppWidgetOptions(appWidgetId);
Adam Cohene8724c82012-04-19 17:11:40 -0700295 }
296
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700297 static int[] getAppWidgetIds(Provider p) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800298 int instancesSize = p.instances.size();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700299 int appWidgetIds[] = new int[instancesSize];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800300 for (int i=0; i<instancesSize; i++) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700301 appWidgetIds[i] = p.instances.get(i).appWidgetId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800302 }
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700303 return appWidgetIds;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700305
306 @Override
307 public List<AppWidgetProviderInfo> getInstalledProviders() throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700308 return getImplForUser(UserHandle.getCallingUserId()).getInstalledProviders();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800309 }
310
Amith Yamasani742a6712011-05-04 14:49:28 -0700311 @Override
312 public void notifyAppWidgetViewDataChanged(int[] appWidgetIds, int viewId)
313 throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700314 getImplForUser(UserHandle.getCallingUserId()).notifyAppWidgetViewDataChanged(
315 appWidgetIds, viewId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316 }
317
Amith Yamasani742a6712011-05-04 14:49:28 -0700318 @Override
319 public void partiallyUpdateAppWidgetIds(int[] appWidgetIds, RemoteViews views)
320 throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700321 getImplForUser(UserHandle.getCallingUserId()).partiallyUpdateAppWidgetIds(
322 appWidgetIds, views);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323 }
324
Amith Yamasani742a6712011-05-04 14:49:28 -0700325 @Override
326 public void stopListening(int hostId) throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700327 getImplForUser(UserHandle.getCallingUserId()).stopListening(hostId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800328 }
329
Amith Yamasani742a6712011-05-04 14:49:28 -0700330 @Override
331 public void unbindRemoteViewsService(int appWidgetId, Intent intent) throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700332 getImplForUser(UserHandle.getCallingUserId()).unbindRemoteViewsService(
333 appWidgetId, intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334 }
335
Amith Yamasani742a6712011-05-04 14:49:28 -0700336 @Override
337 public void updateAppWidgetIds(int[] appWidgetIds, RemoteViews views) throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700338 getImplForUser(UserHandle.getCallingUserId()).updateAppWidgetIds(appWidgetIds, views);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339 }
Adam Cohen97300312011-10-12 15:48:13 -0700340
Amith Yamasani742a6712011-05-04 14:49:28 -0700341 @Override
342 public void updateAppWidgetProvider(ComponentName provider, RemoteViews views)
343 throws RemoteException {
Dianne Hackborn41203752012-08-31 14:05:51 -0700344 getImplForUser(UserHandle.getCallingUserId()).updateAppWidgetProvider(provider, views);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345 }
346
Amith Yamasani742a6712011-05-04 14:49:28 -0700347 @Override
348 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
349 // Dump the state of all the app widget providers
350 for (int i = 0; i < mAppWidgetServices.size(); i++) {
351 AppWidgetServiceImpl service = mAppWidgetServices.valueAt(i);
352 service.dump(fd, pw, args);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800353 }
354 }
355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
357 public void onReceive(Context context, Intent intent) {
358 String action = intent.getAction();
Amith Yamasani742a6712011-05-04 14:49:28 -0700359 // Slog.d(TAG, "received " + action);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360 if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
Dianne Hackborn41203752012-08-31 14:05:51 -0700361 int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
362 if (userId >= 0) {
363 getImplForUser(userId).sendInitialBroadcasts();
364 } else {
365 Slog.w(TAG, "Not user handle supplied in " + intent);
366 }
Eric Fischer63c2d9e2009-10-22 15:22:50 -0700367 } else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700368 for (int i = 0; i < mAppWidgetServices.size(); i++) {
369 AppWidgetServiceImpl service = mAppWidgetServices.valueAt(i);
370 service.onConfigurationChanged();
Eric Fischer63c2d9e2009-10-22 15:22:50 -0700371 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 } else {
Amith Yamasani483f3b02012-03-13 16:08:00 -0700373 for (int i = 0; i < mAppWidgetServices.size(); i++) {
374 AppWidgetServiceImpl service = mAppWidgetServices.valueAt(i);
375 service.onBroadcastReceived(intent);
376 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 }
378 }
379 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380}