diff options
Diffstat (limited to 'packages/CMSettingsProvider/src/org/cyanogenmod/cmsettings/CMDatabaseHelper.java')
-rw-r--r-- | packages/CMSettingsProvider/src/org/cyanogenmod/cmsettings/CMDatabaseHelper.java | 69 |
1 files changed, 65 insertions, 4 deletions
diff --git a/packages/CMSettingsProvider/src/org/cyanogenmod/cmsettings/CMDatabaseHelper.java b/packages/CMSettingsProvider/src/org/cyanogenmod/cmsettings/CMDatabaseHelper.java index 5da7795..819739e 100644 --- a/packages/CMSettingsProvider/src/org/cyanogenmod/cmsettings/CMDatabaseHelper.java +++ b/packages/CMSettingsProvider/src/org/cyanogenmod/cmsettings/CMDatabaseHelper.java @@ -18,12 +18,20 @@ package org.cyanogenmod.cmsettings; import android.content.ContentValues; import android.content.Context; +import android.content.pm.PackageManager; +import android.content.res.AssetManager; +import android.content.res.Configuration; +import android.content.res.Resources; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; +import android.database.sqlite.SQLiteStatement; import android.os.Build; import android.os.Environment; +import android.os.SystemProperties; import android.os.UserHandle; import android.provider.Settings; +import android.text.TextUtils; +import android.util.DisplayMetrics; import android.util.Log; import cyanogenmod.providers.CMSettings; @@ -58,8 +66,11 @@ public class CMDatabaseHelper extends SQLiteOpenHelper{ private static final String DROP_INDEX_SQL_FORMAT = "DROP INDEX IF EXISTS %sIndex%d;"; + private static final String MCC_PROP_NAME = "ro.prebundled.mcc"; + private Context mContext; private int mUserHandle; + private String mPublicSrcDir; /** * Gets the appropriate database path for a specific user @@ -88,6 +99,14 @@ public class CMDatabaseHelper extends SQLiteOpenHelper{ super(context, dbNameForUser(userId), null, DATABASE_VERSION); mContext = context; mUserHandle = userId; + + try { + String packageName = mContext.getPackageName(); + mPublicSrcDir = mContext.getPackageManager().getApplicationInfo(packageName, 0) + .publicSourceDir; + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } } /** @@ -195,11 +214,11 @@ public class CMDatabaseHelper extends SQLiteOpenHelper{ loadBooleanSetting(db, CMTableNames.TABLE_SECURE, CMSettings.Secure.ADVANCED_MODE, R.bool.def_advanced_mode); - loadStringSetting(db, CMTableNames.TABLE_SECURE, CMSettings.Secure.DEFAULT_THEME_COMPONENTS, - R.string.def_theme_components); + loadRegionLockedStringSetting(db, CMTableNames.TABLE_SECURE, + CMSettings.Secure.DEFAULT_THEME_COMPONENTS, R.string.def_theme_components); - loadStringSetting(db, CMTableNames.TABLE_SECURE, CMSettings.Secure.DEFAULT_THEME_PACKAGE, - R.string.def_theme_package); + loadRegionLockedStringSetting(db, CMTableNames.TABLE_SECURE, + CMSettings.Secure.DEFAULT_THEME_PACKAGE, R.string.def_theme_package); loadIntegerSetting(db, CMTableNames.TABLE_SECURE, CMSettings.Secure.DEV_FORCE_SHOW_NAVBAR, R.integer.def_force_show_navbar); @@ -212,6 +231,48 @@ public class CMDatabaseHelper extends SQLiteOpenHelper{ } /** + * Loads a region locked string setting into a database table. If the resource for the specific + * mcc is not found, the setting is loaded from the default resources. + * @param db The {@link SQLiteDatabase} to insert into. + * @param tableName The name of the table to insert into. + * @param name The name of the value to insert into the table. + * @param resId The name of the string resource. + */ + private void loadRegionLockedStringSetting(SQLiteDatabase db, String tableName, String name, + int resId) { + String mcc = SystemProperties.get(MCC_PROP_NAME); + Resources customResources = null; + + if (!TextUtils.isEmpty(mcc)) { + Configuration tempConfiguration = new Configuration(); + boolean useTempConfig = false; + + try { + tempConfiguration.mcc = Integer.parseInt(mcc); + useTempConfig = true; + } catch (NumberFormatException e) { + // not able to parse mcc, catch exception and exit out of this logic + e.printStackTrace(); + } + + if (useTempConfig) { + AssetManager assetManager = new AssetManager(); + + if (!TextUtils.isEmpty(mPublicSrcDir)) { + assetManager.addAssetPath(mPublicSrcDir); + } + + customResources = new Resources(assetManager, new DisplayMetrics(), + tempConfiguration); + } + } + + String value = customResources == null ? mContext.getResources().getString(resId) + : customResources.getString(resId); + loadSettingsForTable(db, tableName, name, value); + } + + /** * Loads a string resource into a database table. If a conflict occurs, that value is not * inserted into the database table. * @param db The {@link SQLiteDatabase} to insert into. |