diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 6ac1ac9d1b1..c42f06478f9 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -3751,6 +3751,25 @@ android:launchMode="singleTask"> + + + + + + + + + + + diff --git a/res/drawable/ic_battery_low.xml b/res/drawable/ic_battery_low.xml new file mode 100644 index 00000000000..82f9546d28e --- /dev/null +++ b/res/drawable/ic_battery_low.xml @@ -0,0 +1,28 @@ + + + + + + diff --git a/res/layout/manage_applications_apps_v2.xml b/res/layout/manage_applications_apps_v2.xml index ecc764a9217..72c8ee8f3cb 100644 --- a/res/layout/manage_applications_apps_v2.xml +++ b/res/layout/manage_applications_apps_v2.xml @@ -48,7 +48,7 @@ android:id="@android:id/empty" android:layout_width="match_parent" android:layout_height="match_parent" - android:gravity="center" + android:gravity="bottom|center_horizontal" android:layout_gravity="center" android:text="@string/no_applications" android:textAppearance="?android:attr/textAppearanceLarge" diff --git a/res/values/attrs.xml b/res/values/attrs.xml index f78120c7e78..bde52886e69 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -170,6 +170,7 @@ + diff --git a/res/values/strings.xml b/res/values/strings.xml index 9fe106b149a..865a8d46f93 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -2836,7 +2836,9 @@ Camera access needed - Tap to manage permissions for Device Personalization Services + Camera access is required for screen attention. Tap to manage permissions for Device Personalization Services + + Manage permissions Prevents your screen from turning off if you\u2019re looking at it @@ -4059,18 +4061,8 @@ Location services for work - - Use location to set time zone - - Location time zone detection - - Allows the device\u2019s location to be used to detect the current time zone. Other location settings such as Wi\u2011Fi scanning can affect the accuracy of time zone detection. - - - On - - Off + + Use location to set time zone @@ -7841,10 +7833,10 @@ dim screen, touchscreen, battery, smart brightness, dynamic brightness, Auto brightness - dim screen, sleep, battery, timeout, attention, display, screen, inactivity + smart, dim screen, sleep, battery, timeout, attention, display, screen, inactivity - rotate, flip, rotation, portrait, landscape, orientation, vertical, horizontal + camera, smart, auto rotate, auto-rotate, rotate, flip, rotation, portrait, landscape, orientation, vertical, horizontal upgrade, android diff --git a/res/xml/date_time_prefs.xml b/res/xml/date_time_prefs.xml index 43a797a4b0c..6fc0b25d1d5 100644 --- a/res/xml/date_time_prefs.xml +++ b/res/xml/date_time_prefs.xml @@ -53,12 +53,12 @@ settings:keywords="@string/keywords_time_zone"/> - + settings:userRestriction="no_config_date_time" + /> - - - - - - - diff --git a/src/com/android/settings/ActivityPicker.java b/src/com/android/settings/ActivityPicker.java index ae61944cbe1..f75ce3740aa 100644 --- a/src/com/android/settings/ActivityPicker.java +++ b/src/com/android/settings/ActivityPicker.java @@ -16,6 +16,8 @@ package com.android.settings; +import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS; + import android.app.Activity; import android.content.Context; import android.content.DialogInterface; @@ -71,6 +73,8 @@ public class ActivityPicker extends AlertActivity implements @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + getWindow().addPrivateFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS); final Intent intent = getIntent(); diff --git a/src/com/android/settings/biometrics/BiometricEnrollBase.java b/src/com/android/settings/biometrics/BiometricEnrollBase.java index 3fb89411190..67148d141ba 100644 --- a/src/com/android/settings/biometrics/BiometricEnrollBase.java +++ b/src/com/android/settings/biometrics/BiometricEnrollBase.java @@ -48,6 +48,8 @@ public abstract class BiometricEnrollBase extends InstrumentedActivity { public static final String EXTRA_KEY_LAUNCHED_CONFIRM = "launched_confirm_lock"; public static final String EXTRA_KEY_REQUIRE_VISION = "accessibility_vision"; public static final String EXTRA_KEY_REQUIRE_DIVERSITY = "accessibility_diversity"; + public static final String EXTRA_KEY_SENSOR_ID = "sensor_id"; + public static final String EXTRA_KEY_CHALLENGE = "challenge"; /** * Used by the choose fingerprint wizard to indicate the wizard is @@ -90,12 +92,16 @@ public abstract class BiometricEnrollBase extends InstrumentedActivity { protected boolean mLaunchedConfirmLock; protected byte[] mToken; protected int mUserId; + protected int mSensorId; + protected long mChallenge; protected boolean mFromSettingsSummary; protected FooterBarMixin mFooterBarMixin; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + mChallenge = getIntent().getLongExtra(EXTRA_KEY_CHALLENGE, -1L); + mSensorId = getIntent().getIntExtra(EXTRA_KEY_SENSOR_ID, -1); // Don't need to retrieve the HAT if it already exists. In some cases, the extras do not // contain EXTRA_KEY_CHALLENGE_TOKEN but contain EXTRA_KEY_GK_PW, in which case enrollment // classes may request a HAT to be created (as opposed to being passed in) @@ -110,6 +116,8 @@ public abstract class BiometricEnrollBase extends InstrumentedActivity { ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN); mFromSettingsSummary = savedInstanceState.getBoolean(EXTRA_FROM_SETTINGS_SUMMARY, false); + mChallenge = savedInstanceState.getLong(EXTRA_KEY_CHALLENGE); + mSensorId = savedInstanceState.getInt(EXTRA_KEY_SENSOR_ID); } mUserId = getIntent().getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId()); } @@ -127,6 +135,8 @@ public abstract class BiometricEnrollBase extends InstrumentedActivity { outState.putBoolean(EXTRA_KEY_LAUNCHED_CONFIRM, mLaunchedConfirmLock); outState.putByteArray(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken); outState.putBoolean(EXTRA_FROM_SETTINGS_SUMMARY, mFromSettingsSummary); + outState.putLong(EXTRA_KEY_CHALLENGE, mChallenge); + outState.putInt(EXTRA_KEY_SENSOR_ID, mSensorId); } @Override @@ -173,10 +183,18 @@ public abstract class BiometricEnrollBase extends InstrumentedActivity { setHeaderText(resId, false /* force */); } + protected void setHeaderText(CharSequence title) { + getLayout().setHeaderText(title); + } + protected void setDescriptionText(int resId) { getLayout().setDescriptionText(resId); } + protected void setDescriptionText(CharSequence descriptionText) { + getLayout().setDescriptionText(descriptionText); + } + protected FooterButton getNextButton() { if (mFooterBarMixin != null) { return mFooterBarMixin.getPrimaryButton(); @@ -192,6 +210,8 @@ public abstract class BiometricEnrollBase extends InstrumentedActivity { intent.setClassName(SETTINGS_PACKAGE_NAME, FingerprintEnrollEnrolling.class.getName()); intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken); intent.putExtra(EXTRA_FROM_SETTINGS_SUMMARY, mFromSettingsSummary); + intent.putExtra(EXTRA_KEY_CHALLENGE, mChallenge); + intent.putExtra(EXTRA_KEY_SENSOR_ID, mSensorId); if (mUserId != UserHandle.USER_NULL) { intent.putExtra(Intent.EXTRA_USER_ID, mUserId); } diff --git a/src/com/android/settings/biometrics/BiometricEnrollIntroduction.java b/src/com/android/settings/biometrics/BiometricEnrollIntroduction.java index 09344b0d0dd..b44c2c9da1a 100644 --- a/src/com/android/settings/biometrics/BiometricEnrollIntroduction.java +++ b/src/com/android/settings/biometrics/BiometricEnrollIntroduction.java @@ -243,6 +243,8 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase } BiometricUtils.copyMultiBiometricExtras(getIntent(), intent); intent.putExtra(EXTRA_FROM_SETTINGS_SUMMARY, mFromSettingsSummary); + intent.putExtra(EXTRA_KEY_CHALLENGE, mChallenge); + intent.putExtra(EXTRA_KEY_SENSOR_ID, mSensorId); startActivityForResult(intent, BIOMETRIC_FIND_SENSOR_REQUEST); } @@ -262,6 +264,8 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase overridePendingTransition(R.anim.sud_slide_next_in, R.anim.sud_slide_next_out); getNextButton().setEnabled(false); getChallenge(((sensorId, challenge) -> { + mSensorId = sensorId; + mChallenge = challenge; mToken = BiometricUtils.requestGatekeeperHat(this, data, mUserId, challenge); BiometricUtils.removeGatekeeperPasswordHandle(this, data); getNextButton().setEnabled(true); @@ -276,6 +280,8 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase overridePendingTransition(R.anim.sud_slide_next_in, R.anim.sud_slide_next_out); getNextButton().setEnabled(false); getChallenge(((sensorId, challenge) -> { + mSensorId = sensorId; + mChallenge = challenge; mToken = BiometricUtils.requestGatekeeperHat(this, data, mUserId, challenge); BiometricUtils.removeGatekeeperPasswordHandle(this, data); getNextButton().setEnabled(true); diff --git a/src/com/android/settings/biometrics/BiometricsEnrollEnrolling.java b/src/com/android/settings/biometrics/BiometricsEnrollEnrolling.java index 9b86e78eff9..0bfe56e36a1 100644 --- a/src/com/android/settings/biometrics/BiometricsEnrollEnrolling.java +++ b/src/com/android/settings/biometrics/BiometricsEnrollEnrolling.java @@ -121,6 +121,8 @@ public abstract class BiometricsEnrollEnrolling extends BiometricEnrollBase | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token); + intent.putExtra(BiometricEnrollBase.EXTRA_KEY_SENSOR_ID, mSensorId); + intent.putExtra(BiometricEnrollBase.EXTRA_KEY_CHALLENGE, mChallenge); intent.putExtra(EXTRA_FROM_SETTINGS_SUMMARY, mFromSettingsSummary); if (mUserId != UserHandle.USER_NULL) { intent.putExtra(Intent.EXTRA_USER_ID, mUserId); diff --git a/src/com/android/settings/biometrics/MultiBiometricEnrollHelper.java b/src/com/android/settings/biometrics/MultiBiometricEnrollHelper.java index 1ea6b08ac20..84128e23e7b 100644 --- a/src/com/android/settings/biometrics/MultiBiometricEnrollHelper.java +++ b/src/com/android/settings/biometrics/MultiBiometricEnrollHelper.java @@ -72,6 +72,8 @@ public class MultiBiometricEnrollHelper { mGkPwHandle, mUserId, challenge); final Intent faceIntent = BiometricUtils.getFaceIntroIntent(mActivity, mActivity.getIntent()); + faceIntent.putExtra(BiometricEnrollBase.EXTRA_KEY_SENSOR_ID, sensorId); + faceIntent.putExtra(BiometricEnrollBase.EXTRA_KEY_CHALLENGE, challenge); if (mRequestEnrollFingerprint) { // Give FaceEnroll a pendingIntent pointing to fingerprint enrollment, so that it @@ -97,6 +99,8 @@ public class MultiBiometricEnrollHelper { mGkPwHandle, mUserId, challenge); final Intent intent = BiometricUtils.getFingerprintIntroIntent(mActivity, mActivity.getIntent()); + intent.putExtra(BiometricEnrollBase.EXTRA_KEY_SENSOR_ID, sensorId); + intent.putExtra(BiometricEnrollBase.EXTRA_KEY_CHALLENGE, challenge); BiometricUtils.launchEnrollForResult(mActivity, intent, REQUEST_FINGERPRINT_ENROLL, hardwareAuthToken, mGkPwHandle, mUserId); })); diff --git a/src/com/android/settings/biometrics/face/FaceEnrollEducation.java b/src/com/android/settings/biometrics/face/FaceEnrollEducation.java index 3e9fba281a9..6c5a4b473ed 100644 --- a/src/com/android/settings/biometrics/face/FaceEnrollEducation.java +++ b/src/com/android/settings/biometrics/face/FaceEnrollEducation.java @@ -183,6 +183,8 @@ public class FaceEnrollEducation extends BiometricEnrollBase { if (mUserId != UserHandle.USER_NULL) { intent.putExtra(Intent.EXTRA_USER_ID, mUserId); } + intent.putExtra(EXTRA_KEY_CHALLENGE, mChallenge); + intent.putExtra(EXTRA_KEY_SENSOR_ID, mSensorId); intent.putExtra(EXTRA_FROM_SETTINGS_SUMMARY, mFromSettingsSummary); BiometricUtils.copyMultiBiometricExtras(getIntent(), intent); final String flattenedString = getString(R.string.config_face_enroll); diff --git a/src/com/android/settings/biometrics/face/FaceEnrollIntroduction.java b/src/com/android/settings/biometrics/face/FaceEnrollIntroduction.java index 3bffbbf9cbf..9110292b2b3 100644 --- a/src/com/android/settings/biometrics/face/FaceEnrollIntroduction.java +++ b/src/com/android/settings/biometrics/face/FaceEnrollIntroduction.java @@ -112,6 +112,8 @@ public class FaceEnrollIntroduction extends BiometricEnrollIntroduction { // the challenge is ready. Let's just do this for now. mFaceManager.generateChallenge((sensorId, challenge) -> { mToken = BiometricUtils.requestGatekeeperHat(this, getIntent(), mUserId, challenge); + mSensorId = sensorId; + mChallenge = challenge; if (BiometricUtils.isMultiBiometricEnrollmentFlow(this)) { BiometricUtils.removeGatekeeperPasswordHandle(this, getIntent()); } diff --git a/src/com/android/settings/biometrics/face/FaceSettings.java b/src/com/android/settings/biometrics/face/FaceSettings.java index 775148532f2..038d448bfda 100644 --- a/src/com/android/settings/biometrics/face/FaceSettings.java +++ b/src/com/android/settings/biometrics/face/FaceSettings.java @@ -37,6 +37,7 @@ import androidx.preference.Preference; import com.android.settings.R; import com.android.settings.SettingsActivity; import com.android.settings.Utils; +import com.android.settings.biometrics.BiometricEnrollBase; import com.android.settings.biometrics.BiometricUtils; import com.android.settings.dashboard.DashboardFragment; import com.android.settings.overlay.FeatureFactory; @@ -67,6 +68,8 @@ public class FaceSettings extends DashboardFragment { private UserManager mUserManager; private FaceManager mFaceManager; private int mUserId; + private int mSensorId; + private long mChallenge; private byte[] mToken; private FaceSettingsAttentionPreferenceController mAttentionController; private FaceSettingsRemoveButtonPreferenceController mRemoveController; @@ -147,6 +150,8 @@ public class FaceSettings extends DashboardFragment { mUserManager = context.getSystemService(UserManager.class); mFaceManager = context.getSystemService(FaceManager.class); mToken = getIntent().getByteArrayExtra(KEY_TOKEN); + mSensorId = getIntent().getIntExtra(BiometricEnrollBase.EXTRA_KEY_SENSOR_ID, -1); + mChallenge = getIntent().getLongExtra(BiometricEnrollBase.EXTRA_KEY_CHALLENGE, 0L); mUserId = getActivity().getIntent().getIntExtra( Intent.EXTRA_USER_ID, UserHandle.myUserId()); @@ -247,6 +252,8 @@ public class FaceSettings extends DashboardFragment { mFaceManager.generateChallenge((sensorId, challenge) -> { mToken = BiometricUtils.requestGatekeeperHat(getPrefContext(), data, mUserId, challenge); + mSensorId = sensorId; + mChallenge = challenge; BiometricUtils.removeGatekeeperPasswordHandle(getPrefContext(), data); mAttentionController.setToken(mToken); mEnrollController.setToken(mToken); @@ -269,7 +276,7 @@ public class FaceSettings extends DashboardFragment { && !mConfirmingPassword) { // Revoke challenge and finish if (mToken != null) { - mFaceManager.revokeChallenge(); + mFaceManager.revokeChallenge(mSensorId, mUserId, mChallenge); mToken = null; } finish(); diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java index b403e420189..10b31e331b9 100644 --- a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java +++ b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java @@ -324,7 +324,9 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling { @Override public void onEnrollmentHelp(int helpMsgId, CharSequence helpString) { if (!TextUtils.isEmpty(helpString)) { - mErrorText.removeCallbacks(mTouchAgainRunnable); + if (!mCanAssumeUdfps) { + mErrorText.removeCallbacks(mTouchAgainRunnable); + } showError(helpString); } } @@ -345,7 +347,9 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling { } showErrorDialog(getText(msgId), errMsgId); stopIconAnimation(); - mErrorText.removeCallbacks(mTouchAgainRunnable); + if (!mCanAssumeUdfps) { + mErrorText.removeCallbacks(mTouchAgainRunnable); + } } @Override @@ -354,8 +358,10 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling { updateTitleAndDescription(); clearError(); animateFlash(); - mErrorText.removeCallbacks(mTouchAgainRunnable); - mErrorText.postDelayed(mTouchAgainRunnable, HINT_TIMEOUT_DURATION); + if (!mCanAssumeUdfps) { + mErrorText.removeCallbacks(mTouchAgainRunnable); + mErrorText.postDelayed(mTouchAgainRunnable, HINT_TIMEOUT_DURATION); + } } private void updateProgress(boolean animate) { @@ -397,22 +403,28 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling { } private void showError(CharSequence error) { - mErrorText.setText(error); - if (mErrorText.getVisibility() == View.INVISIBLE) { - mErrorText.setVisibility(View.VISIBLE); - mErrorText.setTranslationY(getResources().getDimensionPixelSize( - R.dimen.fingerprint_error_text_appear_distance)); - mErrorText.setAlpha(0f); - mErrorText.animate() - .alpha(1f) - .translationY(0f) - .setDuration(200) - .setInterpolator(mLinearOutSlowInInterpolator) - .start(); + if (mCanAssumeUdfps) { + setHeaderText(error); + // Show nothing for subtitle when getting an error message. + setDescriptionText(""); } else { - mErrorText.animate().cancel(); - mErrorText.setAlpha(1f); - mErrorText.setTranslationY(0f); + mErrorText.setText(error); + if (mErrorText.getVisibility() == View.INVISIBLE) { + mErrorText.setVisibility(View.VISIBLE); + mErrorText.setTranslationY(getResources().getDimensionPixelSize( + R.dimen.fingerprint_error_text_appear_distance)); + mErrorText.setAlpha(0f); + mErrorText.animate() + .alpha(1f) + .translationY(0f) + .setDuration(200) + .setInterpolator(mLinearOutSlowInInterpolator) + .start(); + } else { + mErrorText.animate().cancel(); + mErrorText.setAlpha(1f); + mErrorText.setTranslationY(0f); + } } if (isResumed()) { mVibrator.vibrate(VIBRATE_EFFECT_ERROR, FINGERPRINT_ENROLLING_SONFICATION_ATTRIBUTES); @@ -420,7 +432,7 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling { } private void clearError() { - if (mErrorText.getVisibility() == View.VISIBLE) { + if (!mCanAssumeUdfps && mErrorText.getVisibility() == View.VISIBLE) { mErrorText.animate() .alpha(0f) .translationY(getResources().getDimensionPixelSize( diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensor.java b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensor.java index 094336a5c84..94eb2780bee 100644 --- a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensor.java +++ b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensor.java @@ -81,6 +81,8 @@ public class FingerprintEnrollFindSensor extends BiometricEnrollBase { if (mToken == null && BiometricUtils.containsGatekeeperPasswordHandle(getIntent())) { final FingerprintManager fpm = getSystemService(FingerprintManager.class); fpm.generateChallenge(mUserId, (sensorId, challenge) -> { + mChallenge = challenge; + mSensorId = sensorId; mToken = BiometricUtils.requestGatekeeperHat(this, getIntent(), mUserId, challenge); BiometricUtils.removeGatekeeperPasswordHandle(this, getIntent()); diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFinish.java b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFinish.java index 481da1ba071..a989eef93f7 100644 --- a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFinish.java +++ b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFinish.java @@ -141,7 +141,7 @@ public class FingerprintEnrollFinish extends BiometricEnrollBase { private void postEnroll() { final FingerprintManager fpm = Utils.getFingerprintManagerOrNull(this); if (fpm != null) { - fpm.revokeChallenge(mUserId); + fpm.revokeChallenge(mUserId, mChallenge); } } @@ -151,6 +151,7 @@ public class FingerprintEnrollFinish extends BiometricEnrollBase { intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra(Intent.EXTRA_USER_ID, mUserId); + intent.putExtra(BiometricEnrollBase.EXTRA_KEY_CHALLENGE, mChallenge); startActivity(intent); } diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java b/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java index 1d2793ad125..3e0591f81a0 100644 --- a/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java +++ b/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java @@ -138,6 +138,8 @@ public class FingerprintSettings extends SubSettings { private CharSequence mFooterTitle; private boolean mEnrollClicked; + private long mChallenge; + private static final String TAG_AUTHENTICATE_SIDECAR = "authenticate_sidecar"; private static final String TAG_REMOVAL_SIDECAR = "removal_sidecar"; private FingerprintAuthenticateSidecar mAuthenticateSidecar; @@ -287,6 +289,8 @@ public class FingerprintSettings extends SubSettings { mToken = getIntent().getByteArrayExtra( ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN); + mChallenge = activity.getIntent() + .getLongExtra(BiometricEnrollBase.EXTRA_KEY_CHALLENGE, -1L); mAuthenticateSidecar = (FingerprintAuthenticateSidecar) getFragmentManager().findFragmentByTag(TAG_AUTHENTICATE_SIDECAR); @@ -577,6 +581,7 @@ public class FingerprintSettings extends SubSettings { mFingerprintManager.generateChallenge(mUserId, (sensorId, challenge) -> { mToken = BiometricUtils.requestGatekeeperHat(getActivity(), data, mUserId, challenge); + mChallenge = challenge; BiometricUtils.removeGatekeeperPasswordHandle(getActivity(), data); updateAddPreference(); }); @@ -602,7 +607,7 @@ public class FingerprintSettings extends SubSettings { public void onDestroy() { super.onDestroy(); if (getActivity().isFinishing()) { - mFingerprintManager.revokeChallenge(mUserId); + mFingerprintManager.revokeChallenge(mUserId, mChallenge); } } diff --git a/src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollFindSensor.java b/src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollFindSensor.java index 394b6733786..5f2fbb553db 100644 --- a/src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollFindSensor.java +++ b/src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollFindSensor.java @@ -40,6 +40,8 @@ public class SetupFingerprintEnrollFindSensor extends FingerprintEnrollFindSenso protected Intent getFingerprintEnrollingIntent() { Intent intent = new Intent(this, SetupFingerprintEnrollEnrolling.class); intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken); + intent.putExtra(EXTRA_KEY_CHALLENGE, mChallenge); + intent.putExtra(EXTRA_KEY_SENSOR_ID, mSensorId); if (mUserId != UserHandle.USER_NULL) { intent.putExtra(Intent.EXTRA_USER_ID, mUserId); } diff --git a/src/com/android/settings/datetime/LocationTimeZoneDetectionPreferenceController.java b/src/com/android/settings/datetime/LocationTimeZoneDetectionPreferenceController.java index bbfbb193e17..1a45640c1df 100644 --- a/src/com/android/settings/datetime/LocationTimeZoneDetectionPreferenceController.java +++ b/src/com/android/settings/datetime/LocationTimeZoneDetectionPreferenceController.java @@ -31,7 +31,7 @@ import androidx.preference.Preference; import androidx.preference.PreferenceScreen; import com.android.settings.R; -import com.android.settings.core.BasePreferenceController; +import com.android.settings.core.TogglePreferenceController; import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnStart; import com.android.settingslib.core.lifecycle.events.OnStop; @@ -43,7 +43,7 @@ import java.util.concurrent.Executor; * screen. */ public class LocationTimeZoneDetectionPreferenceController - extends BasePreferenceController + extends TogglePreferenceController implements LifecycleObserver, OnStart, OnStop, TimeManager.TimeZoneDetectorListener { private final TimeManager mTimeManager; @@ -57,6 +57,22 @@ public class LocationTimeZoneDetectionPreferenceController mLocationManager = context.getSystemService(LocationManager.class); } + @Override + public boolean isChecked() { + TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = + mTimeManager.getTimeZoneCapabilitiesAndConfig(); + TimeZoneConfiguration configuration = capabilitiesAndConfig.getConfiguration(); + return configuration.isGeoDetectionEnabled(); + } + + @Override + public boolean setChecked(boolean isChecked) { + TimeZoneConfiguration configuration = new TimeZoneConfiguration.Builder() + .setGeoDetectionEnabled(isChecked) + .build(); + return mTimeManager.updateTimeZoneConfiguration(configuration); + } + @Override public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); @@ -126,10 +142,10 @@ public class LocationTimeZoneDetectionPreferenceController summaryResId = R.string.location_time_zone_detection_not_applicable; } } else if (configureGeoDetectionEnabledCapability == CAPABILITY_POSSESSED) { - boolean isGeoDetectionEnabled = configuration.isGeoDetectionEnabled(); - summaryResId = isGeoDetectionEnabled - ? R.string.location_time_zone_detection_on - : R.string.location_time_zone_detection_off; + // If capability is possessed, toggle status already tells all the information needed. + // Returning null will make previous text stick on toggling. + // See AbstractPreferenceController#refreshSummary. + return ""; } else { // This is unexpected: getAvailabilityStatus() should ensure that the UI element isn't // even shown for known cases, or the capability is unknown. diff --git a/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionSettings.java b/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionSettings.java deleted file mode 100644 index db6ffc40e33..00000000000 --- a/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionSettings.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2020 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. - */ -package com.android.settings.datetime.locationtimezone; - -import android.app.settings.SettingsEnums; - -import com.android.settings.R; -import com.android.settings.dashboard.DashboardFragment; -import com.android.settings.search.BaseSearchIndexProvider; -import com.android.settingslib.search.SearchIndexable; - -/** - * The controller for the "location time zone detection" screen. - */ -@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC) -public class TimeZoneDetectionSettings extends DashboardFragment { - private static final String TAG = "LTZDetectionSettings"; - - @Override - public int getMetricsCategory() { - return SettingsEnums.LOCATION_TIME_ZONE_DETECTION; - } - - @Override - protected int getPreferenceScreenResId() { - return R.xml.location_time_zone_detection; - } - - @Override - protected String getLogTag() { - return TAG; - } - - /** - * For Search. - */ - public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = - new BaseSearchIndexProvider(R.xml.location_time_zone_detection); -} diff --git a/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionTogglePreferenceController.java b/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionTogglePreferenceController.java deleted file mode 100644 index c91be7f1ed5..00000000000 --- a/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionTogglePreferenceController.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2020 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. - */ - -package com.android.settings.datetime.locationtimezone; - -import android.app.time.TimeManager; -import android.app.time.TimeZoneCapabilitiesAndConfig; -import android.app.time.TimeZoneConfiguration; -import android.content.Context; - -import com.android.settings.core.TogglePreferenceController; - -/** - * The controller for the "location time zone detection" switch on the location time zone detection - * screen. - */ -public class TimeZoneDetectionTogglePreferenceController extends TogglePreferenceController { - - private final TimeManager mTimeManager; - - public TimeZoneDetectionTogglePreferenceController(Context context, String key) { - super(context, key); - mTimeManager = context.getSystemService(TimeManager.class); - } - - @Override - public int getAvailabilityStatus() { - return AVAILABLE; - } - - @Override - public boolean isChecked() { - TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = - mTimeManager.getTimeZoneCapabilitiesAndConfig(); - TimeZoneConfiguration configuration = capabilitiesAndConfig.getConfiguration(); - return configuration.isGeoDetectionEnabled(); - } - - @Override - public boolean setChecked(boolean isChecked) { - TimeZoneConfiguration configuration = new TimeZoneConfiguration.Builder() - .setGeoDetectionEnabled(isChecked) - .build(); - return mTimeManager.updateTimeZoneConfiguration(configuration); - } -} diff --git a/src/com/android/settings/display/AdaptiveSleepPermissionPreferenceController.java b/src/com/android/settings/display/AdaptiveSleepPermissionPreferenceController.java index 1110ad2b9ca..0d21e9caf80 100644 --- a/src/com/android/settings/display/AdaptiveSleepPermissionPreferenceController.java +++ b/src/com/android/settings/display/AdaptiveSleepPermissionPreferenceController.java @@ -23,11 +23,11 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; -import androidx.preference.Preference; import androidx.preference.PreferenceScreen; import com.android.internal.annotations.VisibleForTesting; import com.android.settings.R; +import com.android.settingslib.widget.BannerMessagePreference; /** * The controller of Screen attention's permission warning preference. The preference appears when @@ -35,8 +35,8 @@ import com.android.settings.R; */ public class AdaptiveSleepPermissionPreferenceController { @VisibleForTesting - Preference mPreference; - private PackageManager mPackageManager; + BannerMessagePreference mPreference; + private final PackageManager mPackageManager; public AdaptiveSleepPermissionPreferenceController(Context context) { final String packageName = context.getPackageManager().getAttentionServicePackageName(); @@ -44,13 +44,12 @@ public class AdaptiveSleepPermissionPreferenceController { final Intent intent = new Intent( android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS); intent.setData(Uri.parse("package:" + packageName)); - mPreference = new Preference(context); + mPreference = new BannerMessagePreference(context); mPreference.setTitle(R.string.adaptive_sleep_title_no_permission); mPreference.setSummary(R.string.adaptive_sleep_summary_no_permission); - mPreference.setIcon(R.drawable.ic_info_outline_24); - mPreference.setOnPreferenceClickListener(p -> { + mPreference.setPositiveButtonText(R.string.adaptive_sleep_manage_permission_button); + mPreference.setPositiveButtonOnClickListener(p -> { context.startActivity(intent); - return true; }); } diff --git a/src/com/android/settings/display/ScreenTimeoutSettings.java b/src/com/android/settings/display/ScreenTimeoutSettings.java index f9bb99ecf0d..3b0d333d5d2 100644 --- a/src/com/android/settings/display/ScreenTimeoutSettings.java +++ b/src/com/android/settings/display/ScreenTimeoutSettings.java @@ -23,7 +23,6 @@ import android.app.settings.SettingsEnums; import android.content.Context; import android.content.res.Resources; import android.graphics.drawable.Drawable; -import android.os.Bundle; import android.os.UserHandle; import android.provider.Settings; import android.text.SpannableString; @@ -39,8 +38,6 @@ import androidx.preference.PreferenceScreen; import com.android.settings.R; import com.android.settings.overlay.FeatureFactory; import com.android.settings.search.BaseSearchIndexProvider; -import com.android.settings.search.actionbar.SearchMenuController; -import com.android.settings.support.actionbar.HelpMenuController; import com.android.settings.support.actionbar.HelpResourceProvider; import com.android.settings.widget.RadioButtonPickerFragment; import com.android.settingslib.RestrictedLockUtils; @@ -91,13 +88,6 @@ public class ScreenTimeoutSettings extends RadioButtonPickerFragment implements .getMetricsFeatureProvider(); } - @Override - public void onCreate(Bundle icicle) { - super.onCreate(icicle); - SearchMenuController.init(this /* host */); - HelpMenuController.init(this /* host */); - } - @Override public void onAttach(Context context) { super.onAttach(context); diff --git a/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceController.java b/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceController.java index 4415e71c11c..51d74d5fc4a 100644 --- a/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceController.java +++ b/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceController.java @@ -21,10 +21,12 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.graphics.ColorFilter; import android.icu.text.NumberFormat; import android.os.BatteryManager; import android.os.PowerManager; import android.text.TextUtils; +import android.widget.ImageView; import androidx.annotation.VisibleForTesting; import androidx.preference.PreferenceFragmentCompat; @@ -60,6 +62,7 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController private Activity mActivity; private PreferenceFragmentCompat mHost; private Lifecycle mLifecycle; + private ColorFilter mAccentColorFilter; private final PowerManager mPowerManager; public BatteryHeaderPreferenceController(Context context, String key) { @@ -85,6 +88,9 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); mBatteryUsageProgressBarPref = screen.findPreference(getPreferenceKey()); + mAccentColorFilter = com.android.settings.Utils.getAlphaInvariantColorFilterForColor( + com.android.settings.Utils.getColorAttrDefaultColor( + mContext, android.R.attr.colorAccent)); if (com.android.settings.Utils.isBatteryPresent(mContext)) { quickUpdateHeaderPreference(); @@ -116,13 +122,12 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController } public void updateHeaderPreference(BatteryInfo info) { - - //TODO(b/179237746): Make progress bar widget support battery state icon - mBatteryUsageProgressBarPref.setUsageSummary( formatBatteryPercentageText(info.batteryLevel)); mBatteryUsageProgressBarPref.setTotalSummary(generateLabel(info)); mBatteryUsageProgressBarPref.setPercent(info.batteryLevel, BATTERY_MAX_LEVEL); + mBatteryUsageProgressBarPref.setCustomContent( + getBatteryIcon(!info.discharging, info.batteryLevel)); } /** @@ -139,14 +144,30 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController final boolean discharging = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) == 0; - //TODO(b/179237746): Make progress bar widget support battery state icon - mBatteryUsageProgressBarPref.setUsageSummary(formatBatteryPercentageText(batteryLevel)); mBatteryUsageProgressBarPref.setPercent(batteryLevel, BATTERY_MAX_LEVEL); + mBatteryUsageProgressBarPref.setCustomContent(getBatteryIcon(!discharging, batteryLevel)); } private CharSequence formatBatteryPercentageText(int batteryLevel) { return TextUtils.expandTemplate(mContext.getText(R.string.battery_header_title_alternate), NumberFormat.getIntegerInstance().format(batteryLevel)); } + + //TODO(b/179237746): Update the battery icon after receiving final asset + private ImageView getBatteryIcon(boolean isCharging, int batteryLevel) { + ImageView batteryIcon = new ImageView(mContext); + + if (batteryLevel <= (mContext.getResources().getInteger( + com.android.internal.R.integer.config_lowBatteryWarningLevel))) { + batteryIcon.setImageResource(R.drawable.ic_battery_low); + } else if (isCharging) { + batteryIcon.setColorFilter(mAccentColorFilter); + batteryIcon.setImageResource(R.drawable.ic_battery_charging_full); + } else { + batteryIcon = null; + } + + return batteryIcon; + } } diff --git a/src/com/android/settings/inputmethod/OWNERS b/src/com/android/settings/inputmethod/OWNERS index 9f333949ff1..556de5f978c 100644 --- a/src/com/android/settings/inputmethod/OWNERS +++ b/src/com/android/settings/inputmethod/OWNERS @@ -1,5 +1,7 @@ -# Default reviewers for this and subdirectories. -yukawa@google.com -michaelwr@google.com +# Bug component: 34867 +include platform/frameworks/base:/services/core/java/com/android/server/inputmethod/OWNERS -# Emergency approvers in case the above are not available \ No newline at end of file +# Settings for physical keyboard and game pad are better to be reviewed by the input team +per-file GameControllerPreferenceController.java = file: platform/frameworks/base:/services/core/java/com/android/server/input/OWNERS +per-file KeyboardLayoutPicker*.java = file: platform/frameworks/base:/services/core/java/com/android/server/input/OWNERS +per-file PhysicalKeyboard*.java = file: platform/frameworks/base:/services/core/java/com/android/server/input/OWNERS diff --git a/src/com/android/settings/widget/LabeledSeekBarPreference.java b/src/com/android/settings/widget/LabeledSeekBarPreference.java index e2b2d686988..3a9ac18beb0 100644 --- a/src/com/android/settings/widget/LabeledSeekBarPreference.java +++ b/src/com/android/settings/widget/LabeledSeekBarPreference.java @@ -18,6 +18,7 @@ package com.android.settings.widget; import android.content.Context; import android.content.res.TypedArray; +import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.widget.SeekBar; import android.widget.TextView; @@ -32,6 +33,7 @@ public class LabeledSeekBarPreference extends SeekBarPreference { private final int mTextStartId; private final int mTextEndId; + private final int mTickMarkId; private OnPreferenceChangeListener mStopListener; public LabeledSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr, @@ -48,6 +50,8 @@ public class LabeledSeekBarPreference extends SeekBarPreference { mTextEndId = styledAttrs.getResourceId( R.styleable.LabeledSeekBarPreference_textEnd, R.string.summary_placeholder); + mTickMarkId = styledAttrs.getResourceId( + R.styleable.LabeledSeekBarPreference_tickMark, /* defValue= */ 0); styledAttrs.recycle(); } @@ -65,6 +69,13 @@ public class LabeledSeekBarPreference extends SeekBarPreference { final TextView endText = (TextView) holder.findViewById(android.R.id.text2); startText.setText(mTextStartId); endText.setText(mTextEndId); + + if (mTickMarkId != 0) { + final Drawable tickMark = getContext().getDrawable(mTickMarkId); + final SeekBar seekBar = (SeekBar) holder.findViewById( + com.android.internal.R.id.seekbar); + seekBar.setTickMark(tickMark); + } } public void setOnPreferenceChangeStopListener(OnPreferenceChangeListener listener) { diff --git a/tests/robotests/src/com/android/settings/datetime/LocationTimeZoneDetectionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datetime/LocationTimeZoneDetectionPreferenceControllerTest.java index 07588691b00..ae200b9a709 100644 --- a/tests/robotests/src/com/android/settings/datetime/LocationTimeZoneDetectionPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/datetime/LocationTimeZoneDetectionPreferenceControllerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 The Android Open Source Project + * Copyright (C) 2020 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. @@ -23,6 +23,7 @@ import static android.app.time.TimeZoneCapabilities.CAPABILITY_POSSESSED; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.app.time.TimeManager; @@ -61,10 +62,34 @@ public class LocationTimeZoneDetectionPreferenceControllerTest { mController = new LocationTimeZoneDetectionPreferenceController(mContext, "key"); } + @Test + public void setChecked_withTrue_shouldUpdateSetting() { + // Simulate the UI being clicked. + mController.setChecked(true); + + // Verify the TimeManager was updated with the UI value. + TimeZoneConfiguration expectedConfiguration = new TimeZoneConfiguration.Builder() + .setGeoDetectionEnabled(true) + .build(); + verify(mTimeManager).updateTimeZoneConfiguration(expectedConfiguration); + } + + @Test + public void setChecked_withFalse_shouldUpdateSetting() { + // Simulate the UI being clicked. + mController.setChecked(false); + + // Verify the TimeManager was updated with the UI value. + TimeZoneConfiguration expectedConfiguration = new TimeZoneConfiguration.Builder() + .setGeoDetectionEnabled(false) + .build(); + verify(mTimeManager).updateTimeZoneConfiguration(expectedConfiguration); + } + @Test public void testLocationTimeZoneDetection_supported_shouldBeShown() { TimeZoneCapabilities capabilities = - createTimeZoneCapabilities(/* geoDetectionSupported= */ true); + createTimeZoneCapabilities(CAPABILITY_POSSESSED); TimeZoneConfiguration configuration = createTimeZoneConfig(/* geoDetectionEnabled= */ true); TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = new TimeZoneCapabilitiesAndConfig(capabilities, configuration); @@ -76,7 +101,7 @@ public class LocationTimeZoneDetectionPreferenceControllerTest { @Test public void testLocationTimeZoneDetection_unsupported_shouldNotBeShown() { TimeZoneCapabilities capabilities = - createTimeZoneCapabilities(/* geoDetectionSupported= */ false); + createTimeZoneCapabilities(CAPABILITY_NOT_SUPPORTED); TimeZoneConfiguration configuration = createTimeZoneConfig(/* geoDetectionEnabled= */ true); TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = new TimeZoneCapabilitiesAndConfig(capabilities, configuration); @@ -91,20 +116,34 @@ public class LocationTimeZoneDetectionPreferenceControllerTest { @Test public void testLocationTimeZoneDetection_summary_geoDetectionEnabled() { TimeZoneCapabilities capabilities = - createTimeZoneCapabilities(/* geoDetectionSupported= */ true); + createTimeZoneCapabilities(CAPABILITY_POSSESSED); TimeZoneConfiguration configuration = createTimeZoneConfig(/* geoDetectionEnabled= */ true); TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = new TimeZoneCapabilitiesAndConfig(capabilities, configuration); when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig); - assertThat(mController.getSummary()).isEqualTo( - mContext.getString(R.string.location_time_zone_detection_on)); + assertThat(mController.getSummary().toString()).isEmpty(); } - private static TimeZoneCapabilities createTimeZoneCapabilities(boolean geoDetectionSupported) { + @Test + public void testLocationTimeZoneDetection_toggleIsOn_whenGeoDetectionEnabledAnsMlsIsOff() { + TimeZoneCapabilities capabilities = + createTimeZoneCapabilities(CAPABILITY_NOT_APPLICABLE); + TimeZoneConfiguration configuration = createTimeZoneConfig(/* geoDetectionEnabled= */ true); + TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = + new TimeZoneCapabilitiesAndConfig(capabilities, configuration); + + when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig); + when(mLocationManager.isLocationEnabled()).thenReturn(false); + + assertThat(mController.isChecked()).isTrue(); + assertThat(mController.getSummary()).isEqualTo( + mContext.getString(R.string.location_app_permission_summary_location_off)); + } + + private static TimeZoneCapabilities createTimeZoneCapabilities( + @TimeZoneCapabilities.CapabilityState int geoDetectionCapability) { UserHandle arbitraryUserHandle = UserHandle.of(123); - int geoDetectionCapability = - geoDetectionSupported ? CAPABILITY_POSSESSED : CAPABILITY_NOT_SUPPORTED; return new TimeZoneCapabilities.Builder(arbitraryUserHandle) .setConfigureAutoDetectionEnabledCapability(CAPABILITY_POSSESSED) .setConfigureGeoDetectionEnabledCapability(geoDetectionCapability) diff --git a/tests/robotests/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionSettingsTest.java b/tests/robotests/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionSettingsTest.java deleted file mode 100644 index 9f164924133..00000000000 --- a/tests/robotests/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionSettingsTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2017 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. - */ - -package com.android.settings.datetime.locationtimezone; - -import static com.google.common.truth.Truth.assertThat; - -import android.content.Context; -import android.provider.SearchIndexableResource; - -import com.android.settings.R; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; -import org.robolectric.RuntimeEnvironment; - -import java.util.List; - -@RunWith(RobolectricTestRunner.class) -public class TimeZoneDetectionSettingsTest { - - private Context mContext; - - @Before - public void setUp() { - mContext = RuntimeEnvironment.application; - } - - @Test - public void searchProvider_shouldIndexDefaultXml() { - final List sir = - TimeZoneDetectionSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex( - mContext, /* enabled= */ true); - - assertThat(sir).hasSize(1); - assertThat(sir.get(0).xmlResId).isEqualTo(R.xml.location_time_zone_detection); - } -} diff --git a/tests/robotests/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionTogglePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionTogglePreferenceControllerTest.java deleted file mode 100644 index 27a985962a3..00000000000 --- a/tests/robotests/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionTogglePreferenceControllerTest.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (C) 2017 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. - */ -package com.android.settings.datetime.locationtimezone; - -import static android.app.time.TimeZoneCapabilities.CAPABILITY_NOT_APPLICABLE; -import static android.app.time.TimeZoneCapabilities.CAPABILITY_POSSESSED; - -import static com.google.common.truth.Truth.assertThat; - -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import android.app.time.TimeManager; -import android.app.time.TimeZoneCapabilities; -import android.app.time.TimeZoneCapabilitiesAndConfig; -import android.app.time.TimeZoneConfiguration; -import android.content.Context; -import android.os.UserHandle; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.robolectric.RobolectricTestRunner; - -@RunWith(RobolectricTestRunner.class) -public class TimeZoneDetectionTogglePreferenceControllerTest { - - private static final String PREF_KEY = "test_key"; - - @Mock - private Context mContext; - - @Mock - private TimeManager mTimeManager; - private TimeZoneDetectionTogglePreferenceController mController; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager); - - mController = new TimeZoneDetectionTogglePreferenceController(mContext, PREF_KEY); - } - - @Test - public void isAvailable_shouldReturnTrue() { - assertThat(mController.isAvailable()).isTrue(); - } - - @Test - public void isChecked_whenEnabled_shouldReturnTrue() { - when(mTimeManager.getTimeZoneCapabilitiesAndConfig()) - .thenReturn(createTimeZoneCapabilitiesAndConfig(true)); - - assertThat(mController.isChecked()).isTrue(); - } - - @Test - public void isChecked_whenDisabled_shouldReturnFalse() { - when(mTimeManager.getTimeZoneCapabilitiesAndConfig()) - .thenReturn(createTimeZoneCapabilitiesAndConfig(false)); - - assertThat(mController.isChecked()).isFalse(); - } - - @Test - public void setChecked_withTrue_shouldUpdateSetting() { - // Simulate the UI being clicked. - mController.setChecked(true); - - // Verify the TimeManager was updated with the UI value. - TimeZoneConfiguration expectedConfiguration = new TimeZoneConfiguration.Builder() - .setGeoDetectionEnabled(true) - .build(); - verify(mTimeManager).updateTimeZoneConfiguration(expectedConfiguration); - } - - @Test - public void setChecked_withFalse_shouldUpdateSetting() { - // Simulate the UI being clicked. - mController.setChecked(false); - - // Verify the TimeManager was updated with the UI value. - TimeZoneConfiguration expectedConfiguration = new TimeZoneConfiguration.Builder() - .setGeoDetectionEnabled(false) - .build(); - verify(mTimeManager).updateTimeZoneConfiguration(expectedConfiguration); - } - - private static TimeZoneCapabilitiesAndConfig createTimeZoneCapabilitiesAndConfig( - boolean geoDetectionEnabled) { - UserHandle arbitraryUserHandle = UserHandle.of(123); - TimeZoneCapabilities capabilities = new TimeZoneCapabilities.Builder(arbitraryUserHandle) - .setConfigureAutoDetectionEnabledCapability(CAPABILITY_POSSESSED) - .setConfigureGeoDetectionEnabledCapability(CAPABILITY_POSSESSED) - .setSuggestManualTimeZoneCapability(CAPABILITY_NOT_APPLICABLE) - .build(); - TimeZoneConfiguration configuration = new TimeZoneConfiguration.Builder() - .setAutoDetectionEnabled(true) - .setGeoDetectionEnabled(geoDetectionEnabled) - .build(); - return new TimeZoneCapabilitiesAndConfig(capabilities, configuration); - } -}