blob: 9be70454cccba5ba95fb6e12136f6da731a089c9 [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 Project9066cfe2009-03-03 19:31:44 -080020import android.app.AlarmManager;
21import android.app.PendingIntent;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070022import android.appwidget.AppWidgetManager;
23import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.content.BroadcastReceiver;
25import android.content.ComponentName;
26import android.content.Context;
27import android.content.Intent;
28import android.content.IntentFilter;
Winson Chung81f39eb2011-01-11 18:05:01 -080029import android.content.ServiceConnection;
Winson Chung81f39eb2011-01-11 18:05:01 -080030import android.content.pm.PackageManager;
Amith Yamasani8fd96ec2012-09-21 17:48:49 -070031import android.os.Binder;
Adam Cohene8724c82012-04-19 17:11:40 -070032import android.os.Bundle;
Winson Chung81f39eb2011-01-11 18:05:01 -080033import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.os.RemoteException;
Dianne Hackborn41203752012-08-31 14:05:51 -070035import android.os.UserHandle;
Winson Chung81f39eb2011-01-11 18:05:01 -080036import android.util.Pair;
Joe Onorato8a9b2202010-02-26 18:56:32 -080037import android.util.Slog;
Amith Yamasani742a6712011-05-04 14:49:28 -070038import android.util.SparseArray;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.widget.RemoteViews;
40
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070041import com.android.internal.appwidget.IAppWidgetHost;
Winson Chung81f39eb2011-01-11 18:05:01 -080042import com.android.internal.appwidget.IAppWidgetService;
Winson Chung81f39eb2011-01-11 18:05:01 -080043import com.android.internal.widget.IRemoteViewsAdapterConnection;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044
Adam Cohen97300312011-10-12 15:48:13 -070045import java.io.FileDescriptor;
Adam Cohen97300312011-10-12 15:48:13 -070046import java.io.PrintWriter;
47import java.util.ArrayList;
Adam Cohen97300312011-10-12 15:48:13 -070048import java.util.List;
49import java.util.Locale;
50
Amith Yamasani742a6712011-05-04 14:49:28 -070051
52/**
53 * Redirects calls to this service to the instance of the service for the appropriate user.
54 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070055class AppWidgetService extends IAppWidgetService.Stub
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056{
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070057 private static final String TAG = "AppWidgetService";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059 /*
60 * When identifying a Host or Provider based on the calling process, use the uid field.
61 * When identifying a Host or Provider based on a package manager broadcast, use the
62 * package given.
63 */
64
65 static class Provider {
66 int uid;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070067 AppWidgetProviderInfo info;
Romain Guya5475592009-07-01 17:20:08 -070068 ArrayList<AppWidgetId> instances = new ArrayList<AppWidgetId>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 PendingIntent broadcast;
70 boolean zombie; // if we're in safe mode, don't prune this just because nobody references it
71
72 int tag; // for use while saving state (the index)
73 }
74
75 static class Host {
76 int uid;
77 int hostId;
78 String packageName;
Romain Guya5475592009-07-01 17:20:08 -070079 ArrayList<AppWidgetId> instances = new ArrayList<AppWidgetId>();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070080 IAppWidgetHost callbacks;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 boolean zombie; // if we're in safe mode, don't prune this just because nobody references it
82
83 int tag; // for use while saving state (the index)
84 }
85
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070086 static class AppWidgetId {
87 int appWidgetId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088 Provider provider;
89 RemoteViews views;
90 Host host;
91 }
92
Winson Chung81f39eb2011-01-11 18:05:01 -080093 /**
94 * Acts as a proxy between the ServiceConnection and the RemoteViewsAdapterConnection.
95 * This needs to be a static inner class since a reference to the ServiceConnection is held
96 * globally and may lead us to leak AppWidgetService instances (if there were more than one).
97 */
98 static class ServiceConnectionProxy implements ServiceConnection {
Winson Chung81f39eb2011-01-11 18:05:01 -080099 private final IBinder mConnectionCb;
100
Winson Chung16c8d8a2011-01-20 16:19:33 -0800101 ServiceConnectionProxy(Pair<Integer, Intent.FilterComparison> key, IBinder connectionCb) {
Winson Chung81f39eb2011-01-11 18:05:01 -0800102 mConnectionCb = connectionCb;
103 }
104 public void onServiceConnected(ComponentName name, IBinder service) {
Winson Chung16c8d8a2011-01-20 16:19:33 -0800105 final IRemoteViewsAdapterConnection cb =
Winson Chung81f39eb2011-01-11 18:05:01 -0800106 IRemoteViewsAdapterConnection.Stub.asInterface(mConnectionCb);
107 try {
108 cb.onServiceConnected(service);
Adam Cohenc2be22c2011-03-16 16:33:53 -0700109 } catch (Exception e) {
Winson Chung81f39eb2011-01-11 18:05:01 -0800110 e.printStackTrace();
111 }
112 }
113 public void onServiceDisconnected(ComponentName name) {
Winson Chung16c8d8a2011-01-20 16:19:33 -0800114 disconnect();
115 }
116 public void disconnect() {
117 final IRemoteViewsAdapterConnection cb =
Winson Chung81f39eb2011-01-11 18:05:01 -0800118 IRemoteViewsAdapterConnection.Stub.asInterface(mConnectionCb);
119 try {
120 cb.onServiceDisconnected();
Adam Cohenc2be22c2011-03-16 16:33:53 -0700121 } catch (Exception e) {
Winson Chung81f39eb2011-01-11 18:05:01 -0800122 e.printStackTrace();
123 }
124 }
125 }
126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127 Context mContext;
Eric Fischer63c2d9e2009-10-22 15:22:50 -0700128 Locale mLocale;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 PackageManager mPackageManager;
130 AlarmManager mAlarmManager;
Romain Guya5475592009-07-01 17:20:08 -0700131 ArrayList<Provider> mInstalledProviders = new ArrayList<Provider>();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700132 int mNextAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID + 1;
Romain Guya5475592009-07-01 17:20:08 -0700133 final ArrayList<AppWidgetId> mAppWidgetIds = new ArrayList<AppWidgetId>();
134 ArrayList<Host> mHosts = new ArrayList<Host>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 boolean mSafeMode;
136
Amith Yamasani742a6712011-05-04 14:49:28 -0700137
138 private final SparseArray<AppWidgetServiceImpl> mAppWidgetServices;
Adam Cohen7bb98832011-10-05 18:10:13 -0700139
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700140 AppWidgetService(Context context) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 mContext = context;
Amith Yamasani742a6712011-05-04 14:49:28 -0700142 mAppWidgetServices = new SparseArray<AppWidgetServiceImpl>(5);
143 AppWidgetServiceImpl primary = new AppWidgetServiceImpl(context, 0);
144 mAppWidgetServices.append(0, primary);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 }
146
147 public void systemReady(boolean safeMode) {
148 mSafeMode = safeMode;
149
Amith Yamasani742a6712011-05-04 14:49:28 -0700150 mAppWidgetServices.get(0).systemReady(safeMode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151
152 // Register for the boot completed broadcast, so we can send the
Amith Yamasani742a6712011-05-04 14:49:28 -0700153 // ENABLE broacasts. If we try to send them now, they time out,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 // because the system isn't ready to handle them yet.
Dianne Hackborn20e80982012-08-31 19:00:44 -0700155 mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 new IntentFilter(Intent.ACTION_BOOT_COMPLETED), null, null);
157
Eric Fischer63c2d9e2009-10-22 15:22:50 -0700158 // Register for configuration changes so we can update the names
159 // of the widgets when the locale changes.
Dianne Hackbornfd8bf5c2012-09-04 18:48:37 -0700160 mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL,
161 new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED), null, null);
Eric Fischer63c2d9e2009-10-22 15:22:50 -0700162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 // Register for broadcasts about package install, etc., so we can
164 // update the provider list.
165 IntentFilter filter = new IntentFilter();
166 filter.addAction(Intent.ACTION_PACKAGE_ADDED);
Joe Onoratod070e892011-01-07 20:50:37 -0800167 filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
169 filter.addDataScheme("package");
Dianne Hackborn20e80982012-08-31 19:00:44 -0700170 mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL,
171 filter, null, null);
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800172 // Register for events related to sdcard installation.
173 IntentFilter sdFilter = new IntentFilter();
Suchi Amalapurapub56ae202010-02-04 22:51:07 -0800174 sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
175 sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
Dianne Hackborn20e80982012-08-31 19:00:44 -0700176 mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL,
177 sdFilter, null, null);
Amith Yamasani13593602012-03-22 16:16:17 -0700178
179 IntentFilter userFilter = new IntentFilter();
180 userFilter.addAction(Intent.ACTION_USER_REMOVED);
181 mContext.registerReceiver(new BroadcastReceiver() {
182 @Override
183 public void onReceive(Context context, Intent intent) {
Amith Yamasani2a003292012-08-14 18:25:45 -0700184 onUserRemoved(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1));
Amith Yamasani13593602012-03-22 16:16:17 -0700185 }
186 }, userFilter);
Dianne Hackborn20e80982012-08-31 19:00:44 -0700187
188 IntentFilter userStopFilter = new IntentFilter();
189 userStopFilter.addAction(Intent.ACTION_USER_STOPPED);
190 mContext.registerReceiverAsUser(new BroadcastReceiver() {
191 @Override
192 public void onReceive(Context context, Intent intent) {
193 onUserStopped(getSendingUserId());
194 }
195 }, UserHandle.ALL, userFilter, null, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800196 }
197
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700198 private int getCallingOrCurrentUserId() {
199 int callingUid = Binder.getCallingUid();
200 if (callingUid == android.os.Process.myUid()) {
201 try {
202 return ActivityManagerNative.getDefault().getCurrentUser().id;
203 } catch (RemoteException re) {
204 return UserHandle.getUserId(callingUid);
205 }
206 } else {
207 return UserHandle.getUserId(callingUid);
208 }
209 }
210
Amith Yamasani742a6712011-05-04 14:49:28 -0700211 @Override
212 public int allocateAppWidgetId(String packageName, int hostId) throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700213 return getImplForUser(getCallingOrCurrentUserId()).allocateAppWidgetId(
Dianne Hackborn41203752012-08-31 14:05:51 -0700214 packageName, hostId);
Jeff Sharkey15d161f2011-09-01 21:30:56 -0700215 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700216
217 @Override
218 public void deleteAppWidgetId(int appWidgetId) throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700219 getImplForUser(getCallingOrCurrentUserId()).deleteAppWidgetId(appWidgetId);
Adam Cohen7bb98832011-10-05 18:10:13 -0700220 }
221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 @Override
Amith Yamasani742a6712011-05-04 14:49:28 -0700223 public void deleteHost(int hostId) throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700224 getImplForUser(getCallingOrCurrentUserId()).deleteHost(hostId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 }
226
Amith Yamasani742a6712011-05-04 14:49:28 -0700227 @Override
228 public void deleteAllHosts() throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700229 getImplForUser(getCallingOrCurrentUserId()).deleteAllHosts();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 }
231
Amith Yamasani742a6712011-05-04 14:49:28 -0700232 @Override
Adam Cohen0aa2d422012-09-07 17:37:26 -0700233 public void bindAppWidgetId(int appWidgetId, ComponentName provider, Bundle options)
234 throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700235 getImplForUser(getCallingOrCurrentUserId()).bindAppWidgetId(appWidgetId, provider,
Adam Cohen0aa2d422012-09-07 17:37:26 -0700236 options);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237 }
238
Amith Yamasani742a6712011-05-04 14:49:28 -0700239 @Override
Michael Jurka61a5b012012-04-13 10:39:45 -0700240 public boolean bindAppWidgetIdIfAllowed(
Adam Cohen0aa2d422012-09-07 17:37:26 -0700241 String packageName, int appWidgetId, ComponentName provider, Bundle options)
242 throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700243 return getImplForUser(getCallingOrCurrentUserId()).bindAppWidgetIdIfAllowed(
Adam Cohen0aa2d422012-09-07 17:37:26 -0700244 packageName, appWidgetId, provider, options);
Michael Jurka61a5b012012-04-13 10:39:45 -0700245 }
246
247 @Override
248 public boolean hasBindAppWidgetPermission(String packageName) throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700249 return getImplForUser(getCallingOrCurrentUserId()).hasBindAppWidgetPermission(
Dianne Hackborn41203752012-08-31 14:05:51 -0700250 packageName);
Michael Jurka61a5b012012-04-13 10:39:45 -0700251 }
252
253 @Override
254 public void setBindAppWidgetPermission(String packageName, boolean permission)
255 throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700256 getImplForUser(getCallingOrCurrentUserId()).setBindAppWidgetPermission(
Dianne Hackborn41203752012-08-31 14:05:51 -0700257 packageName, permission);
Michael Jurka61a5b012012-04-13 10:39:45 -0700258 }
259
260 @Override
Amith Yamasani742a6712011-05-04 14:49:28 -0700261 public void bindRemoteViewsService(int appWidgetId, Intent intent, IBinder connection)
262 throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700263 getImplForUser(getCallingOrCurrentUserId()).bindRemoteViewsService(
Dianne Hackborn41203752012-08-31 14:05:51 -0700264 appWidgetId, intent, connection);
Winson Chung81f39eb2011-01-11 18:05:01 -0800265 }
266
Amith Yamasani742a6712011-05-04 14:49:28 -0700267 @Override
268 public int[] startListening(IAppWidgetHost host, String packageName, int hostId,
269 List<RemoteViews> updatedViews) throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700270 return getImplForUser(getCallingOrCurrentUserId()).startListening(host,
Dianne Hackborn41203752012-08-31 14:05:51 -0700271 packageName, hostId, updatedViews);
Winson Chung81f39eb2011-01-11 18:05:01 -0800272 }
273
Amith Yamasani13593602012-03-22 16:16:17 -0700274 public void onUserRemoved(int userId) {
275 AppWidgetServiceImpl impl = mAppWidgetServices.get(userId);
276 if (userId < 1) return;
277
278 if (impl == null) {
279 AppWidgetServiceImpl.getSettingsFile(userId).delete();
280 } else {
281 impl.onUserRemoved();
282 }
Winson Chung84bbb022011-02-21 13:57:45 -0800283 }
284
Dianne Hackborn20e80982012-08-31 19:00:44 -0700285 public void onUserStopped(int userId) {
286 }
287
Dianne Hackborn41203752012-08-31 14:05:51 -0700288 private AppWidgetServiceImpl getImplForUser(int userId) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700289 AppWidgetServiceImpl service = mAppWidgetServices.get(userId);
290 if (service == null) {
291 Slog.e(TAG, "Unable to find AppWidgetServiceImpl for the current user");
292 // TODO: Verify that it's a valid user
293 service = new AppWidgetServiceImpl(mContext, userId);
294 service.systemReady(mSafeMode);
295 // Assume that BOOT_COMPLETED was received, as this is a non-primary user.
296 service.sendInitialBroadcasts();
297 mAppWidgetServices.append(userId, service);
Winson Chung84bbb022011-02-21 13:57:45 -0800298 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700299
300 return service;
Winson Chung84bbb022011-02-21 13:57:45 -0800301 }
302
Amith Yamasani742a6712011-05-04 14:49:28 -0700303 @Override
304 public int[] getAppWidgetIds(ComponentName provider) throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700305 return getImplForUser(getCallingOrCurrentUserId()).getAppWidgetIds(provider);
Winson Chung84bbb022011-02-21 13:57:45 -0800306 }
307
Amith Yamasani742a6712011-05-04 14:49:28 -0700308 @Override
309 public AppWidgetProviderInfo getAppWidgetInfo(int appWidgetId) throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700310 return getImplForUser(getCallingOrCurrentUserId()).getAppWidgetInfo(appWidgetId);
Winson Chung81f39eb2011-01-11 18:05:01 -0800311 }
312
Amith Yamasani742a6712011-05-04 14:49:28 -0700313 @Override
314 public RemoteViews getAppWidgetViews(int appWidgetId) throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700315 return getImplForUser(getCallingOrCurrentUserId()).getAppWidgetViews(appWidgetId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316 }
317
Adam Cohene8724c82012-04-19 17:11:40 -0700318 @Override
Adam Cohend2097eb2012-05-01 18:10:28 -0700319 public void updateAppWidgetOptions(int appWidgetId, Bundle options) {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700320 getImplForUser(getCallingOrCurrentUserId()).updateAppWidgetOptions(appWidgetId, options);
Adam Cohene8724c82012-04-19 17:11:40 -0700321 }
322
323 @Override
Adam Cohend2097eb2012-05-01 18:10:28 -0700324 public Bundle getAppWidgetOptions(int appWidgetId) {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700325 return getImplForUser(getCallingOrCurrentUserId()).getAppWidgetOptions(appWidgetId);
Adam Cohene8724c82012-04-19 17:11:40 -0700326 }
327
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700328 static int[] getAppWidgetIds(Provider p) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329 int instancesSize = p.instances.size();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700330 int appWidgetIds[] = new int[instancesSize];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 for (int i=0; i<instancesSize; i++) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700332 appWidgetIds[i] = p.instances.get(i).appWidgetId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333 }
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700334 return appWidgetIds;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335 }
Amith Yamasani742a6712011-05-04 14:49:28 -0700336
337 @Override
338 public List<AppWidgetProviderInfo> getInstalledProviders() throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700339 return getImplForUser(getCallingOrCurrentUserId()).getInstalledProviders();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340 }
341
Amith Yamasani742a6712011-05-04 14:49:28 -0700342 @Override
343 public void notifyAppWidgetViewDataChanged(int[] appWidgetIds, int viewId)
344 throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700345 getImplForUser(getCallingOrCurrentUserId()).notifyAppWidgetViewDataChanged(
Dianne Hackborn41203752012-08-31 14:05:51 -0700346 appWidgetIds, viewId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800347 }
348
Amith Yamasani742a6712011-05-04 14:49:28 -0700349 @Override
350 public void partiallyUpdateAppWidgetIds(int[] appWidgetIds, RemoteViews views)
351 throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700352 getImplForUser(getCallingOrCurrentUserId()).partiallyUpdateAppWidgetIds(
Dianne Hackborn41203752012-08-31 14:05:51 -0700353 appWidgetIds, views);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 }
355
Amith Yamasani742a6712011-05-04 14:49:28 -0700356 @Override
357 public void stopListening(int hostId) throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700358 getImplForUser(getCallingOrCurrentUserId()).stopListening(hostId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359 }
360
Amith Yamasani742a6712011-05-04 14:49:28 -0700361 @Override
362 public void unbindRemoteViewsService(int appWidgetId, Intent intent) throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700363 getImplForUser(getCallingOrCurrentUserId()).unbindRemoteViewsService(
Dianne Hackborn41203752012-08-31 14:05:51 -0700364 appWidgetId, intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800365 }
366
Amith Yamasani742a6712011-05-04 14:49:28 -0700367 @Override
368 public void updateAppWidgetIds(int[] appWidgetIds, RemoteViews views) throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700369 getImplForUser(getCallingOrCurrentUserId()).updateAppWidgetIds(appWidgetIds, views);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 }
Adam Cohen97300312011-10-12 15:48:13 -0700371
Amith Yamasani742a6712011-05-04 14:49:28 -0700372 @Override
373 public void updateAppWidgetProvider(ComponentName provider, RemoteViews views)
374 throws RemoteException {
Amith Yamasani8fd96ec2012-09-21 17:48:49 -0700375 getImplForUser(getCallingOrCurrentUserId()).updateAppWidgetProvider(provider, views);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 }
377
Amith Yamasani742a6712011-05-04 14:49:28 -0700378 @Override
379 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
380 // Dump the state of all the app widget providers
381 for (int i = 0; i < mAppWidgetServices.size(); i++) {
382 AppWidgetServiceImpl service = mAppWidgetServices.valueAt(i);
383 service.dump(fd, pw, args);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 }
385 }
386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
388 public void onReceive(Context context, Intent intent) {
389 String action = intent.getAction();
Amith Yamasani742a6712011-05-04 14:49:28 -0700390 // Slog.d(TAG, "received " + action);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
Dianne Hackborn41203752012-08-31 14:05:51 -0700392 int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
393 if (userId >= 0) {
394 getImplForUser(userId).sendInitialBroadcasts();
395 } else {
396 Slog.w(TAG, "Not user handle supplied in " + intent);
397 }
Eric Fischer63c2d9e2009-10-22 15:22:50 -0700398 } else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
Amith Yamasani742a6712011-05-04 14:49:28 -0700399 for (int i = 0; i < mAppWidgetServices.size(); i++) {
400 AppWidgetServiceImpl service = mAppWidgetServices.valueAt(i);
401 service.onConfigurationChanged();
Eric Fischer63c2d9e2009-10-22 15:22:50 -0700402 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403 } else {
Dianne Hackborn20e80982012-08-31 19:00:44 -0700404 int sendingUser = getSendingUserId();
405 if (sendingUser == UserHandle.USER_ALL) {
406 for (int i = 0; i < mAppWidgetServices.size(); i++) {
407 AppWidgetServiceImpl service = mAppWidgetServices.valueAt(i);
408 service.onBroadcastReceived(intent);
409 }
410 } else {
411 AppWidgetServiceImpl service = mAppWidgetServices.get(sendingUser);
412 if (service != null) {
413 service.onBroadcastReceived(intent);
414 }
Amith Yamasani483f3b02012-03-13 16:08:00 -0700415 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800416 }
417 }
418 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419}