/* * Copyright (C) 2015 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.server.pm; import static com.android.server.devicepolicy.DpmTestUtils.assertRestrictions; import static com.android.server.devicepolicy.DpmTestUtils.newRestrictions; import android.os.Bundle; import android.os.UserManager; import android.platform.test.annotations.Presubmit; import android.test.AndroidTestCase; import android.util.SparseArray; import androidx.test.filters.SmallTest; /** * Tests for {@link com.android.server.pm.UserRestrictionsUtils}. * *
Run with:
m FrameworksServicesTests && adb install \ -r out/target/product/hammerhead/data/app/FrameworksServicesTests/FrameworksServicesTests.apk && adb shell am instrument -e class com.android.server.pm.UserRestrictionsUtilsTest \ -w com.android.frameworks.servicestests/androidx.test.runner.AndroidJUnitRunner **/ @Presubmit @SmallTest public class UserRestrictionsUtilsTest extends AndroidTestCase { public void testNonNull() { Bundle out = UserRestrictionsUtils.nonNull(null); assertNotNull(out); out.putBoolean("a", true); // Should not be Bundle.EMPTY. Bundle in = new Bundle(); assertSame(in, UserRestrictionsUtils.nonNull(in)); } public void testMerge() { Bundle a = newRestrictions("a", "d"); Bundle b = newRestrictions("b", "d", "e"); UserRestrictionsUtils.merge(a, b); assertRestrictions(newRestrictions("a", "b", "d", "e"), a); UserRestrictionsUtils.merge(a, null); assertRestrictions(newRestrictions("a", "b", "d", "e"), a); try { UserRestrictionsUtils.merge(a, a); fail(); } catch (IllegalArgumentException expected) { } } public void testCanDeviceOwnerChange() { assertFalse(UserRestrictionsUtils.canDeviceOwnerChange(UserManager.DISALLOW_RECORD_AUDIO)); assertFalse(UserRestrictionsUtils.canDeviceOwnerChange(UserManager.DISALLOW_WALLPAPER)); assertTrue(UserRestrictionsUtils.canDeviceOwnerChange(UserManager.DISALLOW_ADD_USER)); assertTrue(UserRestrictionsUtils.canDeviceOwnerChange(UserManager.DISALLOW_USER_SWITCH)); } public void testCanProfileOwnerChange_mainUser() { assertFalse(UserRestrictionsUtils.canProfileOwnerChange( UserManager.DISALLOW_RECORD_AUDIO, true)); assertFalse(UserRestrictionsUtils.canProfileOwnerChange( UserManager.DISALLOW_WALLPAPER, true)); assertFalse(UserRestrictionsUtils.canProfileOwnerChange( UserManager.DISALLOW_USER_SWITCH, true)); assertTrue(UserRestrictionsUtils.canProfileOwnerChange( UserManager.DISALLOW_ADD_USER, true)); assertTrue(UserRestrictionsUtils.canProfileOwnerChange( UserManager.DISALLOW_ADJUST_VOLUME, true)); } public void testCanProfileOwnerChange_notMainUser() { assertFalse(UserRestrictionsUtils.canProfileOwnerChange( UserManager.DISALLOW_RECORD_AUDIO, false)); assertFalse(UserRestrictionsUtils.canProfileOwnerChange( UserManager.DISALLOW_WALLPAPER, false)); assertFalse(UserRestrictionsUtils.canProfileOwnerChange( UserManager.DISALLOW_ADD_USER, false)); assertFalse(UserRestrictionsUtils.canProfileOwnerChange( UserManager.DISALLOW_USER_SWITCH, false)); assertTrue(UserRestrictionsUtils.canProfileOwnerChange( UserManager.DISALLOW_ADJUST_VOLUME, false)); } public void testMoveRestriction() { SparseArray