Loading packages/SettingsLib/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ package { // to get the below license kinds: // SPDX-license-identifier-Apache-2.0 default_applicable_licenses: ["frameworks_base_license"], default_team: "trendy_team_android_settings_app", } android_library { Loading packages/SettingsLib/Graph/graph.proto +4 −1 Original line number Diff line number Diff line Loading @@ -197,8 +197,11 @@ message IntentProto { // Proto of android.os.Bundle message BundleProto { // Bundle data. // Bundle data. Absent when `parcel_bytes` is provided. map<string, BundleValue> values = 1; // The byte array that this `Bundle` object is marshalled by `Parcel`. It is flexible to support // unknown value types (e.g. `Parcelable`) but the data size is way larger than `values`. bytes parcel_bytes = 2; message BundleValue { // Bundle data value for the associated key name. Loading packages/SettingsLib/Graph/src/com/android/settingslib/graph/ProtoConverters.kt +28 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.settingslib.graph import android.annotation.SuppressLint import android.content.ComponentName import android.content.Context import android.content.Intent Loading @@ -25,6 +26,8 @@ import com.android.settingslib.graph.proto.BundleProto import com.android.settingslib.graph.proto.BundleProto.BundleValue import com.android.settingslib.graph.proto.IntentProto import com.android.settingslib.graph.proto.TextProto import com.android.settingslib.metadata.marshallParcel import com.android.settingslib.metadata.unmarshallBundle import com.google.protobuf.ByteString fun TextProto.getText(context: Context): String? = Loading @@ -44,6 +47,7 @@ fun Intent.toProto(): IntentProto = intentProto { this@toProto.type?.let { mimeType = it } } @SuppressLint("WrongConstant") fun IntentProto.toIntent(): Intent { val intent = Intent() if (hasComponent()) intent.component = ComponentName.unflattenFromString(component) Loading @@ -56,7 +60,25 @@ fun IntentProto.toIntent(): Intent { return intent } @Suppress("DEPRECATION") fun Bundle.toProto(): BundleProto = bundleProto { fun Any.hasUnknownType(): Boolean = when (this@hasUnknownType) { is String, is ByteArray, is Int, is Long, is Boolean, is Double -> false is Bundle -> keySet().any { get(it)?.hasUnknownType() == true } else -> true } if (this@toProto.hasUnknownType()) { parcelBytes = ByteString.copyFrom(marshallParcel()) return@bundleProto } fun toProto(value: Any): BundleValue = bundleValueProto { when (value) { is String -> stringValue = value Loading @@ -71,12 +93,14 @@ fun Bundle.toProto(): BundleProto = bundleProto { } for (key in keySet()) { @Suppress("DEPRECATION") get(key)?.let { putValues(key, toProto(it)) } get(key)?.let { putValues(key, toProto(it)) } } } fun BundleProto.toBundle(): Bundle = Bundle().apply { fun BundleProto.toBundle(): Bundle { val bytes = parcelBytes.toByteArray() if (bytes.isNotEmpty()) return bytes.unmarshallBundle() return Bundle().apply { for ((key, value) in valuesMap) { when { value.hasBooleanValue() -> putBoolean(key, value.booleanValue) Loading @@ -90,3 +114,4 @@ fun BundleProto.toBundle(): Bundle = } } } } packages/SettingsLib/Graph/tests/Android.bp 0 → 100644 +21 −0 Original line number Diff line number Diff line package { default_applicable_licenses: ["frameworks_base_license"], } android_app { name: "SettingsLibGraphShell", platform_apis: true, } android_robolectric_test { name: "SettingsLibGraphTest", srcs: ["src/**/*.kt"], static_libs: [ "SettingsLibGraph", "androidx.test.ext.junit", "truth", ], instrumentation_for: "SettingsLibGraphShell", coverage_libs: ["SettingsLibGraph"], upstream: true, } packages/SettingsLib/Graph/tests/AndroidManifest.xml 0 → 100644 +2 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <manifest package="com.android.settingslib.graph.test" /> Loading
packages/SettingsLib/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ package { // to get the below license kinds: // SPDX-license-identifier-Apache-2.0 default_applicable_licenses: ["frameworks_base_license"], default_team: "trendy_team_android_settings_app", } android_library { Loading
packages/SettingsLib/Graph/graph.proto +4 −1 Original line number Diff line number Diff line Loading @@ -197,8 +197,11 @@ message IntentProto { // Proto of android.os.Bundle message BundleProto { // Bundle data. // Bundle data. Absent when `parcel_bytes` is provided. map<string, BundleValue> values = 1; // The byte array that this `Bundle` object is marshalled by `Parcel`. It is flexible to support // unknown value types (e.g. `Parcelable`) but the data size is way larger than `values`. bytes parcel_bytes = 2; message BundleValue { // Bundle data value for the associated key name. Loading
packages/SettingsLib/Graph/src/com/android/settingslib/graph/ProtoConverters.kt +28 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.settingslib.graph import android.annotation.SuppressLint import android.content.ComponentName import android.content.Context import android.content.Intent Loading @@ -25,6 +26,8 @@ import com.android.settingslib.graph.proto.BundleProto import com.android.settingslib.graph.proto.BundleProto.BundleValue import com.android.settingslib.graph.proto.IntentProto import com.android.settingslib.graph.proto.TextProto import com.android.settingslib.metadata.marshallParcel import com.android.settingslib.metadata.unmarshallBundle import com.google.protobuf.ByteString fun TextProto.getText(context: Context): String? = Loading @@ -44,6 +47,7 @@ fun Intent.toProto(): IntentProto = intentProto { this@toProto.type?.let { mimeType = it } } @SuppressLint("WrongConstant") fun IntentProto.toIntent(): Intent { val intent = Intent() if (hasComponent()) intent.component = ComponentName.unflattenFromString(component) Loading @@ -56,7 +60,25 @@ fun IntentProto.toIntent(): Intent { return intent } @Suppress("DEPRECATION") fun Bundle.toProto(): BundleProto = bundleProto { fun Any.hasUnknownType(): Boolean = when (this@hasUnknownType) { is String, is ByteArray, is Int, is Long, is Boolean, is Double -> false is Bundle -> keySet().any { get(it)?.hasUnknownType() == true } else -> true } if (this@toProto.hasUnknownType()) { parcelBytes = ByteString.copyFrom(marshallParcel()) return@bundleProto } fun toProto(value: Any): BundleValue = bundleValueProto { when (value) { is String -> stringValue = value Loading @@ -71,12 +93,14 @@ fun Bundle.toProto(): BundleProto = bundleProto { } for (key in keySet()) { @Suppress("DEPRECATION") get(key)?.let { putValues(key, toProto(it)) } get(key)?.let { putValues(key, toProto(it)) } } } fun BundleProto.toBundle(): Bundle = Bundle().apply { fun BundleProto.toBundle(): Bundle { val bytes = parcelBytes.toByteArray() if (bytes.isNotEmpty()) return bytes.unmarshallBundle() return Bundle().apply { for ((key, value) in valuesMap) { when { value.hasBooleanValue() -> putBoolean(key, value.booleanValue) Loading @@ -90,3 +114,4 @@ fun BundleProto.toBundle(): Bundle = } } } }
packages/SettingsLib/Graph/tests/Android.bp 0 → 100644 +21 −0 Original line number Diff line number Diff line package { default_applicable_licenses: ["frameworks_base_license"], } android_app { name: "SettingsLibGraphShell", platform_apis: true, } android_robolectric_test { name: "SettingsLibGraphTest", srcs: ["src/**/*.kt"], static_libs: [ "SettingsLibGraph", "androidx.test.ext.junit", "truth", ], instrumentation_for: "SettingsLibGraphShell", coverage_libs: ["SettingsLibGraph"], upstream: true, }
packages/SettingsLib/Graph/tests/AndroidManifest.xml 0 → 100644 +2 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <manifest package="com.android.settingslib.graph.test" />