To enable the another package to manage the application restrictions, a bound service is used 33 | * to pass them to {@link AppRestrictionsProxy}. 34 | * 35 | *
From N onwards, a given package can be granted permission to manage application restrictions,
36 | * which removes the need for the proxy code.
37 | */
38 | public class AppRestrictionsProxy extends Service {
39 |
40 | private Messenger mMessenger;
41 |
42 | @Override
43 | public void onCreate() {
44 | mMessenger =
45 | new Messenger(
46 | new AppRestrictionsProxyHandler(this, DeviceAdminReceiver.getComponentName(this)));
47 | }
48 |
49 | @Override
50 | public IBinder onBind(Intent intent) {
51 | return mMessenger.getBinder();
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/com/afwsamples/testdpc/provision/CheckInState.java:
--------------------------------------------------------------------------------
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 |
17 | package com.afwsamples.testdpc.provision;
18 |
19 | import android.content.Context;
20 | import android.content.Intent;
21 | import android.content.SharedPreferences;
22 | import android.preference.PreferenceManager;
23 | import androidx.localbroadcastmanager.content.LocalBroadcastManager;
24 |
25 | public class CheckInState {
26 | private SharedPreferences mSharedPreferences;
27 | private Context mContext;
28 |
29 | public static final int FIRST_ACCOUNT_STATE_PENDING = 0;
30 | public static final int FIRST_ACCOUNT_STATE_READY = 1;
31 | public static final int FIRST_ACCOUNT_STATE_TIMEOUT = 2;
32 |
33 | private static final String KEY_FIRST_ACCOUNT_STATE = "first_account_state";
34 |
35 | /** Broadcast Action: FIRST_ACCOUNT_READY broadcast is processed. */
36 | public static final String FIRST_ACCOUNT_READY_PROCESSED_ACTION =
37 | "com.afwsamples.testdpc.FIRST_ACCOUNT_READY_PROCESSED";
38 |
39 | public CheckInState(Context context) {
40 | mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
41 | mContext = context.getApplicationContext();
42 | }
43 |
44 | public int getFirstAccountState() {
45 | return mSharedPreferences.getInt(KEY_FIRST_ACCOUNT_STATE, FIRST_ACCOUNT_STATE_PENDING);
46 | }
47 |
48 | public void setFirstAccountState(int state) {
49 | mSharedPreferences.edit().putInt(KEY_FIRST_ACCOUNT_STATE, state).apply();
50 | if (state != FIRST_ACCOUNT_STATE_PENDING) {
51 | LocalBroadcastManager.getInstance(mContext)
52 | .sendBroadcast(new Intent(FIRST_ACCOUNT_READY_PROCESSED_ACTION));
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/com/afwsamples/testdpc/provision/ProvisioningSuccessActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 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 |
17 | package com.afwsamples.testdpc.provision;
18 |
19 | import android.app.Activity;
20 | import android.content.Intent;
21 | import android.os.Bundle;
22 | import android.util.Log;
23 | import android.widget.Toast;
24 | import com.afwsamples.testdpc.R;
25 |
26 | /**
27 | * Activity that gets launched by the {@link
28 | * android.app.admin.DevicePolicyManager#ACTION_PROVISIONING_SUCCESSFUL} intent.
29 | */
30 | public class ProvisioningSuccessActivity extends Activity {
31 | private static final String TAG = "ProvisioningSuccess";
32 |
33 | @Override
34 | public void onCreate(Bundle icicle) {
35 | super.onCreate(icicle);
36 |
37 | PostProvisioningTask task = new PostProvisioningTask(this);
38 | if (!task.performPostProvisioningOperations(getIntent())) {
39 | finish();
40 | return;
41 | }
42 |
43 | Intent launchIntent = task.getPostProvisioningLaunchIntent(getIntent());
44 | if (launchIntent != null) {
45 | startActivity(launchIntent);
46 | } else {
47 | Log.e(TAG, "ProvisioningSuccessActivity.onCreate() invoked, but ownership " + "not assigned");
48 | Toast.makeText(this, R.string.device_admin_receiver_failure, Toast.LENGTH_LONG).show();
49 | }
50 | finish();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/com/afwsamples/testdpc/provision/ProvisioningUtil.java:
--------------------------------------------------------------------------------
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 |
17 | package com.afwsamples.testdpc.provision;
18 |
19 | import android.app.admin.DevicePolicyManager;
20 | import android.content.ComponentName;
21 | import android.content.Context;
22 | import com.afwsamples.testdpc.DeviceAdminReceiver;
23 | import com.afwsamples.testdpc.R;
24 | import com.afwsamples.testdpc.common.ReflectionUtil;
25 |
26 | public class ProvisioningUtil {
27 |
28 | public static void enableProfile(Context context) {
29 | DevicePolicyManager manager =
30 | (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
31 | ComponentName componentName = DeviceAdminReceiver.getReceiverComponentName(context);
32 | // This is the name for the newly created managed profile.
33 | manager.setProfileName(componentName, context.getString(R.string.profile_name));
34 | // We enable the profile here.
35 | manager.setProfileEnabled(componentName);
36 | }
37 |
38 | /**
39 | * Helper method used to automatically provision the device, which is useful in demos.
40 | */
41 | public static boolean isAutoProvisioningDeviceOwnerMode() {
42 | String prop = ReflectionUtil.getSystemProperty("dev.tmp.testdpc.auto_provision_mode");
43 | return "do".equals(prop);
44 | }
45 |
46 | private ProvisioningUtil() {
47 | throw new UnsupportedOperationException("provides only static methods");
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/com/afwsamples/testdpc/search/BaseIndexableFragment.java:
--------------------------------------------------------------------------------
1 | package com.afwsamples.testdpc.search;
2 |
3 | import android.content.Context;
4 | import android.util.Log;
5 | import com.afwsamples.testdpc.common.BaseSearchablePolicyPreferenceFragment;
6 | import java.util.List;
7 |
8 | public abstract class BaseIndexableFragment {
9 | private static final String TAG = "BaseIndexableFragment";
10 | protected String fragmentName;
11 |
12 | public BaseIndexableFragment(
13 | Class extends BaseSearchablePolicyPreferenceFragment> fragmentClass) {
14 | this.fragmentName = fragmentClass.getName();
15 | }
16 |
17 | @SuppressWarnings("unchecked")
18 | public boolean isAvailable(Context context) {
19 | try {
20 | @SuppressWarnings("unchecked")
21 | Class To index a newly added fragment, there are only two things needed to be done. Make you
18 | * fragment extends {@link BaseSearchablePolicyPreferenceFragment} and add it to this class.
19 | */
20 | public class IndexableFragments {
21 | private static final List Shutting down this executor is not supported.
25 | */
26 | public class MainThreadExecutor extends LooperExecutor {
27 |
28 | public MainThreadExecutor() {
29 | super(Looper.getMainLooper());
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlesamples/android-testdpc/305c86d36e9b7c85e41e9e01fbf2d648fa4970fb/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/main/res/drawable-hdpi/ic_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlesamples/android-testdpc/305c86d36e9b7c85e41e9e01fbf2d648fa4970fb/src/main/res/drawable-hdpi/ic_search.png
--------------------------------------------------------------------------------
/src/main/res/drawable-hdpi/setup_illustration.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlesamples/android-testdpc/305c86d36e9b7c85e41e9e01fbf2d648fa4970fb/src/main/res/drawable-hdpi/setup_illustration.png
--------------------------------------------------------------------------------
/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlesamples/android-testdpc/305c86d36e9b7c85e41e9e01fbf2d648fa4970fb/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/main/res/drawable-mdpi/ic_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlesamples/android-testdpc/305c86d36e9b7c85e41e9e01fbf2d648fa4970fb/src/main/res/drawable-mdpi/ic_search.png
--------------------------------------------------------------------------------
/src/main/res/drawable-mdpi/setup_illustration.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlesamples/android-testdpc/305c86d36e9b7c85e41e9e01fbf2d648fa4970fb/src/main/res/drawable-mdpi/setup_illustration.png
--------------------------------------------------------------------------------
/src/main/res/drawable-sw600dp-hdpi/setup_illustration.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlesamples/android-testdpc/305c86d36e9b7c85e41e9e01fbf2d648fa4970fb/src/main/res/drawable-sw600dp-hdpi/setup_illustration.png
--------------------------------------------------------------------------------
/src/main/res/drawable-sw600dp-mdpi/setup_illustration.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlesamples/android-testdpc/305c86d36e9b7c85e41e9e01fbf2d648fa4970fb/src/main/res/drawable-sw600dp-mdpi/setup_illustration.png
--------------------------------------------------------------------------------
/src/main/res/drawable-sw600dp-xhdpi/setup_illustration.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlesamples/android-testdpc/305c86d36e9b7c85e41e9e01fbf2d648fa4970fb/src/main/res/drawable-sw600dp-xhdpi/setup_illustration.png
--------------------------------------------------------------------------------
/src/main/res/drawable-sw600dp-xxhdpi/setup_illustration.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlesamples/android-testdpc/305c86d36e9b7c85e41e9e01fbf2d648fa4970fb/src/main/res/drawable-sw600dp-xxhdpi/setup_illustration.png
--------------------------------------------------------------------------------
/src/main/res/drawable-sw600dp-xxxhdpi/setup_illustration.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlesamples/android-testdpc/305c86d36e9b7c85e41e9e01fbf2d648fa4970fb/src/main/res/drawable-sw600dp-xxxhdpi/setup_illustration.png
--------------------------------------------------------------------------------
/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlesamples/android-testdpc/305c86d36e9b7c85e41e9e01fbf2d648fa4970fb/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/main/res/drawable-xhdpi/ic_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlesamples/android-testdpc/305c86d36e9b7c85e41e9e01fbf2d648fa4970fb/src/main/res/drawable-xhdpi/ic_search.png
--------------------------------------------------------------------------------
/src/main/res/drawable-xhdpi/setup_illustration.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlesamples/android-testdpc/305c86d36e9b7c85e41e9e01fbf2d648fa4970fb/src/main/res/drawable-xhdpi/setup_illustration.png
--------------------------------------------------------------------------------
/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlesamples/android-testdpc/305c86d36e9b7c85e41e9e01fbf2d648fa4970fb/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/main/res/drawable-xxhdpi/ic_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlesamples/android-testdpc/305c86d36e9b7c85e41e9e01fbf2d648fa4970fb/src/main/res/drawable-xxhdpi/ic_search.png
--------------------------------------------------------------------------------
/src/main/res/drawable-xxhdpi/setup_illustration.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlesamples/android-testdpc/305c86d36e9b7c85e41e9e01fbf2d648fa4970fb/src/main/res/drawable-xxhdpi/setup_illustration.png
--------------------------------------------------------------------------------
/src/main/res/drawable-xxxhdpi/setup_illustration.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlesamples/android-testdpc/305c86d36e9b7c85e41e9e01fbf2d648fa4970fb/src/main/res/drawable-xxxhdpi/setup_illustration.png
--------------------------------------------------------------------------------
/src/main/res/drawable/arrow_down.xml:
--------------------------------------------------------------------------------
1 | TestDPC company
2 | This is TestDPC company disclaimer.
3 |
4 |
--------------------------------------------------------------------------------
/src/main/res/raw/emm_disclaimer.txt:
--------------------------------------------------------------------------------
1 | TestDPC EMM
2 | This is TestDPC EMM disclaimer.
3 |
4 |
--------------------------------------------------------------------------------
/src/main/res/values-sw600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |