Skip to content

Commit

Permalink
only grant permission for unit test if we are on a device that needs it
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianKast committed Feb 13, 2024
1 parent 1eaf6aa commit 0b0f350
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.Manifest;
import android.content.ComponentName;
import android.os.Build;
import android.os.Looper;

import androidx.test.ext.junit.runners.AndroidJUnit4;
Expand Down Expand Up @@ -33,7 +34,7 @@
public class TransportManagerTests {

@Rule
public GrantPermissionRule btRuntimePermissionRule = GrantPermissionRule.grant(Manifest.permission.BLUETOOTH_CONNECT);
public GrantPermissionRule btRuntimePermissionRule;
MultiplexTransportConfig config;
final TransportRecord defaultBtRecord = new TransportRecord(TransportType.BLUETOOTH, "12:34:56:78:90");
final ComponentName routerServiceComponentName = new ComponentName("com.smartdevicelink.test", "com.smartdevicelink.test.SdlRouterService");
Expand Down Expand Up @@ -67,6 +68,10 @@ public boolean onLegacyModeEnabled(String info) {

@Before
public void setUp() throws Exception {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
btRuntimePermissionRule =
GrantPermissionRule.grant(Manifest.permission.BLUETOOTH_CONNECT);
}
config = new MultiplexTransportConfig(getInstrumentation().getContext(), SdlUnitTestContants.TEST_APP_ID);
config.setService(routerServiceComponentName);
if (Looper.myLooper() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
@RunWith(AndroidJUnit4.class)
public class MediaStreamingStatusTests {
@Rule
public GrantPermissionRule btRuntimePermissionRule = GrantPermissionRule.grant(Manifest.permission.BLUETOOTH_CONNECT);
public GrantPermissionRule btRuntimePermissionRule;

@Mock
private AudioManager audioManager = mock(AudioManager.class);
Expand All @@ -63,6 +63,9 @@ public Object answer(InvocationOnMock invocation) {

@Before
public void setUp() throws Exception {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
btRuntimePermissionRule = GrantPermissionRule.grant(Manifest.permission.BLUETOOTH_CONNECT);
}
mockedContext = mock(Context.class);
doAnswer(onGetSystemService).when(mockedContext).getSystemService(Context.AUDIO_SERVICE);
defaultMediaStreamingStatus = new MediaStreamingStatus(mockedContext, mock(MediaStreamingStatus.Callback.class));
Expand Down

0 comments on commit 0b0f350

Please sign in to comment.