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
diff --git a/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java b/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java
index fe4e8de..c88313b 100644
--- a/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java
+++ b/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java
@@ -322,7 +322,9 @@
     }
 
     private void handleWifiDpp() {
-        destroyCamera();
+        if (mCamera != null) {
+            mCamera.stop();
+        }
         mDecorateView.setFocused(true);
 
         Message message = mHandler.obtainMessage(MESSAGE_SCAN_WIFI_DPP_SUCCESS);
@@ -332,7 +334,9 @@
     }
 
     private void handleZxingWifiFormat() {
-        destroyCamera();
+        if (mCamera != null) {
+            mCamera.stop();
+        }
         mDecorateView.setFocused(true);
 
         Message message = mHandler.obtainMessage(MESSAGE_SCAN_ZXING_WIFI_FORMAT_SUCCESS);
@@ -443,6 +447,7 @@
             Log.e(TAG, "Invalid networkId " + newNetworkId);
             mLatestStatusCode = EasyConnectStatusCallback.EASY_CONNECT_EVENT_FAILURE_GENERIC;
             showErrorMessage(getString(R.string.wifi_dpp_check_connection_try_again));
+            restartCamera();
         }
 
         @Override
@@ -507,6 +512,7 @@
             }
 
             mLatestStatusCode = code;
+            restartCamera();
         }
 
         @Override
@@ -535,6 +541,7 @@
         Log.d(TAG, "Wi-Fi connect onFailure reason - " + reason);
 
         showErrorMessage(getString(R.string.wifi_dpp_check_connection_try_again));
+        restartCamera();
     }
 
     // Check is Easy Connect handshaking or not
@@ -544,4 +551,21 @@
 
         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);
+    }
 }