blob: b94183cd40d92b743e72ff5dacfb0894c959b4ce [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
Amith Yamasani8fd96ec2012-09-21 17:48:49 -070019import android.app.ActivityManagerNative;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070020import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.content.BroadcastReceiver;
22import android.content.ComponentName;
23import android.content.Context;
24import android.content.Intent;
25import android.content.IntentFilter;
Winson Chung81f39eb2011-01-11 18:05:01 -080026import android.content.pm.PackageManager;
Amith Yamasani8fd96ec2012-09-21 17:48:49 -070027import android.os.Binder;
Adam Cohene8724c82012-04-19 17:11:40 -070028import android.os.Bundle;
Adam Cohena1a2f962012-11-01 14:06:16 -070029import android.os.Handler;
30import android.os.HandlerThread;
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;
Joe Onorato8a9b2202010-02-26 18:56:32 -080034import android.util.Slog;
Amith Yamasani742a6712011-05-04 14:49:28 -070035import android.util.SparseArray;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.widget.RemoteViews;
37
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070038import com.android.internal.appwidget.IAppWidgetHost;
Winson Chung81f39eb2011-01-11 18:05:01 -080039import com.android.internal.appwidget.IAppWidgetService;
Amith Yamasani8320de82012-10-05 16:10:38 -070040import com.android.internal.util.IndentingPrintWriter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041
Adam Cohen97300312011-10-12 15:48:13 -070042import java.io.FileDescriptor;
Adam Cohen97300312011-10-12 15:48:13 -070043import java.io.PrintWriter;
Adam Cohen97300312011-10-12 15:48:13 -070044import java.util.List;
45import java.util.Locale;
46
Amith Yamasani742a6712011-05-04 14:49:28 -070047
48/**
49 * Redirects calls to this service to the instance of the service for the appropriate user.
50 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070051class AppWidgetService extends IAppWidgetService.Stub
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052{
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070053 private static final String TAG = "AppWidgetService";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 Context mContext;
Eric Fischer63c2d9e2009-10-22 15:22:50 -070056 Locale mLocale;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057 PackageManager mPackageManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058 boolean mSafeMode;
Adam Cohena1a2f962012-11-01 14:06:16 -070059 private final Handler mSaveStateHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060
Amith Yamasani742a6712011-05-04 14:49:28 -070061 private final SparseArray<AppWidgetServiceImpl> mAppWidgetServices;
Adam Cohen7bb98832011-10-05 18:10:13 -070062
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070063 AppWidgetService(Context context) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064 mContext = context;
Adam Cohena1a2f962012-11-01 14:06:16 -070065
66 HandlerThread handlerThread = new HandlerThread("AppWidgetService -- Save state");
67 handlerThread.start();
68 mSaveStateHandler = new Handler(handlerThread.getLooper());
69
Amith Yamasani742a6712011-05-04 14:49:28 -070070 mAppWidgetServices = new SparseArray<AppWidgetServiceImpl>(5);
Adam Cohena1a2f962012-11-01 14:06:16 -070071 AppWidgetServiceImpl primary = new AppWidgetServiceImpl(context, 0, mSaveStateHandler);
Amith Yamasani742a6712011-05-04 14:49:28 -070072 mAppWidgetServices.append(0, primary);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073 }
74
75 public void systemReady(boolean safeMode) {
76 mSafeMode = safeMode;
77
Amith Yamasani742a6712011-05-04 14:49:28 -070078 mAppWidgetServices.get(0).systemReady(safeMode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079
80 // Register for the boot completed broadcast, so we can send the
Amith Yamasani742a6712011-05-04 14:49:28 -070081 // ENABLE broacasts. If we try to send them now, they time out,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 // because the system isn't ready to handle them yet.
Dianne Hackborn20e80982012-08-31 19:00:44 -070083 mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 new IntentFilter(Intent.ACTION_BOOT_COMPLETED), null, null);
85
Eric Fischer63c2d9e2009-10-22 15:22:50 -070086 // Register for configuration changes so we can update the names
87 // of the widgets when the locale changes.
Dianne Hackbornfd8bf5c2012-09-04 18:48:37 -070088 mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL,
89 new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED), null, null);
Eric Fischer63c2d9e2009-10-22 15:22:50 -070090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 // 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 Onoratod070e892011-01-07 20:50:37 -080095 filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
97 filter.addDataScheme("package");
Dianne Hackborn20e80982012-08-31 19:00:44 -070098 mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL,
99 filter, null, null);
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800100 // Register for events related to sdcard installation.
101 IntentFilter sdFilter = new IntentFilter();
Suchi Amalapurapub56ae202010-02-04 22:51:07 -0800102 sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
103 sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
Dianne Hackborn20e80982012-08-31 19:00:44 -0700104 mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL,
105 sdFilter, null, null);
Amith Yamasani13593602012-03-22 16:16:17 -0700106
107 IntentFilter userFilter = new IntentFilter();
108 userFilter.addAction(Intent.ACTION_USER_REMOVED);
Amith Yamasani756901d2012-10-12 12:30:07 -0700109 userFilter.addAction(Intent.ACTION_USER_STOPPING);
Amith Yamasani13593602012-03-22 16:16:17 -0700110 mContext.registerReceiver(new BroadcastReceiver() {
111 @Override
112 public void onReceive(Context context, Intent intent) {
Amith Yamasani756901d2012-10-12 12:30:07 -0700113 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 Yamasani13593602012-03-22 16:16:17 -0700120 }
121 }, userFilter);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 }
123
Amith Yamasani8320de82012-10-05 16:10:38 -0700124 /**
125 * This returns the user id of the caller, if the caller is not the system process,
126 * otherwise it assumes that the calls are from the lockscreen and hence are meant for the
127 * current user. TODO: Instead, have lockscreen make explicit calls with userId
128 */
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700129 private int getCallingOrCurrentUserId() {
130 int callingUid = Binder.getCallingUid();
Amith Yamasani8320de82012-10-05 16:10:38 -0700131 // Also check the PID because Settings (power control widget) also runs as System UID
132 if (callingUid == android.os.Process.myUid()
133 && Binder.getCallingPid() == android.os.Process.myPid()) {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700134 try {
135 return ActivityManagerNative.getDefault().getCurrentUser().id;
136 } catch (RemoteException re) {
137 return UserHandle.getUserId(callingUid);
138 }
139 } else {
140 return UserHandle.getUserId(callingUid);
141 }
142 }
143
Amith Yamasani742a6712011-05-04 14:49:28 -0700144 @Override
145 public int allocateAppWidgetId(String packageName, int hostId) throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700146 return getImplForUser(getCallingOrCurrentUserId()).allocateAppWidgetId(
Dianne Hackborn41203752012-08-31 14:05:51 -0700147 packageName, hostId);
Jeff Sharkey15d161f2011-09-01 21:30:56 -0700148 }
Michael Jurka75b5cfb2012-11-15 18:22:47 -0800149
150 @Override
151 public int[] getAppWidgetIdsForHost(int hostId) throws RemoteException {
152 return getImplForUser(getCallingOrCurrentUserId()).getAppWidgetIdsForHost(hostId);
153 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700154
155 @Override
156 public void deleteAppWidgetId(int appWidgetId) throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700157 getImplForUser(getCallingOrCurrentUserId()).deleteAppWidgetId(appWidgetId);
Adam Cohen7bb98832011-10-05 18:10:13 -0700158 }
159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 @Override
Amith Yamasani742a6712011-05-04 14:49:28 -0700161 public void deleteHost(int hostId) throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700162 getImplForUser(getCallingOrCurrentUserId()).deleteHost(hostId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 }
164
Amith Yamasani742a6712011-05-04 14:49:28 -0700165 @Override
166 public void deleteAllHosts() throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700167 getImplForUser(getCallingOrCurrentUserId()).deleteAllHosts();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 }
169
Amith Yamasani742a6712011-05-04 14:49:28 -0700170 @Override
Adam Cohen0aa2d422012-09-07 17:37:26 -0700171 public void bindAppWidgetId(int appWidgetId, ComponentName provider, Bundle options)
172 throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700173 getImplForUser(getCallingOrCurrentUserId()).bindAppWidgetId(appWidgetId, provider,
Adam Cohen0aa2d422012-09-07 17:37:26 -0700174 options);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 }
176
Amith Yamasani742a6712011-05-04 14:49:28 -0700177 @Override
Michael Jurka61a5b012012-04-13 10:39:45 -0700178 public boolean bindAppWidgetIdIfAllowed(
Adam Cohen0aa2d422012-09-07 17:37:26 -0700179 String packageName, int appWidgetId, ComponentName provider, Bundle options)
180 throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700181 return getImplForUser(getCallingOrCurrentUserId()).bindAppWidgetIdIfAllowed(
Adam Cohen0aa2d422012-09-07 17:37:26 -0700182 packageName, appWidgetId, provider, options);
Michael Jurka61a5b012012-04-13 10:39:45 -0700183 }
184
185 @Override
186 public boolean hasBindAppWidgetPermission(String packageName) throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700187 return getImplForUser(getCallingOrCurrentUserId()).hasBindAppWidgetPermission(
Dianne Hackborn41203752012-08-31 14:05:51 -0700188 packageName);
Michael Jurka61a5b012012-04-13 10:39:45 -0700189 }
190
191 @Override
192 public void setBindAppWidgetPermission(String packageName, boolean permission)
193 throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700194 getImplForUser(getCallingOrCurrentUserId()).setBindAppWidgetPermission(
Dianne Hackborn41203752012-08-31 14:05:51 -0700195 packageName, permission);
Michael Jurka61a5b012012-04-13 10:39:45 -0700196 }
197
198 @Override
Amith Yamasani742a6712011-05-04 14:49:28 -0700199 public void bindRemoteViewsService(int appWidgetId, Intent intent, IBinder connection)
200 throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700201 getImplForUser(getCallingOrCurrentUserId()).bindRemoteViewsService(
Dianne Hackborn41203752012-08-31 14:05:51 -0700202 appWidgetId, intent, connection);
Winson Chung81f39eb2011-01-11 18:05:01 -0800203 }
204
Amith Yamasani742a6712011-05-04 14:49:28 -0700205 @Override
206 public int[] startListening(IAppWidgetHost host, String packageName, int hostId,
207 List<RemoteViews> updatedViews) throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700208 return getImplForUser(getCallingOrCurrentUserId()).startListening(host,
Dianne Hackborn41203752012-08-31 14:05:51 -0700209 packageName, hostId, updatedViews);
Winson Chung81f39eb2011-01-11 18:05:01 -0800210 }
211
Amith Yamasani13593602012-03-22 16:16:17 -0700212 public void onUserRemoved(int userId) {
Amith Yamasani13593602012-03-22 16:16:17 -0700213 if (userId < 1) return;
Amith Yamasani8320de82012-10-05 16:10:38 -0700214 synchronized (mAppWidgetServices) {
215 AppWidgetServiceImpl impl = mAppWidgetServices.get(userId);
216 mAppWidgetServices.remove(userId);
Amith Yamasani756901d2012-10-12 12:30:07 -0700217
Amith Yamasani8320de82012-10-05 16:10:38 -0700218 if (impl == null) {
219 AppWidgetServiceImpl.getSettingsFile(userId).delete();
220 } else {
221 impl.onUserRemoved();
222 }
Amith Yamasani13593602012-03-22 16:16:17 -0700223 }
Winson Chung84bbb022011-02-21 13:57:45 -0800224 }
225
Amith Yamasani756901d2012-10-12 12:30:07 -0700226 public void onUserStopping(int userId) {
227 if (userId < 1) return;
228 synchronized (mAppWidgetServices) {
229 AppWidgetServiceImpl impl = mAppWidgetServices.get(userId);
230 if (impl != null) {
231 mAppWidgetServices.remove(userId);
232 impl.onUserStopping();
233 }
234 }
Dianne Hackborn20e80982012-08-31 19:00:44 -0700235 }
236
Dianne Hackborn41203752012-08-31 14:05:51 -0700237 private AppWidgetServiceImpl getImplForUser(int userId) {
Amith Yamasani8320de82012-10-05 16:10:38 -0700238 boolean sendInitial = false;
239 AppWidgetServiceImpl service;
240 synchronized (mAppWidgetServices) {
241 service = mAppWidgetServices.get(userId);
242 if (service == null) {
243 Slog.i(TAG, "Unable to find AppWidgetServiceImpl for user " + userId + ", adding");
244 // TODO: Verify that it's a valid user
Adam Cohena1a2f962012-11-01 14:06:16 -0700245 service = new AppWidgetServiceImpl(mContext, userId, mSaveStateHandler);
Amith Yamasani8320de82012-10-05 16:10:38 -0700246 service.systemReady(mSafeMode);
247 // Assume that BOOT_COMPLETED was received, as this is a non-primary user.
248 mAppWidgetServices.append(userId, service);
249 sendInitial = true;
250 }
Winson Chung84bbb022011-02-21 13:57:45 -0800251 }
Amith Yamasani8320de82012-10-05 16:10:38 -0700252 if (sendInitial) {
253 service.sendInitialBroadcasts();
254 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700255 return service;
Winson Chung84bbb022011-02-21 13:57:45 -0800256 }
257
Amith Yamasani742a6712011-05-04 14:49:28 -0700258 @Override
259 public int[] getAppWidgetIds(ComponentName provider) throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700260 return getImplForUser(getCallingOrCurrentUserId()).getAppWidgetIds(provider);
Winson Chung84bbb022011-02-21 13:57:45 -0800261 }
262
Amith Yamasani742a6712011-05-04 14:49:28 -0700263 @Override
264 public AppWidgetProviderInfo getAppWidgetInfo(int appWidgetId) throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700265 return getImplForUser(getCallingOrCurrentUserId()).getAppWidgetInfo(appWidgetId);
Winson Chung81f39eb2011-01-11 18:05:01 -0800266 }
267
Amith Yamasani742a6712011-05-04 14:49:28 -0700268 @Override
269 public RemoteViews getAppWidgetViews(int appWidgetId) throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700270 return getImplForUser(getCallingOrCurrentUserId()).getAppWidgetViews(appWidgetId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271 }
272
Adam Cohene8724c82012-04-19 17:11:40 -0700273 @Override
Adam Cohend2097eb2012-05-01 18:10:28 -0700274 public void updateAppWidgetOptions(int appWidgetId, Bundle options) {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700275 getImplForUser(getCallingOrCurrentUserId()).updateAppWidgetOptions(appWidgetId, options);
Adam Cohene8724c82012-04-19 17:11:40 -0700276 }
277
278 @Override
Adam Cohend2097eb2012-05-01 18:10:28 -0700279 public Bundle getAppWidgetOptions(int appWidgetId) {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700280 return getImplForUser(getCallingOrCurrentUserId()).getAppWidgetOptions(appWidgetId);
Adam Cohene8724c82012-04-19 17:11:40 -0700281 }
282
Amith Yamasani742a6712011-05-04 14:49:28 -0700283 @Override
Adam Cohend9e5af32012-11-28 16:34:57 -0800284 public List<AppWidgetProviderInfo> getInstalledProviders(int categoryFilter)
285 throws RemoteException {
286 return getImplForUser(getCallingOrCurrentUserId()).getInstalledProviders(categoryFilter);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 }
288
Amith Yamasani742a6712011-05-04 14:49:28 -0700289 @Override
290 public void notifyAppWidgetViewDataChanged(int[] appWidgetIds, int viewId)
291 throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700292 getImplForUser(getCallingOrCurrentUserId()).notifyAppWidgetViewDataChanged(
Dianne Hackborn41203752012-08-31 14:05:51 -0700293 appWidgetIds, viewId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294 }
295
Amith Yamasani742a6712011-05-04 14:49:28 -0700296 @Override
297 public void partiallyUpdateAppWidgetIds(int[] appWidgetIds, RemoteViews views)
298 throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700299 getImplForUser(getCallingOrCurrentUserId()).partiallyUpdateAppWidgetIds(
Dianne Hackborn41203752012-08-31 14:05:51 -0700300 appWidgetIds, views);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301 }
302
Amith Yamasani742a6712011-05-04 14:49:28 -0700303 @Override
304 public void stopListening(int hostId) throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700305 getImplForUser(getCallingOrCurrentUserId()).stopListening(hostId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800306 }
307
Amith Yamasani742a6712011-05-04 14:49:28 -0700308 @Override
309 public void unbindRemoteViewsService(int appWidgetId, Intent intent) throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700310 getImplForUser(getCallingOrCurrentUserId()).unbindRemoteViewsService(
Dianne Hackborn41203752012-08-31 14:05:51 -0700311 appWidgetId, intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312 }
313
Amith Yamasani742a6712011-05-04 14:49:28 -0700314 @Override
315 public void updateAppWidgetIds(int[] appWidgetIds, RemoteViews views) throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700316 getImplForUser(getCallingOrCurrentUserId()).updateAppWidgetIds(appWidgetIds, views);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317 }
Adam Cohen97300312011-10-12 15:48:13 -0700318
Amith Yamasani742a6712011-05-04 14:49:28 -0700319 @Override
320 public void updateAppWidgetProvider(ComponentName provider, RemoteViews views)
321 throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700322 getImplForUser(getCallingOrCurrentUserId()).updateAppWidgetProvider(provider, 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 dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Jeff Sharkey52801aa2012-10-12 16:06:16 -0700327 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);
328
Amith Yamasani742a6712011-05-04 14:49:28 -0700329 // Dump the state of all the app widget providers
Amith Yamasani8320de82012-10-05 16:10:38 -0700330 synchronized (mAppWidgetServices) {
331 IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ");
332 for (int i = 0; i < mAppWidgetServices.size(); i++) {
333 pw.println("User: " + mAppWidgetServices.keyAt(i));
334 ipw.increaseIndent();
335 AppWidgetServiceImpl service = mAppWidgetServices.valueAt(i);
336 service.dump(fd, ipw, args);
337 ipw.decreaseIndent();
338 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339 }
340 }
341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
343 public void onReceive(Context context, Intent intent) {
344 String action = intent.getAction();
Amith Yamasani742a6712011-05-04 14:49:28 -0700345 // Slog.d(TAG, "received " + action);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
Amith Yamasani756901d2012-10-12 12:30:07 -0700347 int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
Dianne Hackborn41203752012-08-31 14:05:51 -0700348 if (userId >= 0) {
349 getImplForUser(userId).sendInitialBroadcasts();
350 } else {
Amith Yamasani756901d2012-10-12 12:30:07 -0700351 Slog.w(TAG, "Incorrect user handle supplied in " + intent);
Dianne Hackborn41203752012-08-31 14:05:51 -0700352 }
Eric Fischer63c2d9e2009-10-22 15:22:50 -0700353 } else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700354 for (int i = 0; i < mAppWidgetServices.size(); i++) {
355 AppWidgetServiceImpl service = mAppWidgetServices.valueAt(i);
356 service.onConfigurationChanged();
Eric Fischer63c2d9e2009-10-22 15:22:50 -0700357 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358 } else {
Dianne Hackborn20e80982012-08-31 19:00:44 -0700359 int sendingUser = getSendingUserId();
360 if (sendingUser == UserHandle.USER_ALL) {
361 for (int i = 0; i < mAppWidgetServices.size(); i++) {
362 AppWidgetServiceImpl service = mAppWidgetServices.valueAt(i);
363 service.onBroadcastReceived(intent);
364 }
365 } else {
366 AppWidgetServiceImpl service = mAppWidgetServices.get(sendingUser);
367 if (service != null) {
368 service.onBroadcastReceived(intent);
369 }
Amith Yamasani483f3b02012-03-13 16:08:00 -0700370 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 }
372 }
373 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374}