Merge "Make AppWidgetService handle components enabling and disabling." into honeycomb

This commit is contained in:
Joe Onorato
2011-01-10 17:33:28 -08:00
committed by Android (Google) Code Review
3 changed files with 33 additions and 2 deletions

View File

@@ -144,6 +144,7 @@ class AppWidgetService extends IAppWidgetService.Stub
// update the provider list.
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addDataScheme("package");
mContext.registerReceiver(mBroadcastReceiver, filter);
@@ -643,6 +644,12 @@ class AppWidgetService extends IAppWidgetService.Stub
}
boolean addProviderLocked(ResolveInfo ri) {
if ((ri.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) {
return false;
}
if (!ri.activityInfo.isEnabled()) {
return false;
}
Provider p = parseProviderInfoXml(new ComponentName(ri.activityInfo.packageName,
ri.activityInfo.name), ri);
if (p != null) {
@@ -1160,6 +1167,7 @@ class AppWidgetService extends IAppWidgetService.Stub
}
} else {
boolean added = false;
boolean changed = false;
String pkgList[] = null;
if (Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE.equals(action)) {
pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
@@ -1178,14 +1186,16 @@ class AppWidgetService extends IAppWidgetService.Stub
}
pkgList = new String[] { pkgName };
added = Intent.ACTION_PACKAGE_ADDED.equals(action);
changed = Intent.ACTION_PACKAGE_CHANGED.equals(action);
}
if (pkgList == null || pkgList.length == 0) {
return;
}
if (added) {
if (added || changed) {
synchronized (mAppWidgetIds) {
Bundle extras = intent.getExtras();
if (extras != null && extras.getBoolean(Intent.EXTRA_REPLACING, false)) {
if (changed || (extras != null &&
extras.getBoolean(Intent.EXTRA_REPLACING, false))) {
for (String pkgName : pkgList) {
// The package was just upgraded
updateProvidersForPackageLocked(pkgName);

View File

@@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.STATUS_BAR" />
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE" />
<application>
<activity android:name="StatusBarTest" android:label="_StatusBar">

View File

@@ -26,6 +26,8 @@ import android.os.IBinder;
import android.os.IPowerManager;
import android.widget.ListView;
import android.content.Intent;
import android.content.ComponentName;
import android.content.pm.PackageManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.StatusBarManager;
@@ -66,6 +68,24 @@ public class PowerTest extends TestActivity
return mTests;
}
private Test[] mTests = new Test[] {
new Test("Enable settings widget") {
public void run() {
PackageManager pm = getPackageManager();
pm.setComponentEnabledSetting(new ComponentName("com.android.settings",
"com.android.settings.widget.SettingsAppWidgetProvider"),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0);
}
},
new Test("Disable settings widget") {
public void run() {
PackageManager pm = getPackageManager();
pm.setComponentEnabledSetting(new ComponentName("com.android.settings",
"com.android.settings.widget.SettingsAppWidgetProvider"),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
}
},
new Test("Enable proximity") {
public void run() {
mProx.acquire();