Skip to content

Commit 2444ae7

Browse files
author
Jeff Brown
committed
Ensure MediaRouter correctly handles renamed Wifi displays.
Fix a couple of bugs that cause MediaRouter to disconnect from the current Wifi display whenever it is renamed. Added an extra check in WifiDisplayAdapter for identity renames. The Settings app already handles this case but it's good to have the service check for it as well so we don't store unnecessary aliases. Bug: 7310777 Change-Id: I8fddd32ca59f9b798ee31b467b81457508c345f8
1 parent a2f7ca7 commit 2444ae7

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

media/java/android/media/MediaRouter.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -751,18 +751,10 @@ static RouteInfo makeWifiDisplayRoute(WifiDisplay display, boolean available) {
751751
RouteInfo.STATUS_AVAILABLE : RouteInfo.STATUS_CONNECTING);
752752
newRoute.mEnabled = available;
753753

754-
newRoute.mName = makeWifiDisplayName(display);
754+
newRoute.mName = display.getFriendlyDisplayName();
755755
return newRoute;
756756
}
757757

758-
static String makeWifiDisplayName(WifiDisplay display) {
759-
String name = display.getDeviceAlias();
760-
if (TextUtils.isEmpty(name)) {
761-
name = display.getDeviceName();
762-
}
763-
return name;
764-
}
765-
766758
private static void updateWifiDisplayRoute(RouteInfo route, WifiDisplay display,
767759
boolean available, WifiDisplayStatus wifiDisplayStatus) {
768760
final boolean isScanning =
@@ -792,8 +784,8 @@ private static void updateWifiDisplayRoute(RouteInfo route, WifiDisplay display,
792784
}
793785
}
794786

795-
final String newName = makeWifiDisplayName(display);
796-
if (route.getName().equals(newName)) {
787+
final String newName = display.getFriendlyDisplayName();
788+
if (!route.getName().equals(newName)) {
797789
route.mName = newName;
798790
changed = true;
799791
}
@@ -814,11 +806,11 @@ private static void updateWifiDisplayRoute(RouteInfo route, WifiDisplay display,
814806
}
815807
}
816808

817-
private static WifiDisplay findMatchingDisplay(WifiDisplay address, WifiDisplay[] displays) {
809+
private static WifiDisplay findMatchingDisplay(WifiDisplay d, WifiDisplay[] displays) {
818810
for (int i = 0; i < displays.length; i++) {
819-
final WifiDisplay d = displays[i];
820-
if (d.equals(address)) {
821-
return d;
811+
final WifiDisplay other = displays[i];
812+
if (d.getDeviceAddress().equals(other.getDeviceAddress())) {
813+
return other;
822814
}
823815
}
824816
return null;

services/java/com/android/server/display/WifiDisplayAdapter.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
final class WifiDisplayAdapter extends DisplayAdapter {
5151
private static final String TAG = "WifiDisplayAdapter";
5252

53+
private static final boolean DEBUG = false;
54+
5355
private final PersistentDataStore mPersistentDataStore;
5456
private final boolean mSupportsProtectedBuffers;
5557

@@ -116,6 +118,10 @@ public void run() {
116118
}
117119

118120
public void requestScanLocked() {
121+
if (DEBUG) {
122+
Slog.d(TAG, "requestScanLocked");
123+
}
124+
119125
getHandler().post(new Runnable() {
120126
@Override
121127
public void run() {
@@ -127,6 +133,10 @@ public void run() {
127133
}
128134

129135
public void requestConnectLocked(final String address, final boolean trusted) {
136+
if (DEBUG) {
137+
Slog.d(TAG, "requestConnectLocked: address=" + address + ", trusted=" + trusted);
138+
}
139+
130140
if (!trusted) {
131141
synchronized (getSyncRoot()) {
132142
if (!isRememberedDisplayLocked(address)) {
@@ -157,6 +167,10 @@ private boolean isRememberedDisplayLocked(String address) {
157167
}
158168

159169
public void requestDisconnectLocked() {
170+
if (DEBUG) {
171+
Slog.d(TAG, "requestDisconnectedLocked");
172+
}
173+
160174
getHandler().post(new Runnable() {
161175
@Override
162176
public void run() {
@@ -168,9 +182,13 @@ public void run() {
168182
}
169183

170184
public void requestRenameLocked(String address, String alias) {
185+
if (DEBUG) {
186+
Slog.d(TAG, "requestRenameLocked: address=" + address + ", alias=" + alias);
187+
}
188+
171189
if (alias != null) {
172190
alias = alias.trim();
173-
if (alias.isEmpty()) {
191+
if (alias.isEmpty() || alias.equals(address)) {
174192
alias = null;
175193
}
176194
}
@@ -183,6 +201,10 @@ public void requestRenameLocked(String address, String alias) {
183201
}
184202

185203
public void requestForgetLocked(String address) {
204+
if (DEBUG) {
205+
Slog.d(TAG, "requestForgetLocked: address=" + address);
206+
}
207+
186208
if (mPersistentDataStore.forgetWifiDisplay(address)) {
187209
mPersistentDataStore.saveIfNeeded();
188210
updateRememberedDisplaysLocked();
@@ -200,6 +222,10 @@ public WifiDisplayStatus getWifiDisplayStatusLocked() {
200222
mFeatureState, mScanState, mActiveDisplayState,
201223
mActiveDisplay, mAvailableDisplays, mRememberedDisplays);
202224
}
225+
226+
if (DEBUG) {
227+
Slog.d(TAG, "getWifiDisplayStatusLocked: result=" + mCurrentStatus);
228+
}
203229
return mCurrentStatus;
204230
}
205231

@@ -295,6 +321,7 @@ public void onScanStarted() {
295321
}
296322
}
297323

324+
@Override
298325
public void onScanFinished(WifiDisplay[] availableDisplays) {
299326
synchronized (getSyncRoot()) {
300327
availableDisplays = mPersistentDataStore.applyWifiDisplayAliases(

0 commit comments

Comments
 (0)