diff options
author | Romain Guy <romainguy@android.com> | 2010-03-23 10:58:18 -0700 |
---|---|---|
committer | Romain Guy <romainguy@android.com> | 2010-03-23 10:58:18 -0700 |
commit | 693599f27be9f3f2d59d3205283133b5b504d3c8 (patch) | |
tree | 8129dcd55bbda0ae26e54cb2bb92f4fbd2d0604c /src/com/android/launcher2/LauncherProvider.java | |
parent | 878f086f754c26d096134e35c33483800585ad2b (diff) | |
download | packages_apps_trebuchet-693599f27be9f3f2d59d3205283133b5b504d3c8.zip packages_apps_trebuchet-693599f27be9f3f2d59d3205283133b5b504d3c8.tar.gz packages_apps_trebuchet-693599f27be9f3f2d59d3205283133b5b504d3c8.tar.bz2 |
Support old-package attribute for default workspace items.
Bug #2509293
Change-Id: I5e76465bceab6b733287f53f6afdcf3d522843fc
Diffstat (limited to 'src/com/android/launcher2/LauncherProvider.java')
-rw-r--r-- | src/com/android/launcher2/LauncherProvider.java | 50 |
1 files changed, 40 insertions, 10 deletions
diff --git a/src/com/android/launcher2/LauncherProvider.java b/src/com/android/launcher2/LauncherProvider.java index 9f55e91..4bf4421 100644 --- a/src/com/android/launcher2/LauncherProvider.java +++ b/src/com/android/launcher2/LauncherProvider.java @@ -506,6 +506,7 @@ public class LauncherProvider extends ContentProvider { update.execute(); } bitmap.recycle(); + //noinspection UnusedAssignment bitmap = null; } } catch (Exception e) { @@ -659,7 +660,7 @@ public class LauncherProvider extends ContentProvider { } else if (TAG_CLOCK.equals(name)) { added = addClockWidget(db, values); } else if (TAG_APPWIDGET.equals(name)) { - added = addAppWidget(db, values, a); + added = addAppWidget(db, values, a, packageManager); } else if (TAG_SHORTCUT.equals(name)) { added = addUriShortcut(db, values, a); } @@ -684,11 +685,20 @@ public class LauncherProvider extends ContentProvider { String packageName = a.getString(R.styleable.Favorite_packageName); String className = a.getString(R.styleable.Favorite_className); try { - ComponentName cn = new ComponentName(packageName, className); - info = packageManager.getActivityInfo(cn, 0); + ComponentName cn; + try { + cn = new ComponentName(packageName, className); + info = packageManager.getActivityInfo(cn, 0); + } catch (PackageManager.NameNotFoundException nnfe) { + String[] packages = packageManager.currentToCanonicalPackageNames( + new String[] { packageName }); + cn = new ComponentName(packages[0], className); + info = packageManager.getActivityInfo(cn, 0); + } + intent.setComponent(cn); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK - | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | + Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); values.put(Favorites.INTENT, intent.toUri(0)); values.put(Favorites.TITLE, info.loadLabel(packageManager).toString()); values.put(Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_APPLICATION); @@ -740,18 +750,38 @@ public class LauncherProvider extends ContentProvider { return addAppWidget(db, values, cn, 2, 2); } - private boolean addAppWidget(SQLiteDatabase db, ContentValues values, TypedArray a) { + private boolean addAppWidget(SQLiteDatabase db, ContentValues values, TypedArray a, + PackageManager packageManager) { + String packageName = a.getString(R.styleable.Favorite_packageName); String className = a.getString(R.styleable.Favorite_className); if (packageName == null || className == null) { return false; } - + + boolean hasPackage = true; ComponentName cn = new ComponentName(packageName, className); - int spanX = a.getInt(R.styleable.Favorite_spanX, 0); - int spanY = a.getInt(R.styleable.Favorite_spanY, 0); - return addAppWidget(db, values, cn, spanX, spanY); + try { + packageManager.getReceiverInfo(cn, 0); + } catch (Exception e) { + String[] packages = packageManager.currentToCanonicalPackageNames( + new String[] { packageName }); + cn = new ComponentName(packages[0], className); + try { + packageManager.getReceiverInfo(cn, 0); + } catch (Exception e1) { + hasPackage = false; + } + } + + if (hasPackage) { + int spanX = a.getInt(R.styleable.Favorite_spanX, 0); + int spanY = a.getInt(R.styleable.Favorite_spanY, 0); + return addAppWidget(db, values, cn, spanX, spanY); + } + + return false; } private boolean addAppWidget(SQLiteDatabase db, ContentValues values, ComponentName cn, |