@@ -359,7 +359,6 @@ public class PolicyManagementFragment extends BaseSearchablePolicyPreferenceFrag
359
359
private static final String SYSTEM_UPDATE_POLICY_KEY = "system_update_policy" ;
360
360
private static final String SYSTEM_UPDATE_PENDING_KEY = "system_update_pending" ;
361
361
private static final String TEST_KEY_USABILITY_KEY = "test_key_usability" ;
362
-
363
362
private static final String UNHIDE_APPS_KEY = "unhide_apps" ;
364
363
private static final String UNSUSPEND_APPS_KEY = "unsuspend_apps" ;
365
364
private static final String CLEAR_APP_DATA_KEY = "clear_app_data" ;
@@ -382,27 +381,20 @@ public class PolicyManagementFragment extends BaseSearchablePolicyPreferenceFrag
382
381
private static final String SET_PROFILE_PARENT_NEW_PASSWORD = "set_profile_parent_new_password" ;
383
382
private static final String BIND_DEVICE_ADMIN_POLICIES = "bind_device_admin_policies" ;
384
383
private static final String CROSS_PROFILE_APPS = "cross_profile_apps" ;
385
-
386
384
private static final String SET_SCREEN_BRIGHTNESS_KEY = "set_screen_brightness" ;
387
385
private static final String AUTO_BRIGHTNESS_KEY = "auto_brightness" ;
388
386
private static final String CROSS_PROFILE_CALENDAR_KEY = "cross_profile_calendar" ;
389
387
private static final String SET_SCREEN_OFF_TIMEOUT_KEY = "set_screen_off_timeout" ;
390
-
391
388
private static final String SET_TIME_KEY = "set_time" ;
392
389
private static final String SET_TIME_ZONE_KEY = "set_time_zone" ;
393
-
394
390
private static final String SET_PROFILE_NAME_KEY = "set_profile_name" ;
395
-
396
391
private static final String MANAGE_OVERRIDE_APN_KEY = "manage_override_apn" ;
397
-
398
392
private static final String MANAGED_SYSTEM_UPDATES_KEY = "managed_system_updates" ;
399
-
400
393
private static final String SET_PRIVATE_DNS_MODE_KEY = "set_private_dns_mode" ;
401
-
402
394
private static final String FACTORY_RESET_ORG_OWNED_DEVICE = "factory_reset_org_owned_device" ;
403
-
404
395
private static final String SET_LOCATION_ENABLED_KEY = "set_location_enabled" ;
405
396
private static final String SET_LOCATION_MODE_KEY = "set_location_mode" ;
397
+ private static final String SUSPEND_PERSONAL_APPS_KEY = "suspend_personal_apps" ;
406
398
407
399
private static final String BATTERY_PLUGGED_ANY = Integer .toString (
408
400
BatteryManager .BATTERY_PLUGGED_AC |
@@ -485,6 +477,7 @@ public class PolicyManagementFragment extends BaseSearchablePolicyPreferenceFrag
485
477
private DpcSwitchPreference mSetLocationModePreference ;
486
478
487
479
private DpcPreference mUserRestrictionsParentPreference ;
480
+ private DpcSwitchPreference mSuspendPersonalApps ;
488
481
489
482
private GetAccessibilityServicesTask mGetAccessibilityServicesTask = null ;
490
483
private GetInputMethodsTask mGetInputMethodsTask = null ;
@@ -736,6 +729,10 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
736
729
mSetLocationModePreference = (DpcSwitchPreference ) findPreference (SET_LOCATION_MODE_KEY );
737
730
mSetLocationModePreference .setOnPreferenceChangeListener (this );
738
731
732
+ mSuspendPersonalApps = (DpcSwitchPreference ) findPreference (SUSPEND_PERSONAL_APPS_KEY );
733
+ mSuspendPersonalApps .setOnPreferenceChangeListener (this );
734
+ mSuspendPersonalApps .setCustomConstraint (
735
+ this ::validateProfileOwnerOfOrganizationOwnedDevice );
739
736
740
737
onCreateSetNewPasswordWithComplexityPreference ();
741
738
constrainSpecialCasePreferences ();
@@ -756,6 +753,40 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
756
753
reloadSetAutoTimeZoneUi ();
757
754
reloadEnableLogoutUi ();
758
755
reloadAutoBrightnessUi ();
756
+ reloadPersonalAppsSuspendedUi ();
757
+ }
758
+
759
+ @ TargetApi (Util .R_VERSION_CODE )
760
+ private void reloadPersonalAppsSuspendedUi () {
761
+ // TODO: nuke it when R sdk is available
762
+ final int PERSONAL_APPS_NOT_SUSPENDED = 0 ;
763
+ if (mSuspendPersonalApps .isEnabled ()) {
764
+ int suspendReasons = getPersonalAppsSuspensionReasons ();
765
+ mSuspendPersonalApps .setChecked (suspendReasons != 0 );
766
+ }
767
+ }
768
+
769
+ // TODO: nuke it when R sdk is available.
770
+ int getPersonalAppsSuspensionReasons () {
771
+ try {
772
+ return (Integer ) ReflectionUtil .invoke (mDevicePolicyManager ,
773
+ "getPersonalAppsSuspendedReasons" , new Class <?>[]{ComponentName .class },
774
+ mAdminComponentName );
775
+ } catch (ReflectionIsTemporaryException e ) {
776
+ Log .e (TAG , "Error invoking getPersonalAppsSuspendedReasons" , e );
777
+ return 0 ;
778
+ }
779
+ }
780
+
781
+ // TODO: nuke it when R sdk is available.
782
+ void setPersonalAppsSuspended (boolean suspended ) {
783
+ try {
784
+ ReflectionUtil .invoke (mDevicePolicyManager , "setPersonalAppsSuspended" ,
785
+ new Class <?>[]{ComponentName .class , boolean .class },
786
+ mAdminComponentName , suspended );
787
+ } catch (ReflectionIsTemporaryException e ) {
788
+ Log .e (TAG , "Error invoking setPersonalAppsSuspended" , e );
789
+ }
759
790
}
760
791
761
792
private void onCreateSetNewPasswordWithComplexityPreference () {
@@ -1453,6 +1484,10 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
1453
1484
reloadLocationEnabledUi ();
1454
1485
reloadLocationModeUi ();
1455
1486
return true ;
1487
+ case SUSPEND_PERSONAL_APPS_KEY :
1488
+ setPersonalAppsSuspended ((Boolean ) newValue );
1489
+ reloadPersonalAppsSuspendedUi ();
1490
+ return true ;
1456
1491
}
1457
1492
return false ;
1458
1493
}
@@ -3826,15 +3861,25 @@ private int validateDeviceOwnerBeforeP() {
3826
3861
return NO_CUSTOM_CONSTRIANT ;
3827
3862
}
3828
3863
3864
+ // TODO: nuke it when R sdk is available
3865
+ private boolean isOrganizationOwnedDeviceWithManagedProfile () {
3866
+ try {
3867
+ return (Boolean ) ReflectionUtil .invoke (
3868
+ mDevicePolicyManager , "isOrganizationOwnedDeviceWithManagedProfile" );
3869
+ } catch (ReflectionIsTemporaryException e ) {
3870
+ Log .e (TAG , "Error invoking isOrganizationOwnedDeviceWithManagedProfile" , e );
3871
+ return false ;
3872
+ }
3873
+ }
3874
+
3829
3875
private int validateProfileOwnerOfOrganizationOwnedDevice () {
3830
- // TODO(b/144486887): Need to check if in COPE mode
3831
- if (!Util .isManagedProfileOwner (getActivity ()) || Util .SDK_INT < Util .R_VERSION_CODE ) {
3876
+ if (Util .SDK_INT < Util .R_VERSION_CODE || !isOrganizationOwnedDeviceWithManagedProfile ()) {
3832
3877
return R .string .requires_profile_owner_organization_owned_device ;
3833
3878
}
3834
3879
return NO_CUSTOM_CONSTRIANT ;
3835
3880
}
3836
3881
3837
- abstract class ManageLockTaskListCallback {
3882
+ abstract static class ManageLockTaskListCallback {
3838
3883
public abstract void onPositiveButtonClicked (String [] lockTaskArray );
3839
3884
}
3840
3885
}
0 commit comments