| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server; |
| 18 | |
| 19 | import android.app.AlarmManager; |
| 20 | import android.app.PendingIntent; |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 21 | import android.appwidget.AppWidgetManager; |
| 22 | import android.appwidget.AppWidgetProviderInfo; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import android.content.BroadcastReceiver; |
| 24 | import android.content.ComponentName; |
| 25 | import android.content.Context; |
| 26 | import android.content.Intent; |
| 27 | import android.content.IntentFilter; |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 28 | import android.content.ServiceConnection; |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 29 | import android.content.pm.PackageManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.os.Binder; |
| Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 31 | import android.os.Bundle; |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 32 | import android.os.IBinder; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import android.os.RemoteException; |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 34 | import android.util.Pair; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 35 | import android.util.Slog; |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 36 | import android.util.SparseArray; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.widget.RemoteViews; |
| 38 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 39 | import com.android.internal.appwidget.IAppWidgetHost; |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 40 | import com.android.internal.appwidget.IAppWidgetService; |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 41 | import com.android.internal.widget.IRemoteViewsAdapterConnection; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | |
| Adam Cohen | 9730031 | 2011-10-12 15:48:13 -0700 | [diff] [blame] | 43 | import java.io.FileDescriptor; |
| Adam Cohen | 9730031 | 2011-10-12 15:48:13 -0700 | [diff] [blame] | 44 | import java.io.PrintWriter; |
| 45 | import java.util.ArrayList; |
| Adam Cohen | 9730031 | 2011-10-12 15:48:13 -0700 | [diff] [blame] | 46 | import java.util.List; |
| 47 | import java.util.Locale; |
| 48 | |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * Redirects calls to this service to the instance of the service for the appropriate user. |
| 52 | */ |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 53 | class AppWidgetService extends IAppWidgetService.Stub |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 55 | private static final String TAG = "AppWidgetService"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | /* |
| 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 Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 65 | AppWidgetProviderInfo info; |
| Romain Guy | a547559 | 2009-07-01 17:20:08 -0700 | [diff] [blame] | 66 | ArrayList<AppWidgetId> instances = new ArrayList<AppWidgetId>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | 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 Guy | a547559 | 2009-07-01 17:20:08 -0700 | [diff] [blame] | 77 | ArrayList<AppWidgetId> instances = new ArrayList<AppWidgetId>(); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 78 | IAppWidgetHost callbacks; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | 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 Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 84 | static class AppWidgetId { |
| 85 | int appWidgetId; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | Provider provider; |
| 87 | RemoteViews views; |
| 88 | Host host; |
| 89 | } |
| 90 | |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 91 | /** |
| 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 Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 97 | private final IBinder mConnectionCb; |
| 98 | |
| Winson Chung | 16c8d8a | 2011-01-20 16:19:33 -0800 | [diff] [blame] | 99 | ServiceConnectionProxy(Pair<Integer, Intent.FilterComparison> key, IBinder connectionCb) { |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 100 | mConnectionCb = connectionCb; |
| 101 | } |
| 102 | public void onServiceConnected(ComponentName name, IBinder service) { |
| Winson Chung | 16c8d8a | 2011-01-20 16:19:33 -0800 | [diff] [blame] | 103 | final IRemoteViewsAdapterConnection cb = |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 104 | IRemoteViewsAdapterConnection.Stub.asInterface(mConnectionCb); |
| 105 | try { |
| 106 | cb.onServiceConnected(service); |
| Adam Cohen | c2be22c | 2011-03-16 16:33:53 -0700 | [diff] [blame] | 107 | } catch (Exception e) { |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 108 | e.printStackTrace(); |
| 109 | } |
| 110 | } |
| 111 | public void onServiceDisconnected(ComponentName name) { |
| Winson Chung | 16c8d8a | 2011-01-20 16:19:33 -0800 | [diff] [blame] | 112 | disconnect(); |
| 113 | } |
| 114 | public void disconnect() { |
| 115 | final IRemoteViewsAdapterConnection cb = |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 116 | IRemoteViewsAdapterConnection.Stub.asInterface(mConnectionCb); |
| 117 | try { |
| 118 | cb.onServiceDisconnected(); |
| Adam Cohen | c2be22c | 2011-03-16 16:33:53 -0700 | [diff] [blame] | 119 | } catch (Exception e) { |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 120 | e.printStackTrace(); |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | Context mContext; |
| Eric Fischer | 63c2d9e | 2009-10-22 15:22:50 -0700 | [diff] [blame] | 126 | Locale mLocale; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | PackageManager mPackageManager; |
| 128 | AlarmManager mAlarmManager; |
| Romain Guy | a547559 | 2009-07-01 17:20:08 -0700 | [diff] [blame] | 129 | ArrayList<Provider> mInstalledProviders = new ArrayList<Provider>(); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 130 | int mNextAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID + 1; |
| Romain Guy | a547559 | 2009-07-01 17:20:08 -0700 | [diff] [blame] | 131 | final ArrayList<AppWidgetId> mAppWidgetIds = new ArrayList<AppWidgetId>(); |
| 132 | ArrayList<Host> mHosts = new ArrayList<Host>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | boolean mSafeMode; |
| 134 | |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 135 | |
| 136 | private final SparseArray<AppWidgetServiceImpl> mAppWidgetServices; |
| Adam Cohen | 7bb9883 | 2011-10-05 18:10:13 -0700 | [diff] [blame] | 137 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 138 | AppWidgetService(Context context) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | mContext = context; |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 140 | mAppWidgetServices = new SparseArray<AppWidgetServiceImpl>(5); |
| 141 | AppWidgetServiceImpl primary = new AppWidgetServiceImpl(context, 0); |
| 142 | mAppWidgetServices.append(0, primary); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | public void systemReady(boolean safeMode) { |
| 146 | mSafeMode = safeMode; |
| 147 | |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 148 | mAppWidgetServices.get(0).systemReady(safeMode); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | |
| 150 | // Register for the boot completed broadcast, so we can send the |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 151 | // ENABLE broacasts. If we try to send them now, they time out, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | // because the system isn't ready to handle them yet. |
| 153 | mContext.registerReceiver(mBroadcastReceiver, |
| 154 | new IntentFilter(Intent.ACTION_BOOT_COMPLETED), null, null); |
| 155 | |
| Eric Fischer | 63c2d9e | 2009-10-22 15:22:50 -0700 | [diff] [blame] | 156 | // Register for configuration changes so we can update the names |
| 157 | // of the widgets when the locale changes. |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 158 | mContext.registerReceiver(mBroadcastReceiver, new IntentFilter( |
| 159 | Intent.ACTION_CONFIGURATION_CHANGED), null, null); |
| Eric Fischer | 63c2d9e | 2009-10-22 15:22:50 -0700 | [diff] [blame] | 160 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | // 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 Onorato | d070e89 | 2011-01-07 20:50:37 -0800 | [diff] [blame] | 165 | filter.addAction(Intent.ACTION_PACKAGE_CHANGED); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | filter.addAction(Intent.ACTION_PACKAGE_REMOVED); |
| 167 | filter.addDataScheme("package"); |
| 168 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 169 | // Register for events related to sdcard installation. |
| 170 | IntentFilter sdFilter = new IntentFilter(); |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 171 | sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE); |
| 172 | sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 173 | mContext.registerReceiver(mBroadcastReceiver, sdFilter); |
| Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 174 | |
| 175 | IntentFilter userFilter = new IntentFilter(); |
| 176 | userFilter.addAction(Intent.ACTION_USER_REMOVED); |
| 177 | mContext.registerReceiver(new BroadcastReceiver() { |
| 178 | @Override |
| 179 | public void onReceive(Context context, Intent intent) { |
| 180 | onUserRemoved(intent.getIntExtra(Intent.EXTRA_USERID, -1)); |
| 181 | } |
| 182 | }, userFilter); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | } |
| 184 | |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 185 | @Override |
| 186 | public int allocateAppWidgetId(String packageName, int hostId) throws RemoteException { |
| 187 | return getImplForUser().allocateAppWidgetId(packageName, hostId); |
| Jeff Sharkey | 15d161f | 2011-09-01 21:30:56 -0700 | [diff] [blame] | 188 | } |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 189 | |
| 190 | @Override |
| 191 | public void deleteAppWidgetId(int appWidgetId) throws RemoteException { |
| 192 | getImplForUser().deleteAppWidgetId(appWidgetId); |
| Adam Cohen | 7bb9883 | 2011-10-05 18:10:13 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 195 | @Override |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 196 | public void deleteHost(int hostId) throws RemoteException { |
| 197 | getImplForUser().deleteHost(hostId); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | } |
| 199 | |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 200 | @Override |
| 201 | public void deleteAllHosts() throws RemoteException { |
| 202 | getImplForUser().deleteAllHosts(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | } |
| 204 | |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 205 | @Override |
| 206 | public void bindAppWidgetId(int appWidgetId, ComponentName provider) throws RemoteException { |
| 207 | getImplForUser().bindAppWidgetId(appWidgetId, provider); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | } |
| 209 | |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 210 | @Override |
| Michael Jurka | 61a5b01 | 2012-04-13 10:39:45 -0700 | [diff] [blame] | 211 | public boolean bindAppWidgetIdIfAllowed( |
| 212 | String packageName, int appWidgetId, ComponentName provider) throws RemoteException { |
| 213 | return getImplForUser().bindAppWidgetIdIfAllowed(packageName, appWidgetId, provider); |
| 214 | } |
| 215 | |
| 216 | @Override |
| 217 | public boolean hasBindAppWidgetPermission(String packageName) throws RemoteException { |
| 218 | return getImplForUser().hasBindAppWidgetPermission(packageName); |
| 219 | } |
| 220 | |
| 221 | @Override |
| 222 | public void setBindAppWidgetPermission(String packageName, boolean permission) |
| 223 | throws RemoteException { |
| 224 | getImplForUser().setBindAppWidgetPermission(packageName, permission); |
| 225 | } |
| 226 | |
| 227 | @Override |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 228 | public void bindRemoteViewsService(int appWidgetId, Intent intent, IBinder connection) |
| 229 | throws RemoteException { |
| 230 | getImplForUser().bindRemoteViewsService(appWidgetId, intent, connection); |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 231 | } |
| 232 | |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 233 | @Override |
| 234 | public int[] startListening(IAppWidgetHost host, String packageName, int hostId, |
| 235 | List<RemoteViews> updatedViews) throws RemoteException { |
| 236 | return getImplForUser().startListening(host, packageName, hostId, updatedViews); |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 237 | } |
| 238 | |
| Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 239 | public void onUserRemoved(int userId) { |
| 240 | AppWidgetServiceImpl impl = mAppWidgetServices.get(userId); |
| 241 | if (userId < 1) return; |
| 242 | |
| 243 | if (impl == null) { |
| 244 | AppWidgetServiceImpl.getSettingsFile(userId).delete(); |
| 245 | } else { |
| 246 | impl.onUserRemoved(); |
| 247 | } |
| Winson Chung | 84bbb02 | 2011-02-21 13:57:45 -0800 | [diff] [blame] | 248 | } |
| 249 | |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 250 | private AppWidgetServiceImpl getImplForUser() { |
| 251 | final int userId = Binder.getOrigCallingUser(); |
| 252 | AppWidgetServiceImpl service = mAppWidgetServices.get(userId); |
| 253 | if (service == null) { |
| 254 | Slog.e(TAG, "Unable to find AppWidgetServiceImpl for the current user"); |
| 255 | // TODO: Verify that it's a valid user |
| 256 | service = new AppWidgetServiceImpl(mContext, userId); |
| 257 | service.systemReady(mSafeMode); |
| 258 | // Assume that BOOT_COMPLETED was received, as this is a non-primary user. |
| 259 | service.sendInitialBroadcasts(); |
| 260 | mAppWidgetServices.append(userId, service); |
| Winson Chung | 84bbb02 | 2011-02-21 13:57:45 -0800 | [diff] [blame] | 261 | } |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 262 | |
| 263 | return service; |
| Winson Chung | 84bbb02 | 2011-02-21 13:57:45 -0800 | [diff] [blame] | 264 | } |
| 265 | |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 266 | @Override |
| 267 | public int[] getAppWidgetIds(ComponentName provider) throws RemoteException { |
| 268 | return getImplForUser().getAppWidgetIds(provider); |
| Winson Chung | 84bbb02 | 2011-02-21 13:57:45 -0800 | [diff] [blame] | 269 | } |
| 270 | |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 271 | @Override |
| 272 | public AppWidgetProviderInfo getAppWidgetInfo(int appWidgetId) throws RemoteException { |
| 273 | return getImplForUser().getAppWidgetInfo(appWidgetId); |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 274 | } |
| 275 | |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 276 | @Override |
| 277 | public RemoteViews getAppWidgetViews(int appWidgetId) throws RemoteException { |
| 278 | return getImplForUser().getAppWidgetViews(appWidgetId); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 279 | } |
| 280 | |
| Adam Cohen | e8724c8 | 2012-04-19 17:11:40 -0700 | [diff] [blame] | 281 | @Override |
| 282 | public void updateAppWidgetExtras(int appWidgetId, Bundle extras) { |
| 283 | getImplForUser().updateAppWidgetExtras(appWidgetId, extras); |
| 284 | } |
| 285 | |
| 286 | @Override |
| 287 | public Bundle getAppWidgetExtras(int appWidgetId) { |
| 288 | return getImplForUser().getAppWidgetExtras(appWidgetId); |
| 289 | } |
| 290 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 291 | static int[] getAppWidgetIds(Provider p) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | int instancesSize = p.instances.size(); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 293 | int appWidgetIds[] = new int[instancesSize]; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | for (int i=0; i<instancesSize; i++) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 295 | appWidgetIds[i] = p.instances.get(i).appWidgetId; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 296 | } |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 297 | return appWidgetIds; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 298 | } |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 299 | |
| 300 | @Override |
| 301 | public List<AppWidgetProviderInfo> getInstalledProviders() throws RemoteException { |
| 302 | return getImplForUser().getInstalledProviders(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 303 | } |
| 304 | |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 305 | @Override |
| 306 | public void notifyAppWidgetViewDataChanged(int[] appWidgetIds, int viewId) |
| 307 | throws RemoteException { |
| 308 | getImplForUser().notifyAppWidgetViewDataChanged(appWidgetIds, viewId); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | } |
| 310 | |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 311 | @Override |
| 312 | public void partiallyUpdateAppWidgetIds(int[] appWidgetIds, RemoteViews views) |
| 313 | throws RemoteException { |
| 314 | getImplForUser().partiallyUpdateAppWidgetIds(appWidgetIds, views); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 315 | } |
| 316 | |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 317 | @Override |
| 318 | public void stopListening(int hostId) throws RemoteException { |
| 319 | getImplForUser().stopListening(hostId); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 320 | } |
| 321 | |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 322 | @Override |
| 323 | public void unbindRemoteViewsService(int appWidgetId, Intent intent) throws RemoteException { |
| 324 | getImplForUser().unbindRemoteViewsService(appWidgetId, intent); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 325 | } |
| 326 | |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 327 | @Override |
| 328 | public void updateAppWidgetIds(int[] appWidgetIds, RemoteViews views) throws RemoteException { |
| 329 | getImplForUser().updateAppWidgetIds(appWidgetIds, views); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 330 | } |
| Adam Cohen | 9730031 | 2011-10-12 15:48:13 -0700 | [diff] [blame] | 331 | |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 332 | @Override |
| 333 | public void updateAppWidgetProvider(ComponentName provider, RemoteViews views) |
| 334 | throws RemoteException { |
| 335 | getImplForUser().updateAppWidgetProvider(provider, views); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 336 | } |
| 337 | |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 338 | @Override |
| 339 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 340 | // Dump the state of all the app widget providers |
| 341 | for (int i = 0; i < mAppWidgetServices.size(); i++) { |
| 342 | AppWidgetServiceImpl service = mAppWidgetServices.valueAt(i); |
| 343 | service.dump(fd, pw, args); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 348 | public void onReceive(Context context, Intent intent) { |
| 349 | String action = intent.getAction(); |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 350 | // Slog.d(TAG, "received " + action); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 351 | if (Intent.ACTION_BOOT_COMPLETED.equals(action)) { |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 352 | getImplForUser().sendInitialBroadcasts(); |
| Eric Fischer | 63c2d9e | 2009-10-22 15:22:50 -0700 | [diff] [blame] | 353 | } else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) { |
| Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 354 | for (int i = 0; i < mAppWidgetServices.size(); i++) { |
| 355 | AppWidgetServiceImpl service = mAppWidgetServices.valueAt(i); |
| 356 | service.onConfigurationChanged(); |
| Eric Fischer | 63c2d9e | 2009-10-22 15:22:50 -0700 | [diff] [blame] | 357 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 358 | } else { |
| Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 359 | for (int i = 0; i < mAppWidgetServices.size(); i++) { |
| 360 | AppWidgetServiceImpl service = mAppWidgetServices.valueAt(i); |
| 361 | service.onBroadcastReceived(intent); |
| 362 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | }; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 366 | } |