Loading src/com/android/settings/bluetooth/BluetoothDevicePreference.java +7 −1 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ public final class BluetoothDevicePreference extends GearPreference implements private AlertDialog mDisconnectDialog; private String contentDescription = null; private boolean mHideSecondTarget = false; /* Talk-back descriptions for various BT icons */ Resources mResources; Loading Loading @@ -86,7 +87,8 @@ public final class BluetoothDevicePreference extends GearPreference implements protected boolean shouldHideSecondTarget() { return mCachedDevice == null || mCachedDevice.getBondState() != BluetoothDevice.BOND_BONDED || mUserManager.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH); || mUserManager.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH) || mHideSecondTarget; } @Override Loading @@ -112,6 +114,10 @@ public final class BluetoothDevicePreference extends GearPreference implements return mCachedDevice; } public void hideSecondTarget(boolean hideSecondTarget) { mHideSecondTarget = hideSecondTarget; } public void onDeviceAttributesChanged() { /* * The preference framework takes care of making sure the value has Loading src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java +25 −18 Original line number Diff line number Diff line Loading @@ -56,29 +56,14 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback, protected final DevicePreferenceCallback mDevicePreferenceCallback; protected final Map<BluetoothDevice, Preference> mPreferenceMap; protected Context mPrefContext; protected DashboardFragment mFragment; private final boolean mShowDeviceWithoutNames; private DashboardFragment mFragment; private Preference.OnPreferenceClickListener mDevicePreferenceClickListener = null; @VisibleForTesting final GearPreference.OnGearClickListener mDeviceProfilesListener = pref -> { final CachedBluetoothDevice device = ((BluetoothDevicePreference) pref).getBluetoothDevice(); if (device == null) { return; } final Bundle args = new Bundle(); args.putString(BluetoothDeviceDetailsFragment.KEY_DEVICE_ADDRESS, device.getDevice().getAddress()); new SubSettingLauncher(mFragment.getContext()) .setDestination(BluetoothDeviceDetailsFragment.class.getName()) .setArguments(args) .setTitle(R.string.device_details_title) .setSourceMetricsCategory(mFragment.getMetricsCategory()) .launch(); launchDeviceDetails(pref); }; private class PreferenceClickListener implements Loading Loading @@ -201,7 +186,7 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback, public abstract boolean isFilterMatched(CachedBluetoothDevice cachedBluetoothDevice); /** * Update whether to show {@cde cachedBluetoothDevice} in the list. * Update whether to show {@link CachedBluetoothDevice} in the list. */ protected void update(CachedBluetoothDevice cachedBluetoothDevice) { if (isFilterMatched(cachedBluetoothDevice)) { Loading Loading @@ -239,6 +224,28 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback, } } /** * Get {@link CachedBluetoothDevice} from {@link Preference} and it is used to init * {@link SubSettingLauncher} to launch {@link BluetoothDeviceDetailsFragment} */ protected void launchDeviceDetails(Preference preference) { final CachedBluetoothDevice device = ((BluetoothDevicePreference) preference).getBluetoothDevice(); if (device == null) { return; } final Bundle args = new Bundle(); args.putString(BluetoothDeviceDetailsFragment.KEY_DEVICE_ADDRESS, device.getDevice().getAddress()); new SubSettingLauncher(mFragment.getContext()) .setDestination(BluetoothDeviceDetailsFragment.class.getName()) .setArguments(args) .setTitle(R.string.device_details_title) .setSourceMetricsCategory(mFragment.getMetricsCategory()) .launch(); } /** * @return {@code true} if {@code cachedBluetoothDevice} is connected * and the bond state is bonded. Loading src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java +24 −1 Original line number Diff line number Diff line Loading @@ -16,12 +16,19 @@ package com.android.settings.bluetooth; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; import android.content.Context; import android.media.AudioManager; import androidx.annotation.VisibleForTesting; import android.os.Bundle; import android.util.Log; import androidx.annotation.VisibleForTesting; import androidx.preference.Preference; import com.android.settings.R; import com.android.settings.connecteddevice.DevicePreferenceCallback; import com.android.settings.core.SubSettingLauncher; import com.android.settings.dashboard.DashboardFragment; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.LocalBluetoothManager; Loading Loading @@ -116,4 +123,20 @@ public class ConnectedBluetoothDeviceUpdater extends BluetoothDeviceUpdater { } return isFilterMatched; } @Override protected void addPreference(CachedBluetoothDevice cachedDevice) { super.addPreference(cachedDevice); final BluetoothDevice device = cachedDevice.getDevice(); if (mPreferenceMap.containsKey(device)) { final BluetoothDevicePreference btPreference = (BluetoothDevicePreference) mPreferenceMap.get(device); btPreference.setOnGearClickListener(null); btPreference.hideSecondTarget(true); btPreference.setOnPreferenceClickListener((Preference p) -> { launchDeviceDetails(p); return true; }); } } } tests/robotests/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdaterTest.java +12 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ package com.android.settings.bluetooth; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; Loading Loading @@ -207,4 +208,15 @@ public class ConnectedBluetoothDeviceUpdaterTest { verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice); } @Test public void addPreference_addPreference_shouldHideSecondTarget() { BluetoothDevicePreference btPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, true); mBluetoothDeviceUpdater.mPreferenceMap.put(mBluetoothDevice, btPreference); mBluetoothDeviceUpdater.addPreference(mCachedBluetoothDevice); assertThat(btPreference.shouldHideSecondTarget()).isTrue(); } } Loading
src/com/android/settings/bluetooth/BluetoothDevicePreference.java +7 −1 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ public final class BluetoothDevicePreference extends GearPreference implements private AlertDialog mDisconnectDialog; private String contentDescription = null; private boolean mHideSecondTarget = false; /* Talk-back descriptions for various BT icons */ Resources mResources; Loading Loading @@ -86,7 +87,8 @@ public final class BluetoothDevicePreference extends GearPreference implements protected boolean shouldHideSecondTarget() { return mCachedDevice == null || mCachedDevice.getBondState() != BluetoothDevice.BOND_BONDED || mUserManager.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH); || mUserManager.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH) || mHideSecondTarget; } @Override Loading @@ -112,6 +114,10 @@ public final class BluetoothDevicePreference extends GearPreference implements return mCachedDevice; } public void hideSecondTarget(boolean hideSecondTarget) { mHideSecondTarget = hideSecondTarget; } public void onDeviceAttributesChanged() { /* * The preference framework takes care of making sure the value has Loading
src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java +25 −18 Original line number Diff line number Diff line Loading @@ -56,29 +56,14 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback, protected final DevicePreferenceCallback mDevicePreferenceCallback; protected final Map<BluetoothDevice, Preference> mPreferenceMap; protected Context mPrefContext; protected DashboardFragment mFragment; private final boolean mShowDeviceWithoutNames; private DashboardFragment mFragment; private Preference.OnPreferenceClickListener mDevicePreferenceClickListener = null; @VisibleForTesting final GearPreference.OnGearClickListener mDeviceProfilesListener = pref -> { final CachedBluetoothDevice device = ((BluetoothDevicePreference) pref).getBluetoothDevice(); if (device == null) { return; } final Bundle args = new Bundle(); args.putString(BluetoothDeviceDetailsFragment.KEY_DEVICE_ADDRESS, device.getDevice().getAddress()); new SubSettingLauncher(mFragment.getContext()) .setDestination(BluetoothDeviceDetailsFragment.class.getName()) .setArguments(args) .setTitle(R.string.device_details_title) .setSourceMetricsCategory(mFragment.getMetricsCategory()) .launch(); launchDeviceDetails(pref); }; private class PreferenceClickListener implements Loading Loading @@ -201,7 +186,7 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback, public abstract boolean isFilterMatched(CachedBluetoothDevice cachedBluetoothDevice); /** * Update whether to show {@cde cachedBluetoothDevice} in the list. * Update whether to show {@link CachedBluetoothDevice} in the list. */ protected void update(CachedBluetoothDevice cachedBluetoothDevice) { if (isFilterMatched(cachedBluetoothDevice)) { Loading Loading @@ -239,6 +224,28 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback, } } /** * Get {@link CachedBluetoothDevice} from {@link Preference} and it is used to init * {@link SubSettingLauncher} to launch {@link BluetoothDeviceDetailsFragment} */ protected void launchDeviceDetails(Preference preference) { final CachedBluetoothDevice device = ((BluetoothDevicePreference) preference).getBluetoothDevice(); if (device == null) { return; } final Bundle args = new Bundle(); args.putString(BluetoothDeviceDetailsFragment.KEY_DEVICE_ADDRESS, device.getDevice().getAddress()); new SubSettingLauncher(mFragment.getContext()) .setDestination(BluetoothDeviceDetailsFragment.class.getName()) .setArguments(args) .setTitle(R.string.device_details_title) .setSourceMetricsCategory(mFragment.getMetricsCategory()) .launch(); } /** * @return {@code true} if {@code cachedBluetoothDevice} is connected * and the bond state is bonded. Loading
src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java +24 −1 Original line number Diff line number Diff line Loading @@ -16,12 +16,19 @@ package com.android.settings.bluetooth; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; import android.content.Context; import android.media.AudioManager; import androidx.annotation.VisibleForTesting; import android.os.Bundle; import android.util.Log; import androidx.annotation.VisibleForTesting; import androidx.preference.Preference; import com.android.settings.R; import com.android.settings.connecteddevice.DevicePreferenceCallback; import com.android.settings.core.SubSettingLauncher; import com.android.settings.dashboard.DashboardFragment; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.LocalBluetoothManager; Loading Loading @@ -116,4 +123,20 @@ public class ConnectedBluetoothDeviceUpdater extends BluetoothDeviceUpdater { } return isFilterMatched; } @Override protected void addPreference(CachedBluetoothDevice cachedDevice) { super.addPreference(cachedDevice); final BluetoothDevice device = cachedDevice.getDevice(); if (mPreferenceMap.containsKey(device)) { final BluetoothDevicePreference btPreference = (BluetoothDevicePreference) mPreferenceMap.get(device); btPreference.setOnGearClickListener(null); btPreference.hideSecondTarget(true); btPreference.setOnPreferenceClickListener((Preference p) -> { launchDeviceDetails(p); return true; }); } } }
tests/robotests/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdaterTest.java +12 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ package com.android.settings.bluetooth; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; Loading Loading @@ -207,4 +208,15 @@ public class ConnectedBluetoothDeviceUpdaterTest { verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice); } @Test public void addPreference_addPreference_shouldHideSecondTarget() { BluetoothDevicePreference btPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, true); mBluetoothDeviceUpdater.mPreferenceMap.put(mBluetoothDevice, btPreference); mBluetoothDeviceUpdater.addPreference(mCachedBluetoothDevice); assertThat(btPreference.shouldHideSecondTarget()).isTrue(); } }