Merge "Encode SpaSearchLandingKey with Base64" into main
This commit is contained in:
@@ -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?) {
|
||||
@@ -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) ->
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user