summaryrefslogtreecommitdiff
path: root/tests/shared
diff options
context:
space:
mode:
author Mark Renouf <mrenouf@google.com> 2024-05-24 09:34:52 -0400
committer Mark Renouf <mrenouf@google.com> 2024-05-29 21:45:15 -0400
commit5c9c3a7462dc45907ee30516f43aff68ada3d06d (patch)
tree00325e5d41b4e1bc8eefd1b6011d7778f2578207 /tests/shared
parent68c1cb781b1ed97398857b7b3054764a1173ec7f (diff)
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
Diffstat (limited to 'tests/shared')
-rw-r--r--tests/shared/src/com/android/intentresolver/platform/FakeSecureSettings.kt60
-rw-r--r--tests/shared/src/com/android/intentresolver/platform/FakeSettings.kt43
2 files changed, 43 insertions, 60 deletions
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<String, String>) :
- 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<String, String>()
-
- 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 <reified T : SettingsProxy> fakeSettings(block: SettingsProxy.() -> Unit): T {
+ return FakeSettings(mutableMapOf()).apply(block) as T
+}
+
+/** A memory-only implementation of [SettingsProxy]. */
+class FakeSettings(
+ private val map: MutableMap<String, String>,
+) : 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
+ }
+}