Revert "Emulate exception for credential protected storage acces..."

Revert submission 34092257-TaskbarDirectBoot

Reason for revert: DroidMonitor: Potential culprit forhttp://b/425765211 - verifying through ABTD before revert submission. This is part of the standard investigation process, and does not mean your CL will be reverted.

Bug: 425765211
Reverted changes: /q/submissionid:34092257-TaskbarDirectBoot

Change-Id: Ie104b7308720f8a7ef9c20d3c5576afa153993cc
diff --git a/tests/multivalentTests/src/com/android/launcher3/util/SandboxApplication.kt b/tests/multivalentTests/src/com/android/launcher3/util/SandboxApplication.kt
index 453d14b..4e9d8a6 100644
--- a/tests/multivalentTests/src/com/android/launcher3/util/SandboxApplication.kt
+++ b/tests/multivalentTests/src/com/android/launcher3/util/SandboxApplication.kt
@@ -21,7 +21,6 @@
 import android.content.Context
 import android.content.ContextParams
 import android.content.ContextWrapper
-import android.content.SharedPreferences
 import android.content.pm.ApplicationInfo
 import android.content.pm.PackageManager
 import android.content.pm.ProviderInfo
@@ -29,7 +28,6 @@
 import android.os.Bundle
 import android.os.IBinder
 import android.os.UserHandle
-import android.os.UserManager
 import android.provider.Settings.Global
 import android.provider.Settings.Secure
 import android.provider.Settings.System
@@ -145,16 +143,6 @@
     override fun getSystemService(name: String): Any? =
         spiedServices[name] ?: super.getSystemService(name)
 
-    override fun getSharedPreferences(name: String?, mode: Int): SharedPreferences? {
-        checkUnlockedIfCredentialProtectedStorage()
-        return super.getSharedPreferences(name, mode)
-    }
-
-    override fun getSharedPreferences(file: File?, mode: Int): SharedPreferences? {
-        checkUnlockedIfCredentialProtectedStorage()
-        return super.getSharedPreferences(file, mode)
-    }
-
     fun <T> spyService(tClass: Class<T>): T {
         val name = getSystemServiceName(tClass)
         val service = spiedServices[name]
@@ -275,28 +263,4 @@
     override fun createTokenContext(token: IBinder, display: Display): Context {
         return SandboxApplicationWrapper(super.createTokenContext(token, display), app)
     }
-
-    override fun getSharedPreferences(name: String?, mode: Int): SharedPreferences? {
-        checkUnlockedIfCredentialProtectedStorage()
-        return super.getSharedPreferences(name, mode)
-    }
-
-    override fun getSharedPreferences(file: File?, mode: Int): SharedPreferences? {
-        checkUnlockedIfCredentialProtectedStorage()
-        return super.getSharedPreferences(file, mode)
-    }
-}
-
-/**
- * Emulates preconditions in `ContextImpl#getSharedPreferences(File, Int)`.
- *
- * Only stubbing [UserManager] is insufficient because `ContextImpl` maintains a static cache for
- * [SharedPreferences], which may populate before creating the stub.
- */
-private fun Context.checkUnlockedIfCredentialProtectedStorage() {
-    if (!isCredentialProtectedStorage) return
-    val userManager = checkNotNull(applicationContext.getSystemService(UserManager::class.java))
-    if (!userManager.isUserUnlockingOrUnlocked(UserHandle.myUserId())) {
-        throw IllegalStateException("Encrypted SharedPreferences accessed while locked")
-    }
 }
diff --git a/tests/multivalentTests/src/com/android/launcher3/util/SandboxApplicationTest.kt b/tests/multivalentTests/src/com/android/launcher3/util/SandboxApplicationTest.kt
index 004c043..8a21cff 100644
--- a/tests/multivalentTests/src/com/android/launcher3/util/SandboxApplicationTest.kt
+++ b/tests/multivalentTests/src/com/android/launcher3/util/SandboxApplicationTest.kt
@@ -16,21 +16,14 @@
 
 package com.android.launcher3.util
 
-import android.content.Context
 import android.hardware.display.DisplayManager
-import android.os.UserHandle
-import android.os.UserManager
 import android.view.Display
 import android.view.Display.DEFAULT_DISPLAY
 import android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
-import com.android.launcher3.LauncherFiles.SHARED_PREFERENCES_KEY
-import com.android.launcher3.LauncherPrefs.Companion.BOOT_AWARE_PREFS_KEY
 import com.google.common.truth.Truth.assertThat
 import org.junit.Rule
 import org.junit.Test
 import org.junit.runner.RunWith
-import org.mockito.kotlin.doReturn
-import org.mockito.kotlin.stub
 
 @RunWith(LauncherMultivalentJUnit::class)
 class SandboxApplicationTest {
@@ -69,50 +62,4 @@
             onDestroy()
         }
     }
-
-    @Test(expected = IllegalStateException::class)
-    fun testGetSharedPreferences_userLocked_throwsException() {
-        app.spyService(UserManager::class.java).stub {
-            on { isUserUnlockingOrUnlocked(UserHandle.myUserId()) } doReturn false
-        }
-        app.createCredentialProtectedStorageContext()
-            .getSharedPreferences(SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE)
-    }
-
-    @Test(expected = IllegalStateException::class)
-    fun testGetSharedPreferences_windowContextAndUserLocked_throwsException() {
-        app.spyService(UserManager::class.java).stub {
-            on { isUserUnlockingOrUnlocked(UserHandle.myUserId()) } doReturn false
-        }
-        val windowContext =
-            app.createCredentialProtectedStorageContext()
-                .createDisplayContext(display)
-                .createWindowContext(TYPE_APPLICATION_OVERLAY, null)
-        windowContext.getSharedPreferences(SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE)
-    }
-
-    @Test
-    fun testGetSharedPreferences_deviceProtectedStorageContextAndUserLocked_returnsPreferences() {
-        app.spyService(UserManager::class.java).stub {
-            on { isUserUnlockingOrUnlocked(UserHandle.myUserId()) } doReturn false
-        }
-        val deviceProtectedStorageContext = app.createDeviceProtectedStorageContext()
-        val sharedPreferences =
-            deviceProtectedStorageContext.getSharedPreferences(
-                BOOT_AWARE_PREFS_KEY,
-                Context.MODE_PRIVATE,
-            )
-        assertThat(sharedPreferences).isNotNull()
-    }
-
-    @Test
-    fun testGetSharedPreferences_userUnlocked_returnsPreferences() {
-        app.spyService(UserManager::class.java).stub {
-            on { isUserUnlockingOrUnlocked(UserHandle.myUserId()) } doReturn true
-        }
-        val sharedPreferences =
-            app.createCredentialProtectedStorageContext()
-                .getSharedPreferences(SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE)
-        assertThat(sharedPreferences).isNotNull()
-    }
 }