Merge "IMS: Customize HD icon in CallCard for some carriers" into atel.lnx.2.0-dev
diff --git a/src/com/android/dialer/database/DialerDatabaseHelper.java b/src/com/android/dialer/database/DialerDatabaseHelper.java
old mode 100755
new mode 100644
index 05f94a5..1d3de31
--- a/src/com/android/dialer/database/DialerDatabaseHelper.java
+++ b/src/com/android/dialer/database/DialerDatabaseHelper.java
@@ -19,6 +19,7 @@
import android.content.ContentValues;
import android.content.Context;
import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
@@ -50,6 +51,7 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
+import java.io.File;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
@@ -84,6 +86,8 @@
* </pre>
*/
public static final int DATABASE_VERSION = 9;
+ public static final int DATABASE_SHAREPREF_VERSION = 1;
+ public static final String DATABASE_SHAREPREF_KEY = "database_sharepref_key";
public static final String DATABASE_NAME = "dialer.db";
/**
@@ -459,6 +463,11 @@
setupTables(db);
}
+ @Override
+ public void onOpen(SQLiteDatabase db) {
+ upgradeSmartSearchDatabase(db);
+ }
+
private void setupTables(SQLiteDatabase db) {
dropTables(db);
db.execSQL("CREATE TABLE " + Tables.SMARTDIAL_TABLE + " ("
@@ -514,6 +523,49 @@
}
}
+ private boolean isNeedUpgradeForSmartSearch() {
+ String FILENAME = "upgradeSmartSearchTable";
+
+ Log.d(TAG, "Shared Preference Created with name: " + FILENAME);
+ SharedPreferences pref = mContext.getSharedPreferences(FILENAME,
+ mContext.MODE_PRIVATE);
+ if (pref != null) {
+ int mSharePrefVersion = pref.getInt(DATABASE_SHAREPREF_KEY,0);
+ if(mSharePrefVersion < DATABASE_SHAREPREF_VERSION) {
+ Editor editor;
+ editor = pref.edit();
+ editor.putInt(DATABASE_SHAREPREF_KEY, DATABASE_SHAREPREF_VERSION);
+ editor.commit();
+ return true;
+ }
+ return false;
+ } else {
+ Log.d(TAG, "fail to get SharedPreferences !");
+ return false;
+ }
+ }
+
+ private void upgradeSmartSearchDatabase(SQLiteDatabase db) {
+ if (isNeedUpgradeForSmartSearch()) {
+ db.beginTransaction();
+ try {
+ upgradeDatabaseSmartSearch(db);
+ db.setTransactionSuccessful();
+ } catch (Throwable ex) {
+ Log.e(TAG, ex.getMessage(), ex);
+ } finally {
+ db.endTransaction();
+ }
+ }
+ }
+
+ private void upgradeDatabaseSmartSearch(SQLiteDatabase db) {
+ db.execSQL("ALTER TABLE " + Tables.SMARTDIAL_TABLE + " ADD COLUMN " +
+ SmartDialDbColumns.ACCOUNT_TYPE + " TEXT;");
+ db.execSQL("ALTER TABLE " + Tables.SMARTDIAL_TABLE + " ADD COLUMN " +
+ SmartDialDbColumns.ACCOUNT_NAME + " TEXT;");
+ }
+
public void dropTables(SQLiteDatabase db) {
db.execSQL("DROP TABLE IF EXISTS " + Tables.PREFIX_TABLE);
db.execSQL("DROP TABLE IF EXISTS " + Tables.SMARTDIAL_TABLE);