Loading src/com/android/settings/spa/search/SpaSearchLandingActivity.kt +3 −11 Original line number Diff line number Diff line Loading @@ -27,9 +27,6 @@ import com.android.settings.core.SubSettingLauncher import com.android.settings.overlay.FeatureFactory.Companion.featureFactory import com.android.settings.password.PasswordUtils import com.android.settings.spa.SpaDestination import com.android.settings.spa.SpaSearchLanding.SpaSearchLandingKey import com.google.protobuf.ByteString import com.google.protobuf.InvalidProtocolBufferException class SpaSearchLandingActivity : Activity() { override fun onCreate(savedInstanceState: Bundle?) { Loading @@ -48,22 +45,17 @@ class SpaSearchLandingActivity : Activity() { companion object { @VisibleForTesting fun tryLaunch(context: Context, keyString: String) { val key = try { SpaSearchLandingKey.parseFrom(ByteString.copyFromUtf8(keyString)) } catch (e: InvalidProtocolBufferException) { Log.w(TAG, "arg key ($keyString) invalid", e) return } val key = decodeToSpaSearchLandingKey(keyString) ?: return if (key.hasSpaPage()) { val destination = key.spaPage.destination if (destination.isNotEmpty()) { Log.d(TAG, "Launch SPA search result: ${key.spaPage}") SpaDestination(destination = destination, highlightMenuKey = null) .startFromExportedActivity(context) } } if (key.hasFragment()) { Log.d(TAG, "Launch fragment search result: ${key.fragment}") val arguments = Bundle().apply { key.fragment.argumentsMap.forEach { (k, v) -> Loading src/com/android/settings/spa/search/SpaSearchLandingKeyExt.kt 0 → 100644 +34 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.spa.search import android.util.Base64 import android.util.Log import com.android.settings.spa.SpaSearchLanding.SpaSearchLandingKey private const val TAG = "SpaSearchLandingKeyExt" fun SpaSearchLandingKey.encodeToString(): String = Base64.encodeToString(toByteArray(), Base64.DEFAULT) fun decodeToSpaSearchLandingKey(input: String): SpaSearchLandingKey? = try { SpaSearchLandingKey.parseFrom(Base64.decode(input, Base64.DEFAULT)) } catch (e: Exception) { Log.w(TAG, "SpaSearchLandingKey ($input) invalid", e) null } src/com/android/settings/spa/search/SpaSearchRepository.kt +1 −1 Original line number Diff line number Diff line Loading @@ -96,7 +96,7 @@ class SpaSearchRepository( keywords: String? = null, ) = SearchIndexableRaw(context).apply { key = spaSearchLandingKey.toByteString().toStringUtf8() key = spaSearchLandingKey.encodeToString() title = itemTitle this.keywords = keywords intentAction = SEARCH_LANDING_ACTION Loading tests/spa_unit/src/com/android/settings/network/telephony/MobileNetworkSettingsSearchIndexTest.kt +2 −2 Original line number Diff line number Diff line Loading @@ -30,8 +30,8 @@ import com.android.settings.spa.SpaSearchLanding.BundleValue import com.android.settings.spa.SpaSearchLanding.SpaSearchLandingFragment import com.android.settings.spa.SpaSearchLanding.SpaSearchLandingKey import com.android.settings.spa.search.SpaSearchLandingActivity import com.android.settings.spa.search.decodeToSpaSearchLandingKey import com.google.common.truth.Truth.assertThat import com.google.protobuf.ByteString import org.junit.Before import org.junit.Test import org.junit.runner.RunWith Loading Loading @@ -104,7 +104,7 @@ class MobileNetworkSettingsSearchIndexTest { searchIndexableData.searchIndexProvider.getDynamicRawDataToIndex(context, true) assertThat(dynamicRawDataToIndex).hasSize(1) val rawData = dynamicRawDataToIndex[0] val key = SpaSearchLandingKey.parseFrom(ByteString.copyFromUtf8(rawData.key)) val key = decodeToSpaSearchLandingKey(rawData.key) assertThat(key) .isEqualTo( SpaSearchLandingKey.newBuilder() Loading tests/spa_unit/src/com/android/settings/spa/search/SpaSearchLandingActivityTest.kt +2 −2 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ class SpaSearchLandingActivityTest { .setSpaPage(SpaSearchLandingSpaPage.newBuilder().setDestination(DESTINATION)) .build() SpaSearchLandingActivity.tryLaunch(context, key.toByteString().toStringUtf8()) SpaSearchLandingActivity.tryLaunch(context, key.encodeToString()) verify(context).startActivity(argThat { getStringExtra(KEY_DESTINATION) == DESTINATION }) } Loading @@ -70,7 +70,7 @@ class SpaSearchLandingActivityTest { BundleValue.newBuilder().setIntValue(ARGUMENT_VALUE).build())) .build() SpaSearchLandingActivity.tryLaunch(context, key.toByteString().toStringUtf8()) SpaSearchLandingActivity.tryLaunch(context, key.encodeToString()) val intent = argumentCaptor<Intent> { verify(context).startActivity(capture()) }.firstValue assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT)) Loading Loading
src/com/android/settings/spa/search/SpaSearchLandingActivity.kt +3 −11 Original line number Diff line number Diff line Loading @@ -27,9 +27,6 @@ import com.android.settings.core.SubSettingLauncher import com.android.settings.overlay.FeatureFactory.Companion.featureFactory import com.android.settings.password.PasswordUtils import com.android.settings.spa.SpaDestination import com.android.settings.spa.SpaSearchLanding.SpaSearchLandingKey import com.google.protobuf.ByteString import com.google.protobuf.InvalidProtocolBufferException class SpaSearchLandingActivity : Activity() { override fun onCreate(savedInstanceState: Bundle?) { Loading @@ -48,22 +45,17 @@ class SpaSearchLandingActivity : Activity() { companion object { @VisibleForTesting fun tryLaunch(context: Context, keyString: String) { val key = try { SpaSearchLandingKey.parseFrom(ByteString.copyFromUtf8(keyString)) } catch (e: InvalidProtocolBufferException) { Log.w(TAG, "arg key ($keyString) invalid", e) return } val key = decodeToSpaSearchLandingKey(keyString) ?: return if (key.hasSpaPage()) { val destination = key.spaPage.destination if (destination.isNotEmpty()) { Log.d(TAG, "Launch SPA search result: ${key.spaPage}") SpaDestination(destination = destination, highlightMenuKey = null) .startFromExportedActivity(context) } } if (key.hasFragment()) { Log.d(TAG, "Launch fragment search result: ${key.fragment}") val arguments = Bundle().apply { key.fragment.argumentsMap.forEach { (k, v) -> Loading
src/com/android/settings/spa/search/SpaSearchLandingKeyExt.kt 0 → 100644 +34 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.spa.search import android.util.Base64 import android.util.Log import com.android.settings.spa.SpaSearchLanding.SpaSearchLandingKey private const val TAG = "SpaSearchLandingKeyExt" fun SpaSearchLandingKey.encodeToString(): String = Base64.encodeToString(toByteArray(), Base64.DEFAULT) fun decodeToSpaSearchLandingKey(input: String): SpaSearchLandingKey? = try { SpaSearchLandingKey.parseFrom(Base64.decode(input, Base64.DEFAULT)) } catch (e: Exception) { Log.w(TAG, "SpaSearchLandingKey ($input) invalid", e) null }
src/com/android/settings/spa/search/SpaSearchRepository.kt +1 −1 Original line number Diff line number Diff line Loading @@ -96,7 +96,7 @@ class SpaSearchRepository( keywords: String? = null, ) = SearchIndexableRaw(context).apply { key = spaSearchLandingKey.toByteString().toStringUtf8() key = spaSearchLandingKey.encodeToString() title = itemTitle this.keywords = keywords intentAction = SEARCH_LANDING_ACTION Loading
tests/spa_unit/src/com/android/settings/network/telephony/MobileNetworkSettingsSearchIndexTest.kt +2 −2 Original line number Diff line number Diff line Loading @@ -30,8 +30,8 @@ import com.android.settings.spa.SpaSearchLanding.BundleValue import com.android.settings.spa.SpaSearchLanding.SpaSearchLandingFragment import com.android.settings.spa.SpaSearchLanding.SpaSearchLandingKey import com.android.settings.spa.search.SpaSearchLandingActivity import com.android.settings.spa.search.decodeToSpaSearchLandingKey import com.google.common.truth.Truth.assertThat import com.google.protobuf.ByteString import org.junit.Before import org.junit.Test import org.junit.runner.RunWith Loading Loading @@ -104,7 +104,7 @@ class MobileNetworkSettingsSearchIndexTest { searchIndexableData.searchIndexProvider.getDynamicRawDataToIndex(context, true) assertThat(dynamicRawDataToIndex).hasSize(1) val rawData = dynamicRawDataToIndex[0] val key = SpaSearchLandingKey.parseFrom(ByteString.copyFromUtf8(rawData.key)) val key = decodeToSpaSearchLandingKey(rawData.key) assertThat(key) .isEqualTo( SpaSearchLandingKey.newBuilder() Loading
tests/spa_unit/src/com/android/settings/spa/search/SpaSearchLandingActivityTest.kt +2 −2 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ class SpaSearchLandingActivityTest { .setSpaPage(SpaSearchLandingSpaPage.newBuilder().setDestination(DESTINATION)) .build() SpaSearchLandingActivity.tryLaunch(context, key.toByteString().toStringUtf8()) SpaSearchLandingActivity.tryLaunch(context, key.encodeToString()) verify(context).startActivity(argThat { getStringExtra(KEY_DESTINATION) == DESTINATION }) } Loading @@ -70,7 +70,7 @@ class SpaSearchLandingActivityTest { BundleValue.newBuilder().setIntValue(ARGUMENT_VALUE).build())) .build() SpaSearchLandingActivity.tryLaunch(context, key.toByteString().toStringUtf8()) SpaSearchLandingActivity.tryLaunch(context, key.encodeToString()) val intent = argumentCaptor<Intent> { verify(context).startActivity(capture()) }.firstValue assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT)) Loading