Loading packages/SettingsLib/src/com/android/settingslib/media/InfoMediaManager.java +15 −0 Original line number Diff line number Diff line Loading @@ -311,6 +311,21 @@ public class InfoMediaManager extends MediaManager { 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() { mMediaDevices.clear(); mCurrentConnectedDevice = null; Loading packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java +9 −0 Original line number Diff line number Diff line Loading @@ -324,6 +324,15 @@ public class LocalMediaManager implements BluetoothCallback { 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() { MediaDevice phoneMediaDevice = null; for (MediaDevice device : mMediaDevices) { Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/InfoMediaManagerTest.java +33 −0 Original line number Diff line number Diff line Loading @@ -460,4 +460,37 @@ public class InfoMediaManagerTest { 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); } } Loading
packages/SettingsLib/src/com/android/settingslib/media/InfoMediaManager.java +15 −0 Original line number Diff line number Diff line Loading @@ -311,6 +311,21 @@ public class InfoMediaManager extends MediaManager { 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() { mMediaDevices.clear(); mCurrentConnectedDevice = null; Loading
packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java +9 −0 Original line number Diff line number Diff line Loading @@ -324,6 +324,15 @@ public class LocalMediaManager implements BluetoothCallback { 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() { MediaDevice phoneMediaDevice = null; for (MediaDevice device : mMediaDevices) { Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/InfoMediaManagerTest.java +33 −0 Original line number Diff line number Diff line Loading @@ -460,4 +460,37 @@ public class InfoMediaManagerTest { 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); } }