Use API to get necessary value when activity init

Framework change intent design from sticky to non-sticky due to
location sensitive data protect. Use APIs to get information when
activity resume.

Intents from sticy to non-sticy:
WifiP2pManager#WIFI_P2P_CONNECTION_CHANGED_ACTION
WifiP2pManager#WIFI_P2P_THIS_DEVICE_CHANGED_ACTION

Bug: 77228252
Test: Manually test Wi-Fi Direct settings
Change-Id: I115515d6832c5c5f290ef9f757ca94afa4e9f1bd
This commit is contained in:
lesl
2019-01-02 18:26:46 +08:00
parent e56df8877a
commit 7818363e71

View File

@@ -85,6 +85,7 @@ public class WifiP2pSettings extends DashboardFragment
private boolean mWifiP2pSearching;
private int mConnectedDevices;
private boolean mLastGroupFormed = false;
private boolean mIsIgnoreInitConnectionInfoCallback = false;
private P2pPeerCategoryPreferenceController mPeerCategoryController;
private P2pPersistentCategoryPreferenceController mPersistentCategoryController;
@@ -131,6 +132,7 @@ public class WifiP2pSettings extends DashboardFragment
startSearch();
}
mLastGroupFormed = wifip2pinfo.groupFormed;
mIsIgnoreInitConnectionInfoCallback = true;
} else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) {
mThisDevice = (WifiP2pDevice) intent.getParcelableExtra(
WifiP2pManager.EXTRA_WIFI_P2P_DEVICE);
@@ -338,6 +340,29 @@ public class WifiP2pSettings extends DashboardFragment
getActivity().registerReceiver(mReceiver, mIntentFilter);
if (mWifiP2pManager != null) {
mWifiP2pManager.requestPeers(mChannel, WifiP2pSettings.this);
mWifiP2pManager.requestDeviceInfo(mChannel, wifiP2pDevice -> {
if (DBG) {
Log.d(TAG, "Get device info: " + wifiP2pDevice);
}
mThisDevice = wifiP2pDevice;
mThisDevicePreferenceController.updateDeviceName(wifiP2pDevice);
});
mIsIgnoreInitConnectionInfoCallback = false;
mWifiP2pManager.requestNetworkInfo(mChannel, networkInfo -> {
mWifiP2pManager.requestConnectionInfo(mChannel, wifip2pinfo -> {
if (!mIsIgnoreInitConnectionInfoCallback) {
if (networkInfo.isConnected()) {
if (DBG) {
Log.d(TAG, "Connected");
}
} else if (!mLastGroupFormed) {
// Find peers when p2p doesn't connected.
startSearch();
}
mLastGroupFormed = wifip2pinfo.groupFormed;
}
});
});
}
}