Skip to content

Commit f8f0edd

Browse files
author
Jeff Brown
committed
Improve reporting of wifi connection state.
We should only report that the wifi display is connected after the RTSP connection has been fully established. Change-Id: Ifc6bc5d5cebd42d551026885b31cbc74b7ece2b1
1 parent 59c53c6 commit f8f0edd

File tree

2 files changed

+122
-130
lines changed

2 files changed

+122
-130
lines changed

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

Lines changed: 22 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import android.media.RemoteDisplay;
2828
import android.os.Handler;
2929
import android.os.IBinder;
30-
import android.util.Slog;
3130
import android.view.Surface;
3231

3332
import java.io.PrintWriter;
@@ -50,8 +49,8 @@
5049
final class WifiDisplayAdapter extends DisplayAdapter {
5150
private static final String TAG = "WifiDisplayAdapter";
5251

53-
private WifiDisplayHandle mDisplayHandle;
5452
private WifiDisplayController mDisplayController;
53+
private WifiDisplayDevice mDisplayDevice;
5554

5655
private WifiDisplayStatus mCurrentStatus;
5756
private boolean mEnabled;
@@ -71,13 +70,6 @@ public WifiDisplayAdapter(DisplayManagerService.SyncRoot syncRoot,
7170
public void dumpLocked(PrintWriter pw) {
7271
super.dumpLocked(pw);
7372

74-
if (mDisplayHandle == null) {
75-
pw.println("mDisplayHandle=null");
76-
} else {
77-
pw.println("mDisplayHandle:");
78-
mDisplayHandle.dumpLocked(pw);
79-
}
80-
8173
pw.println("mCurrentStatus=" + getWifiDisplayStatusLocked());
8274
pw.println("mEnabled=" + mEnabled);
8375
pw.println("mScanState=" + mScanState);
@@ -151,16 +143,29 @@ public WifiDisplayStatus getWifiDisplayStatusLocked() {
151143
return mCurrentStatus;
152144
}
153145

154-
private void handleConnectLocked(WifiDisplay display, String iface) {
146+
private void handleConnectLocked(WifiDisplay display,
147+
Surface surface, int width, int height, int flags) {
155148
handleDisconnectLocked();
156149

157-
mDisplayHandle = new WifiDisplayHandle(display.getDeviceName(), iface);
150+
int deviceFlags = 0;
151+
if ((flags & RemoteDisplay.DISPLAY_FLAG_SECURE) != 0) {
152+
deviceFlags |= DisplayDeviceInfo.FLAG_SECURE;
153+
}
154+
155+
float refreshRate = 60.0f; // TODO: get this for real
156+
157+
String name = display.getDeviceName();
158+
IBinder displayToken = Surface.createDisplay(name);
159+
mDisplayDevice = new WifiDisplayDevice(displayToken, name, width, height,
160+
refreshRate, deviceFlags, surface);
161+
sendDisplayDeviceEventLocked(mDisplayDevice, DISPLAY_DEVICE_EVENT_ADDED);
158162
}
159163

160164
private void handleDisconnectLocked() {
161-
if (mDisplayHandle != null) {
162-
mDisplayHandle.disposeLocked();
163-
mDisplayHandle = null;
165+
if (mDisplayDevice != null) {
166+
mDisplayDevice.clearSurfaceLocked();
167+
sendDisplayDeviceEventLocked(mDisplayDevice, DISPLAY_DEVICE_EVENT_REMOVED);
168+
mDisplayDevice = null;
164169
}
165170
}
166171

@@ -258,9 +263,10 @@ public void onDisplayConnectionFailed() {
258263
}
259264

260265
@Override
261-
public void onDisplayConnected(WifiDisplay display, String iface) {
266+
public void onDisplayConnected(WifiDisplay display, Surface surface,
267+
int width, int height, int flags) {
262268
synchronized (getSyncRoot()) {
263-
handleConnectLocked(display, iface);
269+
handleConnectLocked(display, surface, width, height, flags);
264270

265271
if (mActiveDisplayState != WifiDisplayStatus.DISPLAY_STATE_CONNECTED
266272
|| mActiveDisplay == null
@@ -337,92 +343,4 @@ public DisplayDeviceInfo getDisplayDeviceInfoLocked() {
337343
return mInfo;
338344
}
339345
}
340-
341-
private final class WifiDisplayHandle implements RemoteDisplay.Listener {
342-
private final String mName;
343-
private final String mIface;
344-
private final RemoteDisplay mRemoteDisplay;
345-
346-
private WifiDisplayDevice mDevice;
347-
private int mLastError;
348-
349-
public WifiDisplayHandle(String name, String iface) {
350-
mName = name;
351-
mIface = iface;
352-
mRemoteDisplay = RemoteDisplay.listen(iface, this, getHandler());
353-
354-
Slog.i(TAG, "Listening for Wifi display connections on " + iface
355-
+ " from " + mName);
356-
}
357-
358-
public void disposeLocked() {
359-
Slog.i(TAG, "Stopped listening for Wifi display connections on " + mIface
360-
+ " from " + mName);
361-
362-
removeDisplayLocked();
363-
mRemoteDisplay.dispose();
364-
}
365-
366-
public void dumpLocked(PrintWriter pw) {
367-
pw.println(" " + mName + ": " + (mDevice != null ? "connected" : "disconnected"));
368-
pw.println(" mIface=" + mIface);
369-
pw.println(" mLastError=" + mLastError);
370-
}
371-
372-
// Called on the handler thread.
373-
@Override
374-
public void onDisplayConnected(Surface surface, int width, int height, int flags) {
375-
synchronized (getSyncRoot()) {
376-
mLastError = 0;
377-
removeDisplayLocked();
378-
addDisplayLocked(surface, width, height, flags);
379-
380-
Slog.i(TAG, "Wifi display connected: " + mName);
381-
}
382-
}
383-
384-
// Called on the handler thread.
385-
@Override
386-
public void onDisplayDisconnected() {
387-
synchronized (getSyncRoot()) {
388-
mLastError = 0;
389-
removeDisplayLocked();
390-
391-
Slog.i(TAG, "Wifi display disconnected: " + mName);
392-
}
393-
}
394-
395-
// Called on the handler thread.
396-
@Override
397-
public void onDisplayError(int error) {
398-
synchronized (getSyncRoot()) {
399-
mLastError = error;
400-
removeDisplayLocked();
401-
402-
Slog.i(TAG, "Wifi display disconnected due to error " + error + ": " + mName);
403-
}
404-
}
405-
406-
private void addDisplayLocked(Surface surface, int width, int height, int flags) {
407-
int deviceFlags = 0;
408-
if ((flags & RemoteDisplay.DISPLAY_FLAG_SECURE) != 0) {
409-
deviceFlags |= DisplayDeviceInfo.FLAG_SECURE;
410-
}
411-
412-
float refreshRate = 60.0f; // TODO: get this for real
413-
414-
IBinder displayToken = Surface.createDisplay(mName);
415-
mDevice = new WifiDisplayDevice(displayToken, mName, width, height,
416-
refreshRate, deviceFlags, surface);
417-
sendDisplayDeviceEventLocked(mDevice, DISPLAY_DEVICE_EVENT_ADDED);
418-
}
419-
420-
private void removeDisplayLocked() {
421-
if (mDevice != null) {
422-
mDevice.clearSurfaceLocked();
423-
sendDisplayDeviceEventLocked(mDevice, DISPLAY_DEVICE_EVENT_REMOVED);
424-
mDevice = null;
425-
}
426-
}
427-
}
428346
}

0 commit comments

Comments
 (0)