1*d353a188SXin Li 2*d353a188SXin LiAndroid AppRestrictionSchema Sample 3*d353a188SXin Li=================================== 4*d353a188SXin Li 5*d353a188SXin LiA basic app showing how to allow a device administrator to restrict user 6*d353a188SXin Liactivities using the Android Device Administration API. The app exports 7*d353a188SXin Lia custom policy that enables or disables a UI control. Device Administration 8*d353a188SXin Liapplications are able to enforce a specific value for this policy, as 9*d353a188SXin Lidirected by enterprise administrators. 10*d353a188SXin Li 11*d353a188SXin LiIntroduction 12*d353a188SXin Li------------ 13*d353a188SXin Li 14*d353a188SXin LiThe [Android Device Administration API][1] allows enterprise administrators to 15*d353a188SXin Lienforce specific policies on a managed device. The system provides policies 16*d353a188SXin Lithat control settings such as password complexity, screen lock, or camera 17*d353a188SXin Liavailability. Developers can also augment this list with custom policies 18*d353a188SXin Lithat control specific features within their applications. For example, 19*d353a188SXin Lia web browser could provide access to a whitelist of allowed domains. 20*d353a188SXin Li 21*d353a188SXin LiThe list of policies exposed by an app must be specified using a file 22*d353a188SXin Liinside of the `res/xml` directory, using the `<restriction>` tag: 23*d353a188SXin Li 24*d353a188SXin Li```xml 25*d353a188SXin Li<restrictions xmlns:android="http://schemas.android.com/apk/res/android"> 26*d353a188SXin Li 27*d353a188SXin Li <restriction 28*d353a188SXin Li android:defaultValue="false" 29*d353a188SXin Li android:description="@string/description_can_say_hello" 30*d353a188SXin Li android:key="can_say_hello" 31*d353a188SXin Li android:restrictionType="bool" 32*d353a188SXin Li android:title="@string/title_can_say_hello" /> 33*d353a188SXin Li 34*d353a188SXin Li</restrictions> 35*d353a188SXin Li``` 36*d353a188SXin Li 37*d353a188SXin LiIn this sample, that file can be found at 38*d353a188SXin Li`Application/src/main/res/xml/app_restrictions.xml`. This file must be 39*d353a188SXin Lialso be declared inside of `ApplicationManifest.xml` using a `<meta-data>` 40*d353a188SXin Lielement: 41*d353a188SXin Li 42*d353a188SXin Li```xml 43*d353a188SXin Li<meta-data 44*d353a188SXin Li android:name="android.content.APP_RESTRICTIONS" 45*d353a188SXin Li android:resource="@xml/app_restrictions" /> 46*d353a188SXin Li``` 47*d353a188SXin Li 48*d353a188SXin LiAt runtime, the current list of restrictions enforced by policy can be 49*d353a188SXin Lichecked by calling [RestrictionsManager.getApplicationRestrictions()][2]. 50*d353a188SXin Li 51*d353a188SXin Li[1]: http://developer.android.com/guide/topics/admin/device-admin.html 52*d353a188SXin Li[2]: https://developer.android.com/reference/android/content/RestrictionsManager.html#getApplicationRestrictions() 53*d353a188SXin Li 54*d353a188SXin LiPre-requisites 55*d353a188SXin Li-------------- 56*d353a188SXin Li 57*d353a188SXin Li- Android SDK 27 58*d353a188SXin Li- Android Build Tools v27.0.2 59*d353a188SXin Li- Android Support Repository 60*d353a188SXin Li 61*d353a188SXin LiScreenshots 62*d353a188SXin Li------------- 63*d353a188SXin Li 64*d353a188SXin Li<img src="screenshots/main.png" height="400" alt="Screenshot"/> 65*d353a188SXin Li 66*d353a188SXin LiGetting Started 67*d353a188SXin Li--------------- 68*d353a188SXin Li 69*d353a188SXin LiThis sample uses the Gradle build system. To build this project, use the 70*d353a188SXin Li"gradlew build" command or use "Import Project" in Android Studio. 71*d353a188SXin Li 72*d353a188SXin LiSupport 73*d353a188SXin Li------- 74*d353a188SXin Li 75*d353a188SXin Li- Google+ Community: https://plus.google.com/communities/105153134372062985968 76*d353a188SXin Li- Stack Overflow: http://stackoverflow.com/questions/tagged/android 77*d353a188SXin Li 78*d353a188SXin LiIf you've found an error in this sample, please file an issue: 79*d353a188SXin Lihttps://github.com/googlesamples/android-AppRestrictionSchema 80*d353a188SXin Li 81*d353a188SXin LiPatches are encouraged, and may be submitted by forking this project and 82*d353a188SXin Lisubmitting a pull request through GitHub. Please see CONTRIBUTING.md for more details. 83*d353a188SXin Li 84*d353a188SXin LiLicense 85*d353a188SXin Li------- 86*d353a188SXin Li 87*d353a188SXin LiCopyright 2017 The Android Open Source Project, Inc. 88*d353a188SXin Li 89*d353a188SXin LiLicensed to the Apache Software Foundation (ASF) under one or more contributor 90*d353a188SXin Lilicense agreements. See the NOTICE file distributed with this work for 91*d353a188SXin Liadditional information regarding copyright ownership. The ASF licenses this 92*d353a188SXin Lifile to you under the Apache License, Version 2.0 (the "License"); you may not 93*d353a188SXin Liuse this file except in compliance with the License. You may obtain a copy of 94*d353a188SXin Lithe License at 95*d353a188SXin Li 96*d353a188SXin Lihttp://www.apache.org/licenses/LICENSE-2.0 97*d353a188SXin Li 98*d353a188SXin LiUnless required by applicable law or agreed to in writing, software 99*d353a188SXin Lidistributed under the License is distributed on an "AS IS" BASIS, WITHOUT 100*d353a188SXin LiWARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 101*d353a188SXin LiLicense for the specific language governing permissions and limitations under 102*d353a188SXin Lithe License. 103