Snap for 7956817 from e8d755061d to tm-release

Change-Id: I05442b9d476172eb7e7bfe7761ac9aac42f76251
This commit is contained in:
Android Build Coastguard Worker
2021-12-01 02:15:45 +00:00
5 changed files with 108 additions and 39 deletions

View File

@@ -32,6 +32,7 @@ import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.biometrics.BiometricManager; import android.hardware.biometrics.BiometricManager;
import android.hardware.biometrics.BiometricManager.Authenticators; import android.hardware.biometrics.BiometricManager.Authenticators;
import android.hardware.biometrics.BiometricManager.BiometricError; import android.hardware.biometrics.BiometricManager.BiometricError;
import android.hardware.biometrics.SensorProperties;
import android.hardware.face.FaceManager; import android.hardware.face.FaceManager;
import android.hardware.face.FaceSensorPropertiesInternal; import android.hardware.face.FaceSensorPropertiesInternal;
import android.hardware.fingerprint.FingerprintManager; import android.hardware.fingerprint.FingerprintManager;
@@ -175,8 +176,22 @@ public class BiometricEnrollActivity extends InstrumentedActivity {
mHasFeatureFingerprint = pm.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT); mHasFeatureFingerprint = pm.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT);
mHasFeatureFace = pm.hasSystemFeature(PackageManager.FEATURE_FACE); mHasFeatureFace = pm.hasSystemFeature(PackageManager.FEATURE_FACE);
// Default behavior is to enroll BIOMETRIC_WEAK or above. See ACTION_BIOMETRIC_ENROLL.
final int authenticators = getIntent().getIntExtra(
EXTRA_BIOMETRIC_AUTHENTICATORS_ALLOWED, Authenticators.BIOMETRIC_WEAK);
Log.d(TAG, "Authenticators: " + authenticators);
mParentalOptionsRequired = intent.getBooleanExtra(EXTRA_REQUIRE_PARENTAL_CONSENT, false);
mSkipReturnToParent = intent.getBooleanExtra(EXTRA_SKIP_RETURN_TO_PARENT, false);
// determine what can be enrolled // determine what can be enrolled
final boolean isSetupWizard = WizardManagerHelper.isAnySetupWizard(getIntent()); final boolean isSetupWizard = WizardManagerHelper.isAnySetupWizard(getIntent());
final boolean isMultiSensor = mHasFeatureFace && mHasFeatureFingerprint;
Log.d(TAG, "parentalOptionsRequired: " + mParentalOptionsRequired
+ ", skipReturnToParent: " + mSkipReturnToParent
+ ", isSetupWizard: " + isSetupWizard
+ ", isMultiSensor: " + isMultiSensor);
if (mHasFeatureFace) { if (mHasFeatureFace) {
final FaceManager faceManager = getSystemService(FaceManager.class); final FaceManager faceManager = getSystemService(FaceManager.class);
@@ -185,11 +200,23 @@ public class BiometricEnrollActivity extends InstrumentedActivity {
final int maxFacesEnrollableIfSUW = getApplicationContext().getResources() final int maxFacesEnrollableIfSUW = getApplicationContext().getResources()
.getInteger(R.integer.suw_max_faces_enrollable); .getInteger(R.integer.suw_max_faces_enrollable);
if (!faceProperties.isEmpty()) { if (!faceProperties.isEmpty()) {
final FaceSensorPropertiesInternal props = faceProperties.get(0);
final int maxEnrolls = final int maxEnrolls =
isSetupWizard ? maxFacesEnrollableIfSUW isSetupWizard ? maxFacesEnrollableIfSUW : props.maxEnrollmentsPerUser;
: faceProperties.get(0).maxEnrollmentsPerUser;
mIsFaceEnrollable = mIsFaceEnrollable =
faceManager.getEnrolledFaces(mUserId).size() < maxEnrolls; faceManager.getEnrolledFaces(mUserId).size() < maxEnrolls;
// exclude face enrollment from setup wizard if configured as a convenience
// isSetupWizard is always false for unicorn enrollment, so if consent is
// required check if setup has completed instead.
final boolean isSettingUp = isSetupWizard || (mParentalOptionsRequired
&& !WizardManagerHelper.isUserSetupComplete(this));
if (isSettingUp && isMultiSensor && mIsFaceEnrollable) {
if (props.sensorStrength == SensorProperties.STRENGTH_CONVENIENCE) {
Log.i(TAG, "Excluding face from SuW enrollment (STRENGTH_CONVENIENCE)");
mIsFaceEnrollable = false;
}
}
} }
} }
if (mHasFeatureFingerprint) { if (mHasFeatureFingerprint) {
@@ -207,13 +234,6 @@ public class BiometricEnrollActivity extends InstrumentedActivity {
} }
} }
mParentalOptionsRequired = intent.getBooleanExtra(EXTRA_REQUIRE_PARENTAL_CONSENT, false);
mSkipReturnToParent = intent.getBooleanExtra(EXTRA_SKIP_RETURN_TO_PARENT, false);
Log.d(TAG, "parentalOptionsRequired: " + mParentalOptionsRequired
+ ", skipReturnToParent: " + mSkipReturnToParent
+ ", isSetupWizard: " + isSetupWizard);
// TODO(b/195128094): remove this restriction // TODO(b/195128094): remove this restriction
// Consent can only be recorded when this activity is launched directly from the kids // Consent can only be recorded when this activity is launched directly from the kids
// module. This can be removed when there is a way to notify consent status out of band. // module. This can be removed when there is a way to notify consent status out of band.
@@ -247,19 +267,10 @@ public class BiometricEnrollActivity extends InstrumentedActivity {
setOrConfirmCredentialsNow(); setOrConfirmCredentialsNow();
} else { } else {
// Start enrollment process if we haven't bailed out yet // Start enrollment process if we haven't bailed out yet
startEnroll(); startEnrollWith(authenticators, isSetupWizard);
} }
} }
private void startEnroll() {
// Default behavior is to enroll BIOMETRIC_WEAK or above. See ACTION_BIOMETRIC_ENROLL.
final int authenticators = getIntent().getIntExtra(
EXTRA_BIOMETRIC_AUTHENTICATORS_ALLOWED, Authenticators.BIOMETRIC_WEAK);
Log.d(TAG, "Authenticators: " + authenticators);
startEnrollWith(authenticators, WizardManagerHelper.isAnySetupWizard(getIntent()));
}
private void startEnrollWith(@Authenticators.Types int authenticators, boolean setupWizard) { private void startEnrollWith(@Authenticators.Types int authenticators, boolean setupWizard) {
// If the caller is not setup wizard, and the user has something enrolled, finish. // If the caller is not setup wizard, and the user has something enrolled, finish.
// Allow parental consent flow to skip this check, since one modality could be consented // Allow parental consent flow to skip this check, since one modality could be consented
@@ -339,7 +350,9 @@ public class BiometricEnrollActivity extends InstrumentedActivity {
final boolean fpConsentRequired = ParentalControlsUtils final boolean fpConsentRequired = ParentalControlsUtils
.parentConsentRequired(this, BiometricAuthenticator.TYPE_FINGERPRINT) != null; .parentConsentRequired(this, BiometricAuthenticator.TYPE_FINGERPRINT) != null;
final boolean requestFaceConsent = faceConsentRequired && mHasFeatureFace; final boolean requestFaceConsent = faceConsentRequired
&& mHasFeatureFace
&& mIsFaceEnrollable;
final boolean requestFpConsent = fpConsentRequired && mHasFeatureFingerprint; final boolean requestFpConsent = fpConsentRequired && mHasFeatureFingerprint;
Log.d(TAG, "faceConsentRequired: " + faceConsentRequired Log.d(TAG, "faceConsentRequired: " + faceConsentRequired

View File

@@ -94,6 +94,7 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
private SignalStrengthListener mSignalStrengthListener; private SignalStrengthListener mSignalStrengthListener;
private TelephonyDisplayInfoListener mTelephonyDisplayInfoListener; private TelephonyDisplayInfoListener mTelephonyDisplayInfoListener;
private WifiPickerTrackerHelper mWifiPickerTrackerHelper; private WifiPickerTrackerHelper mWifiPickerTrackerHelper;
private final WifiManager mWifiManager;
@VisibleForTesting @VisibleForTesting
final BroadcastReceiver mConnectionChangeReceiver = new BroadcastReceiver() { final BroadcastReceiver mConnectionChangeReceiver = new BroadcastReceiver() {
@@ -150,6 +151,7 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
mStartOrder = startOrder; mStartOrder = startOrder;
mTelephonyManager = context.getSystemService(TelephonyManager.class); mTelephonyManager = context.getSystemService(TelephonyManager.class);
mSubscriptionManager = context.getSystemService(SubscriptionManager.class); mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
mWifiManager = context.getSystemService(WifiManager.class);
mSubscriptionPreferences = new ArrayMap<>(); mSubscriptionPreferences = new ArrayMap<>();
mSubscriptionsListener = new SubscriptionsChangeListener(context, this); mSubscriptionsListener = new SubscriptionsChangeListener(context, this);
mDataEnabledListener = new MobileDataEnabledListener(context, this); mDataEnabledListener = new MobileDataEnabledListener(context, this);
@@ -271,9 +273,7 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
final boolean isDataInService = (regInfo == null) final boolean isDataInService = (regInfo == null)
? false ? false
: regInfo.isRegistered(); : regInfo.isRegistered();
final boolean isCarrierNetworkActive = final boolean isCarrierNetworkActive = isCarrierNetworkActive();
(mWifiPickerTrackerHelper != null)
&& mWifiPickerTrackerHelper.isCarrierNetworkActive();
String result = mSubsPrefCtrlInjector.getNetworkType( String result = mSubsPrefCtrlInjector.getNetworkType(
mContext, mConfig, mTelephonyDisplayInfo, subId, isCarrierNetworkActive); mContext, mConfig, mTelephonyDisplayInfo, subId, isCarrierNetworkActive);
if (mSubsPrefCtrlInjector.isActiveCellularNetwork(mContext) || isCarrierNetworkActive) { if (mSubsPrefCtrlInjector.isActiveCellularNetwork(mContext) || isCarrierNetworkActive) {
@@ -291,20 +291,15 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
final SignalStrength strength = tmForSubId.getSignalStrength(); final SignalStrength strength = tmForSubId.getSignalStrength();
int level = (strength == null) ? 0 : strength.getLevel(); int level = (strength == null) ? 0 : strength.getLevel();
int numLevels = SignalStrength.NUM_SIGNAL_STRENGTH_BINS; int numLevels = SignalStrength.NUM_SIGNAL_STRENGTH_BINS;
if (shouldInflateSignalStrength(subId)) { boolean isCarrierNetworkActive = isCarrierNetworkActive();
level += 1; if (shouldInflateSignalStrength(subId) || isCarrierNetworkActive) {
level = isCarrierNetworkActive
? SignalStrength.NUM_SIGNAL_STRENGTH_BINS
: (level + 1);
numLevels += 1; numLevels += 1;
} }
Drawable icon = mSubsPrefCtrlInjector.getIcon(mContext, level, numLevels, Drawable icon = mContext.getDrawable(R.drawable.ic_signal_strength_zero_bar_no_internet);
!mTelephonyManager.isDataEnabled());
final boolean isActiveCellularNetwork =
mSubsPrefCtrlInjector.isActiveCellularNetwork(mContext);
if (isActiveCellularNetwork || (mWifiPickerTrackerHelper != null)
&& mWifiPickerTrackerHelper.isCarrierNetworkActive()) {
icon.setTint(Utils.getColorAccentDefaultColor(mContext));
return icon;
}
final ServiceState serviceState = tmForSubId.getServiceState(); final ServiceState serviceState = tmForSubId.getServiceState();
final NetworkRegistrationInfo regInfo = (serviceState == null) final NetworkRegistrationInfo regInfo = (serviceState == null)
@@ -319,11 +314,17 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
final boolean isVoiceInService = (serviceState == null) final boolean isVoiceInService = (serviceState == null)
? false ? false
: (serviceState.getState() == ServiceState.STATE_IN_SERVICE); : (serviceState.getState() == ServiceState.STATE_IN_SERVICE);
if (isDataInService || isVoiceInService) { if (isDataInService || isVoiceInService || isCarrierNetworkActive) {
return icon; icon = mSubsPrefCtrlInjector.getIcon(mContext, level, numLevels,
!mTelephonyManager.isDataEnabled());
}
final boolean isActiveCellularNetwork =
mSubsPrefCtrlInjector.isActiveCellularNetwork(mContext);
if (isActiveCellularNetwork || isCarrierNetworkActive) {
icon.setTint(Utils.getColorAccentDefaultColor(mContext));
} }
icon = mContext.getDrawable(R.drawable.ic_signal_strength_zero_bar_no_internet);
return icon; return icon;
} }
@@ -417,7 +418,8 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
*/ */
@Override @Override
public boolean isAvailable() { public boolean isAvailable() {
if (mSubscriptionsListener.isAirplaneModeOn()) { if (mSubscriptionsListener.isAirplaneModeOn()
&& (!mWifiManager.isWifiEnabled() || !isCarrierNetworkActive())) {
return false; return false;
} }
List<SubscriptionInfo> subInfoList = List<SubscriptionInfo> subInfoList =
@@ -425,6 +427,7 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
if (subInfoList == null) { if (subInfoList == null) {
return false; return false;
} }
return subInfoList.stream() return subInfoList.stream()
// Avoid from showing subscription(SIM)s which has been marked as hidden // Avoid from showing subscription(SIM)s which has been marked as hidden
// For example, only one subscription will be shown when there're multiple // For example, only one subscription will be shown when there're multiple
@@ -495,6 +498,11 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
return new SubsPrefCtrlInjector(); return new SubsPrefCtrlInjector();
} }
boolean isCarrierNetworkActive() {
return mWifiPickerTrackerHelper != null
&& mWifiPickerTrackerHelper.isCarrierNetworkActive();
}
/** /**
* To inject necessary data from each static api. * To inject necessary data from each static api.
*/ */

View File

@@ -108,6 +108,10 @@ public class ConfirmDeviceCredentialActivity extends FragmentActivity {
if (errorCode == BiometricPrompt.BIOMETRIC_ERROR_USER_CANCELED if (errorCode == BiometricPrompt.BIOMETRIC_ERROR_USER_CANCELED
|| errorCode == BiometricPrompt.BIOMETRIC_ERROR_CANCELED) { || errorCode == BiometricPrompt.BIOMETRIC_ERROR_CANCELED) {
finish(); finish();
} else if (mUserManager.getUserInfo(mUserId) == null) {
// This can happen when profile gets wiped due to too many failed auth attempts.
Log.i(TAG, "Finishing, user no longer valid: " + mUserId);
finish();
} else { } else {
// All other errors go to some version of CC // All other errors go to some version of CC
showConfirmCredentials(); showConfirmCredentials();

View File

@@ -152,6 +152,7 @@ public abstract class ConfirmDeviceCredentialBaseFragment extends InstrumentedFr
mForgotButton.setOnClickListener(v -> { mForgotButton.setOnClickListener(v -> {
final Intent intent = new Intent(); final Intent intent = new Intent();
intent.setClassName(SETTINGS_PACKAGE_NAME, ForgotPasswordActivity.class.getName()); intent.setClassName(SETTINGS_PACKAGE_NAME, ForgotPasswordActivity.class.getName());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Intent.EXTRA_USER_ID, mUserId); intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
getActivity().startActivity(intent); getActivity().startActivity(intent);
getActivity().finish(); getActivity().finish();

View File

@@ -39,6 +39,7 @@ import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.Network; import android.net.Network;
import android.net.NetworkCapabilities; import android.net.NetworkCapabilities;
import android.net.wifi.WifiManager;
import android.os.Looper; import android.os.Looper;
import android.os.UserManager; import android.os.UserManager;
import android.provider.Settings; import android.provider.Settings;
@@ -102,6 +103,8 @@ public class SubscriptionsPreferenceControllerTest {
private LifecycleOwner mLifecycleOwner; private LifecycleOwner mLifecycleOwner;
@Mock @Mock
private WifiPickerTrackerHelper mWifiPickerTrackerHelper; private WifiPickerTrackerHelper mWifiPickerTrackerHelper;
@Mock
private WifiManager mWifiManager;
private LifecycleRegistry mLifecycleRegistry; private LifecycleRegistry mLifecycleRegistry;
private int mOnChildUpdatedCount; private int mOnChildUpdatedCount;
@@ -132,6 +135,7 @@ public class SubscriptionsPreferenceControllerTest {
when(mConnectivityManager.getNetworkCapabilities(mActiveNetwork)) when(mConnectivityManager.getNetworkCapabilities(mActiveNetwork))
.thenReturn(mNetworkCapabilities); .thenReturn(mNetworkCapabilities);
when(mUserManager.isAdminUser()).thenReturn(true); when(mUserManager.isAdminUser()).thenReturn(true);
when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
when(mLifecycleOwner.getLifecycle()).thenReturn(mLifecycleRegistry); when(mLifecycleOwner.getLifecycle()).thenReturn(mLifecycleRegistry);
mPreferenceManager = new PreferenceManager(mContext); mPreferenceManager = new PreferenceManager(mContext);
@@ -171,16 +175,55 @@ public class SubscriptionsPreferenceControllerTest {
} }
@Test @Test
public void isAvailable_airplaneModeOn_availableFalse() { public void isAvailable_airplaneModeOnWifiOff_availableFalse() {
setupMockSubscriptions(2); setupMockSubscriptions(2);
assertThat(mController.isAvailable()).isTrue(); assertThat(mController.isAvailable()).isTrue();
when(mWifiManager.isWifiEnabled()).thenReturn(false);
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1); Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1);
assertThat(mController.isAvailable()).isFalse(); assertThat(mController.isAvailable()).isFalse();
} }
@Test
public void isAvailable_airplaneModeOnWifiOnWithNoCarrierNetwork_availableFalse() {
setupMockSubscriptions(2);
assertThat(mController.isAvailable()).isTrue();
when(mWifiManager.isWifiEnabled()).thenReturn(true);
doReturn(false).when(mWifiPickerTrackerHelper).isCarrierNetworkActive();
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void isAvailable_airplaneModeOnWifiOffWithCarrierNetwork_availableTrue() {
setupMockSubscriptions(1);
when(mWifiManager.isWifiEnabled()).thenReturn(false);
doReturn(true).when(mWifiPickerTrackerHelper).isCarrierNetworkActive();
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void isAvailable_airplaneModeOff_availableFalse() {
setupMockSubscriptions(2);
assertThat(mController.isAvailable()).isTrue();
when(mWifiManager.isWifiEnabled()).thenReturn(true);
doReturn(true).when(mWifiPickerTrackerHelper).isCarrierNetworkActive();
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0);
assertThat(mController.isAvailable()).isTrue();
}
@Test @Test
@UiThreadTest @UiThreadTest
public void displayPreference_providerAndHasSim_showPreference() { public void displayPreference_providerAndHasSim_showPreference() {