summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanesh M <daneshm90@gmail.com>2015-10-07 21:19:33 (GMT)
committerGerrit Code Review <gerrit@cyanogenmod.org>2015-10-09 00:36:14 (GMT)
commit769805b18f1627d0650b3126d5edcc68550bedec (patch)
tree8fa77e1a62fa50d327a7aac8393b53ee1604cead
parentb69f0ee68b74501e1eec50df64f4b32814688d56 (diff)
downloadandroid_packages_apps_Trebuchet-769805b18f1627d0650b3126d5edcc68550bedec.zip
android_packages_apps_Trebuchet-769805b18f1627d0650b3126d5edcc68550bedec.tar.gz
android_packages_apps_Trebuchet-769805b18f1627d0650b3126d5edcc68550bedec.tar.bz2
Trebuchet : Ensure workspace icon migration for dialer
Ensure dialer workspace icon migration for c-apps package. CYNGNOS-1194 Change-Id: Id6535f5e8c5b16350666f75dda771311a49fe66b
-rw-r--r--src/com/android/launcher3/LauncherProvider.java76
-rw-r--r--src/com/android/launcher3/Utilities.java10
2 files changed, 85 insertions, 1 deletions
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java
index dd2f48b..753f6e7 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -56,12 +56,13 @@ import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
+import java.util.Set;
public class LauncherProvider extends ContentProvider {
private static final String TAG = "Launcher.LauncherProvider";
private static final boolean LOGD = false;
- private static final int DATABASE_VERSION = 21;
+ private static final int DATABASE_VERSION = 22;
static final String OLD_AUTHORITY = "com.android.launcher2.settings";
static final String AUTHORITY = ProviderConfig.AUTHORITY;
@@ -936,6 +937,11 @@ public class LauncherProvider extends ContentProvider {
version = 21;
}
+ if (oldVersion < 22) {
+ updateDialtactsLauncher(db);
+ version = 22;
+ }
+
if (version != DATABASE_VERSION) {
Log.w(TAG, "Destroying all old data.");
db.execSQL("DROP TABLE IF EXISTS " + TABLE_FAVORITES);
@@ -986,6 +992,74 @@ public class LauncherProvider extends ContentProvider {
return true;
}
+ private void updateDialtactsLauncher(SQLiteDatabase db) {
+ if (!Utilities.isPackageInstalled(mContext, "com.cyngn.dialer")) {
+ return;
+ }
+
+ final String cyngnDialer = "com.cyngn.dialer";
+ final String aospDialer = "com.android.dialer";
+ final String dialtactsClass = "com.android.dialer.DialtactsActivity";
+
+ final String selectWhere = buildOrWhereString(Favorites.ITEM_TYPE,
+ new int[]{Favorites.ITEM_TYPE_SHORTCUT, Favorites.ITEM_TYPE_APPLICATION});
+ Cursor c = null;
+ db.beginTransaction();
+
+ try {
+ // Select and iterate through each matching widget
+ c = db.query(TABLE_FAVORITES,
+ new String[] { Favorites._ID, Favorites.INTENT },
+ selectWhere, null, null, null, null);
+ if (c == null) return;
+
+ while (c.moveToNext()) {
+ long favoriteId = c.getLong(0);
+ final String intentUri = c.getString(1);
+ if (intentUri != null) {
+ try {
+ final Intent intent = Intent.parseUri(intentUri, 0);
+ final ComponentName componentName = intent.getComponent();
+ final Set<String> categories = intent.getCategories();
+
+ if (Intent.ACTION_MAIN.equals(intent.getAction()) &&
+ componentName != null &&
+ aospDialer.equals(componentName.getPackageName()) &&
+ dialtactsClass.equals(componentName.getClassName()) &&
+ categories != null &&
+ categories.contains(Intent.CATEGORY_LAUNCHER)) {
+
+ final ComponentName newName = new ComponentName(cyngnDialer,
+ componentName.getClassName());
+ intent.setComponent(newName);
+ final ContentValues values = new ContentValues();
+ values.put(Favorites.INTENT, intent.toUri(0));
+
+ String updateWhere = Favorites._ID + "=" + favoriteId;
+ db.update(TABLE_FAVORITES, values, updateWhere, null);
+ if (Log.isLoggable(TAG, Log.INFO)) {
+ Log.i(TAG, "Updated " + componentName + " to " + newName);
+ }
+ }
+ } catch (RuntimeException ex) {
+ Log.e(TAG, "Problem moving Dialtacts activity", ex);
+ } catch (URISyntaxException e) {
+ Log.e(TAG, "Problem moving Dialtacts activity", e);
+ }
+ }
+ }
+
+ db.setTransactionSuccessful();
+ } catch (SQLException ex) {
+ Log.w(TAG, "Problem while upgrading dialtacts icon", ex);
+ } finally {
+ db.endTransaction();
+ if (c != null) {
+ c.close();
+ }
+ }
+ }
+
private boolean updateContactsShortcuts(SQLiteDatabase db) {
final String selectWhere = buildOrWhereString(Favorites.ITEM_TYPE,
new int[] { Favorites.ITEM_TYPE_SHORTCUT });
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index cfadeaa..8fe2e84 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -617,4 +617,14 @@ public final class Utilities {
}
return defaultWidgetForSearchPackage;
}
+
+ public static boolean isPackageInstalled(Context context, String pkg) {
+ PackageManager packageManager = context.getPackageManager();
+ try {
+ PackageInfo pi = packageManager.getPackageInfo(pkg, 0);
+ return pi.applicationInfo.enabled;
+ } catch (PackageManager.NameNotFoundException e) {
+ return false;
+ }
+ }
}