Fix issue where sometimes duplicate icons are added on homescreen when

installing a package

Shortcuts placed by the user have no package in their intent.
Ensure that this is accounted for when searching for duplicates.

issue: 12888844

Change-Id: I2fb8b7c2b8f7cb74926904bf49a96aeb59a5a9f8
This commit is contained in:
Sunny Goyal
2014-06-26 15:27:14 -07:00
parent 03f20ba3b2
commit 2a6cf09be9
+19 -2
View File
@@ -842,9 +842,26 @@ public class LauncherModel extends BroadcastReceiver
*/
static boolean shortcutExists(Context context, String title, Intent intent) {
final ContentResolver cr = context.getContentResolver();
final Intent intentWithPkg, intentWithoutPkg;
if (intent.getComponent() != null) {
// If component is not null, an intent with null package will produce
// the same result and should also be a match.
if (intent.getPackage() != null) {
intentWithPkg = intent;
intentWithoutPkg = new Intent(intent).setPackage(null);
} else {
intentWithPkg = new Intent(intent).setPackage(
intent.getComponent().getPackageName());
intentWithoutPkg = intent;
}
} else {
intentWithPkg = intent;
intentWithoutPkg = intent;
}
Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI,
new String[] { "title", "intent" }, "title=? and intent=?",
new String[] { title, intent.toUri(0) }, null);
new String[] { "title", "intent" }, "title=? and (intent=? or intent=?)",
new String[] { title, intentWithPkg.toUri(0), intentWithoutPkg.toUri(0) }, null);
boolean result = false;
try {
result = c.moveToFirst();