@@ -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
- isPreferentialNetworkServiceEnabled ());
616
+ mDevicePolicyManagerGateway . isPreferentialNetworkServiceEnabled ());
617
617
}
618
618
findPreference (LOCK_SCREEN_POLICY_KEY ).setOnPreferenceClickListener (this );
619
619
findPreference (PASSWORD_CONSTRAINTS_KEY ).setOnPreferenceClickListener (this );
@@ -845,27 +845,6 @@ 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
-
869
848
@ Override
870
849
public void dump (String prefix , PrintWriter pw , String [] args ) {
871
850
// TODO(b/173541467): needs to compile against @SystemAPI SDK to get it
@@ -1590,8 +1569,11 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
1590
1569
reloadMuteAudioUi ();
1591
1570
return true ;
1592
1571
case SET_GET_PREFERENTIAL_NETWORK_SERVICE_STATUS :
1593
- setPreferentialNetworkServiceEnabled ((Boolean ) newValue );
1594
- showToast (Boolean .toString (isPreferentialNetworkServiceEnabled ()));
1572
+ mDevicePolicyManagerGateway .setPreferentialNetworkServiceEnabled ((Boolean ) newValue ,
1573
+ (v ) -> onSuccessShowToastWithHardcodedMessage (
1574
+ "setPreferentialNetworkServiceEnabled(%b)" ,
1575
+ mDevicePolicyManagerGateway .isPreferentialNetworkServiceEnabled ()),
1576
+ (e ) -> onErrorLog ("setPreferentialNetworkServiceEnabled" , e ));
1595
1577
return true ;
1596
1578
case STAY_ON_WHILE_PLUGGED_IN :
1597
1579
mDevicePolicyManager .setGlobalSetting (mAdminComponentName ,
@@ -4416,6 +4398,13 @@ private void onSuccessShowToast(String method, int msgId, Object...args) {
4416
4398
showToast (msgId , args );
4417
4399
}
4418
4400
4401
+ /**
4402
+ * Used for messages not backed by resources.
4403
+ */
4404
+ private void onSuccessShowToastWithHardcodedMessage (String format , Object ...args ) {
4405
+ showToast (String .format (format , args ));
4406
+ }
4407
+
4419
4408
private void onErrorShowToast (String method , int msgId , Object ... args ) {
4420
4409
Log .e (TAG , method + "() failed" );
4421
4410
showToast (msgId , args );
0 commit comments