Fix NPE in wifi direct connection establishment.

This commit is contained in:
Cody Henthorne
2023-11-16 16:37:23 -05:00
parent 750825b3c3
commit ae98d5e3bd
2 changed files with 5 additions and 2 deletions

View File

@@ -357,8 +357,11 @@ final class DeviceTransferClient implements Handler.Callback {
public void onNetworkConnected(@NonNull WifiP2pInfo info) { public void onNetworkConnected(@NonNull WifiP2pInfo info) {
if (info.isGroupOwner) { if (info.isGroupOwner) {
handler.sendEmptyMessage(START_IP_EXCHANGE); handler.sendEmptyMessage(START_IP_EXCHANGE);
} else { } else if (info.groupOwnerAddress != null) {
handler.sendMessage(handler.obtainMessage(START_NETWORK_CLIENT, info.groupOwnerAddress.getHostAddress())); handler.sendMessage(handler.obtainMessage(START_NETWORK_CLIENT, info.groupOwnerAddress.getHostAddress()));
} else {
Log.d(TAG, "Group owner address null, re-requesting networking information.");
handler.sendMessage(handler.obtainMessage(NETWORK_CONNECTION_CHANGED, true));
} }
} }

View File

@@ -299,7 +299,7 @@ public final class WifiDirect {
ensureInitialized(); ensureInitialized();
manager.requestConnectionInfo(channel, info -> { manager.requestConnectionInfo(channel, info -> {
Log.i(TAG, "Connection information available. group_formed: " + info.groupFormed + " group_owner: " + info.isGroupOwner); Log.i(TAG, "Connection information available. group_formed: " + info.groupFormed + " is_group_owner: " + info.isGroupOwner + " has_group_owner_address: " + (info.groupOwnerAddress != null));
WifiDirectConnectionListener listener = connectionListener; WifiDirectConnectionListener listener = connectionListener;
if (listener != null) { if (listener != null) {
listener.onNetworkConnected(info); listener.onNetworkConnected(info);