Merge "Add getSessionName() API for group name in SettingsLib" into rvc-dev
This commit is contained in:
@@ -311,6 +311,21 @@ public class InfoMediaManager extends MediaManager {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CharSequence getSessionName() {
|
||||||
|
if (TextUtils.isEmpty(mPackageName)) {
|
||||||
|
Log.w(TAG, "Unable to get session name. The package name is null or empty!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final RoutingSessionInfo info = getRoutingSessionInfo();
|
||||||
|
if (info != null) {
|
||||||
|
return info.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.w(TAG, "Unable to get session name for package: " + mPackageName);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private void refreshDevices() {
|
private void refreshDevices() {
|
||||||
mMediaDevices.clear();
|
mMediaDevices.clear();
|
||||||
mCurrentConnectedDevice = null;
|
mCurrentConnectedDevice = null;
|
||||||
|
|||||||
@@ -324,6 +324,15 @@ public class LocalMediaManager implements BluetoothCallback {
|
|||||||
return mInfoMediaManager.getSessionVolume();
|
return mInfoMediaManager.getSessionVolume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the user-visible name of the {@link android.media.RoutingSessionInfo}.
|
||||||
|
*
|
||||||
|
* @return current name of the session, and return {@code null} if not found.
|
||||||
|
*/
|
||||||
|
public CharSequence getSessionName() {
|
||||||
|
return mInfoMediaManager.getSessionName();
|
||||||
|
}
|
||||||
|
|
||||||
private MediaDevice updateCurrentConnectedDevice() {
|
private MediaDevice updateCurrentConnectedDevice() {
|
||||||
MediaDevice phoneMediaDevice = null;
|
MediaDevice phoneMediaDevice = null;
|
||||||
for (MediaDevice device : mMediaDevices) {
|
for (MediaDevice device : mMediaDevices) {
|
||||||
|
|||||||
@@ -460,4 +460,37 @@ public class InfoMediaManagerTest {
|
|||||||
|
|
||||||
assertThat(mInfoMediaManager.releaseSession()).isTrue();
|
assertThat(mInfoMediaManager.releaseSession()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSessionName_packageNameIsNull_returnNull() {
|
||||||
|
mInfoMediaManager.mPackageName = null;
|
||||||
|
|
||||||
|
assertThat(mInfoMediaManager.getSessionName()).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSessionName_notContainPackageName_returnNull() {
|
||||||
|
final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>();
|
||||||
|
final RoutingSessionInfo info = mock(RoutingSessionInfo.class);
|
||||||
|
routingSessionInfos.add(info);
|
||||||
|
|
||||||
|
mShadowRouter2Manager.setRoutingSessions(routingSessionInfos);
|
||||||
|
when(info.getClientPackageName()).thenReturn("com.fake.packagename");
|
||||||
|
when(info.getName()).thenReturn(TEST_NAME);
|
||||||
|
|
||||||
|
assertThat(mInfoMediaManager.getSessionName()).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSessionName_containPackageName_returnName() {
|
||||||
|
final List<RoutingSessionInfo> routingSessionInfos = new ArrayList<>();
|
||||||
|
final RoutingSessionInfo info = mock(RoutingSessionInfo.class);
|
||||||
|
routingSessionInfos.add(info);
|
||||||
|
|
||||||
|
mShadowRouter2Manager.setRoutingSessions(routingSessionInfos);
|
||||||
|
when(info.getClientPackageName()).thenReturn(TEST_PACKAGE_NAME);
|
||||||
|
when(info.getName()).thenReturn(TEST_NAME);
|
||||||
|
|
||||||
|
assertThat(mInfoMediaManager.getSessionName()).isEqualTo(TEST_NAME);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user