Change the "Blocked by IT admin" to use family related dialog for children.
Test: manual Change-Id: I066415d79ad364aebcf64f678b0b7b1908364e7b
This commit is contained in:
@@ -22,6 +22,7 @@ import static com.android.settingslib.enterprise.ActionDisabledLearnMoreButtonLa
|
||||
import static com.android.settingslib.enterprise.ManagedDeviceActionDisabledByAdminController.DEFAULT_FOREGROUND_USER_CHECKER;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.hardware.biometrics.BiometricAuthenticator;
|
||||
import android.hardware.biometrics.ParentalControlsUtilsInternal;
|
||||
@@ -45,6 +46,8 @@ public final class ActionDisabledByAdminControllerFactory {
|
||||
return new BiometricActionDisabledByAdminController(stringProvider);
|
||||
} else if (isFinancedDevice(context)) {
|
||||
return new FinancedDeviceActionDisabledByAdminController(stringProvider);
|
||||
} else if (isSupervisedDevice(context)) {
|
||||
return new SupervisedDeviceActionDisabledByAdminController(stringProvider, restriction);
|
||||
} else {
|
||||
return new ManagedDeviceActionDisabledByAdminController(
|
||||
stringProvider,
|
||||
@@ -54,6 +57,15 @@ public final class ActionDisabledByAdminControllerFactory {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isSupervisedDevice(Context context) {
|
||||
DevicePolicyManager devicePolicyManager =
|
||||
context.getSystemService(DevicePolicyManager.class);
|
||||
ComponentName supervisionComponent =
|
||||
devicePolicyManager.getProfileOwnerOrDeviceOwnerSupervisionComponent(
|
||||
new UserHandle(UserHandle.myUserId()));
|
||||
return supervisionComponent != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the restriction == UserManager.DISALLOW_BIOMETRIC and parental consent
|
||||
* is required.
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.annotation.NonNull;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -60,6 +61,10 @@ public class BiometricActionDisabledByAdminController extends BaseActionDisabled
|
||||
final Intent intent = new Intent(Settings.ACTION_MANAGE_SUPERVISOR_RESTRICTED_SETTING)
|
||||
.putExtra(Settings.EXTRA_SUPERVISOR_RESTRICTED_SETTING_KEY,
|
||||
Settings.SUPERVISOR_VERIFICATION_SETTING_BIOMETRICS)
|
||||
.setData(new Uri.Builder()
|
||||
.scheme("policy")
|
||||
.appendPath("biometric")
|
||||
.build())
|
||||
.setPackage(enforcedAdmin.component.getPackageName());
|
||||
context.startActivity(intent);
|
||||
};
|
||||
|
||||
@@ -78,6 +78,11 @@ public interface DeviceAdminStringProvider {
|
||||
*/
|
||||
String getDisabledBiometricsParentConsentTitle();
|
||||
|
||||
/**
|
||||
* Returns the dialog title when the setting is blocked by supervision app.
|
||||
*/
|
||||
String getDisabledByParentContent();
|
||||
|
||||
/**
|
||||
* Returns the dialog contents for when biometrics require parental consent.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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.settingslib.enterprise;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
final class SupervisedDeviceActionDisabledByAdminController
|
||||
extends BaseActionDisabledByAdminController {
|
||||
private static final String TAG = "SupervisedDeviceActionDisabledByAdminController";
|
||||
private final String mRestriction;
|
||||
|
||||
SupervisedDeviceActionDisabledByAdminController(
|
||||
DeviceAdminStringProvider stringProvider, String restriction) {
|
||||
super(stringProvider);
|
||||
mRestriction = restriction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupLearnMoreButton(Context context) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAdminSupportTitle(@Nullable String restriction) {
|
||||
return mStringProvider.getDisabledBiometricsParentConsentTitle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getAdminSupportContentString(Context context,
|
||||
@Nullable CharSequence supportMessage) {
|
||||
return mStringProvider.getDisabledByParentContent();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public DialogInterface.OnClickListener getPositiveButtonListener(Context context,
|
||||
RestrictedLockUtils.EnforcedAdmin enforcedAdmin) {
|
||||
final Intent intent = new Intent(Settings.ACTION_MANAGE_SUPERVISOR_RESTRICTED_SETTING)
|
||||
.setData(new Uri.Builder()
|
||||
.scheme("policy")
|
||||
.appendPath("user_restrictions")
|
||||
.appendPath(mRestriction)
|
||||
.build())
|
||||
.setPackage(enforcedAdmin.component.getPackageName());
|
||||
ComponentName resolvedSupervisionActivity =
|
||||
intent.resolveActivity(context.getPackageManager());
|
||||
if (resolvedSupervisionActivity == null) {
|
||||
return null;
|
||||
}
|
||||
return (dialog, which) -> {
|
||||
Log.d(TAG, "Positive button clicked, component: " + enforcedAdmin.component);
|
||||
context.startActivity(intent);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ class FakeDeviceAdminStringProvider implements DeviceAdminStringProvider {
|
||||
"default_disabled_by_policy_title_financed_device";
|
||||
static final String DEFAULT_BIOMETRIC_TITLE = "biometric_title";
|
||||
static final String DEFAULT_BIOMETRIC_CONTENTS = "biometric_contents";
|
||||
static final String DISABLED_BY_PARENT_CONTENT = "disabled_by_parent_constent";
|
||||
static final DeviceAdminStringProvider DEFAULT_DEVICE_ADMIN_STRING_PROVIDER =
|
||||
new FakeDeviceAdminStringProvider(/* url = */ null);
|
||||
|
||||
@@ -96,6 +97,11 @@ class FakeDeviceAdminStringProvider implements DeviceAdminStringProvider {
|
||||
return DEFAULT_BIOMETRIC_TITLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisabledByParentContent() {
|
||||
return DISABLED_BY_PARENT_CONTENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisabledBiometricsParentConsentContent() {
|
||||
return DEFAULT_BIOMETRIC_CONTENTS;
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.settingslib.enterprise;
|
||||
|
||||
import static com.android.settingslib.enterprise.ActionDisabledByAdminControllerTestUtils.ADMIN_COMPONENT;
|
||||
import static com.android.settingslib.enterprise.ActionDisabledByAdminControllerTestUtils.ENFORCED_ADMIN;
|
||||
import static com.android.settingslib.enterprise.ActionDisabledByAdminControllerTestUtils.ENFORCEMENT_ADMIN_USER_ID;
|
||||
import static com.android.settingslib.enterprise.FakeDeviceAdminStringProvider.DEFAULT_DEVICE_ADMIN_STRING_PROVIDER;
|
||||
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.shadows.ShadowResolveInfo;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class SupervisedDeviceActionDisabledByAdminControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private ActionDisabledByAdminControllerTestUtils mTestUtils;
|
||||
private SupervisedDeviceActionDisabledByAdminController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = Robolectric.buildActivity(Activity.class).setup().get();
|
||||
|
||||
mTestUtils = new ActionDisabledByAdminControllerTestUtils();
|
||||
|
||||
mController = new SupervisedDeviceActionDisabledByAdminController(
|
||||
DEFAULT_DEVICE_ADMIN_STRING_PROVIDER, UserManager.DISALLOW_ADD_USER);
|
||||
mController.initialize(mTestUtils.createLearnMoreButtonLauncher());
|
||||
mController.updateEnforcedAdmin(ENFORCED_ADMIN, ENFORCEMENT_ADMIN_USER_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buttonClicked() {
|
||||
Uri restrictionUri = Uri.parse("policy:/user_restrictions/no_add_user");
|
||||
Intent intent = new Intent(Settings.ACTION_MANAGE_SUPERVISOR_RESTRICTED_SETTING)
|
||||
.setData(restrictionUri)
|
||||
.setPackage(ADMIN_COMPONENT.getPackageName());
|
||||
ResolveInfo resolveInfo = ShadowResolveInfo.newResolveInfo("Admin Activity",
|
||||
ADMIN_COMPONENT.getPackageName(), "InfoActivity");
|
||||
shadowOf(mContext.getPackageManager()).addResolveInfoForIntent(intent, resolveInfo);
|
||||
|
||||
DialogInterface.OnClickListener listener =
|
||||
mController.getPositiveButtonListener(mContext, ENFORCED_ADMIN);
|
||||
assertNotNull("Supervision controller must supply a non-null listener", listener);
|
||||
listener.onClick(mock(DialogInterface.class), 0 /* which */);
|
||||
|
||||
Intent nextIntent = shadowOf(RuntimeEnvironment.application).getNextStartedActivity();
|
||||
assertEquals(Settings.ACTION_MANAGE_SUPERVISOR_RESTRICTED_SETTING,
|
||||
nextIntent.getAction());
|
||||
assertEquals(restrictionUri, nextIntent.getData());
|
||||
assertEquals(ADMIN_COMPONENT.getPackageName(), nextIntent.getPackage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noButton() {
|
||||
// No supervisor restricted setting Activity
|
||||
DialogInterface.OnClickListener listener =
|
||||
mController.getPositiveButtonListener(mContext, ENFORCED_ADMIN);
|
||||
assertNull("Supervision controller generates null listener", listener);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user