Skip to content

Commit 00d3ae0

Browse files
committed
Call preferential network service API using reflection
Use reflection to call the preferential network service API until a new Android-S SDK drop is available. Bug: 183663019 Test: That it compiles. Change-Id: I6e90a6afdc390dce3f120b06c8057924120d569b
1 parent 7b88ce8 commit 00d3ae0

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
613613
mPreferentialNetworkServiceSwitchPreference.setOnPreferenceChangeListener(this);
614614
if (mIsProfileOwner) {
615615
mPreferentialNetworkServiceSwitchPreference.setChecked(
616-
mDevicePolicyManager.isPreferentialNetworkServiceEnabled());
616+
isPreferentialNetworkServiceEnabled());
617617
}
618618
findPreference(LOCK_SCREEN_POLICY_KEY).setOnPreferenceClickListener(this);
619619
findPreference(PASSWORD_CONSTRAINTS_KEY).setOnPreferenceClickListener(this);
@@ -845,6 +845,27 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
845845
reloadPersonalAppsSuspendedUi();
846846
}
847847

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+
848869
@Override
849870
public void dump(String prefix, PrintWriter pw, String[] args) {
850871
// TODO(b/173541467): needs to compile against @SystemAPI SDK to get it
@@ -1569,9 +1590,8 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
15691590
reloadMuteAudioUi();
15701591
return true;
15711592
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()));
15751595
return true;
15761596
case STAY_ON_WHILE_PLUGGED_IN:
15771597
mDevicePolicyManager.setGlobalSetting(mAdminComponentName,

0 commit comments

Comments
 (0)