Skip to content

Commit

Permalink
setup design config provider
Browse files Browse the repository at this point in the history
- defines abstraction: NonRelationalProvider
- implements SudConfigProvider
- provides basic configs
- provides overlay config
    - non-card layout for tablets
    - navigation bar light/dark mode
    - status bar light/dark mode
  • Loading branch information
jiteshsingh authored and thestinger committed Mar 20, 2024
1 parent 11e479f commit ad00a8d
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 76 deletions.
2 changes: 1 addition & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5038,7 +5038,7 @@
</activity-alias>

<provider
android:name="com.android.settings.SetupDesignConfigProvider"
android:name="com.android.settings.sudconfig.SudConfigProvider"
android:authorities="com.google.android.setupwizard.partner"
android:directBootAware="true"
android:exported="true" />
Expand Down
5 changes: 5 additions & 0 deletions res/values-night/bools.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="setup_compat_light_navigation_bar">false</bool>
<bool name="setup_compat_light_status_bar">false</bool>
</resources>
5 changes: 5 additions & 0 deletions res/values/bools.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="setup_compat_light_navigation_bar">true</bool>
<bool name="setup_compat_light_status_bar">true</bool>
</resources>
2 changes: 2 additions & 0 deletions res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -471,4 +471,6 @@
<dimen name="sud_progress_bar_margin_top">
@dimen/sud_progress_bar_margin_top_material_you
</dimen>
<dimen name="setup_design_card_view_intrinsic_height">0dp</dimen>
<dimen name="setup_design_card_view_intrinsic_width">0dp</dimen>
</resources>
75 changes: 0 additions & 75 deletions src/com/android/settings/SetupDesignConfigProvider.java

This file was deleted.

51 changes: 51 additions & 0 deletions src/com/android/settings/sudconfig/NonRelationalProvider.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.android.settings.sudconfig

import android.content.ContentProvider
import android.content.ContentValues
import android.database.Cursor
import android.net.Uri

/**
* Useful for implementing content provider interfaces that are exclusively for non-relational
* (non-tabular) models. This reduces the boilerplate code by providing empty implementations for
* methods which are unneeded in non-relational models.
*
* @see [ContentProvider.call]
*/
abstract class NonRelationalProvider : ContentProvider() {

final override fun query(
uri: Uri,
projection: Array<out String>?,
selection: String?,
selectionArgs: Array<out String>?,
sortOrder: String?
): Cursor? {
throw UnsupportedOperationException()
}

final override fun getType(uri: Uri): String? {
throw UnsupportedOperationException()
}

final override fun insert(uri: Uri, values: ContentValues?): Uri? {
throw UnsupportedOperationException()
}

final override fun delete(
uri: Uri,
selection: String?,
selectionArgs: Array<out String>?
): Int {
throw UnsupportedOperationException()
}

final override fun update(
uri: Uri,
values: ContentValues?,
selection: String?,
selectionArgs: Array<out String>?
): Int {
throw UnsupportedOperationException()
}
}
73 changes: 73 additions & 0 deletions src/com/android/settings/sudconfig/SudConfigProvider.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.android.settings.sudconfig

import android.os.Build
import android.os.Bundle
import android.provider.Settings
import android.text.TextUtils
import android.util.Log
import com.android.settings.R;

/**
* Provides system-wide config for setup wizard screens.
*/
class SudConfigProvider : NonRelationalProvider() {
companion object {
private const val TAG = "SudConfigProvider"

// resources to be forwarded via overlay config
private val overlayConfigResources = arrayOf(
R.dimen.setup_design_card_view_intrinsic_height,
R.dimen.setup_design_card_view_intrinsic_width,
R.bool.setup_compat_light_navigation_bar,
R.bool.setup_compat_light_status_bar
)
}

override fun onCreate(): Boolean {
return true
}

override fun call(method: String, arg: String?, extras: Bundle?): Bundle {
Log.d(TAG, "method: $method, caller: $callingPackage")
val bundle = Bundle()
when (method) {
"suwDefaultThemeString" -> bundle.putString(method, "glif_v4_light")

"applyGlifThemeControlledTransition",
"isDynamicColorEnabled",
"isEmbeddedActivityOnePaneEnabled",
"isFullDynamicColorEnabled",
"IsMaterialYouStyleEnabled",
"isNeutralButtonStyleEnabled",
"isSuwDayNightEnabled" -> bundle.putBoolean(method, true)

"getDeviceName" -> bundle.putCharSequence(method, getDeviceName())

"getOverlayConfig" -> fillOverlayConfig(bundle)
}
return bundle
}

private fun getDeviceName(): String {
var name = Settings.Global.getString(
requireContext().contentResolver,
Settings.Global.DEVICE_NAME
)
if (TextUtils.isEmpty(name)) {
name = Build.MODEL
}
return name
}

private fun fillOverlayConfig(bundle: Bundle) {
overlayConfigResources.forEach { resId ->
val context = requireContext()
val resName = context.resources.getResourceEntryName(resId)
val config = Bundle()
config.putString("packageName", context.packageName)
config.putString("resourceName", resName)
config.putInt("resourceId", resId)
bundle.putBundle(resName, config)
}
}
}

0 comments on commit ad00a8d

Please sign in to comment.