RESTRICT AUTOMERGE Make bluetooth not discoverable via SliceDeepLinkTrampoline am: 06139d3ffc
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/18330693 Change-Id: Ic3eecbf76413c2ceeff1f3a838cb7f6250e3a423 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -46,6 +46,7 @@ public class ConnectedDeviceDashboardFragment extends DashboardFragment {
|
|||||||
private static final String SETTINGS_PACKAGE_NAME = "com.android.settings";
|
private static final String SETTINGS_PACKAGE_NAME = "com.android.settings";
|
||||||
private static final String SYSTEMUI_PACKAGE_NAME = "com.android.systemui";
|
private static final String SYSTEMUI_PACKAGE_NAME = "com.android.systemui";
|
||||||
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||||
|
private static final String SLICE_ACTION = "com.android.settings.SEARCH_RESULT_TRAMPOLINE";
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final String KEY_CONNECTED_DEVICES = "connected_device_list";
|
static final String KEY_CONNECTED_DEVICES = "connected_device_list";
|
||||||
@@ -98,8 +99,10 @@ public class ConnectedDeviceDashboardFragment extends DashboardFragment {
|
|||||||
SettingsUIDeviceConfig.BT_NEAR_BY_SUGGESTION_ENABLED, true);
|
SettingsUIDeviceConfig.BT_NEAR_BY_SUGGESTION_ENABLED, true);
|
||||||
String callingAppPackageName = PasswordUtils.getCallingAppPackageName(
|
String callingAppPackageName = PasswordUtils.getCallingAppPackageName(
|
||||||
getActivity().getActivityToken());
|
getActivity().getActivityToken());
|
||||||
|
String action = getIntent() != null ? getIntent().getAction() : "";
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "onAttach() calling package name is : " + callingAppPackageName);
|
Log.d(TAG, "onAttach() calling package name is : " + callingAppPackageName
|
||||||
|
+ ", action : " + action);
|
||||||
}
|
}
|
||||||
use(AvailableMediaDeviceGroupController.class).init(this);
|
use(AvailableMediaDeviceGroupController.class).init(this);
|
||||||
use(ConnectedDeviceGroupController.class).init(this);
|
use(ConnectedDeviceGroupController.class).init(this);
|
||||||
@@ -108,9 +111,15 @@ public class ConnectedDeviceDashboardFragment extends DashboardFragment {
|
|||||||
use(SlicePreferenceController.class).setSliceUri(nearbyEnabled
|
use(SlicePreferenceController.class).setSliceUri(nearbyEnabled
|
||||||
? Uri.parse(getString(R.string.config_nearby_devices_slice_uri))
|
? Uri.parse(getString(R.string.config_nearby_devices_slice_uri))
|
||||||
: null);
|
: null);
|
||||||
use(DiscoverableFooterPreferenceController.class).setAlwaysDiscoverable(
|
use(DiscoverableFooterPreferenceController.class)
|
||||||
TextUtils.equals(SETTINGS_PACKAGE_NAME, callingAppPackageName)
|
.setAlwaysDiscoverable(isAlwaysDiscoverable(callingAppPackageName, action));
|
||||||
|| TextUtils.equals(SYSTEMUI_PACKAGE_NAME, callingAppPackageName));
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
boolean isAlwaysDiscoverable(String callingAppPackageName, String action) {
|
||||||
|
return TextUtils.equals(SLICE_ACTION, action) ? false
|
||||||
|
: TextUtils.equals(SETTINGS_PACKAGE_NAME, callingAppPackageName)
|
||||||
|
|| TextUtils.equals(SYSTEMUI_PACKAGE_NAME, callingAppPackageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -51,16 +51,23 @@ import java.util.List;
|
|||||||
ShadowConnectivityManager.class, ShadowBluetoothAdapter.class})
|
ShadowConnectivityManager.class, ShadowBluetoothAdapter.class})
|
||||||
public class ConnectedDeviceDashboardFragmentTest {
|
public class ConnectedDeviceDashboardFragmentTest {
|
||||||
private static final String KEY_NEARBY_DEVICES = "bt_nearby_slice";
|
private static final String KEY_NEARBY_DEVICES = "bt_nearby_slice";
|
||||||
|
private static final String SETTINGS_PACKAGE_NAME = "com.android.settings";
|
||||||
|
private static final String SYSTEMUI_PACKAGE_NAME = "com.android.systemui";
|
||||||
|
private static final String SLICE_ACTION = "com.android.settings.SEARCH_RESULT_TRAMPOLINE";
|
||||||
|
private static final String TEST_APP_NAME = "com.testapp.settings";
|
||||||
|
private static final String TEST_ACTION = "com.testapp.settings.ACTION_START";
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private PackageManager mPackageManager;
|
private PackageManager mPackageManager;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
private ConnectedDeviceDashboardFragment mFragment;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
mContext = spy(RuntimeEnvironment.application);
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
|
mFragment = new ConnectedDeviceDashboardFragment();
|
||||||
doReturn(mPackageManager).when(mContext).getPackageManager();
|
doReturn(mPackageManager).when(mContext).getPackageManager();
|
||||||
doReturn(true).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
|
doReturn(true).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
|
||||||
}
|
}
|
||||||
@@ -84,6 +91,26 @@ public class ConnectedDeviceDashboardFragmentTest {
|
|||||||
KEY_NEARBY_DEVICES);
|
KEY_NEARBY_DEVICES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAlwaysDiscoverable_callingAppIsNotFromSystemApp_returnsFalse() {
|
||||||
|
assertThat(mFragment.isAlwaysDiscoverable(TEST_APP_NAME, TEST_ACTION)).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAlwaysDiscoverable_callingAppIsFromSettings_returnsTrue() {
|
||||||
|
assertThat(mFragment.isAlwaysDiscoverable(SETTINGS_PACKAGE_NAME, TEST_ACTION)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAlwaysDiscoverable_callingAppIsFromSystemUI_returnsTrue() {
|
||||||
|
assertThat(mFragment.isAlwaysDiscoverable(SYSTEMUI_PACKAGE_NAME, TEST_ACTION)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAlwaysDiscoverable_actionIsFromSlice_returnsFalse() {
|
||||||
|
assertThat(mFragment.isAlwaysDiscoverable(SYSTEMUI_PACKAGE_NAME, SLICE_ACTION)).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getPreferenceControllers_containSlicePrefController() {
|
public void getPreferenceControllers_containSlicePrefController() {
|
||||||
final List<BasePreferenceController> controllers =
|
final List<BasePreferenceController> controllers =
|
||||||
|
Reference in New Issue
Block a user