Crash when scanning WiFi QR code
Fix two crashes when scanning a WiFi QR code. The crashes are due to the asynchronous nature of the scan/decode process, where the result is delivered after the activity has been destroyed. Bug: 223640678 Test: manual, Settings -> Network & internet -> Internet Press the 'Scan QR code' icon Start to scan a WiFi QR code Just before then scan/decode completes, press Back Change-Id: Ic19ca08590ed76ca9be46eabe3e0b17419fb0b44
This commit is contained in:
@@ -168,10 +168,18 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case MESSAGE_SCAN_ZXING_WIFI_FORMAT_SUCCESS:
|
case MESSAGE_SCAN_ZXING_WIFI_FORMAT_SUCCESS:
|
||||||
|
final Context context = getContext();
|
||||||
|
if (context == null) {
|
||||||
|
// Context may be null if the message is received after the Activity has
|
||||||
|
// been destroyed
|
||||||
|
Log.d(TAG, "Scan success but context is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// We may get 2 WifiConfiguration if the QR code has no password in it,
|
// We may get 2 WifiConfiguration if the QR code has no password in it,
|
||||||
// one for open network and one for enhanced open network.
|
// one for open network and one for enhanced open network.
|
||||||
final WifiManager wifiManager =
|
final WifiManager wifiManager =
|
||||||
getContext().getSystemService(WifiManager.class);
|
context.getSystemService(WifiManager.class);
|
||||||
final WifiNetworkConfig qrCodeWifiNetworkConfig =
|
final WifiNetworkConfig qrCodeWifiNetworkConfig =
|
||||||
(WifiNetworkConfig)msg.obj;
|
(WifiNetworkConfig)msg.obj;
|
||||||
final List<WifiConfiguration> qrCodeWifiConfigurations =
|
final List<WifiConfiguration> qrCodeWifiConfigurations =
|
||||||
|
@@ -124,6 +124,7 @@ public class QrCamera extends Handler {
|
|||||||
}
|
}
|
||||||
if (mCamera != null) {
|
if (mCamera != null) {
|
||||||
mCamera.stopPreview();
|
mCamera.stopPreview();
|
||||||
|
releaseCamera();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user