Skip to content

Commit cd876c9

Browse files
author
Sudheer Shanka
committed
Add support for setting auto time required policy.
Change-Id: I1d6b2e417fec9b6c221bf7458e9d4490812e933a
1 parent 78f2d56 commit cd876c9

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

app/src/main/java/com/afwsamples/testdpc/policy/PolicyManagementFragment.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ public class PolicyManagementFragment extends PreferenceFragment implements
224224
private static final String REMOVE_DEVICE_OWNER_KEY = "remove_device_owner";
225225
private static final String REMOVE_USER_KEY = "remove_user";
226226
private static final String SET_ACCESSIBILITY_SERVICES_KEY = "set_accessibility_services";
227+
private static final String SET_AUTO_TIME_REQUIRED_KEY = "set_auto_time_required";
227228
private static final String SET_DISABLE_ACCOUNT_MANAGEMENT_KEY
228229
= "set_disable_account_management";
229230
private static final String SET_INPUT_METHODS_KEY = "set_input_methods";
@@ -257,7 +258,7 @@ public class PolicyManagementFragment extends PreferenceFragment implements
257258
STOP_LOCK_TASK, DISABLE_STATUS_BAR, REENABLE_STATUS_BAR, DISABLE_KEYGUARD,
258259
REENABLE_KEYGUARD, START_KIOSK_MODE, SYSTEM_UPDATE_POLICY_KEY, KEYGUARD_DISABLE_WIDGETS,
259260
KEYGUARD_DISABLE_SECURE_CAMERA, KEYGUARD_DISABLE_SECURE_NOTIFICATIONS,
260-
STAY_ON_WHILE_PLUGGED_IN
261+
SET_AUTO_TIME_REQUIRED_KEY, STAY_ON_WHILE_PLUGGED_IN
261262
};
262263

263264
private static String[] MNC_PLUS_PREFERENCES = {
@@ -315,6 +316,8 @@ public class PolicyManagementFragment extends PreferenceFragment implements
315316
private SwitchPreference mStayOnWhilePluggedInSwitchPreference;
316317
private SwitchPreference mInstallNonMarketAppsPreference;
317318

319+
private SwitchPreference mSetAutoTimeRequiredPreference;
320+
318321
private GetAccessibilityServicesTask mGetAccessibilityServicesTask = null;
319322
private GetInputMethodsTask mGetInputMethodsTask = null;
320323
private ShowCaCertificateListTask mShowCaCertificateListTask = null;
@@ -402,9 +405,13 @@ public void onCreate(Bundle savedInstanceState) {
402405
INSTALL_NONMARKET_APPS_KEY);
403406
mInstallNonMarketAppsPreference.setOnPreferenceChangeListener(this);
404407
findPreference(SET_USER_RESTRICTIONS_KEY).setOnPreferenceClickListener(this);
408+
mSetAutoTimeRequiredPreference = (SwitchPreference) findPreference(
409+
SET_AUTO_TIME_REQUIRED_KEY);
410+
mSetAutoTimeRequiredPreference.setOnPreferenceChangeListener(this);
405411

406412
reloadCameraDisableUi();
407413
reloadScreenCaptureDisableUi();
414+
reloadSetAutoTimeRequiredUi();
408415

409416
setPreferenceChangeListeners(KEYGUARD_DISABLE_PREFERENCES);
410417
updateKeyguardFeaturesUi();
@@ -659,6 +666,11 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
659666
newValue.equals(true) ? "1" : "0");
660667
updateInstallNonMarketAppsPreference();
661668
return true;
669+
case SET_AUTO_TIME_REQUIRED_KEY:
670+
mDevicePolicyManager.setAutoTimeRequired(mAdminComponentName,
671+
newValue.equals(true));
672+
reloadSetAutoTimeRequiredUi();
673+
return true;
662674
}
663675
return false;
664676
}
@@ -1211,6 +1223,13 @@ private void reloadScreenCaptureDisableUi() {
12111223
mDisableScreenCaptureSwitchPreference.setChecked(isScreenCaptureDisabled);
12121224
}
12131225

1226+
private void reloadSetAutoTimeRequiredUi() {
1227+
if (mDevicePolicyManager.isDeviceOwnerApp(mPackageName)) {
1228+
boolean isAutoTimeRequired = mDevicePolicyManager.getAutoTimeRequired();
1229+
mSetAutoTimeRequiredPreference.setChecked(isAutoTimeRequired);
1230+
}
1231+
}
1232+
12141233
/**
12151234
* Shows a prompt to ask for package name which is used to enable a system app.
12161235
*/

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
<string name="this_is_a_managed_profile_owner">This app is a managed profile owner.
7171
Some of the management options are not available.</string>
7272
<string name="device_owner_management">Device owner management</string>
73+
<string name="set_auto_time_required">Set auto (network) time required</string>
7374
<string name="wipe_data">Wipe data</string>
7475
<string name="wipe_data_title">Wipe data?</string>
7576
<string name="wipe_data_confirmation">Are you sure you want to wipe the data?</string>

app/src/main/res/xml/device_policy_header.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@
265265

266266
<PreferenceCategory
267267
android:title="@string/device_owner_management">
268+
<SwitchPreference
269+
android:key="set_auto_time_required"
270+
android:title="@string/set_auto_time_required" />
268271
<Preference
269272
android:key="wipe_data"
270273
android:title="@string/wipe_data"/>

0 commit comments

Comments
 (0)