diff options
| author | Fyodor Kupolov <fkupolov@google.com> | 2015-03-23 18:55:11 -0700 |
|---|---|---|
| committer | Fyodor Kupolov <fkupolov@google.com> | 2015-03-30 17:59:07 -0700 |
| commit | 262f9952e6e78e00a6d42bab97d73dccfb9607f4 (patch) | |
| tree | 6509c3b8d0a43086080794c4d1238a62aab18158 /core/tests | |
| parent | 607f1f09c3da3a52557394d2e764326a29151173 (diff) | |
| download | frameworks_base-262f9952e6e78e00a6d42bab97d73dccfb9607f4.zip frameworks_base-262f9952e6e78e00a6d42bab97d73dccfb9607f4.tar.gz frameworks_base-262f9952e6e78e00a6d42bab97d73dccfb9607f4.tar.bz2 | |
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
Diffstat (limited to 'core/tests')
4 files changed, 139 insertions, 0 deletions
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 @@ <application android:theme="@style/Theme"> <uses-library android:name="android.test.runner" /> <uses-library android:name="org.apache.http.legacy" android:required="false" /> + <meta-data + android:name="android.content.APP_RESTRICTIONS" + android:resource="@xml/app_restrictions" /> <activity android:name="android.view.ViewAttachTestActivity" android:label="View Attach Test"> <intent-filter> <action android:name="android.intent.action.MAIN" /> 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 @@ <string name="first">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.</string> <string name="actor">Abe Lincoln</string> <string name="caption">Lincoln adressing the crowd at Gettysburgh</string> + + <!-- RestrictionsManagerTest --> + <string name="restrictionManager_title">Title</string> + <string name="restrictionManager_desc">Description</string> </resources> 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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. +--> + +<restrictions xmlns:android="http://schemas.android.com/apk/res/android"> + <restriction android:key="hidden_key" + android:restrictionType="hidden"/> + <restriction + android:defaultValue="true" + android:description="@string/restrictionManager_desc" + android:key="bool_key" + android:restrictionType="bool" + android:title="@string/restrictionManager_title"/> + <restriction + android:defaultValue="test" + android:key="string_key" + android:restrictionType="string"/> + + <restriction android:key="int_key" + android:restrictionType="integer" + android:defaultValue="15"/> + <restriction android:key="bundle_key" + android:restrictionType="bundle"> + <restriction + android:key="bundle_string_key" + android:restrictionType="string"/> + <restriction + android:defaultValue="true" + android:key="bundle_bool_key" + android:restrictionType="bool"/> + + </restriction> + <restriction android:key="bundle_array_key" + android:restrictionType="bundle_array"> + <restriction android:key="bundle_array_int" + android:restrictionType="integer"/> + <restriction android:key="bundle_array_bundle_key" + android:restrictionType="bundle"> + <restriction android:key="bundle_array_bundle_int_key" + android:restrictionType="integer"/> + </restriction> + </restriction> +</restrictions>
\ 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<RestrictionEntry> manifestRestrictions = mRm.getManifestRestrictions(packageName); + assertEquals(6, manifestRestrictions.size()); + Set<String> 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<RestrictionEntry> 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); + } + +} |
