1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.cts.apprestrictions.targetapp;
17 
18 import android.app.Activity;
19 import android.content.Context;
20 import android.content.Intent;
21 import android.os.Bundle;
22 import android.os.UserManager;
23 
24 /**
25  * Test activity for {@link android.app.admin.DevicePolicyManager#setApplicationRestrictions}.
26  *
27  * The actual test will set restrictions for this package, and the purpose of this
28  * activity is to retrieve those restrictions and relay them back to the test for validation.
29  */
30 public class ApplicationRestrictionsActivity extends Activity {
31 
32     private static final String ACTION_RESTRICTIONS_VALUE =
33             "com.android.cts.apprestrictions.targetapp.RESTRICTIONS_VALUE";
34 
35     private UserManager mUserManager;
36 
37     @Override
onCreate(Bundle savedInstanceState)38     protected void onCreate(Bundle savedInstanceState) {
39         super.onCreate(savedInstanceState);
40 
41         mUserManager = (UserManager) getSystemService(Context.USER_SERVICE);
42         handleIntent(getIntent());
43     }
44 
45     @Override
onNewIntent(Intent intent)46     protected void onNewIntent(Intent intent) {
47         super.onNewIntent(intent);
48         handleIntent(intent);
49     }
50 
handleIntent(Intent intent)51     private void handleIntent(Intent intent) {
52         Bundle restrictions = mUserManager.getApplicationRestrictions(getPackageName());
53         sendBroadcast(new Intent(ACTION_RESTRICTIONS_VALUE)
54                 .addFlags(Intent.FLAG_RECEIVER_FOREGROUND)
55                 .putExtra("value", restrictions));
56 
57         finish();
58     }
59 }
60