|
| 1 | +package com.android.settings.sudconfig |
| 2 | + |
| 3 | +import android.os.Build |
| 4 | +import android.os.Bundle |
| 5 | +import android.provider.Settings |
| 6 | +import android.text.TextUtils |
| 7 | +import android.util.Log |
| 8 | +import com.android.settings.R; |
| 9 | + |
| 10 | +/** |
| 11 | + * Provides system-wide config for setup wizard screens. |
| 12 | + */ |
| 13 | +class SudConfigProvider : NonRelationalProvider() { |
| 14 | + companion object { |
| 15 | + private const val TAG = "SudConfigProvider" |
| 16 | + |
| 17 | + // resources to be forwarded via overlay config |
| 18 | + private val overlayConfigResources = arrayOf( |
| 19 | + R.dimen.setup_design_card_view_intrinsic_height, |
| 20 | + R.dimen.setup_design_card_view_intrinsic_width, |
| 21 | + R.bool.setup_compat_light_navigation_bar, |
| 22 | + R.bool.setup_compat_light_status_bar |
| 23 | + ) |
| 24 | + } |
| 25 | + |
| 26 | + override fun onCreate(): Boolean { |
| 27 | + return true |
| 28 | + } |
| 29 | + |
| 30 | + override fun call(method: String, arg: String?, extras: Bundle?): Bundle { |
| 31 | + Log.d(TAG, "method: $method, caller: $callingPackage") |
| 32 | + val bundle = Bundle() |
| 33 | + when (method) { |
| 34 | + "suwDefaultThemeString" -> bundle.putString(method, "glif_v4_light") |
| 35 | + |
| 36 | + "applyGlifThemeControlledTransition", |
| 37 | + "isDynamicColorEnabled", |
| 38 | + "isEmbeddedActivityOnePaneEnabled", |
| 39 | + "isFullDynamicColorEnabled", |
| 40 | + "IsMaterialYouStyleEnabled", |
| 41 | + "isNeutralButtonStyleEnabled", |
| 42 | + "isSuwDayNightEnabled" -> bundle.putBoolean(method, true) |
| 43 | + |
| 44 | + "getDeviceName" -> bundle.putCharSequence(method, getDeviceName()) |
| 45 | + |
| 46 | + "getOverlayConfig" -> fillOverlayConfig(bundle) |
| 47 | + } |
| 48 | + return bundle |
| 49 | + } |
| 50 | + |
| 51 | + private fun getDeviceName(): String { |
| 52 | + var name = Settings.Global.getString( |
| 53 | + requireContext().contentResolver, |
| 54 | + Settings.Global.DEVICE_NAME |
| 55 | + ) |
| 56 | + if (TextUtils.isEmpty(name)) { |
| 57 | + name = Build.MODEL |
| 58 | + } |
| 59 | + return name |
| 60 | + } |
| 61 | + |
| 62 | + private fun fillOverlayConfig(bundle: Bundle) { |
| 63 | + overlayConfigResources.forEach { resId -> |
| 64 | + val context = requireContext() |
| 65 | + val resName = context.resources.getResourceEntryName(resId) |
| 66 | + val config = Bundle() |
| 67 | + config.putString("packageName", context.packageName) |
| 68 | + config.putString("resourceName", resName) |
| 69 | + config.putInt("resourceId", resId) |
| 70 | + bundle.putBundle(resName, config) |
| 71 | + } |
| 72 | + } |
| 73 | +} |
0 commit comments