From 5c9c3a7462dc45907ee30516f43aff68ada3d06d Mon Sep 17 00:00:00 2001 From: Mark Renouf Date: Fri, 24 May 2024 09:34:52 -0400 Subject: Disable sharing when device is under active FRP lock Prevent FRP bypass scenarios involving share intents This CL includes a cleanup of our Settings abstraction to cover Global, Secure and System, and updates existing tests. Bug: 327645387 Test: atest IntentResolver-tests-unit Test: atest ChooserActivityTest#chooserDisabledWhileDeviceFrpLocked Flag: EXEMPT refactor Change-Id: I928b6ea68aa8d6d710dc51eb70acd2cc2ec682c3 --- .../intentresolver/platform/FakeSecureSettings.kt | 60 ---------------------- .../intentresolver/platform/FakeSettings.kt | 43 ++++++++++++++++ 2 files changed, 43 insertions(+), 60 deletions(-) delete mode 100644 tests/shared/src/com/android/intentresolver/platform/FakeSecureSettings.kt create mode 100644 tests/shared/src/com/android/intentresolver/platform/FakeSettings.kt (limited to 'tests/shared/src') diff --git a/tests/shared/src/com/android/intentresolver/platform/FakeSecureSettings.kt b/tests/shared/src/com/android/intentresolver/platform/FakeSecureSettings.kt deleted file mode 100644 index 862be76f..00000000 --- a/tests/shared/src/com/android/intentresolver/platform/FakeSecureSettings.kt +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.intentresolver.platform - -/** - * Creates a SecureSettings instance with predefined values: - * - * val settings = fakeSecureSettings { - * putString("stringValue", "example") - * putInt("intValue", 42) - * } - */ -fun fakeSecureSettings(block: FakeSecureSettings.Builder.() -> Unit): SecureSettings { - return FakeSecureSettings.Builder().apply(block).build() -} - -/** An in memory implementation of [SecureSettings]. */ -class FakeSecureSettings private constructor(private val map: Map) : - SecureSettings { - - override fun getString(name: String): String? = map[name] - override fun getInt(name: String): Int? = getString(name)?.toIntOrNull() - override fun getLong(name: String): Long? = getString(name)?.toLongOrNull() - override fun getFloat(name: String): Float? = getString(name)?.toFloatOrNull() - - class Builder { - private val map = mutableMapOf() - - fun putString(name: String, value: String) { - map[name] = value - } - fun putInt(name: String, value: Int) { - map[name] = value.toString() - } - fun putLong(name: String, value: Long) { - map[name] = value.toString() - } - fun putFloat(name: String, value: Float) { - map[name] = value.toString() - } - - fun build(): SecureSettings { - return FakeSecureSettings(map.toMap()) - } - } -} diff --git a/tests/shared/src/com/android/intentresolver/platform/FakeSettings.kt b/tests/shared/src/com/android/intentresolver/platform/FakeSettings.kt new file mode 100644 index 00000000..55cd7127 --- /dev/null +++ b/tests/shared/src/com/android/intentresolver/platform/FakeSettings.kt @@ -0,0 +1,43 @@ +/* + * 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.intentresolver.platform + +/** + * Creates a Settings instance with predefined values: + * + * val settings: SecureSettings = fakeSettings { + * putString("stringValue", "example") + * putInt("intValue", 42) + * } + */ +inline fun fakeSettings(block: SettingsProxy.() -> Unit): T { + return FakeSettings(mutableMapOf()).apply(block) as T +} + +/** A memory-only implementation of [SettingsProxy]. */ +class FakeSettings( + private val map: MutableMap, +) : GlobalSettings, SecureSettings, SystemSettings { + constructor() : this(mutableMapOf()) + + override fun getStringOrNull(name: String): String? = map[name] + + override fun putString(name: String, value: String): Boolean { + map[name] = value + return true + } +} -- cgit v1.2.3-59-g8ed1b