@@ -493,14 +493,8 @@ public void onFailure(int reason) {
493493 return ; // done
494494 }
495495
496- int port = DEFAULT_CONTROL_PORT ;
497- if (mConnectedDevice .deviceName .startsWith ("DIRECT-" )
498- && mConnectedDevice .deviceName .endsWith ("Broadcom" )) {
499- // These dongles ignore the port we broadcast in our WFD IE.
500- port = 8554 ;
501- }
502-
503496 final WifiDisplay display = createWifiDisplay (mConnectedDevice );
497+ final int port = getPortNumber (mConnectedDevice );
504498 final String iface = addr .getHostAddress () + ":" + port ;
505499
506500 mPublishedDevice = mConnectedDevice ;
@@ -647,12 +641,24 @@ private static Inet4Address getInterfaceAddress(WifiP2pGroup info) {
647641 return null ;
648642 }
649643
644+ private static int getPortNumber (WifiP2pDevice device ) {
645+ if (device .deviceName .startsWith ("DIRECT-" )
646+ && device .deviceName .endsWith ("Broadcom" )) {
647+ // These dongles ignore the port we broadcast in our WFD IE.
648+ return 8554 ;
649+ }
650+ return DEFAULT_CONTROL_PORT ;
651+ }
652+
650653 private static boolean isWifiDisplay (WifiP2pDevice device ) {
651- // FIXME: the wfdInfo API doesn't work yet
652- return device .deviceName .startsWith ("DWD-" )
653- || device .deviceName .startsWith ("DIRECT-" )
654- || device .deviceName .startsWith ("CAVM-" );
655- //device.wfdInfo != null && device.wfdInfo.isWfdEnabled();
654+ return device .wfdInfo != null
655+ && device .wfdInfo .isWfdEnabled ()
656+ && isPrimarySinkDeviceType (device .wfdInfo .getDeviceType ());
657+ }
658+
659+ private static boolean isPrimarySinkDeviceType (int deviceType ) {
660+ return deviceType == WifiP2pWfdInfo .PRIMARY_SINK
661+ || deviceType == WifiP2pWfdInfo .SOURCE_OR_PRIMARY_SINK ;
656662 }
657663
658664 private static String describeWifiP2pDevice (WifiP2pDevice device ) {
0 commit comments