Support IntRange of value in PrefService
Bug: 384955673 Test: unit test Flag: com.android.settingslib.flags.settings_catalyst Change-Id: I0d5f67541ee48d758fc8fd0e38fe4c348127017c
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.service
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.service.settings.preferences.GetValueRequest
|
||||
import android.service.settings.preferences.GetValueResult
|
||||
import android.service.settings.preferences.MetadataResult
|
||||
@@ -186,6 +187,11 @@ private data class PreferenceWithScreen(
|
||||
val preference: PreferenceProto,
|
||||
)
|
||||
|
||||
private const val KEY_INT_RANGE = "key_int_range"
|
||||
private const val KEY_MIN = "key_min"
|
||||
private const val KEY_MAX = "key_max"
|
||||
private const val KEY_STEP = "key_step"
|
||||
|
||||
private fun PreferenceProto.toMetadata(
|
||||
context: Context,
|
||||
screenKey: String
|
||||
@@ -196,6 +202,18 @@ private fun PreferenceProto.toMetadata(
|
||||
SensitivityLevel.MEDIUM_SENSITIVITY -> SettingsPreferenceMetadata.DEEPLINK_ONLY
|
||||
else -> SettingsPreferenceMetadata.NO_DIRECT_ACCESS
|
||||
}
|
||||
val extras = Bundle()
|
||||
if (valueDescriptor.hasRangeValue()
|
||||
&& valueDescriptor.rangeValue.hasMin()
|
||||
&& valueDescriptor.rangeValue.hasMax()) {
|
||||
val intRange = Bundle()
|
||||
intRange.putInt(KEY_MIN, valueDescriptor.rangeValue.min)
|
||||
intRange.putInt(KEY_MAX, valueDescriptor.rangeValue.max)
|
||||
if (valueDescriptor.rangeValue.hasStep()) {
|
||||
intRange.putInt(KEY_STEP, valueDescriptor.rangeValue.step)
|
||||
}
|
||||
extras.putBundle(KEY_INT_RANGE, intRange)
|
||||
}
|
||||
return SettingsPreferenceMetadata.Builder(screenKey, key)
|
||||
.setTitle(title.getText(context))
|
||||
.setSummary(summary.getText(context))
|
||||
@@ -208,5 +226,6 @@ private fun PreferenceProto.toMetadata(
|
||||
// Returns all the permissions that are used, some of which are exclusive (e.g. p1 or p2)
|
||||
.setReadPermissions(readPermissions.getAllPermissions())
|
||||
.setWritePermissions(writePermissions.getAllPermissions())
|
||||
.setExtras(extras)
|
||||
.build()
|
||||
}
|
||||
|
@@ -42,8 +42,10 @@ import com.android.settingslib.graph.preferenceGroupProto
|
||||
import com.android.settingslib.graph.preferenceOrGroupProto
|
||||
import com.android.settingslib.graph.preferenceProto
|
||||
import com.android.settingslib.graph.preferenceScreenProto
|
||||
import com.android.settingslib.graph.preferenceValueDescriptorProto
|
||||
import com.android.settingslib.graph.preferenceValueProto
|
||||
import com.android.settingslib.graph.proto.PreferenceGraphProto
|
||||
import com.android.settingslib.graph.rangeValueProto
|
||||
import com.android.settingslib.graph.textProto
|
||||
import com.android.settingslib.graph.toProto
|
||||
import com.android.settingslib.metadata.SensitivityLevel
|
||||
@@ -156,6 +158,13 @@ class PreferenceServiceRequestTransformerTest {
|
||||
available = true
|
||||
restricted = true
|
||||
persistent = true
|
||||
valueDescriptor = preferenceValueDescriptorProto {
|
||||
rangeValue = rangeValueProto {
|
||||
min = 0
|
||||
max = 10
|
||||
step = 2
|
||||
}
|
||||
}
|
||||
sensitivityLevel = SensitivityLevel.LOW_SENSITIVITY
|
||||
readPermissions = Permissions.allOf("read_permission").toProto()
|
||||
writePermissions = Permissions.anyOf("write_permission").toProto()
|
||||
@@ -181,6 +190,11 @@ class PreferenceServiceRequestTransformerTest {
|
||||
assertThat(launchIntent).isNotNull()
|
||||
assertThat(launchIntent!!.component!!.className)
|
||||
.isEqualTo(SettingsHomepageActivity::class.java.name)
|
||||
val intRange = extras.getBundle("key_int_range")
|
||||
assertThat(intRange).isNotNull()
|
||||
assertThat(intRange!!.getInt("key_min", -1)).isEqualTo(0)
|
||||
assertThat(intRange.getInt("key_max", -1)).isEqualTo(10)
|
||||
assertThat(intRange.getInt("key_step", -1)).isEqualTo(2)
|
||||
}
|
||||
with(fResult.value!!) {
|
||||
assertThat(type).isEqualTo(SettingsPreferenceValue.TYPE_BOOLEAN)
|
||||
|
Reference in New Issue
Block a user