| 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 | |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 19 | import java.io.File; |
| 20 | import java.io.FileDescriptor; |
| 21 | import java.io.FileInputStream; |
| 22 | import java.io.FileOutputStream; |
| 23 | import java.io.IOException; |
| 24 | import java.io.PrintWriter; |
| 25 | import java.util.ArrayList; |
| 26 | import java.util.HashMap; |
| 27 | import java.util.HashSet; |
| 28 | import java.util.Iterator; |
| 29 | import java.util.List; |
| 30 | import java.util.Locale; |
| 31 | |
| Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame^] | 32 | import org.apache.commons.logging.impl.SimpleLog; |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 33 | import org.xmlpull.v1.XmlPullParser; |
| 34 | import org.xmlpull.v1.XmlPullParserException; |
| 35 | import org.xmlpull.v1.XmlSerializer; |
| 36 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.app.AlarmManager; |
| 38 | import android.app.PendingIntent; |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 39 | import android.appwidget.AppWidgetManager; |
| 40 | import android.appwidget.AppWidgetProviderInfo; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import android.content.BroadcastReceiver; |
| 42 | import android.content.ComponentName; |
| 43 | import android.content.Context; |
| 44 | import android.content.Intent; |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 45 | import android.content.Intent.FilterComparison; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | import android.content.IntentFilter; |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 47 | import android.content.ServiceConnection; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | import android.content.pm.ActivityInfo; |
| Joe Onorato | 331fbdc7 | 2010-08-24 17:02:09 -0400 | [diff] [blame] | 49 | import android.content.pm.ApplicationInfo; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | import android.content.pm.PackageInfo; |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 51 | import android.content.pm.PackageManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.content.pm.ResolveInfo; |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 53 | import android.content.pm.ServiceInfo; |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 54 | import android.content.res.Resources; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.content.res.TypedArray; |
| 56 | import android.content.res.XmlResourceParser; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | import android.net.Uri; |
| 58 | import android.os.Binder; |
| 59 | import android.os.Bundle; |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 60 | import android.os.IBinder; |
| Marco Nelissen | 54796e7 | 2009-04-30 15:16:30 -0700 | [diff] [blame] | 61 | import android.os.Process; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | import android.os.RemoteException; |
| 63 | import android.os.SystemClock; |
| 64 | import android.util.AttributeSet; |
| Winson Chung | 16c8d8a | 2011-01-20 16:19:33 -0800 | [diff] [blame] | 65 | import android.util.Log; |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 66 | import android.util.Pair; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 67 | import android.util.Slog; |
| Mitsuru Oshima | 8f25c42 | 2009-07-01 00:10:43 -0700 | [diff] [blame] | 68 | import android.util.TypedValue; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | import android.util.Xml; |
| 70 | import android.widget.RemoteViews; |
| Winson Chung | 84bbb02 | 2011-02-21 13:57:45 -0800 | [diff] [blame] | 71 | import android.widget.RemoteViewsService; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 73 | import com.android.internal.appwidget.IAppWidgetHost; |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 74 | import com.android.internal.appwidget.IAppWidgetService; |
| Dianne Hackborn | 2269d157 | 2010-02-24 19:54:22 -0800 | [diff] [blame] | 75 | import com.android.internal.util.FastXmlSerializer; |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 76 | import com.android.internal.widget.IRemoteViewsAdapterConnection; |
| Winson Chung | 84bbb02 | 2011-02-21 13:57:45 -0800 | [diff] [blame] | 77 | import com.android.internal.widget.IRemoteViewsFactory; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 79 | class AppWidgetService extends IAppWidgetService.Stub |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 81 | private static final String TAG = "AppWidgetService"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 83 | private static final String SETTINGS_FILENAME = "appwidgets.xml"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | private static final String SETTINGS_TMP_FILENAME = SETTINGS_FILENAME + ".tmp"; |
| Joe Onorato | be96b3a | 2009-07-14 19:49:27 -0700 | [diff] [blame] | 85 | private static final int MIN_UPDATE_PERIOD = 30 * 60 * 1000; // 30 minutes |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | |
| 87 | /* |
| 88 | * When identifying a Host or Provider based on the calling process, use the uid field. |
| 89 | * When identifying a Host or Provider based on a package manager broadcast, use the |
| 90 | * package given. |
| 91 | */ |
| 92 | |
| 93 | static class Provider { |
| 94 | int uid; |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 95 | AppWidgetProviderInfo info; |
| Romain Guy | a547559 | 2009-07-01 17:20:08 -0700 | [diff] [blame] | 96 | ArrayList<AppWidgetId> instances = new ArrayList<AppWidgetId>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | PendingIntent broadcast; |
| 98 | boolean zombie; // if we're in safe mode, don't prune this just because nobody references it |
| 99 | |
| 100 | int tag; // for use while saving state (the index) |
| 101 | } |
| 102 | |
| 103 | static class Host { |
| 104 | int uid; |
| 105 | int hostId; |
| 106 | String packageName; |
| Romain Guy | a547559 | 2009-07-01 17:20:08 -0700 | [diff] [blame] | 107 | ArrayList<AppWidgetId> instances = new ArrayList<AppWidgetId>(); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 108 | IAppWidgetHost callbacks; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | boolean zombie; // if we're in safe mode, don't prune this just because nobody references it |
| 110 | |
| 111 | int tag; // for use while saving state (the index) |
| 112 | } |
| 113 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 114 | static class AppWidgetId { |
| 115 | int appWidgetId; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | Provider provider; |
| 117 | RemoteViews views; |
| 118 | Host host; |
| 119 | } |
| 120 | |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 121 | /** |
| 122 | * Acts as a proxy between the ServiceConnection and the RemoteViewsAdapterConnection. |
| 123 | * This needs to be a static inner class since a reference to the ServiceConnection is held |
| 124 | * globally and may lead us to leak AppWidgetService instances (if there were more than one). |
| 125 | */ |
| 126 | static class ServiceConnectionProxy implements ServiceConnection { |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 127 | private final Pair<Integer, Intent.FilterComparison> mKey; |
| 128 | private final IBinder mConnectionCb; |
| 129 | |
| Winson Chung | 16c8d8a | 2011-01-20 16:19:33 -0800 | [diff] [blame] | 130 | ServiceConnectionProxy(Pair<Integer, Intent.FilterComparison> key, IBinder connectionCb) { |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 131 | mKey = key; |
| 132 | mConnectionCb = connectionCb; |
| 133 | } |
| 134 | public void onServiceConnected(ComponentName name, IBinder service) { |
| Winson Chung | 16c8d8a | 2011-01-20 16:19:33 -0800 | [diff] [blame] | 135 | final IRemoteViewsAdapterConnection cb = |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 136 | IRemoteViewsAdapterConnection.Stub.asInterface(mConnectionCb); |
| 137 | try { |
| 138 | cb.onServiceConnected(service); |
| Adam Cohen | c2be22c | 2011-03-16 16:33:53 -0700 | [diff] [blame] | 139 | } catch (Exception e) { |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 140 | e.printStackTrace(); |
| 141 | } |
| 142 | } |
| 143 | public void onServiceDisconnected(ComponentName name) { |
| Winson Chung | 16c8d8a | 2011-01-20 16:19:33 -0800 | [diff] [blame] | 144 | disconnect(); |
| 145 | } |
| 146 | public void disconnect() { |
| 147 | final IRemoteViewsAdapterConnection cb = |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 148 | IRemoteViewsAdapterConnection.Stub.asInterface(mConnectionCb); |
| 149 | try { |
| 150 | cb.onServiceDisconnected(); |
| Adam Cohen | c2be22c | 2011-03-16 16:33:53 -0700 | [diff] [blame] | 151 | } catch (Exception e) { |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 152 | e.printStackTrace(); |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | |
| Winson Chung | 84bbb02 | 2011-02-21 13:57:45 -0800 | [diff] [blame] | 157 | // Manages active connections to RemoteViewsServices |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 158 | private final HashMap<Pair<Integer, FilterComparison>, ServiceConnection> |
| 159 | mBoundRemoteViewsServices = new HashMap<Pair<Integer,FilterComparison>,ServiceConnection>(); |
| Winson Chung | 84bbb02 | 2011-02-21 13:57:45 -0800 | [diff] [blame] | 160 | // Manages persistent references to RemoteViewsServices from different App Widgets |
| 161 | private final HashMap<FilterComparison, HashSet<Integer>> |
| 162 | mRemoteViewsServicesAppWidgets = new HashMap<FilterComparison, HashSet<Integer>>(); |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 163 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | Context mContext; |
| Eric Fischer | 63c2d9e | 2009-10-22 15:22:50 -0700 | [diff] [blame] | 165 | Locale mLocale; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | PackageManager mPackageManager; |
| 167 | AlarmManager mAlarmManager; |
| Romain Guy | a547559 | 2009-07-01 17:20:08 -0700 | [diff] [blame] | 168 | ArrayList<Provider> mInstalledProviders = new ArrayList<Provider>(); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 169 | int mNextAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID + 1; |
| Romain Guy | a547559 | 2009-07-01 17:20:08 -0700 | [diff] [blame] | 170 | final ArrayList<AppWidgetId> mAppWidgetIds = new ArrayList<AppWidgetId>(); |
| 171 | ArrayList<Host> mHosts = new ArrayList<Host>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | boolean mSafeMode; |
| 173 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 174 | AppWidgetService(Context context) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | mContext = context; |
| 176 | mPackageManager = context.getPackageManager(); |
| 177 | mAlarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE); |
| 178 | } |
| 179 | |
| 180 | public void systemReady(boolean safeMode) { |
| 181 | mSafeMode = safeMode; |
| 182 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 183 | loadAppWidgetList(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | loadStateLocked(); |
| 185 | |
| 186 | // Register for the boot completed broadcast, so we can send the |
| 187 | // ENABLE broacasts. If we try to send them now, they time out, |
| 188 | // because the system isn't ready to handle them yet. |
| 189 | mContext.registerReceiver(mBroadcastReceiver, |
| 190 | new IntentFilter(Intent.ACTION_BOOT_COMPLETED), null, null); |
| 191 | |
| Eric Fischer | 63c2d9e | 2009-10-22 15:22:50 -0700 | [diff] [blame] | 192 | // Register for configuration changes so we can update the names |
| 193 | // of the widgets when the locale changes. |
| 194 | mContext.registerReceiver(mBroadcastReceiver, |
| 195 | new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED), null, null); |
| 196 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | // Register for broadcasts about package install, etc., so we can |
| 198 | // update the provider list. |
| 199 | IntentFilter filter = new IntentFilter(); |
| 200 | filter.addAction(Intent.ACTION_PACKAGE_ADDED); |
| Joe Onorato | d070e89 | 2011-01-07 20:50:37 -0800 | [diff] [blame] | 201 | filter.addAction(Intent.ACTION_PACKAGE_CHANGED); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 202 | filter.addAction(Intent.ACTION_PACKAGE_REMOVED); |
| 203 | filter.addDataScheme("package"); |
| 204 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 205 | // Register for events related to sdcard installation. |
| 206 | IntentFilter sdFilter = new IntentFilter(); |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 207 | sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE); |
| 208 | sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 209 | mContext.registerReceiver(mBroadcastReceiver, sdFilter); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | @Override |
| 213 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 214 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 215 | != PackageManager.PERMISSION_GRANTED) { |
| 216 | pw.println("Permission Denial: can't dump from from pid=" |
| 217 | + Binder.getCallingPid() |
| 218 | + ", uid=" + Binder.getCallingUid()); |
| 219 | return; |
| 220 | } |
| 221 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 222 | synchronized (mAppWidgetIds) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | int N = mInstalledProviders.size(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 224 | pw.println("Providers:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | for (int i=0; i<N; i++) { |
| 226 | Provider p = mInstalledProviders.get(i); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 227 | AppWidgetProviderInfo info = p.info; |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 228 | pw.print(" ["); pw.print(i); pw.print("] provider "); |
| 229 | pw.print(info.provider.flattenToShortString()); |
| 230 | pw.println(':'); |
| 231 | pw.print(" min=("); pw.print(info.minWidth); |
| 232 | pw.print("x"); pw.print(info.minHeight); |
| 233 | pw.print(") updatePeriodMillis="); |
| 234 | pw.print(info.updatePeriodMillis); |
| 235 | pw.print(" initialLayout=#"); |
| 236 | pw.print(Integer.toHexString(info.initialLayout)); |
| 237 | pw.print(" zombie="); pw.println(p.zombie); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | } |
| 239 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 240 | N = mAppWidgetIds.size(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 241 | pw.println(" "); |
| 242 | pw.println("AppWidgetIds:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | for (int i=0; i<N; i++) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 244 | AppWidgetId id = mAppWidgetIds.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 245 | pw.print(" ["); pw.print(i); pw.print("] id="); |
| Romain Guy | a547559 | 2009-07-01 17:20:08 -0700 | [diff] [blame] | 246 | pw.println(id.appWidgetId); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 247 | pw.print(" hostId="); |
| 248 | pw.print(id.host.hostId); pw.print(' '); |
| 249 | pw.print(id.host.packageName); pw.print('/'); |
| 250 | pw.println(id.host.uid); |
| 251 | if (id.provider != null) { |
| 252 | pw.print(" provider="); |
| 253 | pw.println(id.provider.info.provider.flattenToShortString()); |
| 254 | } |
| 255 | if (id.host != null) { |
| 256 | pw.print(" host.callbacks="); pw.println(id.host.callbacks); |
| 257 | } |
| 258 | if (id.views != null) { |
| 259 | pw.print(" views="); pw.println(id.views); |
| 260 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | N = mHosts.size(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 264 | pw.println(" "); |
| 265 | pw.println("Hosts:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 266 | for (int i=0; i<N; i++) { |
| 267 | Host host = mHosts.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 268 | pw.print(" ["); pw.print(i); pw.print("] hostId="); |
| 269 | pw.print(host.hostId); pw.print(' '); |
| 270 | pw.print(host.packageName); pw.print('/'); |
| 271 | pw.print(host.uid); pw.println(':'); |
| 272 | pw.print(" callbacks="); pw.println(host.callbacks); |
| 273 | pw.print(" instances.size="); pw.print(host.instances.size()); |
| 274 | pw.print(" zombie="); pw.println(host.zombie); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | } |
| 276 | } |
| 277 | } |
| 278 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 279 | public int allocateAppWidgetId(String packageName, int hostId) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 280 | int callingUid = enforceCallingUid(packageName); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 281 | synchronized (mAppWidgetIds) { |
| 282 | int appWidgetId = mNextAppWidgetId++; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | |
| 284 | Host host = lookupOrAddHostLocked(callingUid, packageName, hostId); |
| 285 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 286 | AppWidgetId id = new AppWidgetId(); |
| 287 | id.appWidgetId = appWidgetId; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 288 | id.host = host; |
| 289 | |
| 290 | host.instances.add(id); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 291 | mAppWidgetIds.add(id); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | |
| 293 | saveStateLocked(); |
| 294 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 295 | return appWidgetId; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 299 | public void deleteAppWidgetId(int appWidgetId) { |
| 300 | synchronized (mAppWidgetIds) { |
| 301 | AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 302 | if (id != null) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 303 | deleteAppWidgetLocked(id); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | saveStateLocked(); |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | public void deleteHost(int hostId) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 310 | synchronized (mAppWidgetIds) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 311 | int callingUid = getCallingUid(); |
| 312 | Host host = lookupHostLocked(callingUid, hostId); |
| 313 | if (host != null) { |
| 314 | deleteHostLocked(host); |
| 315 | saveStateLocked(); |
| 316 | } |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | public void deleteAllHosts() { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 321 | synchronized (mAppWidgetIds) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 322 | int callingUid = getCallingUid(); |
| 323 | final int N = mHosts.size(); |
| 324 | boolean changed = false; |
| 325 | for (int i=N-1; i>=0; i--) { |
| 326 | Host host = mHosts.get(i); |
| 327 | if (host.uid == callingUid) { |
| 328 | deleteHostLocked(host); |
| 329 | changed = true; |
| 330 | } |
| 331 | } |
| 332 | if (changed) { |
| 333 | saveStateLocked(); |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | void deleteHostLocked(Host host) { |
| 339 | final int N = host.instances.size(); |
| 340 | for (int i=N-1; i>=0; i--) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 341 | AppWidgetId id = host.instances.get(i); |
| 342 | deleteAppWidgetLocked(id); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 343 | } |
| 344 | host.instances.clear(); |
| 345 | mHosts.remove(host); |
| 346 | // it's gone or going away, abruptly drop the callback connection |
| 347 | host.callbacks = null; |
| 348 | } |
| 349 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 350 | void deleteAppWidgetLocked(AppWidgetId id) { |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 351 | // We first unbind all services that are bound to this id |
| 352 | unbindAppWidgetRemoteViewsServicesLocked(id); |
| 353 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 354 | Host host = id.host; |
| 355 | host.instances.remove(id); |
| 356 | pruneHostLocked(host); |
| 357 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 358 | mAppWidgetIds.remove(id); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 359 | |
| 360 | Provider p = id.provider; |
| 361 | if (p != null) { |
| 362 | p.instances.remove(id); |
| 363 | if (!p.zombie) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 364 | // send the broacast saying that this appWidgetId has been deleted |
| 365 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_DELETED); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 366 | intent.setComponent(p.info.provider); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 367 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id.appWidgetId); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | mContext.sendBroadcast(intent); |
| 369 | if (p.instances.size() == 0) { |
| 370 | // cancel the future updates |
| 371 | cancelBroadcasts(p); |
| 372 | |
| 373 | // send the broacast saying that the provider is not in use any more |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 374 | intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_DISABLED); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 375 | intent.setComponent(p.info.provider); |
| 376 | mContext.sendBroadcast(intent); |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | void cancelBroadcasts(Provider p) { |
| 383 | if (p.broadcast != null) { |
| 384 | mAlarmManager.cancel(p.broadcast); |
| 385 | long token = Binder.clearCallingIdentity(); |
| 386 | try { |
| 387 | p.broadcast.cancel(); |
| 388 | } finally { |
| 389 | Binder.restoreCallingIdentity(token); |
| 390 | } |
| 391 | p.broadcast = null; |
| 392 | } |
| 393 | } |
| 394 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 395 | public void bindAppWidgetId(int appWidgetId, ComponentName provider) { |
| 396 | mContext.enforceCallingPermission(android.Manifest.permission.BIND_APPWIDGET, |
| 397 | "bindGagetId appWidgetId=" + appWidgetId + " provider=" + provider); |
| 398 | synchronized (mAppWidgetIds) { |
| 399 | AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 400 | if (id == null) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 401 | throw new IllegalArgumentException("bad appWidgetId"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | } |
| 403 | if (id.provider != null) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 404 | throw new IllegalArgumentException("appWidgetId " + appWidgetId + " already bound to " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 405 | + id.provider.info.provider); |
| 406 | } |
| 407 | Provider p = lookupProviderLocked(provider); |
| 408 | if (p == null) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 409 | throw new IllegalArgumentException("not a appwidget provider: " + provider); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 410 | } |
| 411 | if (p.zombie) { |
| 412 | throw new IllegalArgumentException("can't bind to a 3rd party provider in" |
| 413 | + " safe mode: " + provider); |
| 414 | } |
| 415 | |
| 416 | id.provider = p; |
| 417 | p.instances.add(id); |
| 418 | int instancesSize = p.instances.size(); |
| 419 | if (instancesSize == 1) { |
| 420 | // tell the provider that it's ready |
| 421 | sendEnableIntentLocked(p); |
| 422 | } |
| 423 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 424 | // send an update now -- We need this update now, and just for this appWidgetId. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 425 | // It's less critical when the next one happens, so when we schdule the next one, |
| 426 | // we add updatePeriodMillis to its start time. That time will have some slop, |
| 427 | // but that's okay. |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 428 | sendUpdateIntentLocked(p, new int[] { appWidgetId }); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | |
| 430 | // schedule the future updates |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 431 | registerForBroadcastsLocked(p, getAppWidgetIds(p)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 432 | saveStateLocked(); |
| 433 | } |
| 434 | } |
| 435 | |
| Winson Chung | 84bbb02 | 2011-02-21 13:57:45 -0800 | [diff] [blame] | 436 | // Binds to a specific RemoteViewsService |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 437 | public void bindRemoteViewsService(int appWidgetId, Intent intent, IBinder connection) { |
| 438 | synchronized (mAppWidgetIds) { |
| 439 | AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId); |
| 440 | if (id == null) { |
| 441 | throw new IllegalArgumentException("bad appWidgetId"); |
| 442 | } |
| 443 | final ComponentName componentName = intent.getComponent(); |
| 444 | try { |
| 445 | final ServiceInfo si = mContext.getPackageManager().getServiceInfo(componentName, |
| 446 | PackageManager.GET_PERMISSIONS); |
| 447 | if (!android.Manifest.permission.BIND_REMOTEVIEWS.equals(si.permission)) { |
| 448 | throw new SecurityException("Selected service does not require " |
| 449 | + android.Manifest.permission.BIND_REMOTEVIEWS |
| 450 | + ": " + componentName); |
| 451 | } |
| 452 | } catch (PackageManager.NameNotFoundException e) { |
| 453 | throw new IllegalArgumentException("Unknown component " + componentName); |
| 454 | } |
| 455 | |
| Winson Chung | 16c8d8a | 2011-01-20 16:19:33 -0800 | [diff] [blame] | 456 | // If there is already a connection made for this service intent, then disconnect from |
| 457 | // that first. (This does not allow multiple connections to the same service under |
| 458 | // the same key) |
| 459 | ServiceConnectionProxy conn = null; |
| Winson Chung | 84bbb02 | 2011-02-21 13:57:45 -0800 | [diff] [blame] | 460 | FilterComparison fc = new FilterComparison(intent); |
| 461 | Pair<Integer, FilterComparison> key = Pair.create(appWidgetId, fc); |
| Winson Chung | 16c8d8a | 2011-01-20 16:19:33 -0800 | [diff] [blame] | 462 | if (mBoundRemoteViewsServices.containsKey(key)) { |
| 463 | conn = (ServiceConnectionProxy) mBoundRemoteViewsServices.get(key); |
| 464 | conn.disconnect(); |
| 465 | mContext.unbindService(conn); |
| 466 | mBoundRemoteViewsServices.remove(key); |
| 467 | } |
| 468 | |
| 469 | // Bind to the RemoteViewsService (which will trigger a callback to the |
| 470 | // RemoteViewsAdapter.onServiceConnected()) |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 471 | final long token = Binder.clearCallingIdentity(); |
| 472 | try { |
| Winson Chung | 16c8d8a | 2011-01-20 16:19:33 -0800 | [diff] [blame] | 473 | conn = new ServiceConnectionProxy(key, connection); |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 474 | mContext.bindService(intent, conn, Context.BIND_AUTO_CREATE); |
| 475 | mBoundRemoteViewsServices.put(key, conn); |
| 476 | } finally { |
| 477 | Binder.restoreCallingIdentity(token); |
| 478 | } |
| Winson Chung | 84bbb02 | 2011-02-21 13:57:45 -0800 | [diff] [blame] | 479 | |
| 480 | // Add it to the mapping of RemoteViewsService to appWidgetIds so that we can determine |
| 481 | // when we can call back to the RemoteViewsService later to destroy associated |
| 482 | // factories. |
| Winson Chung | 22bc69d | 2011-02-25 15:13:38 -0800 | [diff] [blame] | 483 | incrementAppWidgetServiceRefCount(appWidgetId, fc); |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 484 | } |
| 485 | } |
| 486 | |
| Winson Chung | 84bbb02 | 2011-02-21 13:57:45 -0800 | [diff] [blame] | 487 | // Unbinds from a specific RemoteViewsService |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 488 | public void unbindRemoteViewsService(int appWidgetId, Intent intent) { |
| 489 | synchronized (mAppWidgetIds) { |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 490 | // Unbind from the RemoteViewsService (which will trigger a callback to the bound |
| 491 | // RemoteViewsAdapter) |
| 492 | Pair<Integer, FilterComparison> key = Pair.create(appWidgetId, |
| 493 | new FilterComparison(intent)); |
| 494 | if (mBoundRemoteViewsServices.containsKey(key)) { |
| Winson Chung | 16c8d8a | 2011-01-20 16:19:33 -0800 | [diff] [blame] | 495 | // We don't need to use the appWidgetId until after we are sure there is something |
| 496 | // to unbind. Note that this may mask certain issues with apps calling unbind() |
| 497 | // more than necessary. |
| 498 | AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId); |
| 499 | if (id == null) { |
| 500 | throw new IllegalArgumentException("bad appWidgetId"); |
| 501 | } |
| 502 | |
| 503 | ServiceConnectionProxy conn = |
| 504 | (ServiceConnectionProxy) mBoundRemoteViewsServices.get(key); |
| 505 | conn.disconnect(); |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 506 | mContext.unbindService(conn); |
| Winson Chung | 16c8d8a | 2011-01-20 16:19:33 -0800 | [diff] [blame] | 507 | mBoundRemoteViewsServices.remove(key); |
| 508 | } else { |
| 509 | Log.e("AppWidgetService", "Error (unbindRemoteViewsService): Connection not bound"); |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | } |
| 513 | |
| Winson Chung | 84bbb02 | 2011-02-21 13:57:45 -0800 | [diff] [blame] | 514 | // Unbinds from a RemoteViewsService when we delete an app widget |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 515 | private void unbindAppWidgetRemoteViewsServicesLocked(AppWidgetId id) { |
| Winson Chung | 16c8d8a | 2011-01-20 16:19:33 -0800 | [diff] [blame] | 516 | int appWidgetId = id.appWidgetId; |
| 517 | // Unbind all connections to Services bound to this AppWidgetId |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 518 | Iterator<Pair<Integer, Intent.FilterComparison>> it = |
| 519 | mBoundRemoteViewsServices.keySet().iterator(); |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 520 | while (it.hasNext()) { |
| 521 | final Pair<Integer, Intent.FilterComparison> key = it.next(); |
| 522 | if (key.first.intValue() == appWidgetId) { |
| Winson Chung | 16c8d8a | 2011-01-20 16:19:33 -0800 | [diff] [blame] | 523 | final ServiceConnectionProxy conn = (ServiceConnectionProxy) |
| 524 | mBoundRemoteViewsServices.get(key); |
| 525 | conn.disconnect(); |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 526 | mContext.unbindService(conn); |
| Winson Chung | 16c8d8a | 2011-01-20 16:19:33 -0800 | [diff] [blame] | 527 | it.remove(); |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 528 | } |
| 529 | } |
| Winson Chung | 84bbb02 | 2011-02-21 13:57:45 -0800 | [diff] [blame] | 530 | |
| 531 | // Check if we need to destroy any services (if no other app widgets are |
| 532 | // referencing the same service) |
| 533 | decrementAppWidgetServiceRefCount(appWidgetId); |
| 534 | } |
| 535 | |
| 536 | // Destroys the cached factory on the RemoteViewsService's side related to the specified intent |
| 537 | private void destroyRemoteViewsService(final Intent intent) { |
| 538 | final ServiceConnection conn = new ServiceConnection() { |
| 539 | @Override |
| 540 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 541 | final IRemoteViewsFactory cb = |
| 542 | IRemoteViewsFactory.Stub.asInterface(service); |
| 543 | try { |
| 544 | cb.onDestroy(intent); |
| Adam Cohen | c2be22c | 2011-03-16 16:33:53 -0700 | [diff] [blame] | 545 | } catch (Exception e) { |
| Winson Chung | 84bbb02 | 2011-02-21 13:57:45 -0800 | [diff] [blame] | 546 | e.printStackTrace(); |
| 547 | } |
| 548 | mContext.unbindService(this); |
| 549 | } |
| 550 | @Override |
| 551 | public void onServiceDisconnected(android.content.ComponentName name) { |
| 552 | // Do nothing |
| 553 | } |
| 554 | }; |
| 555 | |
| 556 | // Bind to the service and remove the static intent->factory mapping in the |
| 557 | // RemoteViewsService. |
| 558 | final long token = Binder.clearCallingIdentity(); |
| 559 | try { |
| 560 | mContext.bindService(intent, conn, Context.BIND_AUTO_CREATE); |
| 561 | } finally { |
| 562 | Binder.restoreCallingIdentity(token); |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | // Adds to the ref-count for a given RemoteViewsService intent |
| 567 | private void incrementAppWidgetServiceRefCount(int appWidgetId, FilterComparison fc) { |
| 568 | HashSet<Integer> appWidgetIds = null; |
| 569 | if (mRemoteViewsServicesAppWidgets.containsKey(fc)) { |
| 570 | appWidgetIds = mRemoteViewsServicesAppWidgets.get(fc); |
| 571 | } else { |
| 572 | appWidgetIds = new HashSet<Integer>(); |
| 573 | mRemoteViewsServicesAppWidgets.put(fc, appWidgetIds); |
| 574 | } |
| 575 | appWidgetIds.add(appWidgetId); |
| 576 | } |
| 577 | |
| 578 | // Subtracts from the ref-count for a given RemoteViewsService intent, prompting a delete if |
| 579 | // the ref-count reaches zero. |
| 580 | private void decrementAppWidgetServiceRefCount(int appWidgetId) { |
| 581 | Iterator<FilterComparison> it = |
| 582 | mRemoteViewsServicesAppWidgets.keySet().iterator(); |
| 583 | while (it.hasNext()) { |
| 584 | final FilterComparison key = it.next(); |
| 585 | final HashSet<Integer> ids = mRemoteViewsServicesAppWidgets.get(key); |
| 586 | if (ids.remove(appWidgetId)) { |
| 587 | // If we have removed the last app widget referencing this service, then we |
| 588 | // should destroy it and remove it from this set |
| 589 | if (ids.isEmpty()) { |
| 590 | destroyRemoteViewsService(key.getIntent()); |
| 591 | it.remove(); |
| 592 | } |
| 593 | } |
| 594 | } |
| Winson Chung | 81f39eb | 2011-01-11 18:05:01 -0800 | [diff] [blame] | 595 | } |
| 596 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 597 | public AppWidgetProviderInfo getAppWidgetInfo(int appWidgetId) { |
| 598 | synchronized (mAppWidgetIds) { |
| 599 | AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 600 | if (id != null && id.provider != null && !id.provider.zombie) { |
| 601 | return id.provider.info; |
| 602 | } |
| 603 | return null; |
| 604 | } |
| 605 | } |
| 606 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 607 | public RemoteViews getAppWidgetViews(int appWidgetId) { |
| 608 | synchronized (mAppWidgetIds) { |
| 609 | AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 610 | if (id != null) { |
| 611 | return id.views; |
| 612 | } |
| 613 | return null; |
| 614 | } |
| 615 | } |
| 616 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 617 | public List<AppWidgetProviderInfo> getInstalledProviders() { |
| 618 | synchronized (mAppWidgetIds) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 619 | final int N = mInstalledProviders.size(); |
| Romain Guy | a547559 | 2009-07-01 17:20:08 -0700 | [diff] [blame] | 620 | ArrayList<AppWidgetProviderInfo> result = new ArrayList<AppWidgetProviderInfo>(N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 621 | for (int i=0; i<N; i++) { |
| 622 | Provider p = mInstalledProviders.get(i); |
| 623 | if (!p.zombie) { |
| 624 | result.add(p.info); |
| 625 | } |
| 626 | } |
| 627 | return result; |
| 628 | } |
| 629 | } |
| 630 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 631 | public void updateAppWidgetIds(int[] appWidgetIds, RemoteViews views) { |
| 632 | if (appWidgetIds == null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 633 | return; |
| 634 | } |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 635 | if (appWidgetIds.length == 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 636 | return; |
| 637 | } |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 638 | final int N = appWidgetIds.length; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 639 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 640 | synchronized (mAppWidgetIds) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 641 | for (int i=0; i<N; i++) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 642 | AppWidgetId id = lookupAppWidgetIdLocked(appWidgetIds[i]); |
| 643 | updateAppWidgetInstanceLocked(id, views); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 644 | } |
| 645 | } |
| 646 | } |
| 647 | |
| Adam Cohen | 2dd2197 | 2010-08-15 18:20:04 -0700 | [diff] [blame] | 648 | public void partiallyUpdateAppWidgetIds(int[] appWidgetIds, RemoteViews views) { |
| 649 | if (appWidgetIds == null) { |
| 650 | return; |
| 651 | } |
| 652 | if (appWidgetIds.length == 0) { |
| 653 | return; |
| 654 | } |
| 655 | final int N = appWidgetIds.length; |
| 656 | |
| 657 | synchronized (mAppWidgetIds) { |
| 658 | for (int i=0; i<N; i++) { |
| 659 | AppWidgetId id = lookupAppWidgetIdLocked(appWidgetIds[i]); |
| 660 | updateAppWidgetInstanceLocked(id, views, true); |
| 661 | } |
| 662 | } |
| 663 | } |
| 664 | |
| Winson Chung | 6394c0e | 2010-08-16 10:14:56 -0700 | [diff] [blame] | 665 | public void notifyAppWidgetViewDataChanged(int[] appWidgetIds, int viewId) { |
| Winson Chung | 499cb9f | 2010-07-16 11:18:17 -0700 | [diff] [blame] | 666 | if (appWidgetIds == null) { |
| 667 | return; |
| 668 | } |
| 669 | if (appWidgetIds.length == 0) { |
| 670 | return; |
| 671 | } |
| 672 | final int N = appWidgetIds.length; |
| 673 | |
| 674 | synchronized (mAppWidgetIds) { |
| 675 | for (int i=0; i<N; i++) { |
| 676 | AppWidgetId id = lookupAppWidgetIdLocked(appWidgetIds[i]); |
| Winson Chung | 6394c0e | 2010-08-16 10:14:56 -0700 | [diff] [blame] | 677 | notifyAppWidgetViewDataChangedInstanceLocked(id, viewId); |
| Winson Chung | 499cb9f | 2010-07-16 11:18:17 -0700 | [diff] [blame] | 678 | } |
| 679 | } |
| 680 | } |
| 681 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 682 | public void updateAppWidgetProvider(ComponentName provider, RemoteViews views) { |
| 683 | synchronized (mAppWidgetIds) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 684 | Provider p = lookupProviderLocked(provider); |
| 685 | if (p == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 686 | Slog.w(TAG, "updateAppWidgetProvider: provider doesn't exist: " + provider); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 687 | return; |
| 688 | } |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 689 | ArrayList<AppWidgetId> instances = p.instances; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 690 | final int N = instances.size(); |
| 691 | for (int i=0; i<N; i++) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 692 | AppWidgetId id = instances.get(i); |
| 693 | updateAppWidgetInstanceLocked(id, views); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 694 | } |
| 695 | } |
| 696 | } |
| 697 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 698 | void updateAppWidgetInstanceLocked(AppWidgetId id, RemoteViews views) { |
| Adam Cohen | 2dd2197 | 2010-08-15 18:20:04 -0700 | [diff] [blame] | 699 | updateAppWidgetInstanceLocked(id, views, false); |
| 700 | } |
| 701 | |
| 702 | void updateAppWidgetInstanceLocked(AppWidgetId id, RemoteViews views, boolean isPartialUpdate) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 703 | // allow for stale appWidgetIds and other badness |
| 704 | // lookup also checks that the calling process can access the appWidgetId |
| 705 | // drop unbound appWidgetIds (shouldn't be possible under normal circumstances) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 706 | if (id != null && id.provider != null && !id.provider.zombie && !id.host.zombie) { |
| Adam Cohen | 2dd2197 | 2010-08-15 18:20:04 -0700 | [diff] [blame] | 707 | |
| 708 | // We do not want to save this RemoteViews |
| 709 | if (!isPartialUpdate) id.views = views; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 710 | |
| 711 | // is anyone listening? |
| 712 | if (id.host.callbacks != null) { |
| 713 | try { |
| 714 | // the lock is held, but this is a oneway call |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 715 | id.host.callbacks.updateAppWidget(id.appWidgetId, views); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 716 | } catch (RemoteException e) { |
| 717 | // It failed; remove the callback. No need to prune because |
| 718 | // we know that this host is still referenced by this instance. |
| 719 | id.host.callbacks = null; |
| 720 | } |
| 721 | } |
| 722 | } |
| 723 | } |
| 724 | |
| Winson Chung | 6394c0e | 2010-08-16 10:14:56 -0700 | [diff] [blame] | 725 | void notifyAppWidgetViewDataChangedInstanceLocked(AppWidgetId id, int viewId) { |
| Winson Chung | 499cb9f | 2010-07-16 11:18:17 -0700 | [diff] [blame] | 726 | // allow for stale appWidgetIds and other badness |
| 727 | // lookup also checks that the calling process can access the appWidgetId |
| 728 | // drop unbound appWidgetIds (shouldn't be possible under normal circumstances) |
| 729 | if (id != null && id.provider != null && !id.provider.zombie && !id.host.zombie) { |
| Winson Chung | 499cb9f | 2010-07-16 11:18:17 -0700 | [diff] [blame] | 730 | // is anyone listening? |
| 731 | if (id.host.callbacks != null) { |
| 732 | try { |
| 733 | // the lock is held, but this is a oneway call |
| Winson Chung | 6394c0e | 2010-08-16 10:14:56 -0700 | [diff] [blame] | 734 | id.host.callbacks.viewDataChanged(id.appWidgetId, viewId); |
| Winson Chung | 499cb9f | 2010-07-16 11:18:17 -0700 | [diff] [blame] | 735 | } catch (RemoteException e) { |
| 736 | // It failed; remove the callback. No need to prune because |
| 737 | // we know that this host is still referenced by this instance. |
| 738 | id.host.callbacks = null; |
| 739 | } |
| 740 | } |
| 741 | } |
| 742 | } |
| 743 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 744 | public int[] startListening(IAppWidgetHost callbacks, String packageName, int hostId, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 745 | List<RemoteViews> updatedViews) { |
| 746 | int callingUid = enforceCallingUid(packageName); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 747 | synchronized (mAppWidgetIds) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 748 | Host host = lookupOrAddHostLocked(callingUid, packageName, hostId); |
| 749 | host.callbacks = callbacks; |
| 750 | |
| 751 | updatedViews.clear(); |
| 752 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 753 | ArrayList<AppWidgetId> instances = host.instances; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 754 | int N = instances.size(); |
| 755 | int[] updatedIds = new int[N]; |
| 756 | for (int i=0; i<N; i++) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 757 | AppWidgetId id = instances.get(i); |
| 758 | updatedIds[i] = id.appWidgetId; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 759 | updatedViews.add(id.views); |
| 760 | } |
| 761 | return updatedIds; |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | public void stopListening(int hostId) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 766 | synchronized (mAppWidgetIds) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 767 | Host host = lookupHostLocked(getCallingUid(), hostId); |
| Ken Shirriff | e21167a | 2009-09-23 16:42:53 -0700 | [diff] [blame] | 768 | if (host != null) { |
| 769 | host.callbacks = null; |
| 770 | pruneHostLocked(host); |
| 771 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 772 | } |
| 773 | } |
| 774 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 775 | boolean canAccessAppWidgetId(AppWidgetId id, int callingUid) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 776 | if (id.host.uid == callingUid) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 777 | // Apps hosting the AppWidget have access to it. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 778 | return true; |
| 779 | } |
| 780 | if (id.provider != null && id.provider.uid == callingUid) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 781 | // Apps providing the AppWidget have access to it (if the appWidgetId has been bound) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 782 | return true; |
| 783 | } |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 784 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.BIND_APPWIDGET) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 785 | == PackageManager.PERMISSION_GRANTED) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 786 | // Apps that can bind have access to all appWidgetIds. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 787 | return true; |
| 788 | } |
| 789 | // Nobody else can access it. |
| 790 | return false; |
| 791 | } |
| 792 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 793 | AppWidgetId lookupAppWidgetIdLocked(int appWidgetId) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 794 | int callingUid = getCallingUid(); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 795 | final int N = mAppWidgetIds.size(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 796 | for (int i=0; i<N; i++) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 797 | AppWidgetId id = mAppWidgetIds.get(i); |
| 798 | if (id.appWidgetId == appWidgetId && canAccessAppWidgetId(id, callingUid)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 799 | return id; |
| 800 | } |
| 801 | } |
| 802 | return null; |
| 803 | } |
| 804 | |
| 805 | Provider lookupProviderLocked(ComponentName provider) { |
| Romain Guy | d2671e1 | 2010-03-11 18:06:42 -0800 | [diff] [blame] | 806 | final String className = provider.getClassName(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 807 | final int N = mInstalledProviders.size(); |
| 808 | for (int i=0; i<N; i++) { |
| 809 | Provider p = mInstalledProviders.get(i); |
| Romain Guy | d2671e1 | 2010-03-11 18:06:42 -0800 | [diff] [blame] | 810 | if (p.info.provider.equals(provider) || className.equals(p.info.oldName)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 811 | return p; |
| 812 | } |
| 813 | } |
| 814 | return null; |
| 815 | } |
| 816 | |
| 817 | Host lookupHostLocked(int uid, int hostId) { |
| 818 | final int N = mHosts.size(); |
| 819 | for (int i=0; i<N; i++) { |
| 820 | Host h = mHosts.get(i); |
| 821 | if (h.uid == uid && h.hostId == hostId) { |
| 822 | return h; |
| 823 | } |
| 824 | } |
| 825 | return null; |
| 826 | } |
| 827 | |
| 828 | Host lookupOrAddHostLocked(int uid, String packageName, int hostId) { |
| 829 | final int N = mHosts.size(); |
| 830 | for (int i=0; i<N; i++) { |
| 831 | Host h = mHosts.get(i); |
| 832 | if (h.hostId == hostId && h.packageName.equals(packageName)) { |
| 833 | return h; |
| 834 | } |
| 835 | } |
| 836 | Host host = new Host(); |
| 837 | host.packageName = packageName; |
| 838 | host.uid = uid; |
| 839 | host.hostId = hostId; |
| 840 | mHosts.add(host); |
| 841 | return host; |
| 842 | } |
| 843 | |
| 844 | void pruneHostLocked(Host host) { |
| 845 | if (host.instances.size() == 0 && host.callbacks == null) { |
| 846 | mHosts.remove(host); |
| 847 | } |
| 848 | } |
| 849 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 850 | void loadAppWidgetList() { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 851 | PackageManager pm = mPackageManager; |
| 852 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 853 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 854 | List<ResolveInfo> broadcastReceivers = pm.queryBroadcastReceivers(intent, |
| 855 | PackageManager.GET_META_DATA); |
| 856 | |
| Bjorn Bringert | 5f85780 | 2010-02-10 23:09:48 +0000 | [diff] [blame] | 857 | final int N = broadcastReceivers == null ? 0 : broadcastReceivers.size(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 858 | for (int i=0; i<N; i++) { |
| 859 | ResolveInfo ri = broadcastReceivers.get(i); |
| 860 | addProviderLocked(ri); |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | boolean addProviderLocked(ResolveInfo ri) { |
| Joe Onorato | d070e89 | 2011-01-07 20:50:37 -0800 | [diff] [blame] | 865 | if ((ri.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) { |
| 866 | return false; |
| 867 | } |
| 868 | if (!ri.activityInfo.isEnabled()) { |
| 869 | return false; |
| 870 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 871 | Provider p = parseProviderInfoXml(new ComponentName(ri.activityInfo.packageName, |
| 872 | ri.activityInfo.name), ri); |
| 873 | if (p != null) { |
| 874 | mInstalledProviders.add(p); |
| 875 | return true; |
| 876 | } else { |
| 877 | return false; |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | void removeProviderLocked(int index, Provider p) { |
| 882 | int N = p.instances.size(); |
| 883 | for (int i=0; i<N; i++) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 884 | AppWidgetId id = p.instances.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 885 | // Call back with empty RemoteViews |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 886 | updateAppWidgetInstanceLocked(id, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 887 | // Stop telling the host about updates for this from now on |
| 888 | cancelBroadcasts(p); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 889 | // clear out references to this appWidgetId |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 890 | id.host.instances.remove(id); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 891 | mAppWidgetIds.remove(id); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 892 | id.provider = null; |
| 893 | pruneHostLocked(id.host); |
| 894 | id.host = null; |
| 895 | } |
| 896 | p.instances.clear(); |
| 897 | mInstalledProviders.remove(index); |
| 898 | // no need to send the DISABLE broadcast, since the receiver is gone anyway |
| 899 | cancelBroadcasts(p); |
| 900 | } |
| 901 | |
| 902 | void sendEnableIntentLocked(Provider p) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 903 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_ENABLED); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 904 | intent.setComponent(p.info.provider); |
| 905 | mContext.sendBroadcast(intent); |
| 906 | } |
| 907 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 908 | void sendUpdateIntentLocked(Provider p, int[] appWidgetIds) { |
| 909 | if (appWidgetIds != null && appWidgetIds.length > 0) { |
| 910 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE); |
| 911 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 912 | intent.setComponent(p.info.provider); |
| 913 | mContext.sendBroadcast(intent); |
| 914 | } |
| 915 | } |
| 916 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 917 | void registerForBroadcastsLocked(Provider p, int[] appWidgetIds) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 918 | if (p.info.updatePeriodMillis > 0) { |
| 919 | // if this is the first instance, set the alarm. otherwise, |
| 920 | // rely on the fact that we've already set it and that |
| 921 | // PendingIntent.getBroadcast will update the extras. |
| 922 | boolean alreadyRegistered = p.broadcast != null; |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 923 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE); |
| 924 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 925 | intent.setComponent(p.info.provider); |
| 926 | long token = Binder.clearCallingIdentity(); |
| 927 | try { |
| 928 | p.broadcast = PendingIntent.getBroadcast(mContext, 1, intent, |
| 929 | PendingIntent.FLAG_UPDATE_CURRENT); |
| 930 | } finally { |
| 931 | Binder.restoreCallingIdentity(token); |
| 932 | } |
| 933 | if (!alreadyRegistered) { |
| Joe Onorato | be96b3a | 2009-07-14 19:49:27 -0700 | [diff] [blame] | 934 | long period = p.info.updatePeriodMillis; |
| 935 | if (period < MIN_UPDATE_PERIOD) { |
| 936 | period = MIN_UPDATE_PERIOD; |
| 937 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 938 | mAlarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, |
| Joe Onorato | be96b3a | 2009-07-14 19:49:27 -0700 | [diff] [blame] | 939 | SystemClock.elapsedRealtime() + period, period, p.broadcast); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 940 | } |
| 941 | } |
| 942 | } |
| 943 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 944 | static int[] getAppWidgetIds(Provider p) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 945 | int instancesSize = p.instances.size(); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 946 | int appWidgetIds[] = new int[instancesSize]; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 947 | for (int i=0; i<instancesSize; i++) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 948 | appWidgetIds[i] = p.instances.get(i).appWidgetId; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 949 | } |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 950 | return appWidgetIds; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 951 | } |
| 952 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 953 | public int[] getAppWidgetIds(ComponentName provider) { |
| 954 | synchronized (mAppWidgetIds) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 955 | Provider p = lookupProviderLocked(provider); |
| 956 | if (p != null && getCallingUid() == p.uid) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 957 | return getAppWidgetIds(p); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 958 | } else { |
| 959 | return new int[0]; |
| 960 | } |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | private Provider parseProviderInfoXml(ComponentName component, ResolveInfo ri) { |
| 965 | Provider p = null; |
| 966 | |
| 967 | ActivityInfo activityInfo = ri.activityInfo; |
| 968 | XmlResourceParser parser = null; |
| 969 | try { |
| 970 | parser = activityInfo.loadXmlMetaData(mPackageManager, |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 971 | AppWidgetManager.META_DATA_APPWIDGET_PROVIDER); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 972 | if (parser == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 973 | Slog.w(TAG, "No " + AppWidgetManager.META_DATA_APPWIDGET_PROVIDER + " meta-data for " |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 974 | + "AppWidget provider '" + component + '\''); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 975 | return null; |
| 976 | } |
| Adam Cohen | d2e20de | 2011-02-25 12:03:37 -0800 | [diff] [blame] | 977 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 978 | AttributeSet attrs = Xml.asAttributeSet(parser); |
| Adam Cohen | d2e20de | 2011-02-25 12:03:37 -0800 | [diff] [blame] | 979 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 980 | int type; |
| 981 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 982 | && type != XmlPullParser.START_TAG) { |
| 983 | // drain whitespace, comments, etc. |
| 984 | } |
| Adam Cohen | d2e20de | 2011-02-25 12:03:37 -0800 | [diff] [blame] | 985 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 986 | String nodeName = parser.getName(); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 987 | if (!"appwidget-provider".equals(nodeName)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 988 | Slog.w(TAG, "Meta-data does not start with appwidget-provider tag for" |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 989 | + " AppWidget provider '" + component + '\''); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 990 | return null; |
| 991 | } |
| 992 | |
| 993 | p = new Provider(); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 994 | AppWidgetProviderInfo info = p.info = new AppWidgetProviderInfo(); |
| Romain Guy | d2671e1 | 2010-03-11 18:06:42 -0800 | [diff] [blame] | 995 | // If metaData was null, we would have returned earlier when getting |
| 996 | // the parser No need to do the check here |
| 997 | info.oldName = activityInfo.metaData.getString( |
| 998 | AppWidgetManager.META_DATA_APPWIDGET_OLD_NAME); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 999 | |
| 1000 | info.provider = component; |
| 1001 | p.uid = activityInfo.applicationInfo.uid; |
| 1002 | |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 1003 | Resources res = mPackageManager.getResourcesForApplication( |
| 1004 | activityInfo.applicationInfo); |
| Adam Cohen | d2e20de | 2011-02-25 12:03:37 -0800 | [diff] [blame] | 1005 | |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 1006 | TypedArray sa = res.obtainAttributes(attrs, |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1007 | com.android.internal.R.styleable.AppWidgetProviderInfo); |
| Adam Cohen | d2e20de | 2011-02-25 12:03:37 -0800 | [diff] [blame] | 1008 | |
| Mitsuru Oshima | 8f25c42 | 2009-07-01 00:10:43 -0700 | [diff] [blame] | 1009 | // These dimensions has to be resolved in the application's context. |
| 1010 | // We simply send back the raw complex data, which will be |
| 1011 | // converted to dp in {@link AppWidgetManager#getAppWidgetInfo}. |
| 1012 | TypedValue value = sa.peekValue( |
| 1013 | com.android.internal.R.styleable.AppWidgetProviderInfo_minWidth); |
| 1014 | info.minWidth = value != null ? value.data : 0; |
| 1015 | value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minHeight); |
| 1016 | info.minHeight = value != null ? value.data : 0; |
| Adam Cohen | d2e20de | 2011-02-25 12:03:37 -0800 | [diff] [blame] | 1017 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1018 | info.updatePeriodMillis = sa.getInt( |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1019 | com.android.internal.R.styleable.AppWidgetProviderInfo_updatePeriodMillis, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1020 | info.initialLayout = sa.getResourceId( |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1021 | com.android.internal.R.styleable.AppWidgetProviderInfo_initialLayout, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1022 | String className = sa.getString( |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1023 | com.android.internal.R.styleable.AppWidgetProviderInfo_configure); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1024 | if (className != null) { |
| 1025 | info.configure = new ComponentName(component.getPackageName(), className); |
| 1026 | } |
| 1027 | info.label = activityInfo.loadLabel(mPackageManager).toString(); |
| 1028 | info.icon = ri.getIconResource(); |
| Patrick Dubroy | d2db2a5 | 2010-06-23 14:56:28 -0700 | [diff] [blame] | 1029 | info.previewImage = sa.getResourceId( |
| 1030 | com.android.internal.R.styleable.AppWidgetProviderInfo_previewImage, 0); |
| Adam Cohen | a02fdf1 | 2010-11-03 13:27:40 -0700 | [diff] [blame] | 1031 | info.autoAdvanceViewId = sa.getResourceId( |
| 1032 | com.android.internal.R.styleable.AppWidgetProviderInfo_autoAdvanceViewId, -1); |
| Adam Cohen | 9611f2e | 2011-02-28 13:39:38 -0800 | [diff] [blame] | 1033 | info.resizeMode = sa.getInt( |
| Adam Cohen | d2e20de | 2011-02-25 12:03:37 -0800 | [diff] [blame] | 1034 | com.android.internal.R.styleable.AppWidgetProviderInfo_resizeMode, |
| 1035 | AppWidgetProviderInfo.RESIZE_NONE); |
| Patrick Dubroy | d2db2a5 | 2010-06-23 14:56:28 -0700 | [diff] [blame] | 1036 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1037 | sa.recycle(); |
| 1038 | } catch (Exception e) { |
| 1039 | // Ok to catch Exception here, because anything going wrong because |
| 1040 | // of what a client process passes to us should not be fatal for the |
| 1041 | // system process. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1042 | Slog.w(TAG, "XML parsing failed for AppWidget provider '" + component + '\'', e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1043 | return null; |
| 1044 | } finally { |
| 1045 | if (parser != null) parser.close(); |
| 1046 | } |
| 1047 | return p; |
| 1048 | } |
| 1049 | |
| 1050 | int getUidForPackage(String packageName) throws PackageManager.NameNotFoundException { |
| 1051 | PackageInfo pkgInfo = mPackageManager.getPackageInfo(packageName, 0); |
| 1052 | if (pkgInfo == null || pkgInfo.applicationInfo == null) { |
| 1053 | throw new PackageManager.NameNotFoundException(); |
| 1054 | } |
| 1055 | return pkgInfo.applicationInfo.uid; |
| 1056 | } |
| 1057 | |
| 1058 | int enforceCallingUid(String packageName) throws IllegalArgumentException { |
| 1059 | int callingUid = getCallingUid(); |
| 1060 | int packageUid; |
| 1061 | try { |
| 1062 | packageUid = getUidForPackage(packageName); |
| 1063 | } catch (PackageManager.NameNotFoundException ex) { |
| 1064 | throw new IllegalArgumentException("packageName and uid don't match packageName=" |
| 1065 | + packageName); |
| 1066 | } |
| Marco Nelissen | 54796e7 | 2009-04-30 15:16:30 -0700 | [diff] [blame] | 1067 | if (callingUid != packageUid && Process.supportsProcesses()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1068 | throw new IllegalArgumentException("packageName and uid don't match packageName=" |
| 1069 | + packageName); |
| 1070 | } |
| 1071 | return callingUid; |
| 1072 | } |
| 1073 | |
| 1074 | void sendInitialBroadcasts() { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1075 | synchronized (mAppWidgetIds) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1076 | final int N = mInstalledProviders.size(); |
| 1077 | for (int i=0; i<N; i++) { |
| 1078 | Provider p = mInstalledProviders.get(i); |
| 1079 | if (p.instances.size() > 0) { |
| 1080 | sendEnableIntentLocked(p); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1081 | int[] appWidgetIds = getAppWidgetIds(p); |
| 1082 | sendUpdateIntentLocked(p, appWidgetIds); |
| 1083 | registerForBroadcastsLocked(p, appWidgetIds); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1084 | } |
| 1085 | } |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | // only call from initialization -- it assumes that the data structures are all empty |
| 1090 | void loadStateLocked() { |
| 1091 | File temp = savedStateTempFile(); |
| 1092 | File real = savedStateRealFile(); |
| 1093 | |
| 1094 | // prefer the real file. If it doesn't exist, use the temp one, and then copy it to the |
| 1095 | // real one. if there is both a real file and a temp one, assume that the temp one isn't |
| 1096 | // fully written and delete it. |
| 1097 | if (real.exists()) { |
| 1098 | readStateFromFileLocked(real); |
| 1099 | if (temp.exists()) { |
| Romain Guy | a547559 | 2009-07-01 17:20:08 -0700 | [diff] [blame] | 1100 | //noinspection ResultOfMethodCallIgnored |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1101 | temp.delete(); |
| 1102 | } |
| 1103 | } else if (temp.exists()) { |
| 1104 | readStateFromFileLocked(temp); |
| Romain Guy | a547559 | 2009-07-01 17:20:08 -0700 | [diff] [blame] | 1105 | //noinspection ResultOfMethodCallIgnored |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1106 | temp.renameTo(real); |
| 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | void saveStateLocked() { |
| 1111 | File temp = savedStateTempFile(); |
| 1112 | File real = savedStateRealFile(); |
| 1113 | |
| 1114 | if (!real.exists()) { |
| 1115 | // If the real one doesn't exist, it's either because this is the first time |
| 1116 | // or because something went wrong while copying them. In this case, we can't |
| 1117 | // trust anything that's in temp. In order to have the loadState code not |
| 1118 | // use the temporary one until it's fully written, create an empty file |
| 1119 | // for real, which will we'll shortly delete. |
| 1120 | try { |
| Romain Guy | a547559 | 2009-07-01 17:20:08 -0700 | [diff] [blame] | 1121 | //noinspection ResultOfMethodCallIgnored |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1122 | real.createNewFile(); |
| 1123 | } catch (IOException e) { |
| Romain Guy | a547559 | 2009-07-01 17:20:08 -0700 | [diff] [blame] | 1124 | // Ignore |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | if (temp.exists()) { |
| Romain Guy | a547559 | 2009-07-01 17:20:08 -0700 | [diff] [blame] | 1129 | //noinspection ResultOfMethodCallIgnored |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1130 | temp.delete(); |
| 1131 | } |
| 1132 | |
| Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 1133 | if (!writeStateToFileLocked(temp)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1134 | Slog.w(TAG, "Failed to persist new settings"); |
| Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 1135 | return; |
| 1136 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1137 | |
| Romain Guy | a547559 | 2009-07-01 17:20:08 -0700 | [diff] [blame] | 1138 | //noinspection ResultOfMethodCallIgnored |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1139 | real.delete(); |
| Romain Guy | a547559 | 2009-07-01 17:20:08 -0700 | [diff] [blame] | 1140 | //noinspection ResultOfMethodCallIgnored |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1141 | temp.renameTo(real); |
| 1142 | } |
| 1143 | |
| Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 1144 | boolean writeStateToFileLocked(File file) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1145 | FileOutputStream stream = null; |
| 1146 | int N; |
| 1147 | |
| 1148 | try { |
| 1149 | stream = new FileOutputStream(file, false); |
| 1150 | XmlSerializer out = new FastXmlSerializer(); |
| 1151 | out.setOutput(stream, "utf-8"); |
| 1152 | out.startDocument(null, true); |
| 1153 | |
| 1154 | |
| 1155 | out.startTag(null, "gs"); |
| 1156 | |
| 1157 | int providerIndex = 0; |
| 1158 | N = mInstalledProviders.size(); |
| 1159 | for (int i=0; i<N; i++) { |
| 1160 | Provider p = mInstalledProviders.get(i); |
| 1161 | if (p.instances.size() > 0) { |
| 1162 | out.startTag(null, "p"); |
| 1163 | out.attribute(null, "pkg", p.info.provider.getPackageName()); |
| 1164 | out.attribute(null, "cl", p.info.provider.getClassName()); |
| Patrick Tsai | bd742e43 | 2010-05-01 00:30:19 +0800 | [diff] [blame] | 1165 | out.endTag(null, "p"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1166 | p.tag = providerIndex; |
| 1167 | providerIndex++; |
| 1168 | } |
| 1169 | } |
| 1170 | |
| 1171 | N = mHosts.size(); |
| 1172 | for (int i=0; i<N; i++) { |
| 1173 | Host host = mHosts.get(i); |
| 1174 | out.startTag(null, "h"); |
| 1175 | out.attribute(null, "pkg", host.packageName); |
| 1176 | out.attribute(null, "id", Integer.toHexString(host.hostId)); |
| 1177 | out.endTag(null, "h"); |
| 1178 | host.tag = i; |
| 1179 | } |
| 1180 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1181 | N = mAppWidgetIds.size(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1182 | for (int i=0; i<N; i++) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1183 | AppWidgetId id = mAppWidgetIds.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1184 | out.startTag(null, "g"); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1185 | out.attribute(null, "id", Integer.toHexString(id.appWidgetId)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1186 | out.attribute(null, "h", Integer.toHexString(id.host.tag)); |
| 1187 | if (id.provider != null) { |
| 1188 | out.attribute(null, "p", Integer.toHexString(id.provider.tag)); |
| 1189 | } |
| 1190 | out.endTag(null, "g"); |
| 1191 | } |
| 1192 | |
| 1193 | out.endTag(null, "gs"); |
| 1194 | |
| 1195 | out.endDocument(); |
| 1196 | stream.close(); |
| Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 1197 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1198 | } catch (IOException e) { |
| 1199 | try { |
| 1200 | if (stream != null) { |
| 1201 | stream.close(); |
| 1202 | } |
| 1203 | } catch (IOException ex) { |
| Romain Guy | a547559 | 2009-07-01 17:20:08 -0700 | [diff] [blame] | 1204 | // Ignore |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1205 | } |
| 1206 | if (file.exists()) { |
| Romain Guy | a547559 | 2009-07-01 17:20:08 -0700 | [diff] [blame] | 1207 | //noinspection ResultOfMethodCallIgnored |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1208 | file.delete(); |
| 1209 | } |
| Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 1210 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1211 | } |
| 1212 | } |
| 1213 | |
| 1214 | void readStateFromFileLocked(File file) { |
| 1215 | FileInputStream stream = null; |
| 1216 | |
| 1217 | boolean success = false; |
| 1218 | |
| 1219 | try { |
| 1220 | stream = new FileInputStream(file); |
| 1221 | XmlPullParser parser = Xml.newPullParser(); |
| 1222 | parser.setInput(stream, null); |
| 1223 | |
| 1224 | int type; |
| 1225 | int providerIndex = 0; |
| Romain Guy | a547559 | 2009-07-01 17:20:08 -0700 | [diff] [blame] | 1226 | HashMap<Integer,Provider> loadedProviders = new HashMap<Integer, Provider>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1227 | do { |
| 1228 | type = parser.next(); |
| 1229 | if (type == XmlPullParser.START_TAG) { |
| 1230 | String tag = parser.getName(); |
| 1231 | if ("p".equals(tag)) { |
| 1232 | // TODO: do we need to check that this package has the same signature |
| 1233 | // as before? |
| 1234 | String pkg = parser.getAttributeValue(null, "pkg"); |
| 1235 | String cl = parser.getAttributeValue(null, "cl"); |
| Romain Guy | ff3e61c6 | 2010-03-11 15:30:02 -0800 | [diff] [blame] | 1236 | |
| 1237 | final PackageManager packageManager = mContext.getPackageManager(); |
| 1238 | try { |
| 1239 | packageManager.getReceiverInfo(new ComponentName(pkg, cl), 0); |
| 1240 | } catch (PackageManager.NameNotFoundException e) { |
| 1241 | String[] pkgs = packageManager.currentToCanonicalPackageNames( |
| 1242 | new String[] { pkg }); |
| 1243 | pkg = pkgs[0]; |
| 1244 | } |
| 1245 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1246 | Provider p = lookupProviderLocked(new ComponentName(pkg, cl)); |
| 1247 | if (p == null && mSafeMode) { |
| 1248 | // if we're in safe mode, make a temporary one |
| 1249 | p = new Provider(); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1250 | p.info = new AppWidgetProviderInfo(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1251 | p.info.provider = new ComponentName(pkg, cl); |
| 1252 | p.zombie = true; |
| 1253 | mInstalledProviders.add(p); |
| 1254 | } |
| 1255 | if (p != null) { |
| 1256 | // if it wasn't uninstalled or something |
| 1257 | loadedProviders.put(providerIndex, p); |
| 1258 | } |
| 1259 | providerIndex++; |
| 1260 | } |
| 1261 | else if ("h".equals(tag)) { |
| 1262 | Host host = new Host(); |
| 1263 | |
| 1264 | // TODO: do we need to check that this package has the same signature |
| 1265 | // as before? |
| 1266 | host.packageName = parser.getAttributeValue(null, "pkg"); |
| 1267 | try { |
| 1268 | host.uid = getUidForPackage(host.packageName); |
| 1269 | } catch (PackageManager.NameNotFoundException ex) { |
| 1270 | host.zombie = true; |
| 1271 | } |
| 1272 | if (!host.zombie || mSafeMode) { |
| 1273 | // In safe mode, we don't discard the hosts we don't recognize |
| 1274 | // so that they're not pruned from our list. Otherwise, we do. |
| 1275 | host.hostId = Integer.parseInt( |
| 1276 | parser.getAttributeValue(null, "id"), 16); |
| 1277 | mHosts.add(host); |
| 1278 | } |
| 1279 | } |
| 1280 | else if ("g".equals(tag)) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1281 | AppWidgetId id = new AppWidgetId(); |
| 1282 | id.appWidgetId = Integer.parseInt(parser.getAttributeValue(null, "id"), 16); |
| 1283 | if (id.appWidgetId >= mNextAppWidgetId) { |
| 1284 | mNextAppWidgetId = id.appWidgetId + 1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | String providerString = parser.getAttributeValue(null, "p"); |
| 1288 | if (providerString != null) { |
| 1289 | // there's no provider if it hasn't been bound yet. |
| 1290 | // maybe we don't have to save this, but it brings the system |
| 1291 | // to the state it was in. |
| 1292 | int pIndex = Integer.parseInt(providerString, 16); |
| 1293 | id.provider = loadedProviders.get(pIndex); |
| 1294 | if (false) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1295 | Slog.d(TAG, "bound appWidgetId=" + id.appWidgetId + " to provider " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1296 | + pIndex + " which is " + id.provider); |
| 1297 | } |
| 1298 | if (id.provider == null) { |
| 1299 | // This provider is gone. We just let the host figure out |
| 1300 | // that this happened when it fails to load it. |
| 1301 | continue; |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | int hIndex = Integer.parseInt(parser.getAttributeValue(null, "h"), 16); |
| 1306 | id.host = mHosts.get(hIndex); |
| 1307 | if (id.host == null) { |
| 1308 | // This host is gone. |
| 1309 | continue; |
| 1310 | } |
| 1311 | |
| 1312 | if (id.provider != null) { |
| 1313 | id.provider.instances.add(id); |
| 1314 | } |
| 1315 | id.host.instances.add(id); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1316 | mAppWidgetIds.add(id); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1317 | } |
| 1318 | } |
| 1319 | } while (type != XmlPullParser.END_DOCUMENT); |
| 1320 | success = true; |
| 1321 | } catch (NullPointerException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1322 | Slog.w(TAG, "failed parsing " + file, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1323 | } catch (NumberFormatException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1324 | Slog.w(TAG, "failed parsing " + file, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1325 | } catch (XmlPullParserException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1326 | Slog.w(TAG, "failed parsing " + file, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1327 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1328 | Slog.w(TAG, "failed parsing " + file, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1329 | } catch (IndexOutOfBoundsException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1330 | Slog.w(TAG, "failed parsing " + file, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1331 | } |
| 1332 | try { |
| 1333 | if (stream != null) { |
| 1334 | stream.close(); |
| 1335 | } |
| 1336 | } catch (IOException e) { |
| Romain Guy | a547559 | 2009-07-01 17:20:08 -0700 | [diff] [blame] | 1337 | // Ignore |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | if (success) { |
| 1341 | // delete any hosts that didn't manage to get connected (should happen) |
| 1342 | // if it matters, they'll be reconnected. |
| Dianne Hackborn | 002716d | 2009-08-12 11:13:26 -0700 | [diff] [blame] | 1343 | for (int i=mHosts.size()-1; i>=0; i--) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1344 | pruneHostLocked(mHosts.get(i)); |
| 1345 | } |
| 1346 | } else { |
| 1347 | // failed reading, clean up |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1348 | mAppWidgetIds.clear(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1349 | mHosts.clear(); |
| 1350 | final int N = mInstalledProviders.size(); |
| 1351 | for (int i=0; i<N; i++) { |
| 1352 | mInstalledProviders.get(i).instances.clear(); |
| 1353 | } |
| 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | File savedStateTempFile() { |
| 1358 | return new File("/data/system/" + SETTINGS_TMP_FILENAME); |
| 1359 | //return new File(mContext.getFilesDir(), SETTINGS_FILENAME); |
| 1360 | } |
| 1361 | |
| 1362 | File savedStateRealFile() { |
| 1363 | return new File("/data/system/" + SETTINGS_FILENAME); |
| 1364 | //return new File(mContext.getFilesDir(), SETTINGS_TMP_FILENAME); |
| 1365 | } |
| 1366 | |
| 1367 | BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 1368 | public void onReceive(Context context, Intent intent) { |
| 1369 | String action = intent.getAction(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1370 | //Slog.d(TAG, "received " + action); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1371 | if (Intent.ACTION_BOOT_COMPLETED.equals(action)) { |
| 1372 | sendInitialBroadcasts(); |
| Eric Fischer | 63c2d9e | 2009-10-22 15:22:50 -0700 | [diff] [blame] | 1373 | } else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) { |
| 1374 | Locale revised = Locale.getDefault(); |
| 1375 | if (revised == null || mLocale == null || |
| 1376 | !(revised.equals(mLocale))) { |
| 1377 | mLocale = revised; |
| 1378 | |
| 1379 | synchronized (mAppWidgetIds) { |
| 1380 | int N = mInstalledProviders.size(); |
| 1381 | for (int i=N-1; i>=0; i--) { |
| 1382 | Provider p = mInstalledProviders.get(i); |
| 1383 | String pkgName = p.info.provider.getPackageName(); |
| 1384 | updateProvidersForPackageLocked(pkgName); |
| 1385 | } |
| 1386 | saveStateLocked(); |
| 1387 | } |
| 1388 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1389 | } else { |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1390 | boolean added = false; |
| Joe Onorato | d070e89 | 2011-01-07 20:50:37 -0800 | [diff] [blame] | 1391 | boolean changed = false; |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1392 | String pkgList[] = null; |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 1393 | if (Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE.equals(action)) { |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1394 | pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST); |
| 1395 | added = true; |
| Joe Onorato | 94258cd | 2010-08-24 16:45:40 -0400 | [diff] [blame] | 1396 | } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) { |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1397 | pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST); |
| 1398 | added = false; |
| 1399 | } else { |
| 1400 | Uri uri = intent.getData(); |
| 1401 | if (uri == null) { |
| 1402 | return; |
| 1403 | } |
| 1404 | String pkgName = uri.getSchemeSpecificPart(); |
| 1405 | if (pkgName == null) { |
| 1406 | return; |
| 1407 | } |
| 1408 | pkgList = new String[] { pkgName }; |
| 1409 | added = Intent.ACTION_PACKAGE_ADDED.equals(action); |
| Joe Onorato | d070e89 | 2011-01-07 20:50:37 -0800 | [diff] [blame] | 1410 | changed = Intent.ACTION_PACKAGE_CHANGED.equals(action); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1411 | } |
| 1412 | if (pkgList == null || pkgList.length == 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1413 | return; |
| 1414 | } |
| Joe Onorato | d070e89 | 2011-01-07 20:50:37 -0800 | [diff] [blame] | 1415 | if (added || changed) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1416 | synchronized (mAppWidgetIds) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1417 | Bundle extras = intent.getExtras(); |
| Joe Onorato | d070e89 | 2011-01-07 20:50:37 -0800 | [diff] [blame] | 1418 | if (changed || (extras != null && |
| 1419 | extras.getBoolean(Intent.EXTRA_REPLACING, false))) { |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1420 | for (String pkgName : pkgList) { |
| 1421 | // The package was just upgraded |
| 1422 | updateProvidersForPackageLocked(pkgName); |
| 1423 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1424 | } else { |
| 1425 | // The package was just added |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1426 | for (String pkgName : pkgList) { |
| 1427 | addProvidersForPackageLocked(pkgName); |
| 1428 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1429 | } |
| 1430 | saveStateLocked(); |
| 1431 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1432 | } else { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1433 | Bundle extras = intent.getExtras(); |
| 1434 | if (extras != null && extras.getBoolean(Intent.EXTRA_REPLACING, false)) { |
| 1435 | // The package is being updated. We'll receive a PACKAGE_ADDED shortly. |
| 1436 | } else { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1437 | synchronized (mAppWidgetIds) { |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1438 | for (String pkgName : pkgList) { |
| 1439 | removeProvidersForPackageLocked(pkgName); |
| 1440 | saveStateLocked(); |
| 1441 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1442 | } |
| 1443 | } |
| 1444 | } |
| 1445 | } |
| 1446 | } |
| 1447 | }; |
| 1448 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1449 | void addProvidersForPackageLocked(String pkgName) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1450 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE); |
| Joe Onorato | f6133fe | 2010-02-01 18:24:46 -0500 | [diff] [blame] | 1451 | intent.setPackage(pkgName); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1452 | List<ResolveInfo> broadcastReceivers = mPackageManager.queryBroadcastReceivers(intent, |
| 1453 | PackageManager.GET_META_DATA); |
| 1454 | |
| Bjorn Bringert | 5f85780 | 2010-02-10 23:09:48 +0000 | [diff] [blame] | 1455 | final int N = broadcastReceivers == null ? 0 : broadcastReceivers.size(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1456 | for (int i=0; i<N; i++) { |
| 1457 | ResolveInfo ri = broadcastReceivers.get(i); |
| 1458 | ActivityInfo ai = ri.activityInfo; |
| Joe Onorato | 331fbdc7 | 2010-08-24 17:02:09 -0400 | [diff] [blame] | 1459 | if ((ai.applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) { |
| 1460 | continue; |
| 1461 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1462 | if (pkgName.equals(ai.packageName)) { |
| 1463 | addProviderLocked(ri); |
| 1464 | } |
| 1465 | } |
| 1466 | } |
| 1467 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1468 | void updateProvidersForPackageLocked(String pkgName) { |
| Romain Guy | a547559 | 2009-07-01 17:20:08 -0700 | [diff] [blame] | 1469 | HashSet<String> keep = new HashSet<String>(); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1470 | Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE); |
| Joe Onorato | f6133fe | 2010-02-01 18:24:46 -0500 | [diff] [blame] | 1471 | intent.setPackage(pkgName); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1472 | List<ResolveInfo> broadcastReceivers = mPackageManager.queryBroadcastReceivers(intent, |
| 1473 | PackageManager.GET_META_DATA); |
| 1474 | |
| 1475 | // add the missing ones and collect which ones to keep |
| Bjorn Bringert | 5f85780 | 2010-02-10 23:09:48 +0000 | [diff] [blame] | 1476 | int N = broadcastReceivers == null ? 0 : broadcastReceivers.size(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1477 | for (int i=0; i<N; i++) { |
| 1478 | ResolveInfo ri = broadcastReceivers.get(i); |
| 1479 | ActivityInfo ai = ri.activityInfo; |
| Joe Onorato | 331fbdc7 | 2010-08-24 17:02:09 -0400 | [diff] [blame] | 1480 | if ((ai.applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) { |
| 1481 | continue; |
| 1482 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1483 | if (pkgName.equals(ai.packageName)) { |
| 1484 | ComponentName component = new ComponentName(ai.packageName, ai.name); |
| 1485 | Provider p = lookupProviderLocked(component); |
| 1486 | if (p == null) { |
| 1487 | if (addProviderLocked(ri)) { |
| 1488 | keep.add(ai.name); |
| 1489 | } |
| 1490 | } else { |
| 1491 | Provider parsed = parseProviderInfoXml(component, ri); |
| 1492 | if (parsed != null) { |
| 1493 | keep.add(ai.name); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1494 | // Use the new AppWidgetProviderInfo. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1495 | p.info = parsed.info; |
| 1496 | // If it's enabled |
| 1497 | final int M = p.instances.size(); |
| 1498 | if (M > 0) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1499 | int[] appWidgetIds = getAppWidgetIds(p); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1500 | // Reschedule for the new updatePeriodMillis (don't worry about handling |
| 1501 | // it specially if updatePeriodMillis didn't change because we just sent |
| 1502 | // an update, and the next one will be updatePeriodMillis from now). |
| 1503 | cancelBroadcasts(p); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1504 | registerForBroadcastsLocked(p, appWidgetIds); |
| 1505 | // If it's currently showing, call back with the new AppWidgetProviderInfo. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1506 | for (int j=0; j<M; j++) { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1507 | AppWidgetId id = p.instances.get(j); |
| Joe Onorato | a8a8a42 | 2010-06-16 15:06:16 -0400 | [diff] [blame] | 1508 | id.views = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1509 | if (id.host != null && id.host.callbacks != null) { |
| 1510 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1511 | id.host.callbacks.providerChanged(id.appWidgetId, p.info); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1512 | } catch (RemoteException ex) { |
| 1513 | // It failed; remove the callback. No need to prune because |
| 1514 | // we know that this host is still referenced by this |
| 1515 | // instance. |
| 1516 | id.host.callbacks = null; |
| 1517 | } |
| 1518 | } |
| 1519 | } |
| 1520 | // Now that we've told the host, push out an update. |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1521 | sendUpdateIntentLocked(p, appWidgetIds); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1522 | } |
| 1523 | } |
| 1524 | } |
| 1525 | } |
| 1526 | } |
| 1527 | |
| 1528 | // prune the ones we don't want to keep |
| 1529 | N = mInstalledProviders.size(); |
| 1530 | for (int i=N-1; i>=0; i--) { |
| 1531 | Provider p = mInstalledProviders.get(i); |
| 1532 | if (pkgName.equals(p.info.provider.getPackageName()) |
| 1533 | && !keep.contains(p.info.provider.getClassName())) { |
| 1534 | removeProviderLocked(i, p); |
| 1535 | } |
| 1536 | } |
| 1537 | } |
| 1538 | |
| 1539 | void removeProvidersForPackageLocked(String pkgName) { |
| 1540 | int N = mInstalledProviders.size(); |
| 1541 | for (int i=N-1; i>=0; i--) { |
| 1542 | Provider p = mInstalledProviders.get(i); |
| 1543 | if (pkgName.equals(p.info.provider.getPackageName())) { |
| 1544 | removeProviderLocked(i, p); |
| 1545 | } |
| 1546 | } |
| 1547 | |
| 1548 | // Delete the hosts for this package too |
| 1549 | // |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1550 | // By now, we have removed any AppWidgets that were in any hosts here, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1551 | // so we don't need to worry about sending DISABLE broadcasts to them. |
| 1552 | N = mHosts.size(); |
| 1553 | for (int i=N-1; i>=0; i--) { |
| 1554 | Host host = mHosts.get(i); |
| 1555 | if (pkgName.equals(host.packageName)) { |
| 1556 | deleteHostLocked(host); |
| 1557 | } |
| 1558 | } |
| 1559 | } |
| 1560 | } |
| 1561 | |