Snap for 8925421 from 6b806e31f9 to udc-release
Change-Id: If3dc5dc9301024b14ec387ed4e80dd3042e1e38b
This commit is contained in:
@@ -24,8 +24,6 @@ import android.view.View;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||
|
||||
import com.google.android.setupcompat.util.WizardManagerHelper;
|
||||
|
||||
/**
|
||||
* Abstract base activity which handles the actual enrolling for biometrics.
|
||||
*/
|
||||
@@ -62,30 +60,18 @@ public abstract class BiometricsEnrollEnrolling extends BiometricEnrollBase
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
|
||||
if (mSidecar != null) {
|
||||
mSidecar.setListener(null);
|
||||
}
|
||||
|
||||
if (!isChangingConfigurations()) {
|
||||
if (mSidecar != null) {
|
||||
mSidecar.cancelEnrollment();
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction().remove(mSidecar).commitAllowingStateLoss();
|
||||
}
|
||||
if (!WizardManagerHelper.isAnySetupWizard(getIntent())
|
||||
&& !BiometricUtils.isAnyMultiBiometricFlow(this)) {
|
||||
setResult(RESULT_TIMEOUT);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldFinishWhenBackgrounded() {
|
||||
// Prevent super.onStop() from finishing, since we handle this in our onStop().
|
||||
return false;
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,11 +31,13 @@ import com.android.settings.R;
|
||||
import com.android.settings.biometrics.BiometricEnrollBase;
|
||||
import com.android.settings.biometrics.BiometricEnrollSidecar;
|
||||
import com.android.settings.biometrics.BiometricErrorDialog;
|
||||
import com.android.settings.biometrics.BiometricUtils;
|
||||
import com.android.settings.biometrics.BiometricsEnrollEnrolling;
|
||||
import com.android.settings.slices.CustomSliceRegistry;
|
||||
|
||||
import com.google.android.setupcompat.template.FooterBarMixin;
|
||||
import com.google.android.setupcompat.template.FooterButton;
|
||||
import com.google.android.setupcompat.util.WizardManagerHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -112,6 +114,25 @@ public class FaceEnrollEnrolling extends BiometricsEnrollEnrolling {
|
||||
startEnrollment();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
if (!isChangingConfigurations()) {
|
||||
if (!WizardManagerHelper.isAnySetupWizard(getIntent())
|
||||
&& !BiometricUtils.isAnyMultiBiometricFlow(this)) {
|
||||
setResult(RESULT_TIMEOUT);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldFinishWhenBackgrounded() {
|
||||
// Prevent super.onStop() from finishing, since we handle this in our onStop().
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startEnrollment() {
|
||||
super.startEnrollment();
|
||||
|
||||
@@ -339,8 +339,23 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling {
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
if (!isChangingConfigurations()) {
|
||||
if (!WizardManagerHelper.isAnySetupWizard(getIntent())
|
||||
&& !BiometricUtils.isAnyMultiBiometricFlow(this)
|
||||
&& !mFromSettingsSummary) {
|
||||
setResult(RESULT_TIMEOUT);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
stopIconAnimation();
|
||||
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldFinishWhenBackgrounded() {
|
||||
// Prevent super.onStop() from finishing, since we handle this in our onStop().
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -49,8 +49,8 @@ import java.util.List;
|
||||
public class FingerprintEnrollFindSensor extends BiometricEnrollBase implements
|
||||
BiometricEnrollSidecar.Listener {
|
||||
|
||||
|
||||
private static final String TAG = "FingerprintEnrollFindSensor";
|
||||
private static final String SAVED_STATE_IS_NEXT_CLICKED = "is_next_clicked";
|
||||
|
||||
@Nullable
|
||||
private FingerprintFindSensorAnimation mAnimation;
|
||||
@@ -174,6 +174,15 @@ public class FingerprintEnrollFindSensor extends BiometricEnrollBase implements
|
||||
mAnimation = (FingerprintFindSensorAnimation) animationView;
|
||||
}
|
||||
}
|
||||
if (savedInstanceState != null) {
|
||||
mNextClicked = savedInstanceState.getBoolean(SAVED_STATE_IS_NEXT_CLICKED, mNextClicked);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putBoolean(SAVED_STATE_IS_NEXT_CLICKED, mNextClicked);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -240,7 +249,6 @@ public class FingerprintEnrollFindSensor extends BiometricEnrollBase implements
|
||||
@Override
|
||||
public void onEnrollmentError(int errMsgId, CharSequence errString) {
|
||||
if (mNextClicked && errMsgId == FingerprintManager.FINGERPRINT_ERROR_CANCELED) {
|
||||
mNextClicked = false;
|
||||
proceedToEnrolling(false /* cancelEnrollment */);
|
||||
} else {
|
||||
FingerprintErrorDialog.showErrorDialog(this, errMsgId);
|
||||
@@ -341,6 +349,7 @@ public class FingerprintEnrollFindSensor extends BiometricEnrollBase implements
|
||||
finish();
|
||||
} else {
|
||||
// We came back from enrolling but it wasn't completed, start again.
|
||||
mNextClicked = false;
|
||||
startLookingForFingerprint();
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -32,7 +32,6 @@ import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.biometrics.BiometricEnrollBase;
|
||||
import com.android.settings.biometrics.BiometricUtils;
|
||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||
|
||||
import com.google.android.setupcompat.template.FooterBarMixin;
|
||||
import com.google.android.setupcompat.template.FooterButton;
|
||||
@@ -114,9 +113,6 @@ public class FingerprintEnrollFinish extends BiometricEnrollBase {
|
||||
setResult(RESULT_FINISHED);
|
||||
if (WizardManagerHelper.isAnySetupWizard(getIntent())) {
|
||||
postEnroll();
|
||||
} else if (mFromSettingsSummary) {
|
||||
// Only launch fingerprint settings if enrollment was triggered through settings summary
|
||||
launchFingerprintSettings();
|
||||
}
|
||||
finish();
|
||||
}
|
||||
@@ -148,21 +144,15 @@ public class FingerprintEnrollFinish extends BiometricEnrollBase {
|
||||
}
|
||||
}
|
||||
|
||||
private void launchFingerprintSettings() {
|
||||
final Intent intent = new Intent(ACTION_FINGERPRINT_SETTINGS);
|
||||
intent.setPackage(Utils.SETTINGS_PACKAGE_NAME);
|
||||
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);
|
||||
overridePendingTransition(R.anim.sud_slide_back_in, R.anim.sud_slide_back_out);
|
||||
}
|
||||
|
||||
private void onAddAnotherButtonClick(View view) {
|
||||
startActivityForResult(getFingerprintEnrollingIntent(), BiometricUtils.REQUEST_ADD_ANOTHER);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldFinishWhenBackgrounded() {
|
||||
return !isFinishing() && super.shouldFinishWhenBackgrounded();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
updateFingerprintSuggestionEnableState();
|
||||
|
||||
@@ -22,6 +22,7 @@ import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROF
|
||||
import static android.app.admin.DevicePolicyResources.UNDEFINED;
|
||||
|
||||
import static com.android.settings.Utils.SETTINGS_PACKAGE_NAME;
|
||||
import static com.android.settings.biometrics.BiometricEnrollBase.EXTRA_FROM_SETTINGS_SUMMARY;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
@@ -62,6 +63,7 @@ import com.android.settings.SubSettings;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.biometrics.BiometricEnrollBase;
|
||||
import com.android.settings.biometrics.BiometricUtils;
|
||||
import com.android.settings.core.SettingsBaseActivity;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settings.password.ChooseLockGeneric;
|
||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||
@@ -69,6 +71,7 @@ import com.android.settingslib.HelpUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
import com.android.settingslib.transition.SettingsTransitionHelper;
|
||||
import com.android.settingslib.widget.FooterPreference;
|
||||
import com.android.settingslib.widget.TwoTargetPreference;
|
||||
|
||||
@@ -129,6 +132,8 @@ public class FingerprintSettings extends SubSettings {
|
||||
private static final String KEY_FINGERPRINT_ENABLE_KEYGUARD_TOGGLE =
|
||||
"fingerprint_enable_keyguard_toggle";
|
||||
private static final String KEY_LAUNCHED_CONFIRM = "launched_confirm";
|
||||
private static final String KEY_HAS_FIRST_ENROLLED = "has_first_enrolled";
|
||||
private static final String KEY_IS_ENROLLING = "is_enrolled";
|
||||
|
||||
private static final int MSG_REFRESH_FINGERPRINT_TEMPLATES = 1000;
|
||||
private static final int MSG_FINGER_AUTH_SUCCESS = 1001;
|
||||
@@ -140,6 +145,7 @@ public class FingerprintSettings extends SubSettings {
|
||||
private static final int CHOOSE_LOCK_GENERIC_REQUEST = 102;
|
||||
|
||||
private static final int ADD_FINGERPRINT_REQUEST = 10;
|
||||
private static final int AUTO_ADD_FIRST_FINGERPRINT_REQUEST = 11;
|
||||
|
||||
protected static final boolean DEBUG = false;
|
||||
|
||||
@@ -149,10 +155,11 @@ public class FingerprintSettings extends SubSettings {
|
||||
private boolean mInFingerprintLockout;
|
||||
private byte[] mToken;
|
||||
private boolean mLaunchedConfirm;
|
||||
private boolean mHasFirstEnrolled = true;
|
||||
private Drawable mHighlightDrawable;
|
||||
private int mUserId;
|
||||
private final List<FooterColumn> mFooterColumns = new ArrayList<>();
|
||||
private boolean mEnrollClicked;
|
||||
private boolean mIsEnrolling;
|
||||
|
||||
private long mChallenge;
|
||||
|
||||
@@ -341,6 +348,9 @@ public class FingerprintSettings extends SubSettings {
|
||||
}
|
||||
|
||||
mFingerprintsRenaming = new HashMap<Integer, String>();
|
||||
mUserId = getActivity().getIntent().getIntExtra(
|
||||
Intent.EXTRA_USER_ID, UserHandle.myUserId());
|
||||
mHasFirstEnrolled = mFingerprintManager.hasEnrolledFingerprints(mUserId);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
mFingerprintsRenaming = (HashMap<Integer, String>)
|
||||
@@ -349,9 +359,10 @@ public class FingerprintSettings extends SubSettings {
|
||||
ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
|
||||
mLaunchedConfirm = savedInstanceState.getBoolean(
|
||||
KEY_LAUNCHED_CONFIRM, false);
|
||||
mIsEnrolling = savedInstanceState.getBoolean(KEY_IS_ENROLLING, mIsEnrolling);
|
||||
mHasFirstEnrolled = savedInstanceState.getBoolean(KEY_HAS_FIRST_ENROLLED,
|
||||
mHasFirstEnrolled);
|
||||
}
|
||||
mUserId = getActivity().getIntent().getIntExtra(
|
||||
Intent.EXTRA_USER_ID, UserHandle.myUserId());
|
||||
|
||||
// Need to authenticate a session token if none
|
||||
if (mToken == null && mLaunchedConfirm == false) {
|
||||
@@ -546,7 +557,7 @@ public class FingerprintSettings extends SubSettings {
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
if (!getActivity().isChangingConfigurations() && !mLaunchedConfirm && !mEnrollClicked) {
|
||||
if (!getActivity().isChangingConfigurations() && !mLaunchedConfirm && !mIsEnrolling) {
|
||||
getActivity().finish();
|
||||
}
|
||||
}
|
||||
@@ -557,13 +568,15 @@ public class FingerprintSettings extends SubSettings {
|
||||
mToken);
|
||||
outState.putBoolean(KEY_LAUNCHED_CONFIRM, mLaunchedConfirm);
|
||||
outState.putSerializable("mFingerprintsRenaming", mFingerprintsRenaming);
|
||||
outState.putBoolean(KEY_IS_ENROLLING, mIsEnrolling);
|
||||
outState.putBoolean(KEY_HAS_FIRST_ENROLLED, mHasFirstEnrolled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(Preference pref) {
|
||||
final String key = pref.getKey();
|
||||
if (KEY_FINGERPRINT_ADD.equals(key)) {
|
||||
mEnrollClicked = true;
|
||||
mIsEnrolling = true;
|
||||
Intent intent = new Intent();
|
||||
intent.setClassName(SETTINGS_PACKAGE_NAME,
|
||||
FingerprintEnrollEnrolling.class.getName());
|
||||
@@ -659,6 +672,11 @@ public class FingerprintSettings extends SubSettings {
|
||||
BiometricUtils.removeGatekeeperPasswordHandle(getActivity(),
|
||||
data);
|
||||
updateAddPreference();
|
||||
if (!mHasFirstEnrolled && !mIsEnrolling) {
|
||||
mIsEnrolling = true;
|
||||
addFirstFingerprint(
|
||||
BiometricUtils.getGatekeeperPasswordHandle(data));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Log.d(TAG, "Data null or GK PW missing");
|
||||
@@ -669,12 +687,19 @@ public class FingerprintSettings extends SubSettings {
|
||||
finish();
|
||||
}
|
||||
} else if (requestCode == ADD_FINGERPRINT_REQUEST) {
|
||||
mEnrollClicked = false;
|
||||
mIsEnrolling = false;
|
||||
if (resultCode == RESULT_TIMEOUT) {
|
||||
Activity activity = getActivity();
|
||||
activity.setResult(resultCode);
|
||||
activity.finish();
|
||||
}
|
||||
} else if (requestCode == AUTO_ADD_FIRST_FINGERPRINT_REQUEST) {
|
||||
mIsEnrolling = false;
|
||||
mHasFirstEnrolled = false;
|
||||
if (resultCode != RESULT_FINISHED) {
|
||||
Log.d(TAG, "Add first fingerprint fail, result:" + resultCode);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -746,6 +771,23 @@ public class FingerprintSettings extends SubSettings {
|
||||
}
|
||||
}
|
||||
|
||||
private void addFirstFingerprint(@Nullable Long gkPwHandle) {
|
||||
Intent intent = new Intent();
|
||||
intent.setClassName(SETTINGS_PACKAGE_NAME,
|
||||
FingerprintEnrollIntroductionInternal.class.getName());
|
||||
|
||||
intent.putExtra(EXTRA_FROM_SETTINGS_SUMMARY, true);
|
||||
intent.putExtra(SettingsBaseActivity.EXTRA_PAGE_TRANSITION_TYPE,
|
||||
SettingsTransitionHelper.TransitionType.TRANSITION_SLIDE);
|
||||
|
||||
intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
|
||||
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
|
||||
if (gkPwHandle != null) {
|
||||
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_GK_PW_HANDLE, (long) gkPwHandle);
|
||||
}
|
||||
startActivityForResult(intent, AUTO_ADD_FIRST_FINGERPRINT_REQUEST);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void deleteFingerPrint(Fingerprint fingerPrint) {
|
||||
mRemovalSidecar.startRemove(fingerPrint, mUserId);
|
||||
|
||||
@@ -78,8 +78,7 @@ public class FingerprintStatusUtils {
|
||||
* Returns the class name of the Settings page corresponding to fingerprint settings.
|
||||
*/
|
||||
public String getSettingsClassName() {
|
||||
return hasEnrolled() ? FingerprintSettings.class.getName()
|
||||
: FingerprintEnrollIntroductionInternal.class.getName();
|
||||
return FingerprintSettings.class.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.content.Intent;
|
||||
import android.net.NetworkTemplate;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.telephony.data.ApnSetting;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
@@ -78,7 +79,7 @@ public class BillingCyclePreference extends Preference
|
||||
try {
|
||||
setEnabled(mServices.mNetworkService.isBandwidthControlEnabled()
|
||||
&& mServices.mTelephonyManager.createForSubscriptionId(mSubId)
|
||||
.isDataEnabledForApn(ApnSetting.TYPE_DEFAULT)
|
||||
.isDataEnabledForReason(TelephonyManager.DATA_ENABLED_REASON_USER)
|
||||
&& mServices.mUserManager.isAdminUser());
|
||||
} catch (RemoteException e) {
|
||||
setEnabled(false);
|
||||
|
||||
@@ -273,7 +273,7 @@ public class BatteryChartPreferenceControllerV2 extends AbstractPreferenceContro
|
||||
mDailyTimestampFullTexts = null;
|
||||
mDailyViewModel = null;
|
||||
mHourlyViewModels = null;
|
||||
addFooterPreferenceIfNeeded(false);
|
||||
refreshUi();
|
||||
return;
|
||||
}
|
||||
mDailyTimestampFullTexts = generateTimestampDayOfWeekTexts(
|
||||
@@ -284,7 +284,6 @@ public class BatteryChartPreferenceControllerV2 extends AbstractPreferenceContro
|
||||
generateTimestampDayOfWeekTexts(
|
||||
mContext, batteryLevelData.getDailyBatteryLevels().getTimestamps(),
|
||||
/* isAbbreviation= */ true),
|
||||
mDailyChartIndex,
|
||||
BatteryChartViewModel.AxisLabelPosition.CENTER_OF_TRAPEZOIDS);
|
||||
mHourlyViewModels = new ArrayList<>();
|
||||
for (BatteryLevelData.PeriodBatteryLevelData hourlyBatteryLevelsPerDay :
|
||||
@@ -293,7 +292,6 @@ public class BatteryChartPreferenceControllerV2 extends AbstractPreferenceContro
|
||||
hourlyBatteryLevelsPerDay.getLevels(),
|
||||
generateTimestampHourTexts(
|
||||
mContext, hourlyBatteryLevelsPerDay.getTimestamps()),
|
||||
mHourlyChartIndex,
|
||||
BatteryChartViewModel.AxisLabelPosition.BETWEEN_TRAPEZOIDS));
|
||||
}
|
||||
refreshUi();
|
||||
@@ -338,14 +336,20 @@ public class BatteryChartPreferenceControllerV2 extends AbstractPreferenceContro
|
||||
|
||||
@VisibleForTesting
|
||||
boolean refreshUi() {
|
||||
if (mBatteryUsageMap == null || mDailyChartView == null || mHourlyChartView == null) {
|
||||
if (mDailyChartView == null || mHourlyChartView == null) {
|
||||
// Chart views are not initialized.
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mDailyViewModel == null || mHourlyViewModels == null) {
|
||||
// Fail to get battery level data, show an empty hourly chart view.
|
||||
mDailyChartView.setVisibility(View.GONE);
|
||||
mHourlyChartView.setVisibility(View.VISIBLE);
|
||||
mHourlyChartView.setViewModel(null);
|
||||
addFooterPreferenceIfNeeded(false);
|
||||
return false;
|
||||
}
|
||||
if (mBatteryUsageMap == null) {
|
||||
// Battery usage data is not ready, wait for data ready to refresh UI.
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,22 +41,18 @@ class BatteryChartViewModel {
|
||||
private final List<Integer> mLevels;
|
||||
private final List<String> mTexts;
|
||||
private final AxisLabelPosition mAxisLabelPosition;
|
||||
private int mSelectedIndex;
|
||||
private int mSelectedIndex = SELECTED_INDEX_ALL;
|
||||
|
||||
BatteryChartViewModel(
|
||||
@NonNull List<Integer> levels, @NonNull List<String> texts, int selectedIndex,
|
||||
@NonNull List<Integer> levels, @NonNull List<String> texts,
|
||||
@NonNull AxisLabelPosition axisLabelPosition) {
|
||||
Preconditions.checkArgument(
|
||||
levels.size() == texts.size()
|
||||
&& levels.size() >= MIN_LEVELS_DATA_SIZE
|
||||
&& selectedIndex >= SELECTED_INDEX_ALL
|
||||
&& selectedIndex < levels.size(),
|
||||
String.format(Locale.ENGLISH, "Invalid BatteryChartViewModel"
|
||||
+ " levels.size: %d\ntexts.size: %d\nselectedIndex: %d.",
|
||||
levels.size(), texts.size(), selectedIndex));
|
||||
levels.size() == texts.size() && levels.size() >= MIN_LEVELS_DATA_SIZE,
|
||||
String.format(Locale.ENGLISH,
|
||||
"Invalid BatteryChartViewModel levels.size: %d, texts.size: %d.",
|
||||
levels.size(), texts.size()));
|
||||
mLevels = levels;
|
||||
mTexts = texts;
|
||||
mSelectedIndex = selectedIndex;
|
||||
mAxisLabelPosition = axisLabelPosition;
|
||||
}
|
||||
|
||||
@@ -72,6 +68,10 @@ class BatteryChartViewModel {
|
||||
return mTexts;
|
||||
}
|
||||
|
||||
public AxisLabelPosition axisLabelPosition() {
|
||||
return mAxisLabelPosition;
|
||||
}
|
||||
|
||||
public int selectedIndex() {
|
||||
return mSelectedIndex;
|
||||
}
|
||||
@@ -80,10 +80,6 @@ class BatteryChartViewModel {
|
||||
mSelectedIndex = index;
|
||||
}
|
||||
|
||||
public AxisLabelPosition axisLabelPosition() {
|
||||
return mAxisLabelPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(mLevels, mTexts, mSelectedIndex, mAxisLabelPosition);
|
||||
@@ -99,15 +95,15 @@ class BatteryChartViewModel {
|
||||
final BatteryChartViewModel batteryChartViewModel = (BatteryChartViewModel) other;
|
||||
return Objects.equals(mLevels, batteryChartViewModel.mLevels)
|
||||
&& Objects.equals(mTexts, batteryChartViewModel.mTexts)
|
||||
&& mSelectedIndex == batteryChartViewModel.mSelectedIndex
|
||||
&& mAxisLabelPosition == batteryChartViewModel.mAxisLabelPosition;
|
||||
&& mAxisLabelPosition == batteryChartViewModel.mAxisLabelPosition
|
||||
&& mSelectedIndex == batteryChartViewModel.mSelectedIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(Locale.ENGLISH,
|
||||
"levels: %s\ntexts: %s\nselectedIndex: %d, axisLabelPosition: %s",
|
||||
Objects.toString(mLevels), Objects.toString(mTexts), mSelectedIndex,
|
||||
mAxisLabelPosition);
|
||||
"levels: %s,\ntexts: %s,\naxisLabelPosition: %s, selectedIndex: %d",
|
||||
Objects.toString(mLevels), Objects.toString(mTexts), mAxisLabelPosition,
|
||||
mSelectedIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,12 +46,10 @@ import com.android.settings.R;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/** A widget component to draw chart graph. */
|
||||
public class BatteryChartViewV2 extends AppCompatImageView implements View.OnClickListener,
|
||||
@@ -62,8 +60,6 @@ public class BatteryChartViewV2 extends AppCompatImageView implements View.OnCli
|
||||
|
||||
private static final int DIVIDER_COLOR = Color.parseColor("#CDCCC5");
|
||||
private static final long UPDATE_STATE_DELAYED_TIME = 500L;
|
||||
private static final Map<Integer, Integer[]> MODEL_SIZE_TO_LABEL_INDEXES_MAP =
|
||||
buildModelSizeToLabelIndexesMap();
|
||||
|
||||
/** A callback listener for selected group index is updated. */
|
||||
public interface OnSelectListener {
|
||||
@@ -79,7 +75,6 @@ public class BatteryChartViewV2 extends AppCompatImageView implements View.OnCli
|
||||
private float mTrapezoidHOffset;
|
||||
private boolean mIsSlotsClickabled;
|
||||
private String[] mPercentages = getPercentages();
|
||||
private Integer[] mLabelsIndexes;
|
||||
|
||||
@VisibleForTesting
|
||||
int mHoveredIndex = BatteryChartViewModel.SELECTED_INDEX_INVALID;
|
||||
@@ -94,7 +89,8 @@ public class BatteryChartViewV2 extends AppCompatImageView implements View.OnCli
|
||||
private final Rect[] mPercentageBounds =
|
||||
new Rect[]{new Rect(), new Rect(), new Rect()};
|
||||
// For drawing the axis label information.
|
||||
private final Rect[] mAxisLabelsBounds = initializeAxisLabelsBounds();
|
||||
private final List<Rect> mAxisLabelsBounds = new ArrayList<>();
|
||||
|
||||
|
||||
@VisibleForTesting
|
||||
Handler mHandler = new Handler();
|
||||
@@ -138,7 +134,7 @@ public class BatteryChartViewV2 extends AppCompatImageView implements View.OnCli
|
||||
Log.d(TAG, String.format("setViewModel(): size: %d, selectedIndex: %d.",
|
||||
viewModel.size(), viewModel.selectedIndex()));
|
||||
mViewModel = viewModel;
|
||||
mLabelsIndexes = MODEL_SIZE_TO_LABEL_INDEXES_MAP.get(mViewModel.size());
|
||||
initializeAxisLabelsBounds();
|
||||
initializeTrapezoidSlots(viewModel.size() - 1);
|
||||
setClickable(hasAnyValidTrapezoid(viewModel));
|
||||
requestLayout();
|
||||
@@ -158,7 +154,6 @@ public class BatteryChartViewV2 extends AppCompatImageView implements View.OnCli
|
||||
} else {
|
||||
mTextPaint = null;
|
||||
}
|
||||
setVisibility(View.VISIBLE);
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
@@ -167,6 +162,7 @@ public class BatteryChartViewV2 extends AppCompatImageView implements View.OnCli
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
// Measures text bounds and updates indent configuration.
|
||||
if (mTextPaint != null) {
|
||||
mTextPaint.setTextAlign(Paint.Align.LEFT);
|
||||
for (int index = 0; index < mPercentages.length; index++) {
|
||||
mTextPaint.getTextBounds(
|
||||
mPercentages[index], 0, mPercentages[index].length(),
|
||||
@@ -177,13 +173,13 @@ public class BatteryChartViewV2 extends AppCompatImageView implements View.OnCli
|
||||
mIndent.right = mPercentageBounds[0].width() + mTextPadding;
|
||||
|
||||
if (mViewModel != null) {
|
||||
int maxHeight = 0;
|
||||
for (int index = 0; index < mLabelsIndexes.length; index++) {
|
||||
final String text = getAxisLabelText(index);
|
||||
mTextPaint.getTextBounds(text, 0, text.length(), mAxisLabelsBounds[index]);
|
||||
maxHeight = Math.max(maxHeight, mAxisLabelsBounds[index].height());
|
||||
int maxTop = 0;
|
||||
for (int index = 0; index < mViewModel.size(); index++) {
|
||||
final String text = mViewModel.texts().get(index);
|
||||
mTextPaint.getTextBounds(text, 0, text.length(), mAxisLabelsBounds.get(index));
|
||||
maxTop = Math.max(maxTop, -mAxisLabelsBounds.get(index).top);
|
||||
}
|
||||
mIndent.bottom = maxHeight + round(mTextPadding * 1.5f);
|
||||
mIndent.bottom = maxTop + round(mTextPadding * 2f);
|
||||
}
|
||||
Log.d(TAG, "setIndent:" + mPercentageBounds[0]);
|
||||
} else {
|
||||
@@ -386,10 +382,10 @@ public class BatteryChartViewV2 extends AppCompatImageView implements View.OnCli
|
||||
|
||||
private void drawPercentage(Canvas canvas, int index, float offsetY) {
|
||||
if (mTextPaint != null) {
|
||||
mTextPaint.setTextAlign(Paint.Align.RIGHT);
|
||||
canvas.drawText(
|
||||
mPercentages[index],
|
||||
getWidth() - mPercentageBounds[index].width()
|
||||
- mPercentageBounds[index].left,
|
||||
getWidth(),
|
||||
offsetY + mPercentageBounds[index].height() * .5f,
|
||||
mTextPaint);
|
||||
}
|
||||
@@ -417,67 +413,112 @@ public class BatteryChartViewV2 extends AppCompatImageView implements View.OnCli
|
||||
}
|
||||
// Draws the axis label slot information.
|
||||
if (mViewModel != null) {
|
||||
final float[] xOffsets = new float[mLabelsIndexes.length];
|
||||
final float baselineX = mDividerWidth * .5f;
|
||||
final float offsetX = mDividerWidth + unitWidth;
|
||||
for (int index = 0; index < mLabelsIndexes.length; index++) {
|
||||
xOffsets[index] = baselineX + mLabelsIndexes[index] * offsetX;
|
||||
}
|
||||
final float baselineY = getHeight() - mTextPadding * 1.5f;
|
||||
Rect[] axisLabelDisplayAreas;
|
||||
switch (mViewModel.axisLabelPosition()) {
|
||||
case CENTER_OF_TRAPEZOIDS:
|
||||
drawAxisLabelsCenterOfTrapezoids(canvas, xOffsets, unitWidth);
|
||||
axisLabelDisplayAreas = getAxisLabelDisplayAreas(
|
||||
/* size= */ mViewModel.size() - 1,
|
||||
/* baselineX= */ mDividerWidth + unitWidth * .5f,
|
||||
/* offsetX= */ mDividerWidth + unitWidth,
|
||||
baselineY,
|
||||
/* shiftFirstAndLast= */ false);
|
||||
break;
|
||||
case BETWEEN_TRAPEZOIDS:
|
||||
default:
|
||||
drawAxisLabelsBetweenTrapezoids(canvas, xOffsets);
|
||||
axisLabelDisplayAreas = getAxisLabelDisplayAreas(
|
||||
/* size= */ mViewModel.size(),
|
||||
/* baselineX= */ mDividerWidth * .5f,
|
||||
/* offsetX= */ mDividerWidth + unitWidth,
|
||||
baselineY,
|
||||
/* shiftFirstAndLast= */ true);
|
||||
break;
|
||||
}
|
||||
drawAxisLabels(canvas, axisLabelDisplayAreas, baselineY);
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets all the axis label texts displaying area positions if they are shown. */
|
||||
private Rect[] getAxisLabelDisplayAreas(final int size, final float baselineX,
|
||||
final float offsetX, final float baselineY, final boolean shiftFirstAndLast) {
|
||||
final Rect[] result = new Rect[size];
|
||||
for (int index = 0; index < result.length; index++) {
|
||||
final float width = mAxisLabelsBounds.get(index).width();
|
||||
float middle = baselineX + index * offsetX;
|
||||
if (shiftFirstAndLast) {
|
||||
if (index == 0) {
|
||||
middle += width * .5f;
|
||||
}
|
||||
if (index == size - 1) {
|
||||
middle -= width * .5f;
|
||||
}
|
||||
}
|
||||
final float left = middle - width * .5f;
|
||||
final float right = left + width;
|
||||
final float top = baselineY + mAxisLabelsBounds.get(index).top;
|
||||
final float bottom = top + mAxisLabelsBounds.get(index).height();
|
||||
result[index] = new Rect(round(left), round(top), round(right), round(bottom));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pairly draws axis labels from left and right side to middle. If the pair of labels have
|
||||
* any overlap, skips that pair of labels.
|
||||
*/
|
||||
private void drawAxisLabels(Canvas canvas, final Rect[] displayAreas, final float baselineY) {
|
||||
int forwardCheckLine = Integer.MIN_VALUE;
|
||||
int backwardCheckLine = Integer.MAX_VALUE;
|
||||
Rect middleDisplayArea = null;
|
||||
for (int forwardIndex = 0, backwordIndex = displayAreas.length - 1;
|
||||
forwardIndex <= backwordIndex; forwardIndex++, backwordIndex--) {
|
||||
final Rect forwardDisplayArea = displayAreas[forwardIndex];
|
||||
final Rect backwardDisplayArea = displayAreas[backwordIndex];
|
||||
if (forwardDisplayArea.left < forwardCheckLine
|
||||
|| backwardDisplayArea.right > backwardCheckLine) {
|
||||
// Overlapped at left or right, skip the pair of labels
|
||||
continue;
|
||||
}
|
||||
if (middleDisplayArea != null && (
|
||||
forwardDisplayArea.right + mTextPadding > middleDisplayArea.left
|
||||
|| backwardDisplayArea.left - mTextPadding < middleDisplayArea.right)) {
|
||||
// Overlapped with the middle label.
|
||||
continue;
|
||||
}
|
||||
if (forwardIndex != backwordIndex
|
||||
&& forwardDisplayArea.right + mTextPadding > backwardDisplayArea.left) {
|
||||
// Overlapped in the middle, skip the pair of labels
|
||||
continue;
|
||||
}
|
||||
|
||||
drawAxisLabelText(canvas, forwardIndex, forwardDisplayArea, baselineY);
|
||||
drawAxisLabelText(canvas, backwordIndex, backwardDisplayArea, baselineY);
|
||||
|
||||
forwardCheckLine = forwardDisplayArea.right + mTextPadding;
|
||||
backwardCheckLine = backwardDisplayArea.left - mTextPadding;
|
||||
|
||||
// If the number of labels is odd, draw the middle label first
|
||||
if (forwardIndex == 0 && backwordIndex % 2 == 0) {
|
||||
final int middleIndex = backwordIndex / 2;
|
||||
middleDisplayArea = displayAreas[middleIndex];
|
||||
if (middleDisplayArea.left < forwardCheckLine
|
||||
|| middleDisplayArea.right > backwardCheckLine) {
|
||||
// Overlapped at left or right, skip the pair of labels
|
||||
continue;
|
||||
}
|
||||
drawAxisLabelText(canvas, middleIndex, middleDisplayArea, baselineY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void drawAxisLabelsBetweenTrapezoids(Canvas canvas, float[] xOffsets) {
|
||||
// Draws the 1st axis label info.
|
||||
private void drawAxisLabelText(
|
||||
Canvas canvas, final int index, final Rect displayArea, final float baselineY) {
|
||||
mTextPaint.setTextAlign(Paint.Align.CENTER);
|
||||
canvas.drawText(
|
||||
getAxisLabelText(0), xOffsets[0] - mAxisLabelsBounds[0].left, getAxisLabelY(0),
|
||||
mViewModel.texts().get(index),
|
||||
displayArea.centerX(),
|
||||
baselineY,
|
||||
mTextPaint);
|
||||
final int latestIndex = mLabelsIndexes.length - 1;
|
||||
// Draws the last axis label info.
|
||||
canvas.drawText(
|
||||
getAxisLabelText(latestIndex),
|
||||
xOffsets[latestIndex]
|
||||
- mAxisLabelsBounds[latestIndex].width()
|
||||
- mAxisLabelsBounds[latestIndex].left,
|
||||
getAxisLabelY(latestIndex),
|
||||
mTextPaint);
|
||||
// Draws the rest of axis label info since it is located in the center.
|
||||
for (int index = 1; index <= mLabelsIndexes.length - 2; index++) {
|
||||
canvas.drawText(
|
||||
getAxisLabelText(index),
|
||||
xOffsets[index]
|
||||
- (mAxisLabelsBounds[index].width() - mAxisLabelsBounds[index].left)
|
||||
* .5f,
|
||||
getAxisLabelY(index),
|
||||
mTextPaint);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawAxisLabelsCenterOfTrapezoids(
|
||||
Canvas canvas, float[] xOffsets, float unitWidth) {
|
||||
for (int index = 0; index < mLabelsIndexes.length - 1; index++) {
|
||||
canvas.drawText(
|
||||
getAxisLabelText(index),
|
||||
xOffsets[index] + (unitWidth - (mAxisLabelsBounds[index].width()
|
||||
- mAxisLabelsBounds[index].left)) * .5f,
|
||||
getAxisLabelY(index),
|
||||
mTextPaint);
|
||||
}
|
||||
}
|
||||
|
||||
private int getAxisLabelY(int index) {
|
||||
return getHeight()
|
||||
- mAxisLabelsBounds[index].height()
|
||||
+ (mAxisLabelsBounds[index].height() + mAxisLabelsBounds[index].top)
|
||||
+ round(mTextPadding * 1.5f);
|
||||
}
|
||||
|
||||
private void drawTrapezoids(Canvas canvas) {
|
||||
@@ -556,8 +597,11 @@ public class BatteryChartViewV2 extends AppCompatImageView implements View.OnCli
|
||||
return BatteryChartViewModel.SELECTED_INDEX_INVALID;
|
||||
}
|
||||
|
||||
private String getAxisLabelText(int labelIndex) {
|
||||
return mViewModel.texts().get(mLabelsIndexes[labelIndex]);
|
||||
private void initializeAxisLabelsBounds() {
|
||||
mAxisLabelsBounds.clear();
|
||||
for (int i = 0; i < mViewModel.size(); i++) {
|
||||
mAxisLabelsBounds.add(new Rect());
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isTrapezoidValid(
|
||||
@@ -613,33 +657,6 @@ public class BatteryChartViewV2 extends AppCompatImageView implements View.OnCli
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Map<Integer, Integer[]> buildModelSizeToLabelIndexesMap() {
|
||||
final Map<Integer, Integer[]> result = new HashMap<>();
|
||||
result.put(2, new Integer[]{0, 1});
|
||||
result.put(3, new Integer[]{0, 1, 2});
|
||||
result.put(4, new Integer[]{0, 1, 2, 3});
|
||||
result.put(5, new Integer[]{0, 1, 2, 3, 4});
|
||||
result.put(6, new Integer[]{0, 1, 2, 3, 4, 5});
|
||||
result.put(7, new Integer[]{0, 1, 2, 3, 4, 5, 6});
|
||||
result.put(8, new Integer[]{0, 1, 2, 3, 4, 5, 6, 7});
|
||||
result.put(9, new Integer[]{0, 2, 4, 6, 8});
|
||||
result.put(10, new Integer[]{0, 3, 6, 9});
|
||||
result.put(11, new Integer[]{0, 5, 10});
|
||||
result.put(12, new Integer[]{0, 4, 7, 11});
|
||||
result.put(13, new Integer[]{0, 4, 8, 12});
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Rect[] initializeAxisLabelsBounds() {
|
||||
final int maxLabelsLength = MODEL_SIZE_TO_LABEL_INDEXES_MAP.values().stream().max(
|
||||
Comparator.comparingInt(indexes -> indexes.length)).get().length;
|
||||
final Rect[] bounds = new Rect[maxLabelsLength];
|
||||
for (int i = 0; i < maxLabelsLength; i++) {
|
||||
bounds[i] = new Rect();
|
||||
}
|
||||
return bounds;
|
||||
}
|
||||
|
||||
// A container class for each trapezoid left and right location.
|
||||
@VisibleForTesting
|
||||
static final class TrapezoidSlot {
|
||||
|
||||
@@ -137,10 +137,12 @@ public final class DataProcessor {
|
||||
// Wrap and processed history map into easy-to-use format for UI rendering.
|
||||
final BatteryLevelData batteryLevelData =
|
||||
getLevelDataThroughProcessedHistoryMap(context, processedBatteryHistoryMap);
|
||||
return getBatteryUsageMap(
|
||||
context,
|
||||
batteryLevelData.getHourlyBatteryLevelsPerDay(),
|
||||
processedBatteryHistoryMap);
|
||||
return batteryLevelData == null
|
||||
? null
|
||||
: getBatteryUsageMap(
|
||||
context,
|
||||
batteryLevelData.getHourlyBatteryLevelsPerDay(),
|
||||
processedBatteryHistoryMap);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.accessibility.AccessibilityShortcutController;
|
||||
import com.android.settings.R;
|
||||
@@ -39,6 +40,7 @@ import com.android.settingslib.widget.MainSwitchPreference;
|
||||
*/
|
||||
public class OneHandedSettings extends AccessibilityShortcutPreferenceFragment {
|
||||
|
||||
private static final String TAG = "OneHandedSettings";
|
||||
private static final String ONE_HANDED_SHORTCUT_KEY = "one_handed_shortcuts_preference";
|
||||
private static final String ONE_HANDED_ILLUSTRATION_KEY = "one_handed_header";
|
||||
protected static final String ONE_HANDED_MAIN_SWITCH_KEY =
|
||||
@@ -131,9 +133,15 @@ public class OneHandedSettings extends AccessibilityShortcutPreferenceFragment {
|
||||
|
||||
@Override
|
||||
protected CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type) {
|
||||
final Context context = getContext();
|
||||
if (context == null) {
|
||||
Log.w(TAG, "OneHandedSettings not attached to a context.");
|
||||
return null;
|
||||
}
|
||||
return type == QuickSettingsTooltipType.GUIDE_TO_EDIT
|
||||
? getText(R.string.accessibility_one_handed_mode_qs_tooltip_content)
|
||||
: getText(R.string.accessibility_one_handed_mode_auto_added_qs_tooltip_content);
|
||||
? context.getText(R.string.accessibility_one_handed_mode_qs_tooltip_content)
|
||||
: context.getText(
|
||||
R.string.accessibility_one_handed_mode_auto_added_qs_tooltip_content);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -143,7 +151,7 @@ public class OneHandedSettings extends AccessibilityShortcutPreferenceFragment {
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return null;
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -165,4 +165,76 @@ public class FingerprintEnrollFindSensorTest {
|
||||
null);
|
||||
assertThat(Shadows.shadowOf(mActivity).getResultCode()).isEqualTo(Activity.RESULT_CANCELED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onActivityResult_EnrollRequestResultFinishShallBeSentBack() {
|
||||
final int defaultActivityResult = Shadows.shadowOf(mActivity).getResultCode();
|
||||
|
||||
// Start enrolling
|
||||
EnrollmentCallback enrollmentCallback = verifyAndCaptureEnrollmentCallback();
|
||||
enrollmentCallback.onEnrollmentProgress(123);
|
||||
enrollmentCallback.onEnrollmentError(FingerprintManager.FINGERPRINT_ERROR_CANCELED, "test");
|
||||
|
||||
// onStop shall not change default activity result
|
||||
mActivity.onStop();
|
||||
assertThat(Shadows.shadowOf(mActivity).getResultCode()).isEqualTo(defaultActivityResult);
|
||||
|
||||
// onActivityResult from Enrolling activity shall be sent back
|
||||
final int testResult = BiometricEnrollBase.RESULT_FINISHED;
|
||||
mActivity.onActivityResult(BiometricEnrollBase.ENROLL_REQUEST, testResult, null);
|
||||
assertThat(Shadows.shadowOf(mActivity).getResultCode()).isEqualTo(testResult);
|
||||
assertThat(mActivity.isFinishing()).isEqualTo(true);
|
||||
|
||||
// onStop shall not change last activity result
|
||||
mActivity.onStop();
|
||||
assertThat(Shadows.shadowOf(mActivity).getResultCode()).isEqualTo(testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onActivityResult_EnrollRequestResultSkipShallBeSentBack() {
|
||||
final int defaultActivityResult = Shadows.shadowOf(mActivity).getResultCode();
|
||||
|
||||
// Start enrolling
|
||||
EnrollmentCallback enrollmentCallback = verifyAndCaptureEnrollmentCallback();
|
||||
enrollmentCallback.onEnrollmentProgress(123);
|
||||
enrollmentCallback.onEnrollmentError(FingerprintManager.FINGERPRINT_ERROR_CANCELED, "test");
|
||||
|
||||
// onStop shall not change default activity result
|
||||
mActivity.onStop();
|
||||
assertThat(Shadows.shadowOf(mActivity).getResultCode()).isEqualTo(defaultActivityResult);
|
||||
|
||||
// onActivityResult from Enrolling activity shall be sent back
|
||||
final int testResult = BiometricEnrollBase.RESULT_SKIP;
|
||||
mActivity.onActivityResult(BiometricEnrollBase.ENROLL_REQUEST, testResult, null);
|
||||
assertThat(Shadows.shadowOf(mActivity).getResultCode()).isEqualTo(testResult);
|
||||
assertThat(mActivity.isFinishing()).isEqualTo(true);
|
||||
|
||||
// onStop shall not change last activity result
|
||||
mActivity.onStop();
|
||||
assertThat(Shadows.shadowOf(mActivity).getResultCode()).isEqualTo(testResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onActivityResult_EnrollRequestResultTimeoutShallBeSentBack() {
|
||||
final int defaultActivityResult = Shadows.shadowOf(mActivity).getResultCode();
|
||||
|
||||
// Start enrolling
|
||||
EnrollmentCallback enrollmentCallback = verifyAndCaptureEnrollmentCallback();
|
||||
enrollmentCallback.onEnrollmentProgress(123);
|
||||
enrollmentCallback.onEnrollmentError(FingerprintManager.FINGERPRINT_ERROR_CANCELED, "test");
|
||||
|
||||
// onStop shall not change default activity result
|
||||
mActivity.onStop();
|
||||
assertThat(Shadows.shadowOf(mActivity).getResultCode()).isEqualTo(defaultActivityResult);
|
||||
|
||||
// onActivityResult from Enrolling activity shall be sent back
|
||||
final int testResult = BiometricEnrollBase.RESULT_TIMEOUT;
|
||||
mActivity.onActivityResult(BiometricEnrollBase.ENROLL_REQUEST, testResult, null);
|
||||
assertThat(Shadows.shadowOf(mActivity).getResultCode()).isEqualTo(testResult);
|
||||
assertThat(mActivity.isFinishing()).isEqualTo(true);
|
||||
|
||||
// onStop shall not change last activity result
|
||||
mActivity.onStop();
|
||||
assertThat(Shadows.shadowOf(mActivity).getResultCode()).isEqualTo(testResult);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,21 +180,21 @@ public final class BatteryChartPreferenceControllerV2Test {
|
||||
verify(mHourlyChartView).setViewModel(new BatteryChartViewModel(
|
||||
List.of(100, 97, 95),
|
||||
List.of("8 am", "10 am", "12 pm"),
|
||||
BatteryChartViewModel.SELECTED_INDEX_ALL,
|
||||
BatteryChartViewModel.AxisLabelPosition.BETWEEN_TRAPEZOIDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setBatteryChartViewModel_60Hours() {
|
||||
BatteryChartViewModel expectedDailyViewModel = new BatteryChartViewModel(
|
||||
List.of(100, 83, 59, 41),
|
||||
List.of("Sat", "Sun", "Mon", "Mon"),
|
||||
BatteryChartViewModel.AxisLabelPosition.CENTER_OF_TRAPEZOIDS);
|
||||
|
||||
mBatteryChartPreferenceController.setBatteryHistoryMap(createBatteryHistoryMap(60));
|
||||
|
||||
verify(mDailyChartView, atLeastOnce()).setVisibility(View.VISIBLE);
|
||||
verify(mHourlyChartView, atLeastOnce()).setVisibility(View.GONE);
|
||||
verify(mDailyChartView).setViewModel(new BatteryChartViewModel(
|
||||
List.of(100, 83, 59, 41),
|
||||
List.of("Sat", "Sun", "Mon", "Mon"),
|
||||
BatteryChartViewModel.SELECTED_INDEX_ALL,
|
||||
BatteryChartViewModel.AxisLabelPosition.CENTER_OF_TRAPEZOIDS));
|
||||
verify(mDailyChartView).setViewModel(expectedDailyViewModel);
|
||||
|
||||
reset(mDailyChartView);
|
||||
reset(mHourlyChartView);
|
||||
@@ -203,16 +203,13 @@ public final class BatteryChartPreferenceControllerV2Test {
|
||||
mBatteryChartPreferenceController.refreshUi();
|
||||
verify(mDailyChartView).setVisibility(View.VISIBLE);
|
||||
verify(mHourlyChartView).setVisibility(View.VISIBLE);
|
||||
verify(mDailyChartView).setViewModel(new BatteryChartViewModel(
|
||||
List.of(100, 83, 59, 41),
|
||||
List.of("Sat", "Sun", "Mon", "Mon"),
|
||||
0,
|
||||
BatteryChartViewModel.AxisLabelPosition.CENTER_OF_TRAPEZOIDS));
|
||||
|
||||
expectedDailyViewModel.setSelectedIndex(0);
|
||||
verify(mDailyChartView).setViewModel(expectedDailyViewModel);
|
||||
verify(mHourlyChartView).setViewModel(new BatteryChartViewModel(
|
||||
List.of(100, 97, 95, 93, 91, 89, 87, 85, 83),
|
||||
List.of("8 am", "10 am", "12 pm", "2 pm", "4 pm", "6 pm", "8 pm", "10 pm",
|
||||
"12 am"),
|
||||
BatteryChartViewModel.SELECTED_INDEX_ALL,
|
||||
BatteryChartViewModel.AxisLabelPosition.BETWEEN_TRAPEZOIDS));
|
||||
|
||||
reset(mDailyChartView);
|
||||
@@ -223,17 +220,15 @@ public final class BatteryChartPreferenceControllerV2Test {
|
||||
mBatteryChartPreferenceController.refreshUi();
|
||||
verify(mDailyChartView).setVisibility(View.VISIBLE);
|
||||
verify(mHourlyChartView).setVisibility(View.VISIBLE);
|
||||
verify(mDailyChartView).setViewModel(new BatteryChartViewModel(
|
||||
List.of(100, 83, 59, 41),
|
||||
List.of("Sat", "Sun", "Mon", "Mon"),
|
||||
1,
|
||||
BatteryChartViewModel.AxisLabelPosition.CENTER_OF_TRAPEZOIDS));
|
||||
verify(mHourlyChartView).setViewModel(new BatteryChartViewModel(
|
||||
expectedDailyViewModel.setSelectedIndex(1);
|
||||
verify(mDailyChartView).setViewModel(expectedDailyViewModel);
|
||||
BatteryChartViewModel expectedHourlyViewModel = new BatteryChartViewModel(
|
||||
List.of(83, 81, 79, 77, 75, 73, 71, 69, 67, 65, 63, 61, 59),
|
||||
List.of("12 am", "2 am", "4 am", "6 am", "8 am", "10 am", "12 pm", "2 pm",
|
||||
"4 pm", "6 pm", "8 pm", "10 pm", "12 am"),
|
||||
6,
|
||||
BatteryChartViewModel.AxisLabelPosition.BETWEEN_TRAPEZOIDS));
|
||||
BatteryChartViewModel.AxisLabelPosition.BETWEEN_TRAPEZOIDS);
|
||||
expectedHourlyViewModel.setSelectedIndex(6);
|
||||
verify(mHourlyChartView).setViewModel(expectedHourlyViewModel);
|
||||
|
||||
reset(mDailyChartView);
|
||||
reset(mHourlyChartView);
|
||||
@@ -244,16 +239,12 @@ public final class BatteryChartPreferenceControllerV2Test {
|
||||
mBatteryChartPreferenceController.refreshUi();
|
||||
verify(mDailyChartView).setVisibility(View.VISIBLE);
|
||||
verify(mHourlyChartView).setVisibility(View.VISIBLE);
|
||||
verify(mDailyChartView).setViewModel(new BatteryChartViewModel(
|
||||
List.of(100, 83, 59, 41),
|
||||
List.of("Sat", "Sun", "Mon", "Mon"),
|
||||
2,
|
||||
BatteryChartViewModel.AxisLabelPosition.CENTER_OF_TRAPEZOIDS));
|
||||
expectedDailyViewModel.setSelectedIndex(2);
|
||||
verify(mDailyChartView).setViewModel(expectedDailyViewModel);
|
||||
verify(mHourlyChartView).setViewModel(new BatteryChartViewModel(
|
||||
List.of(59, 57, 55, 53, 51, 49, 47, 45, 43, 41),
|
||||
List.of("12 am", "2 am", "4 am", "6 am", "8 am", "10 am", "12 pm", "2 pm",
|
||||
"4 pm", "6 pm"),
|
||||
BatteryChartViewModel.SELECTED_INDEX_ALL,
|
||||
BatteryChartViewModel.AxisLabelPosition.BETWEEN_TRAPEZOIDS));
|
||||
}
|
||||
|
||||
|
||||
@@ -102,10 +102,11 @@ public final class BatteryChartViewV2Test {
|
||||
@Test
|
||||
public void onClick_invokesCallback() {
|
||||
final int originalSelectedIndex = 2;
|
||||
mBatteryChartView.setViewModel(
|
||||
new BatteryChartViewModel(List.of(90, 80, 70, 60), List.of("", "", "", ""),
|
||||
originalSelectedIndex,
|
||||
BatteryChartViewModel.AxisLabelPosition.BETWEEN_TRAPEZOIDS));
|
||||
BatteryChartViewModel batteryChartViewModel = new BatteryChartViewModel(
|
||||
List.of(90, 80, 70, 60), List.of("", "", "", ""),
|
||||
BatteryChartViewModel.AxisLabelPosition.BETWEEN_TRAPEZOIDS);
|
||||
batteryChartViewModel.setSelectedIndex(originalSelectedIndex);
|
||||
mBatteryChartView.setViewModel(batteryChartViewModel);
|
||||
for (int i = 0; i < mBatteryChartView.mTrapezoidSlots.length; i++) {
|
||||
mBatteryChartView.mTrapezoidSlots[i] = new BatteryChartViewV2.TrapezoidSlot();
|
||||
mBatteryChartView.mTrapezoidSlots[i].mLeft = i;
|
||||
@@ -192,8 +193,7 @@ public final class BatteryChartViewV2Test {
|
||||
levels.add(index + 1);
|
||||
texts.add("");
|
||||
}
|
||||
mBatteryChartView.setViewModel(new BatteryChartViewModel(
|
||||
levels, texts, BatteryChartViewModel.SELECTED_INDEX_ALL,
|
||||
mBatteryChartView.setViewModel(new BatteryChartViewModel(levels, texts,
|
||||
BatteryChartViewModel.AxisLabelPosition.BETWEEN_TRAPEZOIDS));
|
||||
mBatteryChartView.setClickableForce(true);
|
||||
when(mPowerUsageFeatureProvider.isChartGraphSlotsEnabled(mContext))
|
||||
|
||||
@@ -18,10 +18,18 @@ package com.android.settings.gestures;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.SystemProperties;
|
||||
import android.provider.SearchIndexableResource;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -31,16 +39,36 @@ import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** Tests for {@link OneHandedSettings}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class OneHandedSettingsTest {
|
||||
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
private OneHandedSettings mSettings;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mSettings = new OneHandedSettings();
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mSettings = spy(new OneHandedSettings());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTileTooltipContent_returnsExpectedValues() {
|
||||
// Simulate to call getTileTooltipContent after onDetach
|
||||
assertThat(mSettings.getTileTooltipContent(QuickSettingsTooltipType.GUIDE_TO_EDIT))
|
||||
.isNull();
|
||||
// Simulate to call getTileTooltipContent after onAttach
|
||||
when(mSettings.getContext()).thenReturn(mContext);
|
||||
assertThat(mSettings.getTileTooltipContent(QuickSettingsTooltipType.GUIDE_TO_EDIT))
|
||||
.isEqualTo(mContext.getText(
|
||||
R.string.accessibility_one_handed_mode_qs_tooltip_content));
|
||||
assertThat(mSettings.getTileTooltipContent(QuickSettingsTooltipType.GUIDE_TO_DIRECT_USE))
|
||||
.isEqualTo(mContext.getText(
|
||||
R.string.accessibility_one_handed_mode_auto_added_qs_tooltip_content));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLogTag_returnsCorrectTag() {
|
||||
assertThat(mSettings.getLogTag()).isEqualTo("OneHandedSettings");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -179,11 +179,11 @@ public class FingerprintStatusUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSettingsClassName_whenNotEnrolled_returnsFingerprintEnrollInduction() {
|
||||
public void getSettingsClassName_whenNotEnrolled_returnsFingerprintSettings() {
|
||||
when(mFingerprintManager.hasEnrolledFingerprints(anyInt())).thenReturn(false);
|
||||
|
||||
assertThat(mFingerprintStatusUtils.getSettingsClassName())
|
||||
.isEqualTo(FingerprintEnrollIntroductionInternal.class.getName());
|
||||
.isEqualTo(FingerprintSettings.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -47,7 +47,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.Settings;
|
||||
import com.android.settings.biometrics.face.FaceEnrollIntroductionInternal;
|
||||
import com.android.settings.biometrics.fingerprint.FingerprintEnrollIntroductionInternal;
|
||||
import com.android.settings.biometrics.fingerprint.FingerprintSettings;
|
||||
import com.android.settings.testutils.ResourcesUtils;
|
||||
|
||||
@@ -186,7 +185,7 @@ public class BiometricsSafetySourceTest {
|
||||
assertSafetySourceEnabledDataSetWithSingularSummary(
|
||||
"security_settings_fingerprint_preference_title",
|
||||
"security_settings_fingerprint_preference_summary_none",
|
||||
FingerprintEnrollIntroductionInternal.class.getName());
|
||||
FingerprintSettings.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user