Don't crash on null Intent in FingerprintEnrollFindSensor
During a run of the setup wizard, a tester one time encountered a case where the 'Accept Legal terms' screen followed by the Security screen showed for a second time after already confirming the pattern in the Security screen. The logs showed a crash in FingerprintEnrollFindSensor.onActivityResult which could only have happened if it was called with a requestCode of CONFIRM_REQUEST and a resultCode of RESULT_OK, but a null Intent. This isn't an expected flow, and AFAIK we haven't been able to reproduce the original problem, but it seems reasonable to at least not crash in settings, so this CL defends against that crash by just calling finish() in this case, which means the caller who started the FingerprintEnrollFindSensor will see the default result code of Activity.RESULT_CANCELLED. Bug: 80099085 Test: make -j RunSettingsRoboTests Change-Id: I94401eabe295e4d5396cf7d324fbf1902dc45f6d
This commit is contained in:
@@ -24,6 +24,7 @@ import androidx.annotation.Nullable;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
@@ -35,7 +36,8 @@ import com.android.settings.password.ChooseLockSettingsHelper;
|
||||
*/
|
||||
public class FingerprintEnrollFindSensor extends FingerprintEnrollBase {
|
||||
|
||||
private static final int CONFIRM_REQUEST = 1;
|
||||
@VisibleForTesting
|
||||
static final int CONFIRM_REQUEST = 1;
|
||||
private static final int ENROLLING = 2;
|
||||
public static final String EXTRA_KEY_LAUNCHED_CONFIRM = "launched_confirm_lock";
|
||||
|
||||
@@ -170,7 +172,7 @@ public class FingerprintEnrollFindSensor extends FingerprintEnrollBase {
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == CONFIRM_REQUEST) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
if (resultCode == RESULT_OK && data != null) {
|
||||
mToken = data.getByteArrayExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
|
||||
overridePendingTransition(R.anim.suw_slide_next_in, R.anim.suw_slide_next_out);
|
||||
getIntent().putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
|
||||
|
||||
@@ -22,6 +22,7 @@ import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.robolectric.RuntimeEnvironment.application;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
@@ -151,4 +152,12 @@ public class FingerprintEnrollFindSensorTest {
|
||||
|
||||
return callbackCaptor.getValue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onActivityResult_withNullIntentShouldNotCrash() {
|
||||
// this should not crash
|
||||
mActivity.onActivityResult(FingerprintEnrollFindSensor.CONFIRM_REQUEST, Activity.RESULT_OK,
|
||||
null);
|
||||
assertThat(Shadows.shadowOf(mActivity).getResultCode()).isEqualTo(Activity.RESULT_CANCELED);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user