Don't show key missing dialog for exclusively managed device
Test: local tested Flag: EXEMPT minor fix Bug: 404890083 Change-Id: I5ec0541b55af81bd3424e3b1af329cecd3a480ad
This commit is contained in:
@@ -59,6 +59,10 @@ public final class BluetoothKeyMissingReceiver extends BroadcastReceiver {
|
|||||||
if (device == null) {
|
if (device == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (BluetoothUtils.isExclusivelyManagedBluetoothDevice(context, device)) {
|
||||||
|
Log.d(TAG, "Exclusively managed device " + device + ", skip");
|
||||||
|
return;
|
||||||
|
}
|
||||||
PowerManager powerManager = context.getSystemService(PowerManager.class);
|
PowerManager powerManager = context.getSystemService(PowerManager.class);
|
||||||
if (TextUtils.equals(action, BluetoothDevice.ACTION_KEY_MISSING)) {
|
if (TextUtils.equals(action, BluetoothDevice.ACTION_KEY_MISSING)) {
|
||||||
Log.d(TAG, "Receive ACTION_KEY_MISSING");
|
Log.d(TAG, "Receive ACTION_KEY_MISSING");
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ import android.bluetooth.BluetoothDevice;
|
|||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.ApplicationInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.platform.test.annotations.DisableFlags;
|
import android.platform.test.annotations.DisableFlags;
|
||||||
import android.platform.test.annotations.EnableFlags;
|
import android.platform.test.annotations.EnableFlags;
|
||||||
@@ -68,9 +70,12 @@ public class BluetoothKeyMissingReceiverTest {
|
|||||||
@Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
@Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||||
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||||
|
|
||||||
|
private static final String TEST_EXCLUSIVE_MANAGER = "com.test.manager";
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private ShadowApplication mShadowApplication;
|
private ShadowApplication mShadowApplication;
|
||||||
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
|
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
|
||||||
|
@Mock private PackageManager mPackageManager;
|
||||||
@Mock private LocalBluetoothManager mLocalBtManager;
|
@Mock private LocalBluetoothManager mLocalBtManager;
|
||||||
@Mock private NotificationManager mNm;
|
@Mock private NotificationManager mNm;
|
||||||
@Mock private BluetoothDevice mBluetoothDevice;
|
@Mock private BluetoothDevice mBluetoothDevice;
|
||||||
@@ -78,6 +83,7 @@ public class BluetoothKeyMissingReceiverTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mContext = spy(RuntimeEnvironment.getApplication());
|
mContext = spy(RuntimeEnvironment.getApplication());
|
||||||
|
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||||
mShadowApplication = Shadow.extract(mContext);
|
mShadowApplication = Shadow.extract(mContext);
|
||||||
mShadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
|
mShadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
|
||||||
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
|
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
|
||||||
@@ -121,6 +127,24 @@ public class BluetoothKeyMissingReceiverTest {
|
|||||||
verifyNoInteractions(mNm);
|
verifyNoInteractions(mNm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_ENABLE_BLUETOOTH_KEY_MISSING_DIALOG)
|
||||||
|
public void broadcastReceiver_exclusiveManaged_skip() throws Exception {
|
||||||
|
Intent intent = spy(new Intent(BluetoothDevice.ACTION_KEY_MISSING));
|
||||||
|
when(intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE)).thenReturn(mBluetoothDevice);
|
||||||
|
when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
|
||||||
|
when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_EXCLUSIVE_MANAGER)).thenReturn(
|
||||||
|
TEST_EXCLUSIVE_MANAGER.getBytes());
|
||||||
|
when(mPackageManager.getApplicationInfo(
|
||||||
|
TEST_EXCLUSIVE_MANAGER, 0)).thenReturn(new ApplicationInfo());
|
||||||
|
BluetoothKeyMissingReceiver bluetoothKeyMissingReceiver = getReceiver(intent);
|
||||||
|
|
||||||
|
bluetoothKeyMissingReceiver.onReceive(mContext, intent);
|
||||||
|
|
||||||
|
verifyNoInteractions(mNm);
|
||||||
|
verify(mContext, never()).startActivityAsUser(any(), any());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Cannot test reflection")
|
@Ignore("Cannot test reflection")
|
||||||
@EnableFlags(Flags.FLAG_ENABLE_BLUETOOTH_KEY_MISSING_DIALOG)
|
@EnableFlags(Flags.FLAG_ENABLE_BLUETOOTH_KEY_MISSING_DIALOG)
|
||||||
|
|||||||
Reference in New Issue
Block a user