diff --git a/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java b/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java index 0fb56fae334..21920d2d5dc 100644 --- a/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java +++ b/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java @@ -140,6 +140,11 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl break; case MESSAGE_SCAN_WIFI_DPP_SUCCESS: + if (mCamera != null) { + mCamera.stop(); + } + + mDecorateView.setFocused(true); mErrorMessage.setVisibility(View.INVISIBLE); if (mScanWifiDppSuccessListener == null) { @@ -154,15 +159,24 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl mSummary.sendAccessibilityEvent( AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); } + + WifiDppUtils.triggerVibrationForQrCodeRecognition(getContext()); break; case MESSAGE_SCAN_ZXING_WIFI_FORMAT_SUCCESS: + if (mCamera != null) { + mCamera.stop(); + } + + mDecorateView.setFocused(true); mErrorMessage.setVisibility(View.INVISIBLE); final WifiNetworkConfig wifiNetworkConfig = (WifiNetworkConfig)msg.obj; mWifiConfiguration = wifiNetworkConfig.getWifiConfigurationOrNull(); wifiNetworkConfig.connect(getContext(), /* listener */ WifiDppQrCodeScannerFragment.this); + + WifiDppUtils.triggerVibrationForQrCodeRecognition(getContext()); break; default: @@ -409,11 +423,6 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl } private void handleWifiDpp() { - if (mCamera != null) { - mCamera.stop(); - } - mDecorateView.setFocused(true); - Message message = mHandler.obtainMessage(MESSAGE_SCAN_WIFI_DPP_SUCCESS); message.obj = new WifiQrCode(mWifiQrCode.getQrCode()); @@ -421,11 +430,6 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl } private void handleZxingWifiFormat() { - if (mCamera != null) { - mCamera.stop(); - } - mDecorateView.setFocused(true); - Message message = mHandler.obtainMessage(MESSAGE_SCAN_ZXING_WIFI_FORMAT_SUCCESS); message.obj = new WifiQrCode(mWifiQrCode.getQrCode()).getWifiNetworkConfig(); diff --git a/src/com/android/settings/wifi/dpp/WifiDppUtils.java b/src/com/android/settings/wifi/dpp/WifiDppUtils.java index 42e88a57b02..2ec3137c27c 100644 --- a/src/com/android/settings/wifi/dpp/WifiDppUtils.java +++ b/src/com/android/settings/wifi/dpp/WifiDppUtils.java @@ -26,6 +26,8 @@ import android.net.wifi.WifiManager; import android.os.CancellationSignal; import android.os.Handler; import android.os.Looper; +import android.os.VibrationEffect; +import android.os.Vibrator; import android.text.TextUtils; import android.util.FeatureFlagUtils; @@ -35,6 +37,8 @@ import com.android.settingslib.wifi.AccessPoint; import java.util.List; +import java.time.Duration; + /** * Here are the items shared by both WifiDppConfiguratorActivity & WifiDppEnrolleeActivity * @@ -94,6 +98,8 @@ public class WifiDppUtils { */ public static final int EASY_CONNECT_EVENT_SUCCESS = 1; + private static final Duration VIBRATE_DURATION_QR_CODE_RECOGNITION = Duration.ofMillis(3); + /** * Returns whether the device support WiFi DPP. */ @@ -386,4 +392,14 @@ public class WifiDppUtils { } return false; } + + static void triggerVibrationForQrCodeRecognition(Context context) { + Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); + if (vibrator == null) { + return; + } + vibrator.vibrate(VibrationEffect.createOneShot( + VIBRATE_DURATION_QR_CODE_RECOGNITION.toMillis(), + VibrationEffect.DEFAULT_AMPLITUDE)); + } }