Loading packages/SettingsLib/Graph/src/com/android/settingslib/graph/PreferenceGraphBuilder.kt +2 −1 Original line number Diff line number Diff line Loading @@ -414,7 +414,8 @@ fun PreferenceMetadata.toProto( restricted = metadata.isRestricted(context) } metadata.intent(context)?.let { actionTarget = it.toActionTarget(context) } screenMetadata.getLaunchIntent(context, metadata)?.let { launchIntent = it.toProto() } val launchTarget = if (screenMetadata != metadata) metadata else null screenMetadata.getLaunchIntent(context, launchTarget)?.let { launchIntent = it.toProto() } for (tag in metadata.tags(context)) addTags(tag) } persistent = metadata.isPersistent(context) Loading packages/SettingsLib/Graph/src/com/android/settingslib/graph/ProtoConverters.kt +2 −4 Original line number Diff line number Diff line Loading @@ -44,11 +44,9 @@ fun Intent.toProto(): IntentProto = intentProto { this@toProto.type?.let { mimeType = it } } fun IntentProto.toIntent(): Intent? { if (!hasComponent()) return null val componentName = ComponentName.unflattenFromString(component) ?: return null fun IntentProto.toIntent(): Intent { val intent = Intent() intent.component = componentName if (hasComponent()) intent.component = ComponentName.unflattenFromString(component) if (hasAction()) intent.action = action if (hasData()) intent.data = Uri.parse(data) if (hasPkg()) intent.`package` = pkg Loading packages/SettingsLib/Metadata/src/com/android/settingslib/metadata/PreferenceHierarchy.kt +10 −0 Original line number Diff line number Diff line Loading @@ -204,3 +204,13 @@ fun preferenceHierarchy( metadata: PreferenceMetadata, init: PreferenceHierarchy.() -> Unit, ) = PreferenceHierarchy(context, metadata).also(init) /** * Builder function to create [PreferenceHierarchy] with coroutine in * [DSL](https://kotlinlang.org/docs/type-safe-builders.html) manner. */ suspend fun asyncPreferenceHierarchy( context: Context, metadata: PreferenceMetadata, init: suspend PreferenceHierarchy.() -> Unit, ) = PreferenceHierarchy(context, metadata).also { init(it) } packages/SettingsLib/Metadata/src/com/android/settingslib/metadata/PreferenceScreenMetadata.kt +15 −1 Original line number Diff line number Diff line Loading @@ -63,10 +63,14 @@ interface PreferenceScreenMetadata : PreferenceMetadata { fun hasCompleteHierarchy(): Boolean = true /** * Returns the hierarchy of preference screen. * Returns the static hierarchy of preference screen. * * The implementation MUST include all preferences into the hierarchy regardless of the runtime * conditions. DO NOT check any condition (except compile time flag) before adding a preference. * * If the screen has different [PreferenceHierarchy] based on additional information (e.g. app * filter, profile), implements [PreferenceHierarchyGenerator]. The UI framework will support * switching [PreferenceHierarchy] on current screen with given type. */ fun getPreferenceHierarchy(context: Context): PreferenceHierarchy Loading @@ -78,6 +82,16 @@ interface PreferenceScreenMetadata : PreferenceMetadata { fun getLaunchIntent(context: Context, metadata: PreferenceMetadata?): Intent? = null } /** Generator of [PreferenceHierarchy] based on given type. */ interface PreferenceHierarchyGenerator<T> { /** Default type to generate [PreferenceHierarchy]. */ val defaultType: T /** Generates [PreferenceHierarchy] with given type. */ suspend fun generatePreferenceHierarchy(context: Context, type: T): PreferenceHierarchy } /** * Factory of [PreferenceScreenMetadata]. * Loading packages/SettingsLib/Metadata/src/com/android/settingslib/metadata/PreferenceStateProviders.kt +7 −1 Original line number Diff line number Diff line Loading @@ -167,6 +167,12 @@ abstract class PreferenceLifecycleContext(context: Context) : ContextWrapper(con /** Notifies that preference state of given key is changed and updates preference widget UI. */ abstract fun notifyPreferenceChange(key: String) /** * Switches preference hierarchy to given type, the screen metadata must implement * `PreferenceHierarchyGenerator`. */ open fun switchPreferenceHierarchy(type: Any?): Unit = TODO() /** * Starts activity for result, see [android.app.Activity.startActivityForResult]. * Loading @@ -184,6 +190,6 @@ abstract class PreferenceLifecycleContext(context: Context) : ContextWrapper(con */ abstract fun <I, O> registerForActivityResult( contract: ActivityResultContract<I, O>, callback: ActivityResultCallback<O> callback: ActivityResultCallback<O>, ): ActivityResultLauncher<I> } Loading
packages/SettingsLib/Graph/src/com/android/settingslib/graph/PreferenceGraphBuilder.kt +2 −1 Original line number Diff line number Diff line Loading @@ -414,7 +414,8 @@ fun PreferenceMetadata.toProto( restricted = metadata.isRestricted(context) } metadata.intent(context)?.let { actionTarget = it.toActionTarget(context) } screenMetadata.getLaunchIntent(context, metadata)?.let { launchIntent = it.toProto() } val launchTarget = if (screenMetadata != metadata) metadata else null screenMetadata.getLaunchIntent(context, launchTarget)?.let { launchIntent = it.toProto() } for (tag in metadata.tags(context)) addTags(tag) } persistent = metadata.isPersistent(context) Loading
packages/SettingsLib/Graph/src/com/android/settingslib/graph/ProtoConverters.kt +2 −4 Original line number Diff line number Diff line Loading @@ -44,11 +44,9 @@ fun Intent.toProto(): IntentProto = intentProto { this@toProto.type?.let { mimeType = it } } fun IntentProto.toIntent(): Intent? { if (!hasComponent()) return null val componentName = ComponentName.unflattenFromString(component) ?: return null fun IntentProto.toIntent(): Intent { val intent = Intent() intent.component = componentName if (hasComponent()) intent.component = ComponentName.unflattenFromString(component) if (hasAction()) intent.action = action if (hasData()) intent.data = Uri.parse(data) if (hasPkg()) intent.`package` = pkg Loading
packages/SettingsLib/Metadata/src/com/android/settingslib/metadata/PreferenceHierarchy.kt +10 −0 Original line number Diff line number Diff line Loading @@ -204,3 +204,13 @@ fun preferenceHierarchy( metadata: PreferenceMetadata, init: PreferenceHierarchy.() -> Unit, ) = PreferenceHierarchy(context, metadata).also(init) /** * Builder function to create [PreferenceHierarchy] with coroutine in * [DSL](https://kotlinlang.org/docs/type-safe-builders.html) manner. */ suspend fun asyncPreferenceHierarchy( context: Context, metadata: PreferenceMetadata, init: suspend PreferenceHierarchy.() -> Unit, ) = PreferenceHierarchy(context, metadata).also { init(it) }
packages/SettingsLib/Metadata/src/com/android/settingslib/metadata/PreferenceScreenMetadata.kt +15 −1 Original line number Diff line number Diff line Loading @@ -63,10 +63,14 @@ interface PreferenceScreenMetadata : PreferenceMetadata { fun hasCompleteHierarchy(): Boolean = true /** * Returns the hierarchy of preference screen. * Returns the static hierarchy of preference screen. * * The implementation MUST include all preferences into the hierarchy regardless of the runtime * conditions. DO NOT check any condition (except compile time flag) before adding a preference. * * If the screen has different [PreferenceHierarchy] based on additional information (e.g. app * filter, profile), implements [PreferenceHierarchyGenerator]. The UI framework will support * switching [PreferenceHierarchy] on current screen with given type. */ fun getPreferenceHierarchy(context: Context): PreferenceHierarchy Loading @@ -78,6 +82,16 @@ interface PreferenceScreenMetadata : PreferenceMetadata { fun getLaunchIntent(context: Context, metadata: PreferenceMetadata?): Intent? = null } /** Generator of [PreferenceHierarchy] based on given type. */ interface PreferenceHierarchyGenerator<T> { /** Default type to generate [PreferenceHierarchy]. */ val defaultType: T /** Generates [PreferenceHierarchy] with given type. */ suspend fun generatePreferenceHierarchy(context: Context, type: T): PreferenceHierarchy } /** * Factory of [PreferenceScreenMetadata]. * Loading
packages/SettingsLib/Metadata/src/com/android/settingslib/metadata/PreferenceStateProviders.kt +7 −1 Original line number Diff line number Diff line Loading @@ -167,6 +167,12 @@ abstract class PreferenceLifecycleContext(context: Context) : ContextWrapper(con /** Notifies that preference state of given key is changed and updates preference widget UI. */ abstract fun notifyPreferenceChange(key: String) /** * Switches preference hierarchy to given type, the screen metadata must implement * `PreferenceHierarchyGenerator`. */ open fun switchPreferenceHierarchy(type: Any?): Unit = TODO() /** * Starts activity for result, see [android.app.Activity.startActivityForResult]. * Loading @@ -184,6 +190,6 @@ abstract class PreferenceLifecycleContext(context: Context) : ContextWrapper(con */ abstract fun <I, O> registerForActivityResult( contract: ActivityResultContract<I, O>, callback: ActivityResultCallback<O> callback: ActivityResultCallback<O>, ): ActivityResultLauncher<I> }