Support GetMetadata for Preference Service
Bug: 379750656 Flag: com.android.settingslib.flags.settings_catalyst Test: unit test Change-Id: Ia9b438360b60ff509a259df0a079ec4d745fb595
This commit is contained in:
@@ -19,6 +19,7 @@ package com.android.settings.service
|
||||
import android.content.Context
|
||||
import android.service.settings.preferences.GetValueRequest
|
||||
import android.service.settings.preferences.GetValueResult
|
||||
import android.service.settings.preferences.MetadataResult
|
||||
import android.service.settings.preferences.SetValueRequest
|
||||
import android.service.settings.preferences.SetValueResult
|
||||
import android.service.settings.preferences.SettingsPreferenceMetadata
|
||||
@@ -34,9 +35,55 @@ import com.android.settingslib.graph.preferenceValueProto
|
||||
import com.android.settingslib.graph.proto.PreferenceProto
|
||||
import com.android.settingslib.graph.proto.PreferenceValueProto
|
||||
import com.android.settingslib.graph.getText
|
||||
import com.android.settingslib.graph.proto.PreferenceGraphProto
|
||||
import com.android.settingslib.graph.proto.PreferenceOrGroupProto
|
||||
import com.android.settingslib.graph.toIntent
|
||||
import com.android.settingslib.metadata.SensitivityLevel
|
||||
|
||||
/** Transform Catalyst Graph result to Framework GET METADATA result */
|
||||
fun transformCatalystGetMetadataResponse(
|
||||
context: Context,
|
||||
graph: PreferenceGraphProto
|
||||
): MetadataResult {
|
||||
val preferences = mutableSetOf<PreferenceWithScreen>()
|
||||
// recursive function to visit all nodes in preference group
|
||||
fun traverseGroupOrPref(
|
||||
screenKey: String,
|
||||
groupOrPref: PreferenceOrGroupProto,
|
||||
) {
|
||||
when (groupOrPref.kindCase) {
|
||||
PreferenceOrGroupProto.KindCase.PREFERENCE ->
|
||||
preferences.add(
|
||||
PreferenceWithScreen(screenKey, groupOrPref.preference)
|
||||
)
|
||||
PreferenceOrGroupProto.KindCase.GROUP -> {
|
||||
for (child in groupOrPref.group.preferencesList) {
|
||||
traverseGroupOrPref(screenKey, child)
|
||||
}
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
// traverse all screens and all preferences on screen
|
||||
for ((screenKey, screen) in graph.screensMap) {
|
||||
for (groupOrPref in screen.root.preferencesList) {
|
||||
traverseGroupOrPref(screenKey, groupOrPref)
|
||||
}
|
||||
}
|
||||
|
||||
return if (preferences.isNotEmpty()) {
|
||||
MetadataResult.Builder(MetadataResult.RESULT_OK)
|
||||
.setMetadataList(
|
||||
preferences.map {
|
||||
it.preference.toMetadata(context, it.screenKey)
|
||||
}
|
||||
)
|
||||
.build()
|
||||
} else {
|
||||
MetadataResult.Builder(MetadataResult.RESULT_UNSUPPORTED).build()
|
||||
}
|
||||
}
|
||||
|
||||
/** Translate Framework GET VALUE request to Catalyst GET VALUE request */
|
||||
fun transformFrameworkGetValueRequest(
|
||||
request: GetValueRequest,
|
||||
@@ -133,6 +180,11 @@ fun transformCatalystSetValueResponse(@PreferenceSetterResult response: Int): Se
|
||||
return SetValueResult.Builder(resultCode).build()
|
||||
}
|
||||
|
||||
private data class PreferenceWithScreen(
|
||||
val screenKey: String,
|
||||
val preference: PreferenceProto,
|
||||
)
|
||||
|
||||
private fun PreferenceProto.toMetadata(
|
||||
context: Context,
|
||||
screenKey: String
|
||||
|
Reference in New Issue
Block a user