• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.Intent;
20 import android.os.Bundle;
21 import android.os.Process;
22 import android.os.UserManager;
23 import android.util.Log;
24 
25 import com.android.bedstead.dpmwrapper.IpcBroadcastReceiver;
26 import com.android.bedstead.dpmwrapper.TestAppSystemServiceFactory;
27 
28 /**
29  * Test activity for {@link android.app.admin.DevicePolicyManager#setApplicationRestrictions}.
30  *
31  * The actual test will set restrictions for this package, and the purpose of this
32  * activity is to retrieve those restrictions and relay them back to the test for validation.
33  */
34 public class ApplicationRestrictionsActivity extends Activity {
35 
36     private static final String TAG = ApplicationRestrictionsActivity.class.getSimpleName();
37 
38     private static final String ACTION_RESTRICTIONS_VALUE =
39             "com.android.cts.apprestrictions.targetapp.RESTRICTIONS_VALUE";
40 
41     private UserManager mUserManager;
42 
43     @Override
onCreate(Bundle savedInstanceState)44     protected void onCreate(Bundle savedInstanceState) {
45         super.onCreate(savedInstanceState);
46 
47         boolean isDeviceOwnerTest = "DeviceOwner".equals(getIntent().getStringExtra("admin_type"));
48         mUserManager = isDeviceOwnerTest
49                 ? TestAppSystemServiceFactory.getUserManager(this, IpcBroadcastReceiver.class)
50                 : getSystemService(UserManager.class);
51         Log.d(TAG, "onCreate(): isDeviceOwnerTest=" + isDeviceOwnerTest + ", um=" + mUserManager);
52 
53         handleIntent(getIntent());
54     }
55 
56     @Override
onNewIntent(Intent intent)57     protected void onNewIntent(Intent intent) {
58         super.onNewIntent(intent);
59         handleIntent(intent);
60     }
61 
handleIntent(Intent intent)62     private void handleIntent(Intent intent) {
63         Bundle restrictions = mUserManager.getApplicationRestrictions(getPackageName());
64         Log.d(TAG, "restrictions on user " + Process.myUid() + " and " + mUserManager + ": "
65                 + restrictions);
66         sendBroadcast(new Intent(ACTION_RESTRICTIONS_VALUE)
67                 .addFlags(Intent.FLAG_RECEIVER_FOREGROUND)
68                 .putExtra("value", restrictions));
69 
70         finish();
71     }
72 }
73