@@ -613,7 +613,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
613
613
mPreferentialNetworkServiceSwitchPreference .setOnPreferenceChangeListener (this );
614
614
if (mIsProfileOwner ) {
615
615
mPreferentialNetworkServiceSwitchPreference .setChecked (
616
- mDevicePolicyManager . isPreferentialNetworkServiceEnabled ());
616
+ isPreferentialNetworkServiceEnabled ());
617
617
}
618
618
findPreference (LOCK_SCREEN_POLICY_KEY ).setOnPreferenceClickListener (this );
619
619
findPreference (PASSWORD_CONSTRAINTS_KEY ).setOnPreferenceClickListener (this );
@@ -845,6 +845,27 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
845
845
reloadPersonalAppsSuspendedUi ();
846
846
}
847
847
848
+ private boolean isPreferentialNetworkServiceEnabled () {
849
+ try {
850
+ //TODO: Call directly when the S SDK is available.
851
+ return (Boolean ) ReflectionUtil .invoke (mDevicePolicyManager ,
852
+ "isPreferentialNetworkServiceEnabled" );
853
+ } catch (ReflectionIsTemporaryException e ) {
854
+ Log .e (TAG , "Error invoking isPreferentialNetworkServiceEnabled" , e );
855
+ }
856
+ return false ;
857
+ }
858
+
859
+ private void setPreferentialNetworkServiceEnabled (Boolean isEnabled ) {
860
+ try {
861
+ //TODO: Call directly when the S SDK is available.
862
+ ReflectionUtil .invoke (mDevicePolicyManager , "setPreferentialNetworkServiceEnabled" ,
863
+ new Class []{Boolean .TYPE }, isEnabled );
864
+ } catch (ReflectionIsTemporaryException e ) {
865
+ Log .e (TAG , "Error invoking setPreferentialNetworkServiceEnabled" , e );
866
+ }
867
+ }
868
+
848
869
@ Override
849
870
public void dump (String prefix , PrintWriter pw , String [] args ) {
850
871
// TODO(b/173541467): needs to compile against @SystemAPI SDK to get it
@@ -1569,9 +1590,8 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
1569
1590
reloadMuteAudioUi ();
1570
1591
return true ;
1571
1592
case SET_GET_PREFERENTIAL_NETWORK_SERVICE_STATUS :
1572
- mDevicePolicyManager .setPreferentialNetworkServiceEnabled ((Boolean ) newValue );
1573
- showToast (Boolean .toString (
1574
- mDevicePolicyManager .isPreferentialNetworkServiceEnabled ()));
1593
+ setPreferentialNetworkServiceEnabled ((Boolean ) newValue );
1594
+ showToast (Boolean .toString (isPreferentialNetworkServiceEnabled ()));
1575
1595
return true ;
1576
1596
case STAY_ON_WHILE_PLUGGED_IN :
1577
1597
mDevicePolicyManager .setGlobalSetting (mAdminComponentName ,
0 commit comments