From 486bcb308dd39e341250348fef68414c0015b656 Mon Sep 17 00:00:00 2001 From: Yvonne Wong Date: Fri, 9 Oct 2015 13:26:24 -0700 Subject: Trebuchet: make workspace layout configurable by prebundled mcc issue-id: PAELLA-42 Change-Id: Ice4f73ee6ebaa55e27c07a02f1cc5b989f91c59a --- src/com/android/launcher3/LauncherProvider.java | 55 ++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) (limited to 'src/com/android/launcher3/LauncherProvider.java') diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java index 753f6e746..c754edb13 100644 --- a/src/com/android/launcher3/LauncherProvider.java +++ b/src/com/android/launcher3/LauncherProvider.java @@ -30,6 +30,9 @@ import android.content.Context; import android.content.Intent; import android.content.OperationApplicationException; import android.content.SharedPreferences; +import android.content.pm.PackageManager; +import android.content.res.AssetManager; +import android.content.res.Configuration; import android.content.res.Resources; import android.database.Cursor; import android.database.SQLException; @@ -40,8 +43,10 @@ import android.database.sqlite.SQLiteStatement; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; +import android.os.SystemProperties; import android.provider.Settings; import android.text.TextUtils; +import android.util.DisplayMetrics; import android.util.Log; import android.util.SparseArray; @@ -90,6 +95,8 @@ public class LauncherProvider extends ContentProvider { static final Uri CONTENT_APPWIDGET_RESET_URI = Uri.parse("content://" + AUTHORITY + "/appWidgetReset"); + private static final String MCC_PROP_NAME = "ro.prebundled.mcc"; + private DatabaseHelper mOpenHelper; private static boolean sJustLoadedFromOldDb; @@ -311,11 +318,57 @@ public class LauncherProvider extends ContentProvider { SharedPreferences sp = getContext().getSharedPreferences(spKey, Context.MODE_PRIVATE); if (sp.getBoolean(EMPTY_DATABASE_CREATED, false)) { - Log.d(TAG, "loading default workspace"); + if (LOGD) Log.d(TAG, "loading default workspace"); AutoInstallsLayout loader = AutoInstallsLayout.get(getContext(), mOpenHelper.mAppWidgetHost, mOpenHelper); + String mcc = SystemProperties.get(MCC_PROP_NAME); + + if (!TextUtils.isEmpty(mcc)) { + if (LOGD) Log.d(TAG, "mcc: " + mcc); + + Configuration tempConfiguration = new Configuration(getContext().getResources(). + getConfiguration()); + boolean shouldUseTempConfig = false; + + try { + tempConfiguration.mcc = Integer.parseInt(mcc); + shouldUseTempConfig = true; + } catch (NumberFormatException e) { + // not able to parse mcc, catch exception and exit out of this logic + e.printStackTrace(); + } + + if (shouldUseTempConfig) { + String publicSrcDir = null; + try { + String packageName = getContext().getPackageName(); + publicSrcDir = getContext().getPackageManager(). + getApplicationInfo(packageName, 0).publicSourceDir; + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } + + AssetManager assetManager = new AssetManager(); + if (!TextUtils.isEmpty(publicSrcDir)) { + assetManager.addAssetPath(publicSrcDir); + } + Resources customResources = new Resources(assetManager, new DisplayMetrics(), + tempConfiguration); + + int mccLayout = LauncherAppState.getInstance() + .getDynamicGrid().getDeviceProfile().defaultLayoutId; + + if (mccLayout != 0) { + if (LOGD) Log.d(TAG, "mcc layout id: " + mccLayout); + + loader = new DefaultLayoutParser(getContext(), mOpenHelper.mAppWidgetHost, + mOpenHelper, customResources, mccLayout); + } + } + } + if (loader == null) { final Partner partner = Partner.get(getContext().getPackageManager()); if (partner != null && partner.hasDefaultLayout()) { -- cgit v1.2.3