Merge "Update ActionDisabledByAdvancedProtectionDialog" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
07f9680835
@@ -4553,7 +4553,7 @@
|
|||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name=".security.ActionDisabledByAdvancedProtectionDialog"
|
<activity android:name=".security.ActionDisabledByAdvancedProtectionDialog"
|
||||||
android:theme="@style/Theme.AlertDialog"
|
android:theme="@style/Theme.SpaLib.Dialog"
|
||||||
android:taskAffinity="com.android.settings.security"
|
android:taskAffinity="com.android.settings.security"
|
||||||
android:excludeFromRecents="true"
|
android:excludeFromRecents="true"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
|
@@ -10892,9 +10892,17 @@ Data usage charges may apply.</string>
|
|||||||
associated with this device, manage apps, and change this device\’s settings.</string>
|
associated with this device, manage apps, and change this device\’s settings.</string>
|
||||||
|
|
||||||
<!-- Title for dialog displayed when user taps a setting on their phone that's blocked by Advanced Protection. [CHAR LIMIT=50] -->
|
<!-- Title for dialog displayed when user taps a setting on their phone that's blocked by Advanced Protection. [CHAR LIMIT=50] -->
|
||||||
<string name="disabled_by_advanced_protection_title">Prevented by Advanced Protection</string>
|
<string name="disabled_by_advanced_protection_title">Restricted by Advanced Protection</string>
|
||||||
<!-- Short summary for dialog displayed when user taps a setting on their phone that's blocked by Advanced Protection. [CHAR LIMIT=NONE] -->
|
<!-- Short summary for dialog displayed when user taps an enabled setting on their phone that's blocked by Advanced Protection. [CHAR LIMIT=NONE] -->
|
||||||
<string name="disabled_by_advanced_protection_message">This action is not allowed because Advanced Protection is on for your device.</string>
|
<string name="disabled_by_advanced_protection_setting_is_on_message">For your security, Advanced Protection requires this setting to remain on</string>
|
||||||
|
<!-- Short summary for dialog displayed when user taps a disabled setting on their phone that's blocked by Advanced Protection. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="disabled_by_advanced_protection_setting_is_off_message">For your security, Advanced Protection requires this setting to remain off</string>
|
||||||
|
<!-- Short summary for dialog displayed when user performs an action on their phone that's blocked by Advanced Protection. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="disabled_by_advanced_protection_action_message">For your security, Advanced Protection prevents this action</string>
|
||||||
|
<!-- Short summary for dialog displayed when user tries to connect to a Wi-Fi Wired Equivalent Privacy (WEP) network on their phone that's blocked by Advanced Protection. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="disabled_by_advanced_protection_wep_action_message">This network uses WEP, an outdated encryption method that can put your data at risk. WEP connections are blocked by Advanced Protection.</string>
|
||||||
|
<!-- Title for a button that will resolve to a help URL explaining what Advanced Protection is. [CHAR LIMIT=50] -->
|
||||||
|
<string name="disabled_by_advanced_protection_help_button_title">Settings</string>
|
||||||
|
|
||||||
<!-- Turn off a conditional state of the device (e.g. airplane mode, or hotspot) [CHAR LIMIT=30] -->
|
<!-- Turn off a conditional state of the device (e.g. airplane mode, or hotspot) [CHAR LIMIT=30] -->
|
||||||
<string name="condition_turn_off">Turn off</string>
|
<string name="condition_turn_off">Turn off</string>
|
||||||
|
@@ -16,44 +16,99 @@
|
|||||||
|
|
||||||
package com.android.settings.security;
|
package com.android.settings.security;
|
||||||
|
|
||||||
import android.app.Activity
|
import android.content.Intent
|
||||||
import android.content.DialogInterface
|
import android.security.advancedprotection.AdvancedProtectionManager.EXTRA_SUPPORT_DIALOG_FEATURE
|
||||||
import android.os.Bundle
|
import android.security.advancedprotection.AdvancedProtectionManager.EXTRA_SUPPORT_DIALOG_TYPE
|
||||||
import android.view.View
|
import android.security.advancedprotection.AdvancedProtectionManager.FEATURE_ID_DISALLOW_CELLULAR_2G
|
||||||
import android.view.ViewGroup
|
import android.security.advancedprotection.AdvancedProtectionManager.FEATURE_ID_DISALLOW_INSTALL_UNKNOWN_SOURCES
|
||||||
import android.widget.TextView
|
import android.security.advancedprotection.AdvancedProtectionManager.FEATURE_ID_DISALLOW_WEP
|
||||||
|
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.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
import com.android.settings.R
|
import com.android.settings.R
|
||||||
|
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 androidx.appcompat.app.AlertDialog;
|
class ActionDisabledByAdvancedProtectionDialog : SpaDialogWindowTypeActivity() {
|
||||||
|
|
||||||
class ActionDisabledByAdvancedProtectionDialog : Activity(), DialogInterface.OnDismissListener {
|
@Composable
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun Content() {
|
||||||
super.onCreate(savedInstanceState)
|
SettingsAlertDialogContent(
|
||||||
val dialogView = layoutInflater.inflate(R.layout.support_details_dialog, null) as ViewGroup
|
confirmButton = AlertDialogButton(getString(R.string.okay)) { finish() },
|
||||||
val builder = AlertDialog.Builder(this)
|
dismissButton = getSupportButtonIfExists(),
|
||||||
.setPositiveButton(R.string.okay, null)
|
title = getString(R.string.disabled_by_advanced_protection_title),
|
||||||
.setView(dialogView)
|
icon = {
|
||||||
.setOnDismissListener(this)
|
Icon(
|
||||||
initializeDialogView(dialogView)
|
painter = painterResource(R.drawable.ic_settings_safety_center),
|
||||||
builder.show()
|
contentDescription = null
|
||||||
|
)
|
||||||
|
},
|
||||||
|
text = { Text(getDialogMessage()) })
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDismiss(dialog: DialogInterface) {
|
private fun getDialogMessage(): String {
|
||||||
|
val featureId = intent.getIntExtra(EXTRA_SUPPORT_DIALOG_FEATURE, -1)
|
||||||
|
val type = intent.getIntExtra(EXTRA_SUPPORT_DIALOG_TYPE, SUPPORT_DIALOG_TYPE_UNKNOWN)
|
||||||
|
val messageId = when (type) {
|
||||||
|
SUPPORT_DIALOG_TYPE_DISABLED_SETTING -> {
|
||||||
|
if (featureIdsWithSettingOn.contains(featureId)) {
|
||||||
|
R.string.disabled_by_advanced_protection_setting_is_on_message
|
||||||
|
} else if (featureIdsWithSettingOff.contains(featureId)) {
|
||||||
|
R.string.disabled_by_advanced_protection_setting_is_off_message
|
||||||
|
} else {
|
||||||
|
defaultMessageId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SUPPORT_DIALOG_TYPE_BLOCKED_INTERACTION -> {
|
||||||
|
if (featureId == FEATURE_ID_DISALLOW_WEP) {
|
||||||
|
R.string.disabled_by_advanced_protection_wep_action_message
|
||||||
|
} else {
|
||||||
|
R.string.disabled_by_advanced_protection_action_message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> defaultMessageId
|
||||||
|
}
|
||||||
|
return getString(messageId)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getSupportButtonIfExists(): AlertDialogButton? {
|
||||||
|
try {
|
||||||
|
val helpIntentUri = getString(R.string.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)
|
||||||
|
?.activityInfo
|
||||||
|
if (helpActivityInfo == null) return null
|
||||||
|
return AlertDialogButton(
|
||||||
|
getString(R.string.disabled_by_advanced_protection_help_button_title)
|
||||||
|
) {
|
||||||
|
startActivity(helpIntent)
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
private fun initializeDialogView(dialogView: View) {
|
Log.w(TAG, "Tried to set up help button, but this exception was thrown: ${e.message}")
|
||||||
setSupportTitle(dialogView)
|
}
|
||||||
setSupportDetails(dialogView)
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setSupportTitle(root: View) {
|
override fun getDialogWindowType(): Int? = if (intent.hasExtra(DIALOG_WINDOW_TYPE)) {
|
||||||
val titleView: TextView = root.findViewById(R.id.admin_support_dialog_title) ?: return
|
intent.getIntExtra(DIALOG_WINDOW_TYPE, WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW)
|
||||||
titleView.setText(R.string.disabled_by_advanced_protection_title)
|
} else null
|
||||||
}
|
|
||||||
|
|
||||||
private fun setSupportDetails(root: View) {
|
private companion object {
|
||||||
val textView: TextView = root.findViewById(R.id.admin_support_msg)
|
const val TAG = "AdvancedProtectionDlg"
|
||||||
textView.setText(R.string.disabled_by_advanced_protection_message)
|
val defaultMessageId = R.string.disabled_by_advanced_protection_action_message
|
||||||
|
val featureIdsWithSettingOn = setOf(FEATURE_ID_DISALLOW_CELLULAR_2G, FEATURE_ID_ENABLE_MTE)
|
||||||
|
val featureIdsWithSettingOff =
|
||||||
|
setOf(FEATURE_ID_DISALLOW_WEP, FEATURE_ID_DISALLOW_INSTALL_UNKNOWN_SOURCES)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,181 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2025 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.settings.security
|
||||||
|
|
||||||
|
import android.content.ComponentName
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.platform.test.annotations.RequiresFlagsEnabled
|
||||||
|
import android.platform.test.flag.junit.CheckFlagsRule
|
||||||
|
import android.platform.test.flag.junit.DeviceFlagsValueProvider
|
||||||
|
import android.security.Flags
|
||||||
|
import android.security.advancedprotection.AdvancedProtectionManager
|
||||||
|
import android.security.advancedprotection.AdvancedProtectionManager.FEATURE_ID_DISALLOW_CELLULAR_2G
|
||||||
|
import android.security.advancedprotection.AdvancedProtectionManager.FEATURE_ID_DISALLOW_WEP
|
||||||
|
import android.security.advancedprotection.AdvancedProtectionManager.SUPPORT_DIALOG_TYPE_BLOCKED_INTERACTION
|
||||||
|
import android.security.advancedprotection.AdvancedProtectionManager.SUPPORT_DIALOG_TYPE_DISABLED_SETTING
|
||||||
|
import androidx.compose.ui.test.assertIsDisplayed
|
||||||
|
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
||||||
|
import androidx.compose.ui.test.onNodeWithText
|
||||||
|
import androidx.test.core.app.ActivityScenario
|
||||||
|
import androidx.test.core.app.ActivityScenario.launch
|
||||||
|
import androidx.test.core.app.ApplicationProvider
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
|
import com.android.settings.R
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
|
||||||
|
@RequiresFlagsEnabled(Flags.FLAG_AAPM_API)
|
||||||
|
@RunWith(AndroidJUnit4::class)
|
||||||
|
class ActionDisabledByAdvancedProtectionDialogTest {
|
||||||
|
@get:Rule
|
||||||
|
val composeTestRule = createAndroidComposeRule<ActionDisabledByAdvancedProtectionDialog>()
|
||||||
|
|
||||||
|
@get:Rule
|
||||||
|
val checkFlagsRule: CheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule()
|
||||||
|
|
||||||
|
val context: Context = ApplicationProvider.getApplicationContext()
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun blockedInteractionDialog_showsCorrectTitleAndMessage() {
|
||||||
|
val intent = AdvancedProtectionManager.createSupportIntent(
|
||||||
|
FEATURE_ID_DISALLOW_CELLULAR_2G,
|
||||||
|
SUPPORT_DIALOG_TYPE_BLOCKED_INTERACTION
|
||||||
|
)
|
||||||
|
|
||||||
|
launchDialogActivity(intent) {
|
||||||
|
composeTestRule
|
||||||
|
.onNodeWithText(context.getString(R.string.disabled_by_advanced_protection_title))
|
||||||
|
.assertIsDisplayed()
|
||||||
|
composeTestRule
|
||||||
|
.onNodeWithText(context.getString(
|
||||||
|
R.string.disabled_by_advanced_protection_action_message))
|
||||||
|
.assertIsDisplayed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun wepBlockedInteraction_showsCorrectTitleAndMessage() {
|
||||||
|
val intent = AdvancedProtectionManager.createSupportIntent(
|
||||||
|
FEATURE_ID_DISALLOW_WEP,
|
||||||
|
SUPPORT_DIALOG_TYPE_BLOCKED_INTERACTION
|
||||||
|
)
|
||||||
|
|
||||||
|
launchDialogActivity(intent) {
|
||||||
|
composeTestRule
|
||||||
|
.onNodeWithText(context.getString(R.string.disabled_by_advanced_protection_title))
|
||||||
|
.assertIsDisplayed()
|
||||||
|
composeTestRule
|
||||||
|
.onNodeWithText(context.getString(
|
||||||
|
R.string.disabled_by_advanced_protection_wep_action_message))
|
||||||
|
.assertIsDisplayed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun disabled2gSettingDialog_showsCorrectTitleAndMessage() {
|
||||||
|
val intent = AdvancedProtectionManager.createSupportIntent(
|
||||||
|
FEATURE_ID_DISALLOW_CELLULAR_2G,
|
||||||
|
SUPPORT_DIALOG_TYPE_DISABLED_SETTING
|
||||||
|
)
|
||||||
|
|
||||||
|
launchDialogActivity(intent) {
|
||||||
|
composeTestRule
|
||||||
|
.onNodeWithText(context.getString(R.string.disabled_by_advanced_protection_title))
|
||||||
|
.assertIsDisplayed()
|
||||||
|
composeTestRule
|
||||||
|
.onNodeWithText(context.getString(
|
||||||
|
R.string.disabled_by_advanced_protection_setting_is_on_message))
|
||||||
|
.assertIsDisplayed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun disabledMteSettingDialog_showsCorrectTitleAndMessage() {
|
||||||
|
val intent = AdvancedProtectionManager.createSupportIntent(
|
||||||
|
AdvancedProtectionManager.FEATURE_ID_ENABLE_MTE,
|
||||||
|
SUPPORT_DIALOG_TYPE_DISABLED_SETTING
|
||||||
|
)
|
||||||
|
|
||||||
|
launchDialogActivity(intent) {
|
||||||
|
composeTestRule
|
||||||
|
.onNodeWithText(context.getString(R.string.disabled_by_advanced_protection_title))
|
||||||
|
.assertIsDisplayed()
|
||||||
|
composeTestRule
|
||||||
|
.onNodeWithText(context.getString(
|
||||||
|
R.string.disabled_by_advanced_protection_setting_is_on_message))
|
||||||
|
.assertIsDisplayed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun disabledWepSettingDialog_showsCorrectTitleAndMessage() {
|
||||||
|
val intent = AdvancedProtectionManager.createSupportIntent(
|
||||||
|
FEATURE_ID_DISALLOW_WEP,
|
||||||
|
SUPPORT_DIALOG_TYPE_DISABLED_SETTING
|
||||||
|
)
|
||||||
|
|
||||||
|
launchDialogActivity(intent) {
|
||||||
|
composeTestRule
|
||||||
|
.onNodeWithText(context.getString(R.string.disabled_by_advanced_protection_title))
|
||||||
|
.assertIsDisplayed()
|
||||||
|
composeTestRule
|
||||||
|
.onNodeWithText(context.getString(
|
||||||
|
R.string.disabled_by_advanced_protection_setting_is_off_message))
|
||||||
|
.assertIsDisplayed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun disabledInstallUnknownSourcesSettingDialog_showsCorrectTitleAndMessage() {
|
||||||
|
val intent = AdvancedProtectionManager.createSupportIntent(
|
||||||
|
AdvancedProtectionManager.FEATURE_ID_DISALLOW_INSTALL_UNKNOWN_SOURCES,
|
||||||
|
SUPPORT_DIALOG_TYPE_DISABLED_SETTING
|
||||||
|
)
|
||||||
|
|
||||||
|
launchDialogActivity(intent) {
|
||||||
|
composeTestRule
|
||||||
|
.onNodeWithText(context.getString(R.string.disabled_by_advanced_protection_title))
|
||||||
|
.assertIsDisplayed()
|
||||||
|
composeTestRule
|
||||||
|
.onNodeWithText(context.getString(
|
||||||
|
R.string.disabled_by_advanced_protection_setting_is_off_message))
|
||||||
|
.assertIsDisplayed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun launchDialogActivity(
|
||||||
|
intent: Intent,
|
||||||
|
onScenario: (ActivityScenario<ActionDisabledByAdvancedProtectionDialog>) -> Unit
|
||||||
|
) {
|
||||||
|
intent.setComponent(
|
||||||
|
ComponentName(
|
||||||
|
context,
|
||||||
|
ActionDisabledByAdvancedProtectionDialog::class.java
|
||||||
|
)
|
||||||
|
)
|
||||||
|
launch<ActionDisabledByAdvancedProtectionDialog>(intent).use(onScenario)
|
||||||
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
val defaultIntent = AdvancedProtectionManager.createSupportIntent(
|
||||||
|
FEATURE_ID_DISALLOW_CELLULAR_2G,
|
||||||
|
SUPPORT_DIALOG_TYPE_BLOCKED_INTERACTION
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user