Fix camera stop forever after error occurs while sharing or adding network

Restart QrCamera decoding task after Wi-Fi DPP handshake fail or
Wi-Fi connection fail.

Bug: 124128539
Test: manual test
Change-Id: I6d916ed1378f50038089e2c1e2870915ca083d68
This commit is contained in:
Arc Wang
2019-02-15 14:21:26 +08:00
parent 7bdcadbe72
commit ffae615d25

View File

@@ -322,7 +322,9 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
} }
private void handleWifiDpp() { private void handleWifiDpp() {
destroyCamera(); if (mCamera != null) {
mCamera.stop();
}
mDecorateView.setFocused(true); mDecorateView.setFocused(true);
Message message = mHandler.obtainMessage(MESSAGE_SCAN_WIFI_DPP_SUCCESS); Message message = mHandler.obtainMessage(MESSAGE_SCAN_WIFI_DPP_SUCCESS);
@@ -332,7 +334,9 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
} }
private void handleZxingWifiFormat() { private void handleZxingWifiFormat() {
destroyCamera(); if (mCamera != null) {
mCamera.stop();
}
mDecorateView.setFocused(true); mDecorateView.setFocused(true);
Message message = mHandler.obtainMessage(MESSAGE_SCAN_ZXING_WIFI_FORMAT_SUCCESS); Message message = mHandler.obtainMessage(MESSAGE_SCAN_ZXING_WIFI_FORMAT_SUCCESS);
@@ -443,6 +447,7 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
Log.e(TAG, "Invalid networkId " + newNetworkId); Log.e(TAG, "Invalid networkId " + newNetworkId);
mLatestStatusCode = EasyConnectStatusCallback.EASY_CONNECT_EVENT_FAILURE_GENERIC; mLatestStatusCode = EasyConnectStatusCallback.EASY_CONNECT_EVENT_FAILURE_GENERIC;
showErrorMessage(getString(R.string.wifi_dpp_check_connection_try_again)); showErrorMessage(getString(R.string.wifi_dpp_check_connection_try_again));
restartCamera();
} }
@Override @Override
@@ -507,6 +512,7 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
} }
mLatestStatusCode = code; mLatestStatusCode = code;
restartCamera();
} }
@Override @Override
@@ -535,6 +541,7 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
Log.d(TAG, "Wi-Fi connect onFailure reason - " + reason); Log.d(TAG, "Wi-Fi connect onFailure reason - " + reason);
showErrorMessage(getString(R.string.wifi_dpp_check_connection_try_again)); showErrorMessage(getString(R.string.wifi_dpp_check_connection_try_again));
restartCamera();
} }
// Check is Easy Connect handshaking or not // Check is Easy Connect handshaking or not
@@ -544,4 +551,21 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
return model.isGoingInitiator(); return model.isGoingInitiator();
} }
/**
* To resume camera decoding task after handshake fail or Wi-Fi connection fail.
*/
private void restartCamera() {
if (mCamera == null) {
Log.d(TAG, "mCamera is not available for restarting camera");
return;
}
final SurfaceTexture surfaceTexture = mTextureView.getSurfaceTexture();
if (surfaceTexture == null) {
throw new IllegalStateException("SurfaceTexture is not ready for restarting camera");
}
mCamera.start(surfaceTexture);
}
} }