Merge "Revert "[AAPM] Add advanced protection dialog according to API f..."" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
47d59ab974
@@ -4460,19 +4460,6 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".security.ActionDisabledByAdvancedProtectionDialog"
|
||||
android:theme="@style/Theme.AlertDialog"
|
||||
android:taskAffinity="com.android.settings.security"
|
||||
android:excludeFromRecents="true"
|
||||
android:exported="false"
|
||||
android:launchMode="singleTop"
|
||||
android:featureFlag="android.security.aapm_api">
|
||||
<intent-filter android:priority="1">
|
||||
<action android:name="android.security.advancedprotection.action.SHOW_ADVANCED_PROTECTION_SUPPORT_DIALOG" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="Settings$ManageExternalStorageActivity"
|
||||
android:knownActivityEmbeddingCerts="@array/config_known_host_certs"
|
||||
|
@@ -10696,11 +10696,6 @@
|
||||
<string name="admin_financed_message">Your device administrator may be able to access data
|
||||
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] -->
|
||||
<string name="disabled_by_advanced_protection_title">Prevented 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] -->
|
||||
<string name="disabled_by_advanced_protection_message">This action is not allowed because Advanced Protection is on for your device.</string>
|
||||
|
||||
<!-- 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>
|
||||
|
||||
|
@@ -109,9 +109,12 @@ public class ActionDisabledByAdminDialog extends Activity
|
||||
}
|
||||
if (enforcingAdmin.getAuthority() instanceof UnknownAuthority authority
|
||||
&& ADVANCED_PROTECTION_SYSTEM_ENTITY.equals(authority.getName())) {
|
||||
Intent apmSupportIntent = AdvancedProtectionManager
|
||||
.createSupportIntentForPolicyIdentifierOrRestriction(restriction,
|
||||
AdvancedProtectionManager.SUPPORT_DIALOG_TYPE_UNKNOWN);
|
||||
AdvancedProtectionManager apm = getSystemService(AdvancedProtectionManager.class);
|
||||
if (apm == null) {
|
||||
return;
|
||||
}
|
||||
Intent apmSupportIntent = apm.createSupportIntentForPolicyIdentifierOrRestriction(
|
||||
restriction, /* type */ null);
|
||||
startActivityAsUser(apmSupportIntent, UserHandle.of(userId));
|
||||
finish();
|
||||
} else {
|
||||
|
@@ -1,59 +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.settings.security;
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.DialogInterface
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import com.android.settings.R
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
class ActionDisabledByAdvancedProtectionDialog : Activity(), DialogInterface.OnDismissListener {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val dialogView = layoutInflater.inflate(R.layout.support_details_dialog, null) as ViewGroup
|
||||
val builder = AlertDialog.Builder(this)
|
||||
.setPositiveButton(R.string.okay, null)
|
||||
.setView(dialogView)
|
||||
.setOnDismissListener(this)
|
||||
initializeDialogView(dialogView)
|
||||
builder.show()
|
||||
}
|
||||
|
||||
override fun onDismiss(dialog: DialogInterface) {
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun initializeDialogView(dialogView: View) {
|
||||
setSupportTitle(dialogView)
|
||||
setSupportDetails(dialogView)
|
||||
}
|
||||
|
||||
private fun setSupportTitle(root: View) {
|
||||
val titleView: TextView = root.findViewById(R.id.admin_support_dialog_title) ?: return
|
||||
titleView.setText(R.string.disabled_by_advanced_protection_title)
|
||||
}
|
||||
|
||||
private fun setSupportDetails(root: View) {
|
||||
val textView: TextView = root.findViewById(R.id.admin_support_msg)
|
||||
textView.setText(R.string.disabled_by_advanced_protection_message)
|
||||
}
|
||||
}
|
@@ -162,10 +162,10 @@ class WepNetworksPreferenceController(context: Context, preferenceKey: String) :
|
||||
emit(aapmManager?.isAdvancedProtectionEnabled ?: false) }.flowOn(Dispatchers.Default)
|
||||
|
||||
private fun startSupportIntent() {
|
||||
AdvancedProtectionManager.createSupportIntent(
|
||||
aapmManager?.createSupportIntent(
|
||||
AdvancedProtectionManager.FEATURE_ID_DISALLOW_WEP,
|
||||
AdvancedProtectionManager.SUPPORT_DIALOG_TYPE_DISABLED_SETTING
|
||||
).let { mContext.startActivity(it) }
|
||||
)?.let { mContext.startActivity(it) }
|
||||
}
|
||||
|
||||
val wepAllowedFlow =
|
||||
|
@@ -20,14 +20,9 @@ import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
|
||||
import static android.security.advancedprotection.AdvancedProtectionManager.ACTION_SHOW_ADVANCED_PROTECTION_SUPPORT_DIALOG;
|
||||
import static android.security.advancedprotection.AdvancedProtectionManager.ADVANCED_PROTECTION_SYSTEM_ENTITY;
|
||||
import static android.security.advancedprotection.AdvancedProtectionManager.EXTRA_SUPPORT_DIALOG_FEATURE;
|
||||
import static android.security.advancedprotection.AdvancedProtectionManager.EXTRA_SUPPORT_DIALOG_TYPE;
|
||||
import static android.security.advancedprotection.AdvancedProtectionManager.FEATURE_ID_DISALLOW_INSTALL_UNKNOWN_SOURCES;
|
||||
import static android.security.advancedprotection.AdvancedProtectionManager.SUPPORT_DIALOG_TYPE_UNKNOWN;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -45,6 +40,7 @@ import android.os.UserManager;
|
||||
import android.platform.test.annotations.RequiresFlagsEnabled;
|
||||
import android.platform.test.flag.junit.CheckFlagsRule;
|
||||
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
||||
import android.security.advancedprotection.AdvancedProtectionManager;
|
||||
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
|
||||
@@ -52,7 +48,6 @@ import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
@@ -64,6 +59,8 @@ public class ActionDisabledByAdminDialogTest {
|
||||
|
||||
@Mock
|
||||
private DevicePolicyManager mDevicePolicyManager;
|
||||
@Mock
|
||||
private AdvancedProtectionManager mAdvancedProtectionManager;
|
||||
|
||||
private ActionDisabledByAdminDialog mDialog;
|
||||
private final ComponentName mAdminComponent = new ComponentName("admin", "adminclass");
|
||||
@@ -73,6 +70,8 @@ public class ActionDisabledByAdminDialogTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mDialog = spy(new ActionDisabledByAdminDialog());
|
||||
doReturn(mDevicePolicyManager).when(mDialog).getSystemService(DevicePolicyManager.class);
|
||||
doReturn(mAdvancedProtectionManager).when(mDialog).getSystemService(
|
||||
AdvancedProtectionManager.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -119,28 +118,24 @@ public class ActionDisabledByAdminDialogTest {
|
||||
advancedProtectionAuthority, UserHandle.of(userId), mAdminComponent);
|
||||
final String userRestriction = UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY;
|
||||
|
||||
final Intent apmIntent = new Intent(ACTION_SHOW_ADVANCED_PROTECTION_SUPPORT_DIALOG);
|
||||
apmIntent.setFlags(FLAG_ACTIVITY_NEW_TASK);
|
||||
apmIntent.putExtra(EXTRA_SUPPORT_DIALOG_FEATURE, "featureId");
|
||||
|
||||
final Intent dialogIntent = new Intent();
|
||||
dialogIntent.putExtra(Intent.EXTRA_USER_ID, userId);
|
||||
dialogIntent.putExtra(DevicePolicyManager.EXTRA_RESTRICTION, userRestriction);
|
||||
|
||||
when(mDevicePolicyManager.getEnforcingAdmin(userId, userRestriction))
|
||||
.thenReturn(advancedProtectionEnforcingAdmin);
|
||||
doNothing().when(mDialog).startActivityAsUser(any(), eq(UserHandle.of(userId)));
|
||||
when(mAdvancedProtectionManager.createSupportIntentForPolicyIdentifierOrRestriction(
|
||||
userRestriction, /* type */ null)).thenReturn(apmIntent);
|
||||
doNothing().when(mDialog).startActivityAsUser(apmIntent, UserHandle.of(userId));
|
||||
|
||||
mDialog.getAdminDetailsFromIntent(dialogIntent);
|
||||
|
||||
ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mDialog).startActivityAsUser(intentCaptor.capture(), eq(UserHandle.of(userId)));
|
||||
verify(mDialog).startActivityAsUser(apmIntent, UserHandle.of(userId));
|
||||
assertTrue(mDialog.isFinishing());
|
||||
|
||||
Intent launchedIntent = intentCaptor.getValue();
|
||||
assertEquals("Intent action is incorrect", ACTION_SHOW_ADVANCED_PROTECTION_SUPPORT_DIALOG,
|
||||
launchedIntent.getAction());
|
||||
assertEquals("Feature ID extra is incorrect", FEATURE_ID_DISALLOW_INSTALL_UNKNOWN_SOURCES,
|
||||
launchedIntent.getIntExtra(EXTRA_SUPPORT_DIALOG_FEATURE, -1));
|
||||
assertEquals("Type is incorrect", SUPPORT_DIALOG_TYPE_UNKNOWN,
|
||||
launchedIntent.getIntExtra(EXTRA_SUPPORT_DIALOG_TYPE, -1));
|
||||
assertEquals(FLAG_ACTIVITY_NEW_TASK, launchedIntent.getFlags());
|
||||
}
|
||||
|
||||
@RequiresFlagsEnabled(android.security.Flags.FLAG_AAPM_API)
|
||||
|
@@ -200,6 +200,7 @@ class WepNetworksPreferenceControllerTest {
|
||||
fun whenClick_aapmEnabled_openDialog() {
|
||||
mockAapmManager.stub {
|
||||
on { isAdvancedProtectionEnabled } doReturn true
|
||||
on { createSupportIntent(any(), any()) } doReturn Intent()
|
||||
}
|
||||
doNothing().whenever(context).startActivity(any())
|
||||
composeTestRule.setContent { controller.Content() }
|
||||
|
Reference in New Issue
Block a user