Should not decode Wi-Fi QR code after onPause
Bug: 130141694 Test: manual atest WifiDppQrCodeScannerFragmentTest Change-Id: I412fb7c06220c23bddc7b3c448fcc72a00bdecc3
This commit is contained in:
@@ -47,6 +47,7 @@ import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.annotation.UiThread;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -261,6 +262,24 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
if (mCamera != null) {
|
||||
mCamera.stop();
|
||||
}
|
||||
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (!isGoingInitiator()) {
|
||||
restartCamera();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
if (mIsConfiguratorMode) {
|
||||
@@ -702,4 +721,9 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
||||
public void onAccessPointsChanged() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected boolean isDecodeTaskAlive() {
|
||||
return mCamera != null && mCamera.isDecodeTaskAlive();
|
||||
}
|
||||
}
|
||||
|
@@ -401,4 +401,14 @@ public class QrCamera extends Handler {
|
||||
mScannerCallback.handleSuccessfulResult(qrCode.getText());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* After {@link #start(SurfaceTexture)}, DecodingTask runs continuously to capture images and
|
||||
* decode QR code. DecodingTask become null After {@link #stop()}.
|
||||
*
|
||||
* Uses this method in test case to prevent power consumption problem.
|
||||
*/
|
||||
public boolean isDecodeTaskAlive() {
|
||||
return mDecodeTask != null;
|
||||
}
|
||||
}
|
||||
|
@@ -16,9 +16,16 @@
|
||||
|
||||
package com.android.settings.wifi.dpp;
|
||||
|
||||
import static com.android.settings.wifi.dpp.WifiDppUtils.TAG_FRAGMENT_QR_CODE_SCANNER;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
@@ -38,6 +45,7 @@ public class WifiDppQrCodeScannerFragmentTest {
|
||||
Intent intent = new Intent(WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_SCANNER);
|
||||
intent.putExtra(WifiDppUtils.EXTRA_WIFI_SECURITY, "WEP");
|
||||
intent.putExtra(WifiDppUtils.EXTRA_WIFI_SSID, "GoogleGuest");
|
||||
intent.putExtra(WifiDppUtils.EXTRA_WIFI_PRE_SHARED_KEY, "password");
|
||||
mActivityRule.launchActivity(intent);
|
||||
}
|
||||
|
||||
@@ -48,4 +56,21 @@ public class WifiDppQrCodeScannerFragmentTest {
|
||||
mActivityRule.getActivity().setRequestedOrientation(
|
||||
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPause_shouldNotDecodeQrCode() {
|
||||
final WifiDppConfiguratorActivity hostActivity =
|
||||
(WifiDppConfiguratorActivity) mActivityRule.getActivity();
|
||||
final FragmentManager fragmentManager = hostActivity.getSupportFragmentManager();
|
||||
final WifiDppQrCodeScannerFragment scannerFragment =
|
||||
(WifiDppQrCodeScannerFragment) fragmentManager
|
||||
.findFragmentByTag(TAG_FRAGMENT_QR_CODE_SCANNER);
|
||||
final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
|
||||
|
||||
instrumentation.runOnMainSync(() -> {
|
||||
instrumentation.callActivityOnPause(hostActivity);
|
||||
|
||||
assertThat(scannerFragment.isDecodeTaskAlive()).isEqualTo(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user