diff options
Diffstat (limited to 'tests/utils/safetycenter/java/com/android/safetycenter/testing/TestActivity.kt')
-rw-r--r-- | tests/utils/safetycenter/java/com/android/safetycenter/testing/TestActivity.kt | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/utils/safetycenter/java/com/android/safetycenter/testing/TestActivity.kt b/tests/utils/safetycenter/java/com/android/safetycenter/testing/TestActivity.kt index 124f44101..eceffb74f 100644 --- a/tests/utils/safetycenter/java/com/android/safetycenter/testing/TestActivity.kt +++ b/tests/utils/safetycenter/java/com/android/safetycenter/testing/TestActivity.kt @@ -16,9 +16,15 @@ package com.android.safetycenter.testing import android.app.Activity +import android.content.ComponentName +import android.content.Context +import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED +import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED +import android.content.pm.PackageManager.DONT_KILL_APP import android.os.Bundle import android.view.View import android.widget.TextView +import androidx.test.core.app.ApplicationProvider /** An activity used in tests to assert the redirects. */ class TestActivity : Activity() { @@ -32,4 +38,32 @@ class TestActivity : Activity() { val exitButton: View? = findViewById(R.id.button) exitButton?.setOnClickListener { finish() } } + + companion object { + + /** + * Enable a higher-priority alias of TestActivity. + * + * <p>We have seen flakes where implicit intents for TEST_ACTIVITY fail owing to multiple + * receivers, perhaps due to an older CTS APK hanging around. This component should be + * turned on (and off in tidyup) in tests in the hope of only resolving to the actively + * running test in these cases. + */ + fun enableHighPriorityAlias() { + setAliasEnabledState(COMPONENT_ENABLED_STATE_ENABLED) + } + /** @see [enableHighPriorityAlias] */ + fun disableHighPriorityAlias() { + setAliasEnabledState(COMPONENT_ENABLED_STATE_DISABLED) + } + private fun setAliasEnabledState(state: Int) { + val name = + ComponentName(getApplicationContext(), TestActivity::class.java.name + "Priority") + getApplicationContext() + .packageManager + .setComponentEnabledSetting(name, state, DONT_KILL_APP) + } + + private fun getApplicationContext(): Context = ApplicationProvider.getApplicationContext() + } } |