diff --git a/res/values/strings.xml b/res/values/strings.xml index 3785b21224f..b81f7a3369c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -12227,9 +12227,6 @@ Data usage charges may apply. - - - Update Do Not Disturb diff --git a/src/com/android/settings/security/ActionDisabledByAdvancedProtectionDialog.kt b/src/com/android/settings/security/ActionDisabledByAdvancedProtectionDialog.kt index 0c96473b6d4..1d70823f49f 100644 --- a/src/com/android/settings/security/ActionDisabledByAdvancedProtectionDialog.kt +++ b/src/com/android/settings/security/ActionDisabledByAdvancedProtectionDialog.kt @@ -14,21 +14,23 @@ * limitations under the License. */ -package com.android.settings.security; +package com.android.settings.security import android.content.Intent +import android.content.pm.PackageManager +import android.security.advancedprotection.AdvancedProtectionManager import android.security.advancedprotection.AdvancedProtectionManager.EXTRA_SUPPORT_DIALOG_FEATURE import android.security.advancedprotection.AdvancedProtectionManager.EXTRA_SUPPORT_DIALOG_TYPE import android.security.advancedprotection.AdvancedProtectionManager.FEATURE_ID_DISALLOW_CELLULAR_2G import android.security.advancedprotection.AdvancedProtectionManager.FEATURE_ID_DISALLOW_INSTALL_UNKNOWN_SOURCES import android.security.advancedprotection.AdvancedProtectionManager.FEATURE_ID_DISALLOW_WEP -import android.content.pm.PackageManager import android.security.advancedprotection.AdvancedProtectionManager.FEATURE_ID_ENABLE_MTE import android.security.advancedprotection.AdvancedProtectionManager.SUPPORT_DIALOG_TYPE_BLOCKED_INTERACTION import android.security.advancedprotection.AdvancedProtectionManager.SUPPORT_DIALOG_TYPE_DISABLED_SETTING import android.security.advancedprotection.AdvancedProtectionManager.SUPPORT_DIALOG_TYPE_UNKNOWN import android.util.Log import android.view.WindowManager +import androidx.annotation.VisibleForTesting import androidx.compose.material3.Icon import androidx.compose.material3.Text import androidx.compose.runtime.Composable @@ -38,7 +40,6 @@ import com.android.settingslib.spa.SpaDialogWindowTypeActivity import com.android.settingslib.spa.widget.dialog.AlertDialogButton import com.android.settingslib.spa.widget.dialog.SettingsAlertDialogContent import com.android.settingslib.wifi.WifiUtils.Companion.DIALOG_WINDOW_TYPE -import android.security.advancedprotection.AdvancedProtectionManager class ActionDisabledByAdvancedProtectionDialog : SpaDialogWindowTypeActivity() { @@ -85,9 +86,12 @@ class ActionDisabledByAdvancedProtectionDialog : SpaDialogWindowTypeActivity() { return getString(messageId) } - private fun getSupportButtonIfExists(): AlertDialogButton? { + @VisibleForTesting + fun getSupportButtonIfExists(): AlertDialogButton? { try { - val helpIntentUri = getString(R.string.help_url_action_disabled_by_advanced_protection) + val helpIntentUri = getString( + com.android.internal.R.string.config_help_url_action_disabled_by_advanced_protection + ) val helpIntent = Intent.parseUri(helpIntentUri, Intent.URI_INTENT_SCHEME) if (helpIntent == null) return null val helpActivityInfo = packageManager.resolveActivity(helpIntent, /* flags */ 0) diff --git a/tests/spa_unit/AndroidManifest.xml b/tests/spa_unit/AndroidManifest.xml index 1950f209868..d225a03061a 100644 --- a/tests/spa_unit/AndroidManifest.xml +++ b/tests/spa_unit/AndroidManifest.xml @@ -30,6 +30,14 @@ + + + + + + + () + + private val context: Context = ApplicationProvider.getApplicationContext() @Test fun blockedInteractionDialog_showsCorrectTitleAndMessage() { @@ -159,6 +178,85 @@ class ActionDisabledByAdvancedProtectionDialogTest { } } + @Test + fun helpIntentDoesNotExist_getSupportButtonIfExists_returnsNull() { + launchDialogActivity(defaultIntent) { scenario -> + scenario.onActivity { activity -> + val spyActivity = spyOnActivityHelpIntentUri(activity, /* uriToReturn */ null) + + val button = spyActivity.getSupportButtonIfExists() + assertNull(button) + } + } + } + + @Test + fun helpIntentExistsAndDoesNotResolveToActivity_getSupportButtonIfExists_returnsNull() { + launchDialogActivity(defaultIntent) { scenario -> + scenario.onActivity { activity -> + val spyActivity = spyOnActivityHelpIntentUri(activity, helpIntentUri) + mockResolveActivity(spyActivity, /* resolveInfoToReturn */ null) + + val button = spyActivity.getSupportButtonIfExists() + assertNull(button) + } + } + } + + @Test + fun helpIntentExistsAndResolvesToActivity_getSupportButtonIfExists_returnsButton() { + launchDialogActivity(defaultIntent) { scenario -> + scenario.onActivity { activity -> + val spyActivity = spyOnActivityHelpIntentUri(activity, helpIntentUri) + val resolveInfoToReturn = ResolveInfo().apply { + activityInfo = ActivityInfo().apply { + packageName = HELP_INTENT_PKG_NAME + } + } + mockResolveActivity(spyActivity, resolveInfoToReturn) + + // 1. Check the button is returned. + val button = spyActivity.getSupportButtonIfExists() + assertNotNull(button) + + // 2. Check the button has correct text. + assertEquals(context.getString( + R.string.disabled_by_advanced_protection_help_button_title), button!!.text + ) + + // 3. Check the button's onClick launches the help activity and finishes the dialog. + button.onClick() + + val intentCaptor = ArgumentCaptor.forClass(Intent::class.java) + verify(spyActivity).startActivity(intentCaptor.capture()) + val launchedIntent = intentCaptor.value + assertEquals(HELP_INTENT_ACTION, launchedIntent.action) + assertEquals(HELP_INTENT_PKG_NAME, launchedIntent.`package`) + + assertTrue(spyActivity.isFinishing) + } + } + } + + private fun spyOnActivityHelpIntentUri( + activity: ActionDisabledByAdvancedProtectionDialog, + uriToReturn: String? + ): ActionDisabledByAdvancedProtectionDialog { + val spyActivity = spy(activity) + val spyResources = spy(spyActivity.resources) + doReturn(spyResources).whenever(spyActivity).resources + doReturn(uriToReturn).whenever(spyResources).getString(helpUriResourceId) + return spyActivity + } + + private fun mockResolveActivity( + spyActivity: ActionDisabledByAdvancedProtectionDialog, + resolveInfoToReturn: ResolveInfo? + ) { + doReturn(mockPackageManager).whenever(spyActivity).packageManager + doReturn(resolveInfoToReturn).whenever(mockPackageManager).resolveActivity(any(), anyInt()) + } + private fun launchDialogActivity( intent: Intent, onScenario: (ActivityScenario) -> Unit @@ -172,10 +270,23 @@ class ActionDisabledByAdvancedProtectionDialogTest { launch(intent).use(onScenario) } + class HelpTestActivity : Activity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + finish() + } + } + private companion object { val defaultIntent = AdvancedProtectionManager.createSupportIntent( FEATURE_ID_DISALLOW_CELLULAR_2G, SUPPORT_DIALOG_TYPE_BLOCKED_INTERACTION ) + const val HELP_INTENT_PKG_NAME = "com.android.settings.tests.spa_unit" + const val HELP_INTENT_ACTION = "$HELP_INTENT_PKG_NAME.HELP_ACTION" + val helpIntent = Intent(HELP_INTENT_ACTION).setPackage(HELP_INTENT_PKG_NAME) + val helpIntentUri = helpIntent.toUri(Intent.URI_INTENT_SCHEME) + val helpUriResourceId = + com.android.internal.R.string.config_help_url_action_disabled_by_advanced_protection } }