From 262f9952e6e78e00a6d42bab97d73dccfb9607f4 Mon Sep 17 00:00:00 2001 From: Fyodor Kupolov Date: Mon, 23 Mar 2015 18:55:11 -0700 Subject: Support for nested bundles in setApplicationRestrictions Added new restriction types - bundle and bundle-array. Modified RestrictionsManager.getManifestRestrictions to support new hierarchical restrictions. Added RestrictionsManager.convertRestrictionsToBundle, which enables programmatic conversion from a list of RestrictionEntries to a Bundle. Modified read/write methods for application restrictions in UserManagerService. Added unit tests. Bug: 19540606 Change-Id: I32b264e04d5d177ea5b4c39a8ace5ee0ce907970 --- core/tests/coretests/AndroidManifest.xml | 3 + core/tests/coretests/res/values/strings.xml | 4 ++ core/tests/coretests/res/xml/app_restrictions.xml | 55 ++++++++++++++++ .../android/content/RestrictionsManagerTest.java | 77 ++++++++++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 core/tests/coretests/res/xml/app_restrictions.xml create mode 100644 core/tests/coretests/src/android/content/RestrictionsManagerTest.java (limited to 'core/tests') diff --git a/core/tests/coretests/AndroidManifest.xml b/core/tests/coretests/AndroidManifest.xml index bfaea8f..b07d338 100644 --- a/core/tests/coretests/AndroidManifest.xml +++ b/core/tests/coretests/AndroidManifest.xml @@ -113,6 +113,9 @@ + diff --git a/core/tests/coretests/res/values/strings.xml b/core/tests/coretests/res/values/strings.xml index ce0d9a2..04b0478 100644 --- a/core/tests/coretests/res/values/strings.xml +++ b/core/tests/coretests/res/values/strings.xml @@ -135,4 +135,8 @@ Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal. Abe Lincoln Lincoln adressing the crowd at Gettysburgh + + + Title + Description diff --git a/core/tests/coretests/res/xml/app_restrictions.xml b/core/tests/coretests/res/xml/app_restrictions.xml new file mode 100644 index 0000000..c84cabc --- /dev/null +++ b/core/tests/coretests/res/xml/app_restrictions.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/tests/coretests/src/android/content/RestrictionsManagerTest.java b/core/tests/coretests/src/android/content/RestrictionsManagerTest.java new file mode 100644 index 0000000..8921924 --- /dev/null +++ b/core/tests/coretests/src/android/content/RestrictionsManagerTest.java @@ -0,0 +1,77 @@ +/* + * 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 android.content; + +import android.os.Bundle; +import android.os.Parcelable; +import android.test.AndroidTestCase; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class RestrictionsManagerTest extends AndroidTestCase { + private RestrictionsManager mRm; + + @Override + protected void setUp() throws Exception { + super.setUp(); + mRm = (RestrictionsManager) mContext.getSystemService(Context.RESTRICTIONS_SERVICE); + } + + public void testGetManifestRestrictions() { + String packageName = getContext().getPackageName(); + List manifestRestrictions = mRm.getManifestRestrictions(packageName); + assertEquals(6, manifestRestrictions.size()); + Set verifiedKeys = new HashSet<>(Arrays.asList("bundle_key", "bundle_array_key", + "bundle_array_bundle_key")); + for (RestrictionEntry entry : manifestRestrictions) { + if ("bundle_key".equals(entry.getKey())) { + assertEquals("bundle_key entry should have 2 children entries", + 2, entry.getRestrictions().length); + verifiedKeys.remove(entry.getKey()); + } else if ("bundle_array_key".equals(entry.getKey())) { + assertEquals("bundle_array_key should have 2 children entries", + 2, entry.getRestrictions().length); + assertNotNull(entry.getRestrictions()); + for (RestrictionEntry childEntry : entry.getRestrictions()) { + if ("bundle_array_bundle_key".equals(childEntry.getKey())) { + assertNotNull(childEntry.getRestrictions()); + assertEquals("bundle_array_bundle_key should have 1 child entry", + 1, childEntry.getRestrictions().length); + verifiedKeys.remove(childEntry.getKey()); + } + } + verifiedKeys.remove(entry.getKey()); + } + } + assertTrue("Entries" + verifiedKeys + " were not found", verifiedKeys.isEmpty()); + } + + public void testConvertRestrictionsToBundle() { + String packageName = getContext().getPackageName(); + List manifestRestrictions = mRm.getManifestRestrictions(packageName); + Bundle bundle = RestrictionsManager.convertRestrictionsToBundle(manifestRestrictions); + assertEquals(6, bundle.size()); + Bundle childBundle = bundle.getBundle("bundle_key"); + assertNotNull(childBundle); + assertEquals(2, childBundle.size()); + Parcelable[] childBundleArray = bundle.getParcelableArray("bundle_array_key"); + assertEquals(2, childBundleArray.length); + } + +} -- cgit v1.1