blob: b8b8880b9d5c355d0069c281e4ee99168d1ff8ff [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
19import android.app.AlarmManager;
20import android.app.PendingIntent;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070021import android.appwidget.AppWidgetManager;
22import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.content.BroadcastReceiver;
24import android.content.ComponentName;
25import android.content.Context;
26import android.content.Intent;
27import android.content.IntentFilter;
28import android.content.pm.ActivityInfo;
29import android.content.pm.PackageManager;
30import android.content.pm.PackageInfo;
31import android.content.pm.ResolveInfo;
Dianne Hackborn20cb56e2010-03-04 00:58:29 -080032import android.content.res.Resources;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.content.res.TypedArray;
34import android.content.res.XmlResourceParser;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import android.net.Uri;
36import android.os.Binder;
37import android.os.Bundle;
Marco Nelissen54796e72009-04-30 15:16:30 -070038import android.os.Process;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.os.RemoteException;
40import android.os.SystemClock;
41import android.util.AttributeSet;
Joe Onorato8a9b2202010-02-26 18:56:32 -080042import android.util.Slog;
Mitsuru Oshima8f25c422009-07-01 00:10:43 -070043import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import android.util.Xml;
45import android.widget.RemoteViews;
46
47import java.io.IOException;
48import java.io.File;
49import java.io.FileDescriptor;
50import java.io.FileInputStream;
51import java.io.FileOutputStream;
52import java.io.PrintWriter;
53import java.util.ArrayList;
54import java.util.List;
Eric Fischer63c2d9e2009-10-22 15:22:50 -070055import java.util.Locale;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import java.util.HashMap;
57import java.util.HashSet;
58
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070059import com.android.internal.appwidget.IAppWidgetService;
60import com.android.internal.appwidget.IAppWidgetHost;
Dianne Hackborn2269d1572010-02-24 19:54:22 -080061import com.android.internal.util.FastXmlSerializer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062
63import org.xmlpull.v1.XmlPullParser;
64import org.xmlpull.v1.XmlPullParserException;
65import org.xmlpull.v1.XmlSerializer;
66
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070067class AppWidgetService extends IAppWidgetService.Stub
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068{
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070069 private static final String TAG = "AppWidgetService";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070071 private static final String SETTINGS_FILENAME = "appwidgets.xml";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072 private static final String SETTINGS_TMP_FILENAME = SETTINGS_FILENAME + ".tmp";
Joe Onoratobe96b3a2009-07-14 19:49:27 -070073 private static final int MIN_UPDATE_PERIOD = 30 * 60 * 1000; // 30 minutes
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074
75 /*
76 * When identifying a Host or Provider based on the calling process, use the uid field.
77 * When identifying a Host or Provider based on a package manager broadcast, use the
78 * package given.
79 */
80
81 static class Provider {
82 int uid;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070083 AppWidgetProviderInfo info;
Romain Guya5475592009-07-01 17:20:08 -070084 ArrayList<AppWidgetId> instances = new ArrayList<AppWidgetId>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085 PendingIntent broadcast;
86 boolean zombie; // if we're in safe mode, don't prune this just because nobody references it
87
88 int tag; // for use while saving state (the index)
89 }
90
91 static class Host {
92 int uid;
93 int hostId;
94 String packageName;
Romain Guya5475592009-07-01 17:20:08 -070095 ArrayList<AppWidgetId> instances = new ArrayList<AppWidgetId>();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -070096 IAppWidgetHost callbacks;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 boolean zombie; // if we're in safe mode, don't prune this just because nobody references it
98
99 int tag; // for use while saving state (the index)
100 }
101
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700102 static class AppWidgetId {
103 int appWidgetId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 Provider provider;
105 RemoteViews views;
106 Host host;
107 }
108
109 Context mContext;
Eric Fischer63c2d9e2009-10-22 15:22:50 -0700110 Locale mLocale;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111 PackageManager mPackageManager;
112 AlarmManager mAlarmManager;
Romain Guya5475592009-07-01 17:20:08 -0700113 ArrayList<Provider> mInstalledProviders = new ArrayList<Provider>();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700114 int mNextAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID + 1;
Romain Guya5475592009-07-01 17:20:08 -0700115 final ArrayList<AppWidgetId> mAppWidgetIds = new ArrayList<AppWidgetId>();
116 ArrayList<Host> mHosts = new ArrayList<Host>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 boolean mSafeMode;
118
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700119 AppWidgetService(Context context) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 mContext = context;
121 mPackageManager = context.getPackageManager();
122 mAlarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
123 }
124
125 public void systemReady(boolean safeMode) {
126 mSafeMode = safeMode;
127
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700128 loadAppWidgetList();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 loadStateLocked();
130
131 // Register for the boot completed broadcast, so we can send the
132 // ENABLE broacasts. If we try to send them now, they time out,
133 // because the system isn't ready to handle them yet.
134 mContext.registerReceiver(mBroadcastReceiver,
135 new IntentFilter(Intent.ACTION_BOOT_COMPLETED), null, null);
136
Eric Fischer63c2d9e2009-10-22 15:22:50 -0700137 // Register for configuration changes so we can update the names
138 // of the widgets when the locale changes.
139 mContext.registerReceiver(mBroadcastReceiver,
140 new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED), null, null);
141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 // Register for broadcasts about package install, etc., so we can
143 // update the provider list.
144 IntentFilter filter = new IntentFilter();
145 filter.addAction(Intent.ACTION_PACKAGE_ADDED);
146 filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
147 filter.addDataScheme("package");
148 mContext.registerReceiver(mBroadcastReceiver, filter);
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800149 // Register for events related to sdcard installation.
150 IntentFilter sdFilter = new IntentFilter();
Suchi Amalapurapub56ae202010-02-04 22:51:07 -0800151 sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
152 sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800153 mContext.registerReceiver(mBroadcastReceiver, sdFilter);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 }
155
156 @Override
157 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
158 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
159 != PackageManager.PERMISSION_GRANTED) {
160 pw.println("Permission Denial: can't dump from from pid="
161 + Binder.getCallingPid()
162 + ", uid=" + Binder.getCallingUid());
163 return;
164 }
165
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700166 synchronized (mAppWidgetIds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 int N = mInstalledProviders.size();
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700168 pw.println("Providers:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 for (int i=0; i<N; i++) {
170 Provider p = mInstalledProviders.get(i);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700171 AppWidgetProviderInfo info = p.info;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700172 pw.print(" ["); pw.print(i); pw.print("] provider ");
173 pw.print(info.provider.flattenToShortString());
174 pw.println(':');
175 pw.print(" min=("); pw.print(info.minWidth);
176 pw.print("x"); pw.print(info.minHeight);
177 pw.print(") updatePeriodMillis=");
178 pw.print(info.updatePeriodMillis);
179 pw.print(" initialLayout=#");
180 pw.print(Integer.toHexString(info.initialLayout));
181 pw.print(" zombie="); pw.println(p.zombie);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 }
183
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700184 N = mAppWidgetIds.size();
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700185 pw.println(" ");
186 pw.println("AppWidgetIds:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800187 for (int i=0; i<N; i++) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700188 AppWidgetId id = mAppWidgetIds.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700189 pw.print(" ["); pw.print(i); pw.print("] id=");
Romain Guya5475592009-07-01 17:20:08 -0700190 pw.println(id.appWidgetId);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700191 pw.print(" hostId=");
192 pw.print(id.host.hostId); pw.print(' ');
193 pw.print(id.host.packageName); pw.print('/');
194 pw.println(id.host.uid);
195 if (id.provider != null) {
196 pw.print(" provider=");
197 pw.println(id.provider.info.provider.flattenToShortString());
198 }
199 if (id.host != null) {
200 pw.print(" host.callbacks="); pw.println(id.host.callbacks);
201 }
202 if (id.views != null) {
203 pw.print(" views="); pw.println(id.views);
204 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 }
206
207 N = mHosts.size();
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700208 pw.println(" ");
209 pw.println("Hosts:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 for (int i=0; i<N; i++) {
211 Host host = mHosts.get(i);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700212 pw.print(" ["); pw.print(i); pw.print("] hostId=");
213 pw.print(host.hostId); pw.print(' ');
214 pw.print(host.packageName); pw.print('/');
215 pw.print(host.uid); pw.println(':');
216 pw.print(" callbacks="); pw.println(host.callbacks);
217 pw.print(" instances.size="); pw.print(host.instances.size());
218 pw.print(" zombie="); pw.println(host.zombie);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 }
220 }
221 }
222
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700223 public int allocateAppWidgetId(String packageName, int hostId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 int callingUid = enforceCallingUid(packageName);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700225 synchronized (mAppWidgetIds) {
226 int appWidgetId = mNextAppWidgetId++;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227
228 Host host = lookupOrAddHostLocked(callingUid, packageName, hostId);
229
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700230 AppWidgetId id = new AppWidgetId();
231 id.appWidgetId = appWidgetId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 id.host = host;
233
234 host.instances.add(id);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700235 mAppWidgetIds.add(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236
237 saveStateLocked();
238
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700239 return appWidgetId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240 }
241 }
242
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700243 public void deleteAppWidgetId(int appWidgetId) {
244 synchronized (mAppWidgetIds) {
245 AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 if (id != null) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700247 deleteAppWidgetLocked(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 saveStateLocked();
249 }
250 }
251 }
252
253 public void deleteHost(int hostId) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700254 synchronized (mAppWidgetIds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800255 int callingUid = getCallingUid();
256 Host host = lookupHostLocked(callingUid, hostId);
257 if (host != null) {
258 deleteHostLocked(host);
259 saveStateLocked();
260 }
261 }
262 }
263
264 public void deleteAllHosts() {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700265 synchronized (mAppWidgetIds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800266 int callingUid = getCallingUid();
267 final int N = mHosts.size();
268 boolean changed = false;
269 for (int i=N-1; i>=0; i--) {
270 Host host = mHosts.get(i);
271 if (host.uid == callingUid) {
272 deleteHostLocked(host);
273 changed = true;
274 }
275 }
276 if (changed) {
277 saveStateLocked();
278 }
279 }
280 }
281
282 void deleteHostLocked(Host host) {
283 final int N = host.instances.size();
284 for (int i=N-1; i>=0; i--) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700285 AppWidgetId id = host.instances.get(i);
286 deleteAppWidgetLocked(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 }
288 host.instances.clear();
289 mHosts.remove(host);
290 // it's gone or going away, abruptly drop the callback connection
291 host.callbacks = null;
292 }
293
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700294 void deleteAppWidgetLocked(AppWidgetId id) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 Host host = id.host;
296 host.instances.remove(id);
297 pruneHostLocked(host);
298
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700299 mAppWidgetIds.remove(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800300
301 Provider p = id.provider;
302 if (p != null) {
303 p.instances.remove(id);
304 if (!p.zombie) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700305 // send the broacast saying that this appWidgetId has been deleted
306 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_DELETED);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 intent.setComponent(p.info.provider);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700308 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id.appWidgetId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800309 mContext.sendBroadcast(intent);
310 if (p.instances.size() == 0) {
311 // cancel the future updates
312 cancelBroadcasts(p);
313
314 // send the broacast saying that the provider is not in use any more
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700315 intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_DISABLED);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316 intent.setComponent(p.info.provider);
317 mContext.sendBroadcast(intent);
318 }
319 }
320 }
321 }
322
323 void cancelBroadcasts(Provider p) {
324 if (p.broadcast != null) {
325 mAlarmManager.cancel(p.broadcast);
326 long token = Binder.clearCallingIdentity();
327 try {
328 p.broadcast.cancel();
329 } finally {
330 Binder.restoreCallingIdentity(token);
331 }
332 p.broadcast = null;
333 }
334 }
335
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700336 public void bindAppWidgetId(int appWidgetId, ComponentName provider) {
337 mContext.enforceCallingPermission(android.Manifest.permission.BIND_APPWIDGET,
338 "bindGagetId appWidgetId=" + appWidgetId + " provider=" + provider);
339 synchronized (mAppWidgetIds) {
340 AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 if (id == null) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700342 throw new IllegalArgumentException("bad appWidgetId");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800343 }
344 if (id.provider != null) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700345 throw new IllegalArgumentException("appWidgetId " + appWidgetId + " already bound to "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 + id.provider.info.provider);
347 }
348 Provider p = lookupProviderLocked(provider);
349 if (p == null) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700350 throw new IllegalArgumentException("not a appwidget provider: " + provider);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 }
352 if (p.zombie) {
353 throw new IllegalArgumentException("can't bind to a 3rd party provider in"
354 + " safe mode: " + provider);
355 }
356
357 id.provider = p;
358 p.instances.add(id);
359 int instancesSize = p.instances.size();
360 if (instancesSize == 1) {
361 // tell the provider that it's ready
362 sendEnableIntentLocked(p);
363 }
364
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700365 // send an update now -- We need this update now, and just for this appWidgetId.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 // It's less critical when the next one happens, so when we schdule the next one,
367 // we add updatePeriodMillis to its start time. That time will have some slop,
368 // but that's okay.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700369 sendUpdateIntentLocked(p, new int[] { appWidgetId });
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370
371 // schedule the future updates
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700372 registerForBroadcastsLocked(p, getAppWidgetIds(p));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 saveStateLocked();
374 }
375 }
376
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700377 public AppWidgetProviderInfo getAppWidgetInfo(int appWidgetId) {
378 synchronized (mAppWidgetIds) {
379 AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 if (id != null && id.provider != null && !id.provider.zombie) {
381 return id.provider.info;
382 }
383 return null;
384 }
385 }
386
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700387 public RemoteViews getAppWidgetViews(int appWidgetId) {
388 synchronized (mAppWidgetIds) {
389 AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800390 if (id != null) {
391 return id.views;
392 }
393 return null;
394 }
395 }
396
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700397 public List<AppWidgetProviderInfo> getInstalledProviders() {
398 synchronized (mAppWidgetIds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 final int N = mInstalledProviders.size();
Romain Guya5475592009-07-01 17:20:08 -0700400 ArrayList<AppWidgetProviderInfo> result = new ArrayList<AppWidgetProviderInfo>(N);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800401 for (int i=0; i<N; i++) {
402 Provider p = mInstalledProviders.get(i);
403 if (!p.zombie) {
404 result.add(p.info);
405 }
406 }
407 return result;
408 }
409 }
410
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700411 public void updateAppWidgetIds(int[] appWidgetIds, RemoteViews views) {
412 if (appWidgetIds == null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 return;
414 }
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700415 if (appWidgetIds.length == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800416 return;
417 }
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700418 final int N = appWidgetIds.length;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700420 synchronized (mAppWidgetIds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800421 for (int i=0; i<N; i++) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700422 AppWidgetId id = lookupAppWidgetIdLocked(appWidgetIds[i]);
423 updateAppWidgetInstanceLocked(id, views);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800424 }
425 }
426 }
427
Adam Cohen2dd21972010-08-15 18:20:04 -0700428 public void partiallyUpdateAppWidgetIds(int[] appWidgetIds, RemoteViews views) {
429 if (appWidgetIds == null) {
430 return;
431 }
432 if (appWidgetIds.length == 0) {
433 return;
434 }
435 final int N = appWidgetIds.length;
436
437 synchronized (mAppWidgetIds) {
438 for (int i=0; i<N; i++) {
439 AppWidgetId id = lookupAppWidgetIdLocked(appWidgetIds[i]);
440 updateAppWidgetInstanceLocked(id, views, true);
441 }
442 }
443 }
444
Winson Chung499cb9f2010-07-16 11:18:17 -0700445 public void notifyAppWidgetViewDataChanged(int[] appWidgetIds, RemoteViews views, int viewId) {
446 if (appWidgetIds == null) {
447 return;
448 }
449 if (appWidgetIds.length == 0) {
450 return;
451 }
452 final int N = appWidgetIds.length;
453
454 synchronized (mAppWidgetIds) {
455 for (int i=0; i<N; i++) {
456 AppWidgetId id = lookupAppWidgetIdLocked(appWidgetIds[i]);
457 notifyAppWidgetViewDataChangedInstanceLocked(id, views, viewId);
458 }
459 }
460 }
461
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700462 public void updateAppWidgetProvider(ComponentName provider, RemoteViews views) {
463 synchronized (mAppWidgetIds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800464 Provider p = lookupProviderLocked(provider);
465 if (p == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800466 Slog.w(TAG, "updateAppWidgetProvider: provider doesn't exist: " + provider);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800467 return;
468 }
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700469 ArrayList<AppWidgetId> instances = p.instances;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800470 final int N = instances.size();
471 for (int i=0; i<N; i++) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700472 AppWidgetId id = instances.get(i);
473 updateAppWidgetInstanceLocked(id, views);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800474 }
475 }
476 }
477
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700478 void updateAppWidgetInstanceLocked(AppWidgetId id, RemoteViews views) {
Adam Cohen2dd21972010-08-15 18:20:04 -0700479 updateAppWidgetInstanceLocked(id, views, false);
480 }
481
482 void updateAppWidgetInstanceLocked(AppWidgetId id, RemoteViews views, boolean isPartialUpdate) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700483 // allow for stale appWidgetIds and other badness
484 // lookup also checks that the calling process can access the appWidgetId
485 // drop unbound appWidgetIds (shouldn't be possible under normal circumstances)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 if (id != null && id.provider != null && !id.provider.zombie && !id.host.zombie) {
Adam Cohen2dd21972010-08-15 18:20:04 -0700487
488 // We do not want to save this RemoteViews
489 if (!isPartialUpdate) id.views = views;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490
491 // is anyone listening?
492 if (id.host.callbacks != null) {
493 try {
494 // the lock is held, but this is a oneway call
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700495 id.host.callbacks.updateAppWidget(id.appWidgetId, views);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 } catch (RemoteException e) {
497 // It failed; remove the callback. No need to prune because
498 // we know that this host is still referenced by this instance.
499 id.host.callbacks = null;
500 }
501 }
502 }
503 }
504
Winson Chung499cb9f2010-07-16 11:18:17 -0700505 void notifyAppWidgetViewDataChangedInstanceLocked(AppWidgetId id, RemoteViews views, int viewId) {
506 // allow for stale appWidgetIds and other badness
507 // lookup also checks that the calling process can access the appWidgetId
508 // drop unbound appWidgetIds (shouldn't be possible under normal circumstances)
509 if (id != null && id.provider != null && !id.provider.zombie && !id.host.zombie) {
510 id.views = views;
511
512 // is anyone listening?
513 if (id.host.callbacks != null) {
514 try {
515 // the lock is held, but this is a oneway call
516 id.host.callbacks.viewDataChanged(id.appWidgetId, views, viewId);
517 } catch (RemoteException e) {
518 // It failed; remove the callback. No need to prune because
519 // we know that this host is still referenced by this instance.
520 id.host.callbacks = null;
521 }
522 }
523 }
524 }
525
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700526 public int[] startListening(IAppWidgetHost callbacks, String packageName, int hostId,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800527 List<RemoteViews> updatedViews) {
528 int callingUid = enforceCallingUid(packageName);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700529 synchronized (mAppWidgetIds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530 Host host = lookupOrAddHostLocked(callingUid, packageName, hostId);
531 host.callbacks = callbacks;
532
533 updatedViews.clear();
534
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700535 ArrayList<AppWidgetId> instances = host.instances;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 int N = instances.size();
537 int[] updatedIds = new int[N];
538 for (int i=0; i<N; i++) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700539 AppWidgetId id = instances.get(i);
540 updatedIds[i] = id.appWidgetId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 updatedViews.add(id.views);
542 }
543 return updatedIds;
544 }
545 }
546
547 public void stopListening(int hostId) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700548 synchronized (mAppWidgetIds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800549 Host host = lookupHostLocked(getCallingUid(), hostId);
Ken Shirriffe21167a2009-09-23 16:42:53 -0700550 if (host != null) {
551 host.callbacks = null;
552 pruneHostLocked(host);
553 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554 }
555 }
556
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700557 boolean canAccessAppWidgetId(AppWidgetId id, int callingUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558 if (id.host.uid == callingUid) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700559 // Apps hosting the AppWidget have access to it.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800560 return true;
561 }
562 if (id.provider != null && id.provider.uid == callingUid) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700563 // Apps providing the AppWidget have access to it (if the appWidgetId has been bound)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 return true;
565 }
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700566 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.BIND_APPWIDGET)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 == PackageManager.PERMISSION_GRANTED) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700568 // Apps that can bind have access to all appWidgetIds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 return true;
570 }
571 // Nobody else can access it.
572 return false;
573 }
574
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700575 AppWidgetId lookupAppWidgetIdLocked(int appWidgetId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 int callingUid = getCallingUid();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700577 final int N = mAppWidgetIds.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 for (int i=0; i<N; i++) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700579 AppWidgetId id = mAppWidgetIds.get(i);
580 if (id.appWidgetId == appWidgetId && canAccessAppWidgetId(id, callingUid)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 return id;
582 }
583 }
584 return null;
585 }
586
587 Provider lookupProviderLocked(ComponentName provider) {
Romain Guyd2671e12010-03-11 18:06:42 -0800588 final String className = provider.getClassName();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 final int N = mInstalledProviders.size();
590 for (int i=0; i<N; i++) {
591 Provider p = mInstalledProviders.get(i);
Romain Guyd2671e12010-03-11 18:06:42 -0800592 if (p.info.provider.equals(provider) || className.equals(p.info.oldName)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 return p;
594 }
595 }
596 return null;
597 }
598
599 Host lookupHostLocked(int uid, int hostId) {
600 final int N = mHosts.size();
601 for (int i=0; i<N; i++) {
602 Host h = mHosts.get(i);
603 if (h.uid == uid && h.hostId == hostId) {
604 return h;
605 }
606 }
607 return null;
608 }
609
610 Host lookupOrAddHostLocked(int uid, String packageName, int hostId) {
611 final int N = mHosts.size();
612 for (int i=0; i<N; i++) {
613 Host h = mHosts.get(i);
614 if (h.hostId == hostId && h.packageName.equals(packageName)) {
615 return h;
616 }
617 }
618 Host host = new Host();
619 host.packageName = packageName;
620 host.uid = uid;
621 host.hostId = hostId;
622 mHosts.add(host);
623 return host;
624 }
625
626 void pruneHostLocked(Host host) {
627 if (host.instances.size() == 0 && host.callbacks == null) {
628 mHosts.remove(host);
629 }
630 }
631
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700632 void loadAppWidgetList() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 PackageManager pm = mPackageManager;
634
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700635 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800636 List<ResolveInfo> broadcastReceivers = pm.queryBroadcastReceivers(intent,
637 PackageManager.GET_META_DATA);
638
Bjorn Bringert5f857802010-02-10 23:09:48 +0000639 final int N = broadcastReceivers == null ? 0 : broadcastReceivers.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640 for (int i=0; i<N; i++) {
641 ResolveInfo ri = broadcastReceivers.get(i);
642 addProviderLocked(ri);
643 }
644 }
645
646 boolean addProviderLocked(ResolveInfo ri) {
647 Provider p = parseProviderInfoXml(new ComponentName(ri.activityInfo.packageName,
648 ri.activityInfo.name), ri);
649 if (p != null) {
650 mInstalledProviders.add(p);
651 return true;
652 } else {
653 return false;
654 }
655 }
656
657 void removeProviderLocked(int index, Provider p) {
658 int N = p.instances.size();
659 for (int i=0; i<N; i++) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700660 AppWidgetId id = p.instances.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800661 // Call back with empty RemoteViews
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700662 updateAppWidgetInstanceLocked(id, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663 // Stop telling the host about updates for this from now on
664 cancelBroadcasts(p);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700665 // clear out references to this appWidgetId
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800666 id.host.instances.remove(id);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700667 mAppWidgetIds.remove(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800668 id.provider = null;
669 pruneHostLocked(id.host);
670 id.host = null;
671 }
672 p.instances.clear();
673 mInstalledProviders.remove(index);
674 // no need to send the DISABLE broadcast, since the receiver is gone anyway
675 cancelBroadcasts(p);
676 }
677
678 void sendEnableIntentLocked(Provider p) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700679 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_ENABLED);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800680 intent.setComponent(p.info.provider);
681 mContext.sendBroadcast(intent);
682 }
683
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700684 void sendUpdateIntentLocked(Provider p, int[] appWidgetIds) {
685 if (appWidgetIds != null && appWidgetIds.length > 0) {
686 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
687 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800688 intent.setComponent(p.info.provider);
689 mContext.sendBroadcast(intent);
690 }
691 }
692
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700693 void registerForBroadcastsLocked(Provider p, int[] appWidgetIds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800694 if (p.info.updatePeriodMillis > 0) {
695 // if this is the first instance, set the alarm. otherwise,
696 // rely on the fact that we've already set it and that
697 // PendingIntent.getBroadcast will update the extras.
698 boolean alreadyRegistered = p.broadcast != null;
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700699 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
700 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800701 intent.setComponent(p.info.provider);
702 long token = Binder.clearCallingIdentity();
703 try {
704 p.broadcast = PendingIntent.getBroadcast(mContext, 1, intent,
705 PendingIntent.FLAG_UPDATE_CURRENT);
706 } finally {
707 Binder.restoreCallingIdentity(token);
708 }
709 if (!alreadyRegistered) {
Joe Onoratobe96b3a2009-07-14 19:49:27 -0700710 long period = p.info.updatePeriodMillis;
711 if (period < MIN_UPDATE_PERIOD) {
712 period = MIN_UPDATE_PERIOD;
713 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800714 mAlarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
Joe Onoratobe96b3a2009-07-14 19:49:27 -0700715 SystemClock.elapsedRealtime() + period, period, p.broadcast);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800716 }
717 }
718 }
719
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700720 static int[] getAppWidgetIds(Provider p) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800721 int instancesSize = p.instances.size();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700722 int appWidgetIds[] = new int[instancesSize];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800723 for (int i=0; i<instancesSize; i++) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700724 appWidgetIds[i] = p.instances.get(i).appWidgetId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 }
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700726 return appWidgetIds;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800727 }
728
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700729 public int[] getAppWidgetIds(ComponentName provider) {
730 synchronized (mAppWidgetIds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800731 Provider p = lookupProviderLocked(provider);
732 if (p != null && getCallingUid() == p.uid) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700733 return getAppWidgetIds(p);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800734 } else {
735 return new int[0];
736 }
737 }
738 }
739
740 private Provider parseProviderInfoXml(ComponentName component, ResolveInfo ri) {
741 Provider p = null;
742
743 ActivityInfo activityInfo = ri.activityInfo;
744 XmlResourceParser parser = null;
745 try {
746 parser = activityInfo.loadXmlMetaData(mPackageManager,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700747 AppWidgetManager.META_DATA_APPWIDGET_PROVIDER);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800748 if (parser == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800749 Slog.w(TAG, "No " + AppWidgetManager.META_DATA_APPWIDGET_PROVIDER + " meta-data for "
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700750 + "AppWidget provider '" + component + '\'');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800751 return null;
752 }
753
754 AttributeSet attrs = Xml.asAttributeSet(parser);
755
756 int type;
757 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
758 && type != XmlPullParser.START_TAG) {
759 // drain whitespace, comments, etc.
760 }
761
762 String nodeName = parser.getName();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700763 if (!"appwidget-provider".equals(nodeName)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800764 Slog.w(TAG, "Meta-data does not start with appwidget-provider tag for"
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700765 + " AppWidget provider '" + component + '\'');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800766 return null;
767 }
768
769 p = new Provider();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700770 AppWidgetProviderInfo info = p.info = new AppWidgetProviderInfo();
Romain Guyd2671e12010-03-11 18:06:42 -0800771 // If metaData was null, we would have returned earlier when getting
772 // the parser No need to do the check here
773 info.oldName = activityInfo.metaData.getString(
774 AppWidgetManager.META_DATA_APPWIDGET_OLD_NAME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800775
776 info.provider = component;
777 p.uid = activityInfo.applicationInfo.uid;
778
Dianne Hackborn20cb56e2010-03-04 00:58:29 -0800779 Resources res = mPackageManager.getResourcesForApplication(
780 activityInfo.applicationInfo);
781
782 TypedArray sa = res.obtainAttributes(attrs,
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700783 com.android.internal.R.styleable.AppWidgetProviderInfo);
Mitsuru Oshima8f25c422009-07-01 00:10:43 -0700784
785 // These dimensions has to be resolved in the application's context.
786 // We simply send back the raw complex data, which will be
787 // converted to dp in {@link AppWidgetManager#getAppWidgetInfo}.
788 TypedValue value = sa.peekValue(
789 com.android.internal.R.styleable.AppWidgetProviderInfo_minWidth);
790 info.minWidth = value != null ? value.data : 0;
791 value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minHeight);
792 info.minHeight = value != null ? value.data : 0;
793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800794 info.updatePeriodMillis = sa.getInt(
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700795 com.android.internal.R.styleable.AppWidgetProviderInfo_updatePeriodMillis, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800796 info.initialLayout = sa.getResourceId(
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700797 com.android.internal.R.styleable.AppWidgetProviderInfo_initialLayout, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800798 String className = sa.getString(
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700799 com.android.internal.R.styleable.AppWidgetProviderInfo_configure);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800800 if (className != null) {
801 info.configure = new ComponentName(component.getPackageName(), className);
802 }
803 info.label = activityInfo.loadLabel(mPackageManager).toString();
804 info.icon = ri.getIconResource();
Patrick Dubroyd2db2a52010-06-23 14:56:28 -0700805 info.previewImage = sa.getResourceId(
806 com.android.internal.R.styleable.AppWidgetProviderInfo_previewImage, 0);
807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800808 sa.recycle();
809 } catch (Exception e) {
810 // Ok to catch Exception here, because anything going wrong because
811 // of what a client process passes to us should not be fatal for the
812 // system process.
Joe Onorato8a9b2202010-02-26 18:56:32 -0800813 Slog.w(TAG, "XML parsing failed for AppWidget provider '" + component + '\'', e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800814 return null;
815 } finally {
816 if (parser != null) parser.close();
817 }
818 return p;
819 }
820
821 int getUidForPackage(String packageName) throws PackageManager.NameNotFoundException {
822 PackageInfo pkgInfo = mPackageManager.getPackageInfo(packageName, 0);
823 if (pkgInfo == null || pkgInfo.applicationInfo == null) {
824 throw new PackageManager.NameNotFoundException();
825 }
826 return pkgInfo.applicationInfo.uid;
827 }
828
829 int enforceCallingUid(String packageName) throws IllegalArgumentException {
830 int callingUid = getCallingUid();
831 int packageUid;
832 try {
833 packageUid = getUidForPackage(packageName);
834 } catch (PackageManager.NameNotFoundException ex) {
835 throw new IllegalArgumentException("packageName and uid don't match packageName="
836 + packageName);
837 }
Marco Nelissen54796e72009-04-30 15:16:30 -0700838 if (callingUid != packageUid && Process.supportsProcesses()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800839 throw new IllegalArgumentException("packageName and uid don't match packageName="
840 + packageName);
841 }
842 return callingUid;
843 }
844
845 void sendInitialBroadcasts() {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700846 synchronized (mAppWidgetIds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800847 final int N = mInstalledProviders.size();
848 for (int i=0; i<N; i++) {
849 Provider p = mInstalledProviders.get(i);
850 if (p.instances.size() > 0) {
851 sendEnableIntentLocked(p);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700852 int[] appWidgetIds = getAppWidgetIds(p);
853 sendUpdateIntentLocked(p, appWidgetIds);
854 registerForBroadcastsLocked(p, appWidgetIds);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800855 }
856 }
857 }
858 }
859
860 // only call from initialization -- it assumes that the data structures are all empty
861 void loadStateLocked() {
862 File temp = savedStateTempFile();
863 File real = savedStateRealFile();
864
865 // prefer the real file. If it doesn't exist, use the temp one, and then copy it to the
866 // real one. if there is both a real file and a temp one, assume that the temp one isn't
867 // fully written and delete it.
868 if (real.exists()) {
869 readStateFromFileLocked(real);
870 if (temp.exists()) {
Romain Guya5475592009-07-01 17:20:08 -0700871 //noinspection ResultOfMethodCallIgnored
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800872 temp.delete();
873 }
874 } else if (temp.exists()) {
875 readStateFromFileLocked(temp);
Romain Guya5475592009-07-01 17:20:08 -0700876 //noinspection ResultOfMethodCallIgnored
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800877 temp.renameTo(real);
878 }
879 }
880
881 void saveStateLocked() {
882 File temp = savedStateTempFile();
883 File real = savedStateRealFile();
884
885 if (!real.exists()) {
886 // If the real one doesn't exist, it's either because this is the first time
887 // or because something went wrong while copying them. In this case, we can't
888 // trust anything that's in temp. In order to have the loadState code not
889 // use the temporary one until it's fully written, create an empty file
890 // for real, which will we'll shortly delete.
891 try {
Romain Guya5475592009-07-01 17:20:08 -0700892 //noinspection ResultOfMethodCallIgnored
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800893 real.createNewFile();
894 } catch (IOException e) {
Romain Guya5475592009-07-01 17:20:08 -0700895 // Ignore
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800896 }
897 }
898
899 if (temp.exists()) {
Romain Guya5475592009-07-01 17:20:08 -0700900 //noinspection ResultOfMethodCallIgnored
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800901 temp.delete();
902 }
903
Suchi Amalapurapu8550f252009-09-29 15:20:32 -0700904 if (!writeStateToFileLocked(temp)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800905 Slog.w(TAG, "Failed to persist new settings");
Suchi Amalapurapu8550f252009-09-29 15:20:32 -0700906 return;
907 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800908
Romain Guya5475592009-07-01 17:20:08 -0700909 //noinspection ResultOfMethodCallIgnored
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800910 real.delete();
Romain Guya5475592009-07-01 17:20:08 -0700911 //noinspection ResultOfMethodCallIgnored
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800912 temp.renameTo(real);
913 }
914
Suchi Amalapurapu8550f252009-09-29 15:20:32 -0700915 boolean writeStateToFileLocked(File file) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800916 FileOutputStream stream = null;
917 int N;
918
919 try {
920 stream = new FileOutputStream(file, false);
921 XmlSerializer out = new FastXmlSerializer();
922 out.setOutput(stream, "utf-8");
923 out.startDocument(null, true);
924
925
926 out.startTag(null, "gs");
927
928 int providerIndex = 0;
929 N = mInstalledProviders.size();
930 for (int i=0; i<N; i++) {
931 Provider p = mInstalledProviders.get(i);
932 if (p.instances.size() > 0) {
933 out.startTag(null, "p");
934 out.attribute(null, "pkg", p.info.provider.getPackageName());
935 out.attribute(null, "cl", p.info.provider.getClassName());
Patrick Tsaibd742e432010-05-01 00:30:19 +0800936 out.endTag(null, "p");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800937 p.tag = providerIndex;
938 providerIndex++;
939 }
940 }
941
942 N = mHosts.size();
943 for (int i=0; i<N; i++) {
944 Host host = mHosts.get(i);
945 out.startTag(null, "h");
946 out.attribute(null, "pkg", host.packageName);
947 out.attribute(null, "id", Integer.toHexString(host.hostId));
948 out.endTag(null, "h");
949 host.tag = i;
950 }
951
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700952 N = mAppWidgetIds.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800953 for (int i=0; i<N; i++) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700954 AppWidgetId id = mAppWidgetIds.get(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800955 out.startTag(null, "g");
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -0700956 out.attribute(null, "id", Integer.toHexString(id.appWidgetId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800957 out.attribute(null, "h", Integer.toHexString(id.host.tag));
958 if (id.provider != null) {
959 out.attribute(null, "p", Integer.toHexString(id.provider.tag));
960 }
961 out.endTag(null, "g");
962 }
963
964 out.endTag(null, "gs");
965
966 out.endDocument();
967 stream.close();
Suchi Amalapurapu8550f252009-09-29 15:20:32 -0700968 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800969 } catch (IOException e) {
970 try {
971 if (stream != null) {
972 stream.close();
973 }
974 } catch (IOException ex) {
Romain Guya5475592009-07-01 17:20:08 -0700975 // Ignore
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800976 }
977 if (file.exists()) {
Romain Guya5475592009-07-01 17:20:08 -0700978 //noinspection ResultOfMethodCallIgnored
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800979 file.delete();
980 }
Suchi Amalapurapu8550f252009-09-29 15:20:32 -0700981 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800982 }
983 }
984
985 void readStateFromFileLocked(File file) {
986 FileInputStream stream = null;
987
988 boolean success = false;
989
990 try {
991 stream = new FileInputStream(file);
992 XmlPullParser parser = Xml.newPullParser();
993 parser.setInput(stream, null);
994
995 int type;
996 int providerIndex = 0;
Romain Guya5475592009-07-01 17:20:08 -0700997 HashMap<Integer,Provider> loadedProviders = new HashMap<Integer, Provider>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800998 do {
999 type = parser.next();
1000 if (type == XmlPullParser.START_TAG) {
1001 String tag = parser.getName();
1002 if ("p".equals(tag)) {
1003 // TODO: do we need to check that this package has the same signature
1004 // as before?
1005 String pkg = parser.getAttributeValue(null, "pkg");
1006 String cl = parser.getAttributeValue(null, "cl");
Romain Guyff3e61c62010-03-11 15:30:02 -08001007
1008 final PackageManager packageManager = mContext.getPackageManager();
1009 try {
1010 packageManager.getReceiverInfo(new ComponentName(pkg, cl), 0);
1011 } catch (PackageManager.NameNotFoundException e) {
1012 String[] pkgs = packageManager.currentToCanonicalPackageNames(
1013 new String[] { pkg });
1014 pkg = pkgs[0];
1015 }
1016
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001017 Provider p = lookupProviderLocked(new ComponentName(pkg, cl));
1018 if (p == null && mSafeMode) {
1019 // if we're in safe mode, make a temporary one
1020 p = new Provider();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001021 p.info = new AppWidgetProviderInfo();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001022 p.info.provider = new ComponentName(pkg, cl);
1023 p.zombie = true;
1024 mInstalledProviders.add(p);
1025 }
1026 if (p != null) {
1027 // if it wasn't uninstalled or something
1028 loadedProviders.put(providerIndex, p);
1029 }
1030 providerIndex++;
1031 }
1032 else if ("h".equals(tag)) {
1033 Host host = new Host();
1034
1035 // TODO: do we need to check that this package has the same signature
1036 // as before?
1037 host.packageName = parser.getAttributeValue(null, "pkg");
1038 try {
1039 host.uid = getUidForPackage(host.packageName);
1040 } catch (PackageManager.NameNotFoundException ex) {
1041 host.zombie = true;
1042 }
1043 if (!host.zombie || mSafeMode) {
1044 // In safe mode, we don't discard the hosts we don't recognize
1045 // so that they're not pruned from our list. Otherwise, we do.
1046 host.hostId = Integer.parseInt(
1047 parser.getAttributeValue(null, "id"), 16);
1048 mHosts.add(host);
1049 }
1050 }
1051 else if ("g".equals(tag)) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001052 AppWidgetId id = new AppWidgetId();
1053 id.appWidgetId = Integer.parseInt(parser.getAttributeValue(null, "id"), 16);
1054 if (id.appWidgetId >= mNextAppWidgetId) {
1055 mNextAppWidgetId = id.appWidgetId + 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001056 }
1057
1058 String providerString = parser.getAttributeValue(null, "p");
1059 if (providerString != null) {
1060 // there's no provider if it hasn't been bound yet.
1061 // maybe we don't have to save this, but it brings the system
1062 // to the state it was in.
1063 int pIndex = Integer.parseInt(providerString, 16);
1064 id.provider = loadedProviders.get(pIndex);
1065 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001066 Slog.d(TAG, "bound appWidgetId=" + id.appWidgetId + " to provider "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 + pIndex + " which is " + id.provider);
1068 }
1069 if (id.provider == null) {
1070 // This provider is gone. We just let the host figure out
1071 // that this happened when it fails to load it.
1072 continue;
1073 }
1074 }
1075
1076 int hIndex = Integer.parseInt(parser.getAttributeValue(null, "h"), 16);
1077 id.host = mHosts.get(hIndex);
1078 if (id.host == null) {
1079 // This host is gone.
1080 continue;
1081 }
1082
1083 if (id.provider != null) {
1084 id.provider.instances.add(id);
1085 }
1086 id.host.instances.add(id);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001087 mAppWidgetIds.add(id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001088 }
1089 }
1090 } while (type != XmlPullParser.END_DOCUMENT);
1091 success = true;
1092 } catch (NullPointerException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001093 Slog.w(TAG, "failed parsing " + file, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001094 } catch (NumberFormatException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001095 Slog.w(TAG, "failed parsing " + file, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001096 } catch (XmlPullParserException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001097 Slog.w(TAG, "failed parsing " + file, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001098 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001099 Slog.w(TAG, "failed parsing " + file, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001100 } catch (IndexOutOfBoundsException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001101 Slog.w(TAG, "failed parsing " + file, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001102 }
1103 try {
1104 if (stream != null) {
1105 stream.close();
1106 }
1107 } catch (IOException e) {
Romain Guya5475592009-07-01 17:20:08 -07001108 // Ignore
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001109 }
1110
1111 if (success) {
1112 // delete any hosts that didn't manage to get connected (should happen)
1113 // if it matters, they'll be reconnected.
Dianne Hackborn002716d2009-08-12 11:13:26 -07001114 for (int i=mHosts.size()-1; i>=0; i--) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 pruneHostLocked(mHosts.get(i));
1116 }
1117 } else {
1118 // failed reading, clean up
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001119 mAppWidgetIds.clear();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120 mHosts.clear();
1121 final int N = mInstalledProviders.size();
1122 for (int i=0; i<N; i++) {
1123 mInstalledProviders.get(i).instances.clear();
1124 }
1125 }
1126 }
1127
1128 File savedStateTempFile() {
1129 return new File("/data/system/" + SETTINGS_TMP_FILENAME);
1130 //return new File(mContext.getFilesDir(), SETTINGS_FILENAME);
1131 }
1132
1133 File savedStateRealFile() {
1134 return new File("/data/system/" + SETTINGS_FILENAME);
1135 //return new File(mContext.getFilesDir(), SETTINGS_TMP_FILENAME);
1136 }
1137
1138 BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1139 public void onReceive(Context context, Intent intent) {
1140 String action = intent.getAction();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001141 //Slog.d(TAG, "received " + action);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
1143 sendInitialBroadcasts();
Eric Fischer63c2d9e2009-10-22 15:22:50 -07001144 } else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
1145 Locale revised = Locale.getDefault();
1146 if (revised == null || mLocale == null ||
1147 !(revised.equals(mLocale))) {
1148 mLocale = revised;
1149
1150 synchronized (mAppWidgetIds) {
1151 int N = mInstalledProviders.size();
1152 for (int i=N-1; i>=0; i--) {
1153 Provider p = mInstalledProviders.get(i);
1154 String pkgName = p.info.provider.getPackageName();
1155 updateProvidersForPackageLocked(pkgName);
1156 }
1157 saveStateLocked();
1158 }
1159 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 } else {
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08001161 boolean added = false;
1162 String pkgList[] = null;
Suchi Amalapurapub56ae202010-02-04 22:51:07 -08001163 if (Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE.equals(action)) {
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08001164 pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
1165 added = true;
Suchi Amalapurapub56ae202010-02-04 22:51:07 -08001166 } if (Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) {
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08001167 pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
1168 added = false;
1169 } else {
1170 Uri uri = intent.getData();
1171 if (uri == null) {
1172 return;
1173 }
1174 String pkgName = uri.getSchemeSpecificPart();
1175 if (pkgName == null) {
1176 return;
1177 }
1178 pkgList = new String[] { pkgName };
1179 added = Intent.ACTION_PACKAGE_ADDED.equals(action);
1180 }
1181 if (pkgList == null || pkgList.length == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001182 return;
1183 }
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08001184 if (added) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001185 synchronized (mAppWidgetIds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001186 Bundle extras = intent.getExtras();
1187 if (extras != null && extras.getBoolean(Intent.EXTRA_REPLACING, false)) {
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08001188 for (String pkgName : pkgList) {
1189 // The package was just upgraded
1190 updateProvidersForPackageLocked(pkgName);
1191 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001192 } else {
1193 // The package was just added
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08001194 for (String pkgName : pkgList) {
1195 addProvidersForPackageLocked(pkgName);
1196 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001197 }
1198 saveStateLocked();
1199 }
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08001200 } else {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001201 Bundle extras = intent.getExtras();
1202 if (extras != null && extras.getBoolean(Intent.EXTRA_REPLACING, false)) {
1203 // The package is being updated. We'll receive a PACKAGE_ADDED shortly.
1204 } else {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001205 synchronized (mAppWidgetIds) {
Suchi Amalapurapu08675a32010-01-28 09:57:30 -08001206 for (String pkgName : pkgList) {
1207 removeProvidersForPackageLocked(pkgName);
1208 saveStateLocked();
1209 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001210 }
1211 }
1212 }
1213 }
1214 }
1215 };
1216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001217 void addProvidersForPackageLocked(String pkgName) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001218 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
Joe Onoratof6133fe2010-02-01 18:24:46 -05001219 intent.setPackage(pkgName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001220 List<ResolveInfo> broadcastReceivers = mPackageManager.queryBroadcastReceivers(intent,
1221 PackageManager.GET_META_DATA);
1222
Bjorn Bringert5f857802010-02-10 23:09:48 +00001223 final int N = broadcastReceivers == null ? 0 : broadcastReceivers.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 for (int i=0; i<N; i++) {
1225 ResolveInfo ri = broadcastReceivers.get(i);
1226 ActivityInfo ai = ri.activityInfo;
1227
1228 if (pkgName.equals(ai.packageName)) {
1229 addProviderLocked(ri);
1230 }
1231 }
1232 }
1233
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001234 void updateProvidersForPackageLocked(String pkgName) {
Romain Guya5475592009-07-01 17:20:08 -07001235 HashSet<String> keep = new HashSet<String>();
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001236 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
Joe Onoratof6133fe2010-02-01 18:24:46 -05001237 intent.setPackage(pkgName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001238 List<ResolveInfo> broadcastReceivers = mPackageManager.queryBroadcastReceivers(intent,
1239 PackageManager.GET_META_DATA);
1240
1241 // add the missing ones and collect which ones to keep
Bjorn Bringert5f857802010-02-10 23:09:48 +00001242 int N = broadcastReceivers == null ? 0 : broadcastReceivers.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001243 for (int i=0; i<N; i++) {
1244 ResolveInfo ri = broadcastReceivers.get(i);
1245 ActivityInfo ai = ri.activityInfo;
1246 if (pkgName.equals(ai.packageName)) {
1247 ComponentName component = new ComponentName(ai.packageName, ai.name);
1248 Provider p = lookupProviderLocked(component);
1249 if (p == null) {
1250 if (addProviderLocked(ri)) {
1251 keep.add(ai.name);
1252 }
1253 } else {
1254 Provider parsed = parseProviderInfoXml(component, ri);
1255 if (parsed != null) {
1256 keep.add(ai.name);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001257 // Use the new AppWidgetProviderInfo.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001258 p.info = parsed.info;
1259 // If it's enabled
1260 final int M = p.instances.size();
1261 if (M > 0) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001262 int[] appWidgetIds = getAppWidgetIds(p);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001263 // Reschedule for the new updatePeriodMillis (don't worry about handling
1264 // it specially if updatePeriodMillis didn't change because we just sent
1265 // an update, and the next one will be updatePeriodMillis from now).
1266 cancelBroadcasts(p);
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001267 registerForBroadcastsLocked(p, appWidgetIds);
1268 // If it's currently showing, call back with the new AppWidgetProviderInfo.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001269 for (int j=0; j<M; j++) {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001270 AppWidgetId id = p.instances.get(j);
Joe Onoratoa8a8a422010-06-16 15:06:16 -04001271 id.views = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001272 if (id.host != null && id.host.callbacks != null) {
1273 try {
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001274 id.host.callbacks.providerChanged(id.appWidgetId, p.info);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001275 } catch (RemoteException ex) {
1276 // It failed; remove the callback. No need to prune because
1277 // we know that this host is still referenced by this
1278 // instance.
1279 id.host.callbacks = null;
1280 }
1281 }
1282 }
1283 // Now that we've told the host, push out an update.
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001284 sendUpdateIntentLocked(p, appWidgetIds);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001285 }
1286 }
1287 }
1288 }
1289 }
1290
1291 // prune the ones we don't want to keep
1292 N = mInstalledProviders.size();
1293 for (int i=N-1; i>=0; i--) {
1294 Provider p = mInstalledProviders.get(i);
1295 if (pkgName.equals(p.info.provider.getPackageName())
1296 && !keep.contains(p.info.provider.getClassName())) {
1297 removeProviderLocked(i, p);
1298 }
1299 }
1300 }
1301
1302 void removeProvidersForPackageLocked(String pkgName) {
1303 int N = mInstalledProviders.size();
1304 for (int i=N-1; i>=0; i--) {
1305 Provider p = mInstalledProviders.get(i);
1306 if (pkgName.equals(p.info.provider.getPackageName())) {
1307 removeProviderLocked(i, p);
1308 }
1309 }
1310
1311 // Delete the hosts for this package too
1312 //
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001313 // By now, we have removed any AppWidgets that were in any hosts here,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001314 // so we don't need to worry about sending DISABLE broadcasts to them.
1315 N = mHosts.size();
1316 for (int i=N-1; i>=0; i--) {
1317 Host host = mHosts.get(i);
1318 if (pkgName.equals(host.packageName)) {
1319 deleteHostLocked(host);
1320 }
1321 }
1322 }
1323}
1324