Loading packages/SettingsLib/Graph/src/com/android/settingslib/graph/PreferenceGetterCodecs.kt +39 −41 Original line number Diff line number Diff line Loading @@ -17,10 +17,10 @@ package com.android.settingslib.graph import android.os.Bundle import android.os.Parcel import com.android.settingslib.graph.proto.PreferenceProto import com.android.settingslib.ipc.MessageCodec import com.android.settingslib.metadata.PreferenceCoordinate import com.android.settingslib.metadata.useParcel import java.util.Arrays /** Message codec for [PreferenceGetterRequest]. */ Loading Loading @@ -57,20 +57,19 @@ class PreferenceGetterResponseCodec : MessageCodec<PreferenceGetterResponse> { private fun Map<PreferenceCoordinate, Int>.toErrorsByteArray(): ByteArray? { if (isEmpty()) return null val parcel = Parcel.obtain() return useParcel { parcel -> parcel.writeInt(size) for ((coordinate, code) in this) { coordinate.writeToParcel(parcel, 0) parcel.writeInt(code) } val bytes = parcel.marshall() parcel.recycle() return bytes parcel.marshall() } } private fun Map<PreferenceCoordinate, PreferenceProto>.toPreferencesByteArray(): ByteArray? { if (isEmpty()) return null val parcel = Parcel.obtain() return useParcel { parcel -> parcel.writeInt(size) for ((coordinate, preferenceProto) in this) { coordinate.writeToParcel(parcel, 0) Loading @@ -78,9 +77,8 @@ class PreferenceGetterResponseCodec : MessageCodec<PreferenceGetterResponse> { parcel.writeInt(data.size) parcel.writeByteArray(data) } val bytes = parcel.marshall() parcel.recycle() return bytes parcel.marshall() } } override fun decode(data: Bundle) = Loading @@ -91,7 +89,7 @@ class PreferenceGetterResponseCodec : MessageCodec<PreferenceGetterResponse> { private fun ByteArray?.toErrors(): Map<PreferenceCoordinate, Int> { if (this == null) return emptyMap() val parcel = Parcel.obtain() return useParcel { parcel -> parcel.unmarshall(this, 0, size) parcel.setDataPosition(0) val count = parcel.readInt() Loading @@ -100,13 +98,13 @@ class PreferenceGetterResponseCodec : MessageCodec<PreferenceGetterResponse> { val coordinate = PreferenceCoordinate(parcel) errors[coordinate] = parcel.readInt() } parcel.recycle() return errors errors } } private fun ByteArray?.toPreferences(): Map<PreferenceCoordinate, PreferenceProto> { if (this == null) return emptyMap() val parcel = Parcel.obtain() return useParcel { parcel -> parcel.unmarshall(this, 0, size) parcel.setDataPosition(0) val count = parcel.readInt() Loading @@ -117,8 +115,8 @@ class PreferenceGetterResponseCodec : MessageCodec<PreferenceGetterResponse> { val array = ByteArray(bytes).also { parcel.readByteArray(it) } preferences[coordinate] = PreferenceProto.parseFrom(array) } parcel.recycle() return preferences preferences } } companion object { Loading packages/SettingsLib/Metadata/src/com/android/settingslib/metadata/Bundles.kt +5 −6 Original line number Diff line number Diff line Loading @@ -61,8 +61,7 @@ fun Parcelable.marshallParcel(): ByteArray = useParcel { parcel -> fun ByteArray.unmarshallBundle(): Bundle = unmarshallParcel(Bundle.CREATOR) /** Unmarshall a byte array to [Parcelable]. */ inline fun <reified T> ByteArray.unmarshallParcel(creator: Parcelable.Creator<T>): T = useParcel { parcel -> fun <T> ByteArray.unmarshallParcel(creator: Parcelable.Creator<T>): T = useParcel { parcel -> parcel.unmarshall(this, 0, size) parcel.setDataPosition(0) return@useParcel creator.createFromParcel(parcel) Loading packages/SettingsLib/Metadata/src/com/android/settingslib/metadata/PreferenceMetadata.kt +8 −1 Original line number Diff line number Diff line Loading @@ -141,7 +141,14 @@ interface PreferenceMetadata { */ fun isEnabled(context: Context): Boolean = true /** Returns the keys of depended preferences. */ /** * Returns the keys of depended preferences. * * Keep in mind that the dependency is effective only on the same screen. For cross screen * dependency, especially for preference screen entry point, add observer (e.g. on the depended * preference's data store) explicitly to update the preference with * [PreferenceLifecycleProvider]. */ fun dependencies(context: Context): Array<String> = arrayOf() /** Returns if the preference is persistent in datastore. */ Loading packages/SettingsLib/Metadata/src/com/android/settingslib/metadata/PreferenceStateProviders.kt +4 −2 Original line number Diff line number Diff line Loading @@ -84,9 +84,11 @@ interface PreferenceRestrictionProvider { } /** * Preference lifecycle to deal with preference state. * Preference lifecycle to deal with preference UI state. * * Implement this interface when preference depends on runtime conditions. * Implement this interface when preference depends on runtime conditions for UI update. Note that * [PreferenceMetadata] could be created for UI (shown in UI widget) or background (e.g. external * Get/Set), callbacks in this interface will ONLY be invoked when it is for UI. */ interface PreferenceLifecycleProvider { Loading Loading
packages/SettingsLib/Graph/src/com/android/settingslib/graph/PreferenceGetterCodecs.kt +39 −41 Original line number Diff line number Diff line Loading @@ -17,10 +17,10 @@ package com.android.settingslib.graph import android.os.Bundle import android.os.Parcel import com.android.settingslib.graph.proto.PreferenceProto import com.android.settingslib.ipc.MessageCodec import com.android.settingslib.metadata.PreferenceCoordinate import com.android.settingslib.metadata.useParcel import java.util.Arrays /** Message codec for [PreferenceGetterRequest]. */ Loading Loading @@ -57,20 +57,19 @@ class PreferenceGetterResponseCodec : MessageCodec<PreferenceGetterResponse> { private fun Map<PreferenceCoordinate, Int>.toErrorsByteArray(): ByteArray? { if (isEmpty()) return null val parcel = Parcel.obtain() return useParcel { parcel -> parcel.writeInt(size) for ((coordinate, code) in this) { coordinate.writeToParcel(parcel, 0) parcel.writeInt(code) } val bytes = parcel.marshall() parcel.recycle() return bytes parcel.marshall() } } private fun Map<PreferenceCoordinate, PreferenceProto>.toPreferencesByteArray(): ByteArray? { if (isEmpty()) return null val parcel = Parcel.obtain() return useParcel { parcel -> parcel.writeInt(size) for ((coordinate, preferenceProto) in this) { coordinate.writeToParcel(parcel, 0) Loading @@ -78,9 +77,8 @@ class PreferenceGetterResponseCodec : MessageCodec<PreferenceGetterResponse> { parcel.writeInt(data.size) parcel.writeByteArray(data) } val bytes = parcel.marshall() parcel.recycle() return bytes parcel.marshall() } } override fun decode(data: Bundle) = Loading @@ -91,7 +89,7 @@ class PreferenceGetterResponseCodec : MessageCodec<PreferenceGetterResponse> { private fun ByteArray?.toErrors(): Map<PreferenceCoordinate, Int> { if (this == null) return emptyMap() val parcel = Parcel.obtain() return useParcel { parcel -> parcel.unmarshall(this, 0, size) parcel.setDataPosition(0) val count = parcel.readInt() Loading @@ -100,13 +98,13 @@ class PreferenceGetterResponseCodec : MessageCodec<PreferenceGetterResponse> { val coordinate = PreferenceCoordinate(parcel) errors[coordinate] = parcel.readInt() } parcel.recycle() return errors errors } } private fun ByteArray?.toPreferences(): Map<PreferenceCoordinate, PreferenceProto> { if (this == null) return emptyMap() val parcel = Parcel.obtain() return useParcel { parcel -> parcel.unmarshall(this, 0, size) parcel.setDataPosition(0) val count = parcel.readInt() Loading @@ -117,8 +115,8 @@ class PreferenceGetterResponseCodec : MessageCodec<PreferenceGetterResponse> { val array = ByteArray(bytes).also { parcel.readByteArray(it) } preferences[coordinate] = PreferenceProto.parseFrom(array) } parcel.recycle() return preferences preferences } } companion object { Loading
packages/SettingsLib/Metadata/src/com/android/settingslib/metadata/Bundles.kt +5 −6 Original line number Diff line number Diff line Loading @@ -61,8 +61,7 @@ fun Parcelable.marshallParcel(): ByteArray = useParcel { parcel -> fun ByteArray.unmarshallBundle(): Bundle = unmarshallParcel(Bundle.CREATOR) /** Unmarshall a byte array to [Parcelable]. */ inline fun <reified T> ByteArray.unmarshallParcel(creator: Parcelable.Creator<T>): T = useParcel { parcel -> fun <T> ByteArray.unmarshallParcel(creator: Parcelable.Creator<T>): T = useParcel { parcel -> parcel.unmarshall(this, 0, size) parcel.setDataPosition(0) return@useParcel creator.createFromParcel(parcel) Loading
packages/SettingsLib/Metadata/src/com/android/settingslib/metadata/PreferenceMetadata.kt +8 −1 Original line number Diff line number Diff line Loading @@ -141,7 +141,14 @@ interface PreferenceMetadata { */ fun isEnabled(context: Context): Boolean = true /** Returns the keys of depended preferences. */ /** * Returns the keys of depended preferences. * * Keep in mind that the dependency is effective only on the same screen. For cross screen * dependency, especially for preference screen entry point, add observer (e.g. on the depended * preference's data store) explicitly to update the preference with * [PreferenceLifecycleProvider]. */ fun dependencies(context: Context): Array<String> = arrayOf() /** Returns if the preference is persistent in datastore. */ Loading
packages/SettingsLib/Metadata/src/com/android/settingslib/metadata/PreferenceStateProviders.kt +4 −2 Original line number Diff line number Diff line Loading @@ -84,9 +84,11 @@ interface PreferenceRestrictionProvider { } /** * Preference lifecycle to deal with preference state. * Preference lifecycle to deal with preference UI state. * * Implement this interface when preference depends on runtime conditions. * Implement this interface when preference depends on runtime conditions for UI update. Note that * [PreferenceMetadata] could be created for UI (shown in UI widget) or background (e.g. external * Get/Set), callbacks in this interface will ONLY be invoked when it is for UI. */ interface PreferenceLifecycleProvider { Loading