Make DevloperOptions frag listen to sysprop change

Add System Properties change callback in
DevelopmentSettingsDashboardFragment, to listen to the changed
and update preference states accordingly.

This will fix the bug that the pref is not updated accordingly
when user modifies the setting from quick-settings.

Test: Manual/Visual Verification
Fixes: 127761520
Change-Id: I478775902a1d0df1e91f98027d4b8d65d6e9fd28
This commit is contained in:
lindatseng
2019-04-02 13:07:11 -07:00
committed by Linda Tseng
parent 8eb02d1e18
commit 6b094edbb5

View File

@@ -27,6 +27,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.SystemProperties;
import android.os.UserManager;
import android.provider.SearchIndexableResource;
import android.util.Log;
@@ -136,6 +137,20 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
}
};
private final Runnable mSystemPropertiesChanged = new Runnable() {
@Override
public void run() {
synchronized (this) {
Activity activity = getActivity();
if (activity != null) {
activity.runOnUiThread(() -> {
updatePreferenceStates();
});
}
}
}
};
public DevelopmentSettingsDashboardFragment() {
super(UserManager.DISALLOW_DEBUGGING_FEATURES);
}
@@ -184,7 +199,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
registerReceivers();
SystemProperties.addChangeCallback(mSystemPropertiesChanged);
final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null) {
adapter.getProfileProxy(getActivity(), mBluetoothA2dpServiceListener,
@@ -203,6 +218,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
adapter.closeProfileProxy(BluetoothProfile.A2DP, mBluetoothA2dp);
mBluetoothA2dp = null;
}
SystemProperties.removeChangeCallback(mSystemPropertiesChanged);
}
@Override