Snap for 9794275 from 72237b55f8 to udc-release

Change-Id: Idf0459e1734e4e6a03c8835847a0101c5637bb90
This commit is contained in:
Android Build Coastguard Worker
2023-03-23 01:44:48 +00:00
18 changed files with 234 additions and 120 deletions

View File

@@ -30,5 +30,5 @@ Copyright (C) 2018 The Android Open Source Project
android:height="@dimen/dashboard_tile_foreground_image_size"
android:start="@dimen/dashboard_tile_foreground_image_inset"
android:top="@dimen/dashboard_tile_foreground_image_inset"
android:drawable="@drawable/ic_event_white" />
android:drawable="@drawable/ic_event_shape" />
</layer-list>

View File

@@ -20,6 +20,6 @@ Copyright (C) 2018 The Android Open Source Project
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:fillColor="@color/settingslib_colorSurface"
android:pathData="M17.0,12.0l-5.0,0.0l0.0,5.0l5.0,0.0l0.0,-5.0zM16.0,1.0l0.0,2.0L8.0,3.0L8.0,1.0L6.0,1.0l0.0,2.0L5.0,3.0c-1.11,0.0 -1.9,0.9 -1.99,2.0L3.0,19.0c0.0,1.0 0.89,2.0 2.0,2.0l14.0,0.0c1.1,0.0 2.0,-0.9 2.0,-2.0L21.0,5.0c0.0,-1.1 -0.9,-2.0 -2.0,-2.0l-1.0,0.0L18.0,1.0l-2.0,0.0zm3.0,18.0L5.0,19.0L5.0,8.0l14.0,0.0l0.0,11.0z"/>
</vector>

View File

@@ -30,5 +30,5 @@ Copyright (C) 2018 The Android Open Source Project
android:height="@dimen/dashboard_tile_foreground_image_size"
android:start="@dimen/dashboard_tile_foreground_image_inset"
android:top="@dimen/dashboard_tile_foreground_image_inset"
android:drawable="@drawable/ic_timelapse_white" />
android:drawable="@drawable/ic_timelapse_shape" />
</layer-list>

View File

@@ -20,6 +20,6 @@ Copyright (C) 2018 The Android Open Source Project
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:fillColor="@color/settingslib_colorSurface"
android:pathData="M16.24,7.76C15.07,6.59 13.54,6.0 12.0,6.0l0.0,6.0l-4.24,4.24c2.34,2.34 6.14,2.34 8.49,0.0 2.34,-2.34 2.34,-6.14 -0.01,-8.48zM12.0,2.0C6.48,2.0 2.0,6.48 2.0,12.0s4.48,10.0 10.0,10.0 10.0,-4.48 10.0,-10.0S17.52,2.0 12.0,2.0zm0.0,18.0c-4.42,0.0 -8.0,-3.58 -8.0,-8.0s3.58,-8.0 8.0,-8.0 8.0,3.58 8.0,8.0 -3.58,8.0 -8.0,8.0z"/>
</vector>

View File

@@ -1,26 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/SudDescription.Glif"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingTop="@dimen/sud_description_glif_margin_top"
android:paddingBottom="@dimen/sud_description_glif_margin_bottom_lists"
android:text="@string/lock_settings_picker_biometrics_added_security_message" />

View File

@@ -1,26 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/SudDescription.Glif"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingTop="@dimen/sud_description_glif_margin_top"
android:paddingBottom="@dimen/sud_description_glif_margin_bottom_lists"
android:text="@string/setup_lock_settings_picker_message" />

View File

@@ -147,7 +147,7 @@
<string name="bluetooth_call_title">Audio during calls</string>
<!-- Bluetooth audio output settings. Title of the option managing media audio path. [CHAR LIMIT=30] -->
<string name="bluetooth_media_title">Media</string>
<!-- Bluetooth audio output settings. Title of the option managing system sounds related audio path. [CHAR LIMIT=30] -->
<!-- Bluetooth audio output settings. Title of the option managing system sounds related audio path. [CHAR LIMIT=60] -->
<string name="bluetooth_system_sounds_title">Notifications and other system sounds</string>
<!-- Description for text in accessibility hearing aids footer. [CHAR LIMIT=NONE] -->
<string name="bluetooth_audio_routing_footer_summary">By default, audio output is determined by individual apps</string>

View File

@@ -28,7 +28,6 @@ import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.applications.AppInfoBase;
import com.android.settings.applications.AppLocaleUtil;
import com.android.settings.localepicker.AppLocalePickerActivity;
@@ -72,7 +71,6 @@ public class AppLocalePreferenceController extends AppInfoPreferenceControllerBa
if (mParent != null) {
Intent intent = new Intent(mContext, AppLocalePickerActivity.class);
intent.setData(Uri.parse("package:" + mParent.getAppEntry().info.packageName));
intent.putExtra(AppInfoBase.ARG_PACKAGE_UID, mParent.getAppEntry().info.uid);
mContext.startActivity(intent);
return true;
} else {

View File

@@ -709,8 +709,8 @@ public class ManageApplications extends InstrumentedFragment
case LIST_TYPE_APPS_LOCALE:
Intent intent = new Intent(getContext(), AppLocalePickerActivity.class);
intent.setData(Uri.parse("package:" + mCurrentPkgName));
intent.putExtra(AppInfoBase.ARG_PACKAGE_UID, mCurrentUid);
startActivity(intent);
getContext().startActivityAsUser(intent,
UserHandle.getUserHandleForUid(mCurrentUid));
break;
case LIST_TYPE_BATTERY_OPTIMIZATION:
AdvancedPowerUsageDetail.startBatteryDetailPage(

View File

@@ -185,7 +185,9 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase
mUserManager = getUserManager();
updatePasswordQuality();
if (!mConfirmingCredentials) {
// Check isFinishing() because FaceEnrollIntroduction may finish self to launch
// FaceSettings during onCreate()
if (!mConfirmingCredentials && !isFinishing()) {
if (!mHasPassword) {
// No password registered, launch into enrollment wizard.
mConfirmingCredentials = true;

View File

@@ -28,6 +28,7 @@ import android.hardware.SensorPrivacyManager;
import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.face.FaceManager;
import android.os.Bundle;
import android.os.UserHandle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
@@ -42,6 +43,7 @@ import androidx.annotation.StringRes;
import androidx.annotation.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.Settings;
import com.android.settings.Utils;
import com.android.settings.biometrics.BiometricEnrollActivity;
import com.android.settings.biometrics.BiometricEnrollIntroduction;
@@ -110,8 +112,26 @@ public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
@Override
protected void onCreate(Bundle savedInstanceState) {
mFaceManager = getFaceManager();
if (savedInstanceState == null
&& !WizardManagerHelper.isAnySetupWizard(getIntent())
&& !getIntent().getBooleanExtra(EXTRA_FROM_SETTINGS_SUMMARY, false)
&& maxFacesEnrolled()) {
// from tips && maxEnrolled
Log.d(TAG, "launch face settings");
launchFaceSettingsActivity();
finish();
}
super.onCreate(savedInstanceState);
// Wait super::onCreated() then return because SuperNotCalledExceptio will be thrown
// if we don't wait for it.
if (isFinishing()) {
return;
}
// Apply extracted theme color to icons.
final ImageView iconGlasses = findViewById(R.id.icon_glasses);
final ImageView iconLooking = findViewById(R.id.icon_looking);
@@ -152,8 +172,6 @@ public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
infoMessageRequireEyes.setText(getInfoMessageRequireEyes());
}
mFaceManager = getFaceManager();
// This path is an entry point for SetNewPasswordController, e.g.
// adb shell am start -a android.app.action.SET_NEW_PASSWORD
if (mToken == null && BiometricUtils.containsGatekeeperPasswordHandle(getIntent())) {
@@ -191,6 +209,24 @@ public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
Log.v(TAG, "cameraPrivacyEnabled : " + cameraPrivacyEnabled);
}
private void launchFaceSettingsActivity() {
final Intent intent = new Intent(this, Settings.FaceSettingsInternalActivity.class);
final byte[] token = getIntent().getByteArrayExtra(
ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
if (token != null) {
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token);
}
final int userId = getIntent().getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId());
if (userId != UserHandle.USER_NULL) {
intent.putExtra(Intent.EXTRA_USER_ID, userId);
}
BiometricUtils.copyMultiBiometricExtras(getIntent(), intent);
intent.putExtra(EXTRA_FROM_SETTINGS_SUMMARY, true);
intent.putExtra(EXTRA_KEY_CHALLENGE, getIntent().getLongExtra(EXTRA_KEY_CHALLENGE, -1L));
intent.putExtra(EXTRA_KEY_SENSOR_ID, getIntent().getIntExtra(EXTRA_KEY_SENSOR_ID, -1));
startActivity(intent);
}
@VisibleForTesting
@Nullable
protected FaceManager getFaceManager() {
@@ -232,6 +268,15 @@ public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
@Override
protected void onStart() {
super.onStart();
listenFoldEventForPostureGuidance();
}
private void listenFoldEventForPostureGuidance() {
if (maxFacesEnrolled()) {
Log.d(TAG, "Device has enrolled face, do not show posture guidance");
return;
}
if (getPostureGuidanceIntent() == null) {
Log.d(TAG, "Device do not support posture guidance");
return;

View File

@@ -18,12 +18,10 @@ package com.android.settings.localepicker;
import android.app.FragmentTransaction;
import android.app.LocaleManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.LocaleList;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.Log;
import android.view.MenuItem;
@@ -34,7 +32,6 @@ import android.widget.ListView;
import com.android.internal.app.LocalePickerWithRegion;
import com.android.internal.app.LocaleStore;
import com.android.settings.R;
import com.android.settings.applications.AppInfoBase;
import com.android.settings.applications.AppLocaleUtil;
import com.android.settings.applications.appinfo.AppLocaleDetails;
import com.android.settings.core.SettingsBaseActivity;
@@ -46,7 +43,6 @@ public class AppLocalePickerActivity extends SettingsBaseActivity
private String mPackageName;
private LocalePickerWithRegion mLocalePickerWithRegion;
private AppLocaleDetails mAppLocaleDetails;
private Context mContextAsUser;
private View mAppLocaleDetailContainer;
@Override
@@ -64,16 +60,8 @@ public class AppLocalePickerActivity extends SettingsBaseActivity
finish();
return;
}
mContextAsUser = this;
if (getIntent().hasExtra(AppInfoBase.ARG_PACKAGE_UID)) {
int uid = getIntent().getIntExtra(AppInfoBase.ARG_PACKAGE_UID, -1);
if (uid != -1) {
UserHandle userHandle = UserHandle.getUserHandleForUid(uid);
mContextAsUser = createContextAsUser(userHandle, 0);
}
}
if (!canDisplayLocaleUi() || mContextAsUser.getUserId() != UserHandle.myUserId()) {
if (!canDisplayLocaleUi()) {
Log.w(TAG, "Not allow to display Locale Settings UI.");
finish();
return;
@@ -83,13 +71,13 @@ public class AppLocalePickerActivity extends SettingsBaseActivity
getActionBar().setDisplayHomeAsUpEnabled(true);
mLocalePickerWithRegion = LocalePickerWithRegion.createLanguagePicker(
mContextAsUser,
this,
this,
false /* translate only */,
null,
mPackageName,
this);
mAppLocaleDetails = AppLocaleDetails.newInstance(mPackageName, mContextAsUser.getUserId());
mAppLocaleDetails = AppLocaleDetails.newInstance(mPackageName, getUserId());
mAppLocaleDetailContainer = launchAppLocaleDetailsPage();
// Launch Locale picker part.
launchLocalePickerPage();
@@ -129,7 +117,7 @@ public class AppLocalePickerActivity extends SettingsBaseActivity
/** Sets the app's locale to the supplied language tag */
private void setAppDefaultLocale(String languageTag) {
Log.d(TAG, "setAppDefaultLocale: " + languageTag);
LocaleManager localeManager = mContextAsUser.getSystemService(LocaleManager.class);
LocaleManager localeManager = getSystemService(LocaleManager.class);
if (localeManager == null) {
Log.w(TAG, "LocaleManager is null, cannot set default app locale");
return;
@@ -172,8 +160,8 @@ public class AppLocalePickerActivity extends SettingsBaseActivity
private boolean canDisplayLocaleUi() {
try {
PackageManager packageManager = mContextAsUser.getPackageManager();
return AppLocaleUtil.canDisplayLocaleUi(mContextAsUser,
PackageManager packageManager = getPackageManager();
return AppLocaleUtil.canDisplayLocaleUi(this,
packageManager.getApplicationInfo(mPackageName, 0),
packageManager.queryIntentActivities(AppLocaleUtil.LAUNCHER_ENTRY_INTENT,
PackageManager.GET_META_DATA));

View File

@@ -108,6 +108,7 @@ public class SetupChooseLockGeneric extends ChooseLockGeneric {
super.onViewCreated(view, savedInstanceState);
GlifPreferenceLayout layout = (GlifPreferenceLayout) view;
layout.setDescriptionText(loadDescriptionText());
layout.setDividerItemDecoration(new SettingsDividerItemDecoration(getContext()));
layout.setDividerInset(getContext().getResources().getDimensionPixelSize(
R.dimen.sud_items_glif_text_divider_inset));
@@ -128,11 +129,9 @@ public class SetupChooseLockGeneric extends ChooseLockGeneric {
@Override
protected void addHeaderView() {
if (isForBiometric()) {
setHeaderView(R.layout.setup_choose_lock_generic_biometrics_header);
} else {
setHeaderView(R.layout.setup_choose_lock_generic_header);
}
// The original logic has been moved to onViewCreated and
// uses GlifLayout#setDescriptionText instead,
// keep empty body here since we won't call super method.
}
@Override
@@ -229,6 +228,12 @@ public class SetupChooseLockGeneric extends ChooseLockGeneric {
private boolean isForBiometric() {
return mForFingerprint || mForFace || mForBiometrics;
}
String loadDescriptionText() {
return getString(isForBiometric()
? R.string.lock_settings_picker_biometrics_added_security_message
: R.string.setup_lock_settings_picker_message);
}
}
public static class InternalActivity extends ChooseLockGeneric.InternalActivity {

View File

@@ -21,6 +21,7 @@ import android.content.Intent
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.net.Uri
import android.os.UserHandle
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.remember
@@ -94,9 +95,9 @@ class AppLanguagesListModel(private val context: Context) : AppListModel<AppLang
AppListItem {
val intent = Intent(context, AppLocalePickerActivity::class.java).apply {
data = Uri.parse("package:${record.app.packageName}")
this.putExtra("uid", record.app.uid)
}
context.startActivity(intent)
val userHandle : UserHandle = UserHandle.getUserHandleForUid(record.app.uid)
context.startActivityAsUser(intent, userHandle)
}
}
}

View File

@@ -51,6 +51,8 @@ import androidx.test.core.app.ApplicationProvider;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R;
import com.android.settings.Settings;
import com.android.settings.biometrics.BiometricEnrollBase;
import com.android.settings.biometrics.BiometricUtils;
import com.android.settings.password.ChooseLockSettingsHelper;
import com.android.settings.testutils.FakeFeatureFactory;
@@ -62,6 +64,7 @@ import com.android.settings.testutils.shadow.ShadowUtils;
import com.google.android.setupcompat.template.FooterBarMixin;
import com.google.android.setupcompat.template.FooterButton;
import com.google.android.setupcompat.util.WizardManagerHelper;
import com.google.android.setupdesign.GlifLayout;
import com.google.android.setupdesign.view.BottomScrollView;
@@ -168,6 +171,7 @@ public class FaceEnrollIntroductionTest {
@After
public void tearDown() {
ShadowUtils.reset();
ShadowLockPatternUtils.reset();
}
private void setupActivity() {
@@ -315,7 +319,7 @@ public class FaceEnrollIntroductionTest {
}
@Test
public void testFaceEnrollEducation_hasBottomScrollView() {
public void testFaceEnrollIntroduction_hasBottomScrollView() {
setupActivity();
BottomScrollView scrollView = getGlifLayout(mActivity).findViewById(R.id.sud_scroll_view);
@@ -387,7 +391,7 @@ public class FaceEnrollIntroductionTest {
}
@Test
public void testFaceEnrollEducation_onFoldedUpdated_folded() {
public void testFaceEnrollIntroduction_onFoldedUpdated_folded() {
final Configuration newConfig = new Configuration();
newConfig.smallestScreenWidthDp = DENSITY_DEFAULT;
setupActivityForPosture();
@@ -400,4 +404,97 @@ public class FaceEnrollIntroductionTest {
assertThat(mSpyActivity.getDevicePostureState()).isEqualTo(DEVICE_POSTURE_CLOSED);
}
@Test
public void testFaceEnrollIntroduction_maxFacesEnrolled_launchFaceSettings() {
setFaceManagerToHave(1 /* numEnrollments */);
final Intent intent = new Intent();
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]);
mController = Robolectric.buildActivity(TestFaceEnrollIntroduction.class, intent);
mActivity = (TestFaceEnrollIntroduction) mController.get();
mActivity.mOverrideFaceManager = mFaceManager;
mController.create();
ShadowActivity shadowActivity = Shadows.shadowOf(mActivity);
final Intent nextStartedActivity = shadowActivity.getNextStartedActivity();
assertThat(nextStartedActivity).isNotNull();
assertThat(nextStartedActivity.getComponent().getClassName())
.isEqualTo(Settings.FaceSettingsInternalActivity.class.getName());
}
@Test
public void testFaceEnrollIntroduction_maxFacesEnrolled_isSuw_notLaunchFaceSettings() {
setFaceManagerToHave(1 /* numEnrollments */);
ShadowLockPatternUtils.setActivePasswordQuality(PASSWORD_QUALITY_NUMERIC);
final Intent intent = new Intent();
intent.putExtra(WizardManagerHelper.EXTRA_IS_SETUP_FLOW, true);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]);
mController = Robolectric.buildActivity(TestFaceEnrollIntroduction.class, intent);
mActivity = (TestFaceEnrollIntroduction) mController.get();
mActivity.mOverrideFaceManager = mFaceManager;
mController.create();
ShadowActivity shadowActivity = Shadows.shadowOf(mActivity);
final Intent nextStartedActivity = shadowActivity.getNextStartedActivity();
assertThat(nextStartedActivity).isNull();
}
@Test
public void testFaceEnrollIntroduction_maxFacesEnrolled_fromSettings_notLaunchFaceSettings() {
setFaceManagerToHave(1 /* numEnrollments */);
ShadowLockPatternUtils.setActivePasswordQuality(PASSWORD_QUALITY_NUMERIC);
final Intent intent = new Intent();
intent.putExtra(BiometricEnrollBase.EXTRA_FROM_SETTINGS_SUMMARY, true);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]);
mController = Robolectric.buildActivity(TestFaceEnrollIntroduction.class, intent);
mActivity = (TestFaceEnrollIntroduction) mController.get();
mActivity.mOverrideFaceManager = mFaceManager;
mController.create();
ShadowActivity shadowActivity = Shadows.shadowOf(mActivity);
final Intent nextStartedActivity = shadowActivity.getNextStartedActivity();
assertThat(nextStartedActivity).isNull();
}
@Test
public void testFaceEnrollIntroduction_hasPostureCallback() {
when(mFakeFeatureFactory.mFaceFeatureProvider.getPostureGuidanceIntent(any()))
.thenReturn(new Intent());
setFaceManagerToHave(0 /* numEnrollments */);
ShadowLockPatternUtils.setActivePasswordQuality(PASSWORD_QUALITY_NUMERIC);
final Intent intent = new Intent();
intent.putExtra(BiometricEnrollBase.EXTRA_FROM_SETTINGS_SUMMARY, true);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]);
mController = Robolectric.buildActivity(TestFaceEnrollIntroduction.class, intent);
mActivity = (TestFaceEnrollIntroduction) mController.get();
mActivity.mOverrideFaceManager = mFaceManager;
mController.create();
mController.start();
assertThat(mActivity.getPostureCallback()).isNotNull();
}
@Test
public void testFaceEnrollIntroduction_maxFacesEnrolled_noPostureCallback() {
when(mFakeFeatureFactory.mFaceFeatureProvider.getPostureGuidanceIntent(any()))
.thenReturn(new Intent());
setFaceManagerToHave(1 /* numEnrollments */);
ShadowLockPatternUtils.setActivePasswordQuality(PASSWORD_QUALITY_NUMERIC);
final Intent intent = new Intent();
intent.putExtra(BiometricEnrollBase.EXTRA_FROM_SETTINGS_SUMMARY, true);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]);
mController = Robolectric.buildActivity(TestFaceEnrollIntroduction.class, intent);
mActivity = (TestFaceEnrollIntroduction) mController.get();
mActivity.mOverrideFaceManager = mFaceManager;
mController.create();
mController.start();
assertThat(mActivity.getPostureCallback()).isNull();
}
}

View File

@@ -75,7 +75,6 @@ import java.util.Locale;
shadows = {
AppLocalePickerActivityTest.ShadowApplicationPackageManager.class,
AppLocalePickerActivityTest.ShadowResources.class,
AppLocalePickerActivityTest.ShadowUserHandle.class,
})
public class AppLocalePickerActivityTest {
private static final String TEST_PACKAGE_NAME = "com.android.settings";
@@ -108,7 +107,6 @@ public class AppLocalePickerActivityTest {
ReflectionHelpers.setStaticField(AppLocaleUtil.class, "sLocaleConfig", null);
ShadowResources.setDisAllowPackage(false);
ShadowApplicationPackageManager.setNoLaunchEntry(false);
ShadowUserHandle.setUserId(0);
}
@Test
@@ -171,17 +169,6 @@ public class AppLocalePickerActivityTest {
assertThat(controller.get().isFinishing()).isTrue();
}
@Test
public void launchAppLocalePickerActivity_modifyAppLocalesOfAnotherUser_failed() {
ShadowUserHandle.setUserId(10);
ActivityController<TestAppLocalePickerActivity> controller =
initActivityController(true);
controller.create();
assertThat(controller.get().isFinishing()).isTrue();
}
@Test
public void launchAppLocalePickerActivity_intentWithoutPackageName_failed() {
ActivityController<TestAppLocalePickerActivity> controller =
@@ -292,17 +279,4 @@ public class AppLocalePickerActivityTest {
sDisAllowPackage = disAllowPackage;
}
}
@Implements(UserHandle.class)
public static class ShadowUserHandle {
private static int sUserId = 0;
private static void setUserId(int userId) {
sUserId = userId;
}
@Implementation
public static int getUserId(int userId) {
return sUserId;
}
}
}

View File

@@ -23,15 +23,20 @@ import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_R
import static com.google.common.truth.Truth.assertThat;
import static org.robolectric.Shadows.shadowOf;
import android.content.Intent;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import com.android.settings.password.SetupChooseLockGeneric.SetupChooseLockGenericFragment;
import com.android.settings.testutils.shadow.ShadowLockPatternUtils;
import com.android.settings.testutils.shadow.ShadowPasswordUtils;
import com.android.settings.testutils.shadow.ShadowUserManager;
import com.android.settings.testutils.shadow.ShadowUtils;
import com.google.android.setupdesign.GlifPreferenceLayout;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -41,6 +46,8 @@ import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowActivity;
import java.util.List;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {
ShadowUserManager.class,
@@ -78,4 +85,43 @@ public class SetupChooseLockGenericTest {
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
assertThat(shadowActivity.isFinishing()).isFalse();
}
@Test
public void setupChooseLockGenericUsingDescriptionTextOfGlifLayout() {
SetupChooseLockGenericFragment fragment = getFragmentOfSetupChooseLockGeneric(false);
GlifPreferenceLayout view = getViewOfSetupChooseLockGenericFragment(fragment);
assertThat(TextUtils.isEmpty(view.getDescriptionText())).isFalse();
assertThat(view.getDescriptionText().toString()).isEqualTo(fragment.loadDescriptionText());
}
@Test
public void setupChooseLockGenericUsingDescriptionTextOfGlifLayoutForBiometric() {
SetupChooseLockGenericFragment fragment = getFragmentOfSetupChooseLockGeneric(true);
GlifPreferenceLayout view = getViewOfSetupChooseLockGenericFragment(fragment);
assertThat(TextUtils.isEmpty(view.getDescriptionText())).isFalse();
assertThat(view.getDescriptionText().toString()).isEqualTo(fragment.loadDescriptionText());
}
private SetupChooseLockGenericFragment getFragmentOfSetupChooseLockGeneric(boolean biometric) {
ShadowPasswordUtils.addGrantedPermission(REQUEST_PASSWORD_COMPLEXITY);
Intent intent = new Intent("com.android.settings.SETUP_LOCK_SCREEN");
intent.putExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY, PASSWORD_COMPLEXITY_HIGH);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, biometric);
SetupChooseLockGeneric activity =
Robolectric.buildActivity(SetupChooseLockGeneric.class, intent).setup().get();
List<Fragment> fragments = activity.getSupportFragmentManager().getFragments();
assertThat(fragments).isNotNull();
assertThat(fragments.size()).isEqualTo(1);
assertThat(fragments.get(0)).isInstanceOf(SetupChooseLockGenericFragment.class);
return (SetupChooseLockGenericFragment) fragments.get(0);
}
private GlifPreferenceLayout getViewOfSetupChooseLockGenericFragment(
@NonNull SetupChooseLockGenericFragment fragment) {
assertThat(fragment.getView()).isNotNull();
assertThat(fragment.getView()).isInstanceOf(GlifPreferenceLayout.class);
return (GlifPreferenceLayout) fragment.getView();
}
}

View File

@@ -40,6 +40,7 @@ import java.util.Map;
public class ShadowLockPatternUtils {
private static boolean sDeviceEncryptionEnabled;
private static Map<Integer, Integer> sUserToActivePasswordQualityMap = new HashMap<>();
private static Map<Integer, Integer> sUserToComplexityMap = new HashMap<>();
private static Map<Integer, Integer> sUserToProfileComplexityMap = new HashMap<>();
private static Map<Integer, PasswordMetrics> sUserToMetricsMap = new HashMap<>();
@@ -54,6 +55,7 @@ public class ShadowLockPatternUtils {
@Resetter
public static void reset() {
sUserToActivePasswordQualityMap.clear();
sUserToComplexityMap.clear();
sUserToProfileComplexityMap.clear();
sUserToMetricsMap.clear();
@@ -87,8 +89,12 @@ public class ShadowLockPatternUtils {
@Implementation
protected int getActivePasswordQuality(int userId) {
final Integer activePasswordQuality = sUserToActivePasswordQualityMap.get(userId);
if (activePasswordQuality == null) {
return DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
}
return activePasswordQuality;
}
@Implementation
protected int getKeyguardStoredPasswordQuality(int userHandle) {
@@ -227,6 +233,10 @@ public class ShadowLockPatternUtils {
sUserToProfileMetricsMap.put(UserHandle.myUserId(), metrics);
}
public static void setActivePasswordQuality(int quality) {
sUserToActivePasswordQualityMap.put(UserHandle.myUserId(), quality);
}
@Implementation
public boolean isLockScreenDisabled(int userId) {
return false;