Merge "Make icon size are the same in factory reset account list."
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 25fc62b..7034dc3 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1710,6 +1710,11 @@
<activity android:name="ChooseLockGeneric"
android:label="@string/lockpassword_choose_lock_generic_header"
+ android:excludeFromRecents="true"
+ android:exported="false" />
+
+ <activity android:name=".password.SetNewPasswordActivity"
+ android:theme="@android:style/Theme.NoDisplay"
android:excludeFromRecents="true" >
<intent-filter android:priority="1">
<action android:name="android.app.action.SET_NEW_PASSWORD" />
@@ -3014,7 +3019,7 @@
</activity>
<activity android:name="Settings$AutomaticStorageManagerSettingsActivity"
- android:exported="@bool/config_has_storage_manager"
+ android:exported="@bool/config_storage_manager_settings_enabled"
android:label="@string/automatic_storage_manager_settings"
android:taskAffinity="">
<intent-filter android:priority="1">
diff --git a/res/layout/choose_lock_generic_fingerprint_header.xml b/res/layout/choose_lock_generic_fingerprint_header.xml
index 5ad3004..6a107bf 100644
--- a/res/layout/choose_lock_generic_fingerprint_header.xml
+++ b/res/layout/choose_lock_generic_fingerprint_header.xml
@@ -15,6 +15,7 @@
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/fingerprint_header_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
@@ -22,4 +23,4 @@
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:text="@string/lock_settings_picker_fingerprint_message"
- android:textAppearance="@android:style/TextAppearance.Material.Subhead" />
+ style="@style/FingerprintHeaderStyle" />
diff --git a/res/layout/regulatory_info.xml b/res/layout/regulatory_info.xml
index 8cd4157..0a74886 100755
--- a/res/layout/regulatory_info.xml
+++ b/res/layout/regulatory_info.xml
@@ -22,6 +22,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
+ android:contentDescription="@string/regulatory_labels"
android:src="@drawable/regulatory_info" />
</ScrollView>
diff --git a/res/layout/wifi_dialog.xml b/res/layout/wifi_dialog.xml
index ceb7201..ba1f6fc 100644
--- a/res/layout/wifi_dialog.xml
+++ b/res/layout/wifi_dialog.xml
@@ -287,11 +287,14 @@
android:layout_height="wrap_content"
style="@style/wifi_item"
android:paddingBottom="4dp"
+ android:importantForAccessibility="yes"
+ android:contentDescription="@string/wifi_advanced_toggle_description_collapsed"
android:visibility="gone">
<CheckBox android:id="@+id/wifi_advanced_togglebox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/wifi_advanced_toggle"
+ android:importantForAccessibility="noHideDescendants"
android:text="@string/wifi_show_advanced" />
</LinearLayout>
diff --git a/res/values/bools.xml b/res/values/bools.xml
index eef0f5d..59367b55 100644
--- a/res/values/bools.xml
+++ b/res/values/bools.xml
@@ -46,9 +46,6 @@
<!-- Whether swipe security option is hidden or not -->
<bool name="config_hide_swipe_security_option">false</bool>
- <!--Whether the storage manager exists. -->
- <bool name="config_has_storage_manager">false</bool>
-
<!--Whether help links are defined. -->
<bool name="config_has_help">false</bool>
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index ef9c3dd..b1180c4 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1102,6 +1102,12 @@
<!-- Title for preference that guides the user through creating a backup unlock password for fingerprint [CHAR LIMIT=45]-->
<string name="fingerprint_unlock_set_unlock_password">Fingerprint + Password</string>
+ <!-- Title for preference that guides the user to skip fingerprint setup [CHAR LIMIT=60]-->
+ <string name="fingerprint_unlock_skip_fingerprint">Continue without fingerprint</string>
+
+ <!-- Message shown in screen lock picker while setting up the new screen lock with fingerprint option. [CHAR LIMIT=NONE]-->
+ <string name="fingerprint_unlock_title">You can unlock your phone using your fingerprint. For security, this option requires a backup screen lock.</string>
+
<!-- Summary for preference that has been disabled by because of the DevicePolicyAdmin, or because device encryption is enabled, or because there are credentials in the credential storage [CHAR LIMIT=50] -->
<string name="unlock_set_unlock_disabled_summary">Disabled by administrator, encryption policy, or credential storage</string>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 6d7a40c..32c0b4d 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -439,4 +439,10 @@
<item name="android:paddingEnd">56dp</item>
</style>
+ <style name="FingerprintHeaderStyle" parent="android:style/TextAppearance.Material.Subhead">
+ <item name="android:paddingTop">16dp</item>
+ <item name="android:textColor">@color/primary_dark_material_light</item>
+ <item name="android:lineSpacingMultiplier">1.2</item>
+ </style>
+
</resources>
diff --git a/res/xml/security_settings_picker.xml b/res/xml/security_settings_picker.xml
index 7b6069d..6b52156 100644
--- a/res/xml/security_settings_picker.xml
+++ b/res/xml/security_settings_picker.xml
@@ -47,4 +47,9 @@
android:key="unlock_set_managed"
android:persistent="false"/>
+ <com.android.settingslib.RestrictedPreference
+ android:key="unlock_skip_fingerprint"
+ android:title="@string/fingerprint_unlock_skip_fingerprint"
+ android:persistent="false"/>
+
</PreferenceScreen>
diff --git a/src/com/android/settings/ChooseLockGeneric.java b/src/com/android/settings/ChooseLockGeneric.java
index f650fae..4ed080d 100644
--- a/src/com/android/settings/ChooseLockGeneric.java
+++ b/src/com/android/settings/ChooseLockGeneric.java
@@ -16,6 +16,11 @@
package com.android.settings;
+import static android.app.admin.DevicePolicyManager.ACTION_SET_NEW_PARENT_PROFILE_PASSWORD;
+import static android.app.admin.DevicePolicyManager.ACTION_SET_NEW_PASSWORD;
+import static com.android.settings.ChooseLockPassword.ChooseLockPasswordFragment.RESULT_FINISHED;
+import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+
import android.accessibilityservice.AccessibilityServiceInfo;
import android.app.Activity;
import android.app.AlertDialog;
@@ -41,17 +46,18 @@
import android.util.EventLog;
import android.util.Log;
import android.view.accessibility.AccessibilityManager;
+import android.widget.TextView;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
+import com.android.settings.fingerprint.FingerprintEnrollBase;
+import com.android.settings.fingerprint.FingerprintEnrollFindSensor;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedPreference;
import java.util.List;
-import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
-
public class ChooseLockGeneric extends SettingsActivity {
public static final String CONFIRM_CREDENTIALS = "confirm_credentials";
@@ -61,8 +67,8 @@
modIntent.putExtra(EXTRA_SHOW_FRAGMENT, getFragmentClass().getName());
String action = modIntent.getAction();
- if (DevicePolicyManager.ACTION_SET_NEW_PASSWORD.equals(action)
- || DevicePolicyManager.ACTION_SET_NEW_PARENT_PROFILE_PASSWORD.equals(action)) {
+ if (ACTION_SET_NEW_PASSWORD.equals(action)
+ || ACTION_SET_NEW_PARENT_PROFILE_PASSWORD.equals(action)) {
modIntent.putExtra(EXTRA_HIDE_DRAWER, true);
}
return modIntent;
@@ -90,6 +96,7 @@
private static final String KEY_UNLOCK_SET_PASSWORD = "unlock_set_password";
private static final String KEY_UNLOCK_SET_PATTERN = "unlock_set_pattern";
private static final String KEY_UNLOCK_SET_MANAGED = "unlock_set_managed";
+ private static final String KEY_SKIP_FINGERPRINT = "unlock_skip_fingerprint";
private static final String PASSWORD_CONFIRMED = "password_confirmed";
private static final String WAITING_FOR_CONFIRMATION = "waiting_for_confirmation";
public static final String MINIMUM_QUALITY_KEY = "minimum_quality";
@@ -101,6 +108,8 @@
private static final int CONFIRM_EXISTING_REQUEST = 100;
private static final int ENABLE_ENCRYPTION_REQUEST = 101;
private static final int CHOOSE_LOCK_REQUEST = 102;
+ private static final int CHOOSE_LOCK_BEFORE_FINGERPRINT_REQUEST = 103;
+ private static final int SKIP_FINGERPRINT_REQUEST = 104;
private ChooseLockSettingsHelper mChooseLockSettingsHelper;
private DevicePolicyManager mDPM;
@@ -119,6 +128,7 @@
private int mUserId;
private boolean mHideDrawer = false;
private ManagedLockPasswordProvider mManagedPasswordProvider;
+ private boolean mIsSetNewPassword = false;
protected boolean mForFingerprint = false;
@@ -131,12 +141,15 @@
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ String chooseLockAction = getActivity().getIntent().getAction();
mFingerprintManager =
(FingerprintManager) getActivity().getSystemService(Context.FINGERPRINT_SERVICE);
mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
mKeyStore = KeyStore.getInstance();
mChooseLockSettingsHelper = new ChooseLockSettingsHelper(this.getActivity());
mLockPatternUtils = new LockPatternUtils(getActivity());
+ mIsSetNewPassword = ACTION_SET_NEW_PARENT_PROFILE_PASSWORD.equals(chooseLockAction)
+ || ACTION_SET_NEW_PASSWORD.equals(chooseLockAction);
// Defaults to needing to confirm credentials
final boolean confirmCredentials = getActivity().getIntent()
@@ -154,6 +167,16 @@
ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, false);
mForChangeCredRequiredForBoot = getArguments() != null && getArguments().getBoolean(
ChooseLockSettingsHelper.EXTRA_KEY_FOR_CHANGE_CRED_REQUIRED_FOR_BOOT);
+ if (mIsSetNewPassword) {
+ // In ACTION_SET_NEW_PARENT_PROFILE_PASSWORD or ACTION_SET_NEW_PASSWORD, the user
+ // will be asked to confirm the password if one has been set.
+ // On fingerprint supported device, fingerprint options are represented in the
+ // options. If the user chooses to skip fingerprint setup, ChooseLockGeneric is
+ // relaunched to only show options without fingerprint. In this case, we shouldn't
+ // ask the user to confirm the password again.
+ mPasswordConfirmed = getActivity().getIntent().getBooleanExtra(
+ PASSWORD_CONFIRMED, false);
+ }
if (savedInstanceState != null) {
mPasswordConfirmed = savedInstanceState.getBoolean(PASSWORD_CONFIRMED);
@@ -168,9 +191,8 @@
UserManager.get(getActivity()),
null,
getActivity().getIntent().getExtras()).getIdentifier();
- if (DevicePolicyManager.ACTION_SET_NEW_PARENT_PROFILE_PASSWORD.equals(
- getActivity().getIntent().getAction()) ||
- !mLockPatternUtils.isSeparateProfileChallengeAllowed(targetUser)) {
+ if (ACTION_SET_NEW_PARENT_PROFILE_PASSWORD.equals(chooseLockAction)
+ || !mLockPatternUtils.isSeparateProfileChallengeAllowed(targetUser)) {
// Always use parent if explicitely requested or if profile challenge is not
// supported
Bundle arguments = getArguments();
@@ -180,8 +202,7 @@
mUserId = targetUser;
}
- if (DevicePolicyManager.ACTION_SET_NEW_PASSWORD
- .equals(getActivity().getIntent().getAction())
+ if (ACTION_SET_NEW_PASSWORD.equals(chooseLockAction)
&& UserManager.get(getActivity()).isManagedProfile(mUserId)
&& mLockPatternUtils.isSeparateProfileChallengeEnabled(mUserId)) {
getActivity().setTitle(R.string.lock_settings_picker_title_profile);
@@ -216,6 +237,10 @@
protected void addHeaderView() {
if (mForFingerprint) {
setHeaderView(R.layout.choose_lock_generic_fingerprint_header);
+ if (mIsSetNewPassword) {
+ ((TextView) getHeaderView().findViewById(R.id.fingerprint_header_description))
+ .setText(R.string.fingerprint_unlock_title);
+ }
}
}
@@ -228,6 +253,12 @@
// unlock method to an insecure one
showFactoryResetProtectionWarningDialog(key);
return true;
+ } else if (KEY_SKIP_FINGERPRINT.equals(key)) {
+ Intent chooseLockGenericIntent = new Intent(getActivity(), ChooseLockGeneric.class);
+ chooseLockGenericIntent.setAction(getIntent().getAction());
+ chooseLockGenericIntent.putExtra(PASSWORD_CONFIRMED, mPasswordConfirmed);
+ startActivityForResult(chooseLockGenericIntent, SKIP_FINGERPRINT_REQUEST);
+ return true;
} else {
return setUnlockMethod(key);
}
@@ -302,6 +333,20 @@
getActivity().setResult(resultCode, data);
finish();
}
+ } else if (requestCode == CHOOSE_LOCK_BEFORE_FINGERPRINT_REQUEST
+ && resultCode == FingerprintEnrollBase.RESULT_FINISHED) {
+ Intent intent = new Intent(getActivity(), FingerprintEnrollFindSensor.class);
+ if (data != null) {
+ intent.putExtras(data.getExtras());
+ }
+ startActivity(intent);
+ finish();
+ } else if (requestCode == SKIP_FINGERPRINT_REQUEST) {
+ if (resultCode != RESULT_CANCELED) {
+ getActivity().setResult(
+ resultCode == RESULT_FINISHED ? RESULT_OK : resultCode, data);
+ finish();
+ }
} else {
getActivity().setResult(Activity.RESULT_CANCELED);
finish();
@@ -375,6 +420,10 @@
} else {
removePreference(KEY_UNLOCK_SET_MANAGED);
}
+
+ if (!(mForFingerprint && mIsSetNewPassword)) {
+ removePreference(KEY_SKIP_FINGERPRINT);
+ }
}
private void updateCurrentPreference() {
@@ -612,7 +661,10 @@
quality = upgradeQuality(quality);
Intent intent = getIntentForUnlockMethod(quality, disabled);
if (intent != null) {
- startActivityForResult(intent, CHOOSE_LOCK_REQUEST);
+ startActivityForResult(intent,
+ mIsSetNewPassword && mHasChallenge
+ ? CHOOSE_LOCK_BEFORE_FINGERPRINT_REQUEST
+ : CHOOSE_LOCK_REQUEST);
return;
}
@@ -620,8 +672,8 @@
mLockPatternUtils.setSeparateProfileChallengeEnabled(mUserId, true, mUserPassword);
mChooseLockSettingsHelper.utils().clearLock(mUserId);
mChooseLockSettingsHelper.utils().setLockScreenDisabled(disabled, mUserId);
- removeAllFingerprintForUserAndFinish(mUserId);
getActivity().setResult(Activity.RESULT_OK);
+ removeAllFingerprintForUserAndFinish(mUserId);
} else {
removeAllFingerprintForUserAndFinish(mUserId);
}
diff --git a/src/com/android/settings/RadioInfo.java b/src/com/android/settings/RadioInfo.java
index af1392c..9c9eceb 100644
--- a/src/com/android/settings/RadioInfo.java
+++ b/src/com/android/settings/RadioInfo.java
@@ -29,7 +29,6 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
-import android.os.SystemProperties;
import android.telephony.CellInfo;
import android.telephony.CellInfoCdma;
import android.telephony.CellInfoGsm;
@@ -343,6 +342,11 @@
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
+ if (!android.os.Process.myUserHandle().isSystem()) {
+ Log.e(TAG, "Not run from system user, don't do anything.");
+ finish();
+ return;
+ }
setContentView(R.layout.radio_info);
diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java
index 5cc4011..575194b 100644
--- a/src/com/android/settings/SettingsPreferenceFragment.java
+++ b/src/com/android/settings/SettingsPreferenceFragment.java
@@ -86,11 +86,36 @@
private boolean mIsDataSetObserverRegistered = false;
private RecyclerView.AdapterDataObserver mDataSetObserver =
new RecyclerView.AdapterDataObserver() {
- @Override
- public void onChanged() {
- onDataSetChanged();
- }
- };
+ @Override
+ public void onChanged() {
+ onDataSetChanged();
+ }
+
+ @Override
+ public void onItemRangeChanged(int positionStart, int itemCount) {
+ onDataSetChanged();
+ }
+
+ @Override
+ public void onItemRangeChanged(int positionStart, int itemCount, Object payload) {
+ onDataSetChanged();
+ }
+
+ @Override
+ public void onItemRangeInserted(int positionStart, int itemCount) {
+ onDataSetChanged();
+ }
+
+ @Override
+ public void onItemRangeRemoved(int positionStart, int itemCount) {
+ onDataSetChanged();
+ }
+
+ @Override
+ public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) {
+ onDataSetChanged();
+ }
+ };
private ViewGroup mPinnedHeaderFrameLayout;
private ViewGroup mButtonBar;
diff --git a/src/com/android/settings/bluetooth/DeviceProfilesSettings.java b/src/com/android/settings/bluetooth/DeviceProfilesSettings.java
index f9b507d..a2c6776 100755
--- a/src/com/android/settings/bluetooth/DeviceProfilesSettings.java
+++ b/src/com/android/settings/bluetooth/DeviceProfilesSettings.java
@@ -115,7 +115,7 @@
EditText deviceName = (EditText) mRootView.findViewById(R.id.name);
mCachedDevice.setName(deviceName.getText().toString());
break;
- case DialogInterface.BUTTON_NEGATIVE:
+ case DialogInterface.BUTTON_NEUTRAL:
mCachedDevice.unpair();
com.android.settings.bluetooth.Utils.updateSearchIndex(getContext(),
BluetoothSettings.class.getName(), mCachedDevice.getName(),
diff --git a/src/com/android/settings/core/instrumentation/SharedPreferencesLogger.java b/src/com/android/settings/core/instrumentation/SharedPreferencesLogger.java
index 6a67e45..101f1b5 100644
--- a/src/com/android/settings/core/instrumentation/SharedPreferencesLogger.java
+++ b/src/com/android/settings/core/instrumentation/SharedPreferencesLogger.java
@@ -21,6 +21,7 @@
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.text.TextUtils;
+import android.util.ArraySet;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.settings.overlay.FeatureFactory;
@@ -33,11 +34,13 @@
private final String mTag;
private final Context mContext;
private final MetricsFeatureProvider mMetricsFeature;
+ private final Set<String> mPreferenceKeySet;
public SharedPreferencesLogger(Context context, String tag) {
mContext = context;
mTag = tag;
mMetricsFeature = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
+ mPreferenceKeySet = new ArraySet<>();
}
@Override
@@ -96,7 +99,15 @@
}
private void logValue(String key, String value) {
- mMetricsFeature.count(mContext, mTag + "/" + key + "|" + value, 1);
+ final String prefKey = mTag + "/" + key;
+ if (!mPreferenceKeySet.contains(prefKey)) {
+ // Pref key doesn't exist in set, this is initial display so we skip metrics but
+ // keeps track of this key.
+ mPreferenceKeySet.add(prefKey);
+ return;
+ }
+ // Pref key exists in set, log it's change in metrics.
+ mMetricsFeature.count(mContext, prefKey + "|" + value, 1);
}
private void logPackageName(String key, String value) {
diff --git a/src/com/android/settings/dashboard/DashboardFeatureProvider.java b/src/com/android/settings/dashboard/DashboardFeatureProvider.java
new file mode 100644
index 0000000..e4976f5
--- /dev/null
+++ b/src/com/android/settings/dashboard/DashboardFeatureProvider.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.dashboard;
+
+import android.content.Context;
+
+/**
+ * FeatureProvider for dashboard (aka settings homepage).
+ */
+public interface DashboardFeatureProvider {
+
+ boolean shouldUseNewIALayout(Context context);
+}
diff --git a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
new file mode 100644
index 0000000..d07729a
--- /dev/null
+++ b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2015 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.dashboard;
+
+import android.content.Context;
+
+/**
+ * Impl for {@code DashboardFeatureProvider}.
+ */
+public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
+
+ @Override
+ public boolean shouldUseNewIALayout(Context context) {
+ return false;
+ }
+
+}
diff --git a/src/com/android/settings/datausage/BillingCycleSettings.java b/src/com/android/settings/datausage/BillingCycleSettings.java
index deadc54..ce020b1 100644
--- a/src/com/android/settings/datausage/BillingCycleSettings.java
+++ b/src/com/android/settings/datausage/BillingCycleSettings.java
@@ -35,6 +35,7 @@
import android.widget.NumberPicker;
import android.widget.Spinner;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
@@ -60,7 +61,7 @@
private static final String KEY_BILLING_CYCLE = "billing_cycle";
private static final String KEY_SET_DATA_WARNING = "set_data_warning";
private static final String KEY_DATA_WARNING = "data_warning";
- private static final String KEY_SET_DATA_LIMIT = "set_data_limit";
+ @VisibleForTesting static final String KEY_SET_DATA_LIMIT = "set_data_limit";
private static final String KEY_DATA_LIMIT = "data_limit";
private NetworkTemplate mNetworkTemplate;
@@ -139,12 +140,13 @@
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (mEnableDataLimit == preference) {
boolean enabled = (Boolean) newValue;
- if (enabled) {
- ConfirmLimitFragment.show(this);
- } else {
+ if (!enabled) {
setPolicyLimitBytes(LIMIT_DISABLED);
+ return true;
}
- return true;
+ ConfirmLimitFragment.show(this);
+ // This preference is enabled / disabled by ConfirmLimitFragment.
+ return false;
} else if (mEnableDataWarning == preference) {
boolean enabled = (Boolean) newValue;
if (enabled) {
@@ -162,7 +164,8 @@
return MetricsEvent.BILLING_CYCLE;
}
- private void setPolicyLimitBytes(long limitBytes) {
+ @VisibleForTesting
+ void setPolicyLimitBytes(long limitBytes) {
if (LOGD) Log.d(TAG, "setPolicyLimitBytes()");
services.mPolicyEditor.setPolicyLimitBytes(mNetworkTemplate, limitBytes);
updatePrefs();
@@ -373,7 +376,7 @@
public static class ConfirmLimitFragment extends InstrumentedDialogFragment implements
DialogInterface.OnClickListener {
private static final String EXTRA_MESSAGE = "message";
- private static final String EXTRA_LIMIT_BYTES = "limitBytes";
+ @VisibleForTesting static final String EXTRA_LIMIT_BYTES = "limitBytes";
public static final float FLOAT = 1.2f;
public static void show(BillingCycleSettings parent) {
@@ -423,12 +426,14 @@
@Override
public void onClick(DialogInterface dialog, int which) {
+ final BillingCycleSettings target = (BillingCycleSettings) getTargetFragment();
if (which != DialogInterface.BUTTON_POSITIVE) return;
final long limitBytes = getArguments().getLong(EXTRA_LIMIT_BYTES);
- final BillingCycleSettings target = (BillingCycleSettings) getTargetFragment();
if (target != null) {
target.setPolicyLimitBytes(limitBytes);
}
+ target.getPreferenceManager().getSharedPreferences().edit()
+ .putBoolean(KEY_SET_DATA_LIMIT, true).apply();
}
}
}
diff --git a/src/com/android/settings/fingerprint/FingerprintEnrollBase.java b/src/com/android/settings/fingerprint/FingerprintEnrollBase.java
index 65cc92e..d581804 100644
--- a/src/com/android/settings/fingerprint/FingerprintEnrollBase.java
+++ b/src/com/android/settings/fingerprint/FingerprintEnrollBase.java
@@ -36,7 +36,7 @@
*/
public abstract class FingerprintEnrollBase extends InstrumentedActivity
implements View.OnClickListener {
- static final int RESULT_FINISHED = FingerprintSettings.RESULT_FINISHED;
+ public static final int RESULT_FINISHED = FingerprintSettings.RESULT_FINISHED;
static final int RESULT_SKIP = FingerprintSettings.RESULT_SKIP;
static final int RESULT_TIMEOUT = FingerprintSettings.RESULT_TIMEOUT;
diff --git a/src/com/android/settings/overlay/FeatureFactory.java b/src/com/android/settings/overlay/FeatureFactory.java
index 83ea297..7099b3f 100644
--- a/src/com/android/settings/overlay/FeatureFactory.java
+++ b/src/com/android/settings/overlay/FeatureFactory.java
@@ -22,6 +22,7 @@
import com.android.settings.R;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
+import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
/**
@@ -67,6 +68,8 @@
public abstract PowerUsageFeatureProvider getPowerUsageFeatureProvider();
+ public abstract DashboardFeatureProvider getDashboardFeatureProvider();
+
public static final class FactoryNotFoundException extends RuntimeException {
public FactoryNotFoundException(Throwable throwable) {
super("Unable to create factory. Did you misconfigure Proguard?", throwable);
diff --git a/src/com/android/settings/overlay/FeatureFactoryImpl.java b/src/com/android/settings/overlay/FeatureFactoryImpl.java
index 035a7f9..8f71363 100644
--- a/src/com/android/settings/overlay/FeatureFactoryImpl.java
+++ b/src/com/android/settings/overlay/FeatureFactoryImpl.java
@@ -21,6 +21,8 @@
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.core.instrumentation.MetricsFeatureProviderImpl;
+import com.android.settings.dashboard.DashboardFeatureProvider;
+import com.android.settings.dashboard.DashboardFeatureProviderImpl;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
/**
@@ -30,6 +32,7 @@
public final class FeatureFactoryImpl extends FeatureFactory {
private MetricsFeatureProvider mMetricsFeatureProvider;
+ private DashboardFeatureProviderImpl mDashboardFeatureProvider;
@Override
public SupportFeatureProvider getSupportFeatureProvider(Context context) {
@@ -49,4 +52,12 @@
return null;
}
+ @Override
+ public DashboardFeatureProvider getDashboardFeatureProvider() {
+ if (mDashboardFeatureProvider == null) {
+ mDashboardFeatureProvider = new DashboardFeatureProviderImpl();
+ }
+ return mDashboardFeatureProvider;
+ }
+
}
diff --git a/src/com/android/settings/password/SetNewPasswordActivity.java b/src/com/android/settings/password/SetNewPasswordActivity.java
new file mode 100644
index 0000000..7cdf006
--- /dev/null
+++ b/src/com/android/settings/password/SetNewPasswordActivity.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.password;
+
+import android.annotation.Nullable;
+import android.app.Activity;
+import android.app.admin.DevicePolicyManager;
+import android.content.Intent;
+import android.os.Bundle;
+
+import com.android.settings.ChooseLockGeneric;
+
+/**
+ * Trampolines {@link DevicePolicyManager#ACTION_SET_NEW_PASSWORD} and
+ * {@link DevicePolicyManager#ACTION_SET_NEW_PARENT_PROFILE_PASSWORD} intent to the appropriate UI
+ * activity for handling set new password.
+ */
+public class SetNewPasswordActivity extends Activity implements SetNewPasswordController.Ui {
+ private String mNewPasswordAction;
+ private SetNewPasswordController mSetNewPasswordController;
+
+ @Override
+ protected void onCreate(Bundle savedState) {
+ super.onCreate(savedState);
+
+ mNewPasswordAction = getIntent().getAction();
+ mSetNewPasswordController = new SetNewPasswordController(this, this);
+ mSetNewPasswordController.dispatchSetNewPasswordIntent();
+ }
+
+ @Override
+ public void launchChooseLock(@Nullable Bundle chooseLockFingerprintExtras) {
+ Intent intent = new Intent(this, ChooseLockGeneric.class)
+ .setAction(mNewPasswordAction);
+ if (chooseLockFingerprintExtras != null) {
+ intent.putExtras(chooseLockFingerprintExtras);
+ }
+ startActivity(intent);
+ finish();
+ }
+}
diff --git a/src/com/android/settings/password/SetNewPasswordController.java b/src/com/android/settings/password/SetNewPasswordController.java
new file mode 100644
index 0000000..470723b
--- /dev/null
+++ b/src/com/android/settings/password/SetNewPasswordController.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.password;
+
+import static com.android.internal.util.Preconditions.checkNotNull;
+
+import android.annotation.Nullable;
+import android.app.admin.DevicePolicyManager;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.hardware.fingerprint.FingerprintManager;
+import android.os.Bundle;
+import android.os.UserHandle;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.settings.ChooseLockGeneric;
+import com.android.settings.ChooseLockSettingsHelper;
+
+/**
+ * Business logic for {@link SetNewPasswordActivity}.
+ *
+ * <p>On devices that supports fingerprint, this controller directs the user to configure
+ * fingerprint + a backup password if the device admin allows fingerprint for keyguard and
+ * the user has never configured a fingerprint before.
+ */
+final class SetNewPasswordController {
+
+ interface Ui {
+ /** Starts the {@link ChooseLockGeneric} activity with the given extras. */
+ void launchChooseLock(@Nullable Bundle chooseLockFingerprintExtras);
+ }
+
+ private final int mCurrentUserId;
+ private final PackageManager mPackageManager;
+ @Nullable private final FingerprintManager mFingerprintManager;
+ private final DevicePolicyManager mDevicePolicyManager;
+ private final Ui mUi;
+
+ public SetNewPasswordController(Context context, Ui ui) {
+ this(context.getUserId(),
+ context.getPackageManager(),
+ (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE),
+ (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE),
+ ui);
+ }
+
+ @VisibleForTesting
+ SetNewPasswordController(
+ int currentUserId,
+ PackageManager packageManager,
+ FingerprintManager fingerprintManager,
+ DevicePolicyManager devicePolicyManager,
+ Ui ui) {
+ mCurrentUserId = currentUserId;
+ mPackageManager = checkNotNull(packageManager);
+ mFingerprintManager = fingerprintManager;
+ mDevicePolicyManager = checkNotNull(devicePolicyManager);
+ mUi = checkNotNull(ui);
+ }
+
+ /**
+ * Dispatches the set new password intent to the correct activity that handles it.
+ */
+ public void dispatchSetNewPasswordIntent() {
+ if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)
+ && mFingerprintManager != null
+ && mFingerprintManager.isHardwareDetected()
+ && !mFingerprintManager.hasEnrolledFingerprints()
+ && !isFingerprintDisabledByAdmin()) {
+ mUi.launchChooseLock(getFingerprintChooseLockExtras());
+ } else {
+ mUi.launchChooseLock(null);
+ }
+ }
+
+ private Bundle getFingerprintChooseLockExtras() {
+ Bundle chooseLockExtras = new Bundle();
+ if (mFingerprintManager != null) {
+ long challenge = mFingerprintManager.preEnroll();
+ chooseLockExtras.putInt(ChooseLockGeneric.ChooseLockGenericFragment.MINIMUM_QUALITY_KEY,
+ DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
+ chooseLockExtras.putBoolean(
+ ChooseLockGeneric.ChooseLockGenericFragment.HIDE_DISABLED_PREFS, true);
+ chooseLockExtras.putBoolean(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, true);
+ chooseLockExtras.putLong(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, challenge);
+ chooseLockExtras.putBoolean(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, true);
+ if (mCurrentUserId != UserHandle.USER_NULL) {
+ chooseLockExtras.putInt(Intent.EXTRA_USER_ID, mCurrentUserId);
+ }
+ }
+ return chooseLockExtras;
+ }
+
+ private boolean isFingerprintDisabledByAdmin() {
+ int disabledFeatures = mDevicePolicyManager.getKeyguardDisabledFeatures(
+ null, mCurrentUserId);
+ return (disabledFeatures & DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT) != 0;
+ }
+}
diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java
index 350e0c3..460d210 100644
--- a/src/com/android/settings/wifi/WifiConfigController.java
+++ b/src/com/android/settings/wifi/WifiConfigController.java
@@ -54,6 +54,7 @@
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
+import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
@@ -262,13 +263,13 @@
showSecurityFields();
showIpConfigFields();
showProxyFields();
+ final CheckBox advancedTogglebox =
+ (CheckBox) mView.findViewById(R.id.wifi_advanced_togglebox);
mView.findViewById(R.id.wifi_advanced_toggle).setVisibility(View.VISIBLE);
- ((CheckBox) mView.findViewById(R.id.wifi_advanced_togglebox))
- .setOnCheckedChangeListener(this);
- if (showAdvancedFields) {
- ((CheckBox) mView.findViewById(R.id.wifi_advanced_togglebox)).setChecked(true);
- mView.findViewById(R.id.wifi_advanced_fields).setVisibility(View.VISIBLE);
- }
+ advancedTogglebox.setOnCheckedChangeListener(this);
+ advancedTogglebox.setChecked(showAdvancedFields);
+ mView.findViewById(R.id.wifi_advanced_fields)
+ .setVisibility(showAdvancedFields ? View.VISIBLE : View.GONE);
}
if (mMode == WifiConfigUiBase.MODE_MODIFY) {
@@ -1210,11 +1211,18 @@
((EditText) mPasswordView).setSelection(pos);
}
} else if (view.getId() == R.id.wifi_advanced_togglebox) {
+ final View advancedToggle = mView.findViewById(R.id.wifi_advanced_toggle);
+ final int toggleVisibility;
+ final int stringID;
if (isChecked) {
- mView.findViewById(R.id.wifi_advanced_fields).setVisibility(View.VISIBLE);
+ toggleVisibility = View.VISIBLE;
+ stringID = R.string.wifi_advanced_toggle_description_expanded;
} else {
- mView.findViewById(R.id.wifi_advanced_fields).setVisibility(View.GONE);
+ toggleVisibility = View.GONE;
+ stringID = R.string.wifi_advanced_toggle_description_collapsed;
}
+ mView.findViewById(R.id.wifi_advanced_fields).setVisibility(toggleVisibility);
+ advancedToggle.setContentDescription(mContext.getString(stringID));
}
}
diff --git a/tests/robotests/src/com/android/settings/core/instrumentation/InstrumentedDialogFragmentTest.java b/tests/robotests/src/com/android/settings/core/instrumentation/InstrumentedDialogFragmentTest.java
index f9e6b46..14b3bb4 100644
--- a/tests/robotests/src/com/android/settings/core/instrumentation/InstrumentedDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/core/instrumentation/InstrumentedDialogFragmentTest.java
@@ -23,7 +23,7 @@
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
-import org.robolectric.util.FragmentTestUtil;
+import org.robolectric.shadows.ShadowApplication;
import static com.google.common.truth.Truth.assertThat;
@@ -58,7 +58,7 @@
// Precondition: no metrics feature
assertThat(fragment.getMetricsFeatureProvider()).isNull();
- FragmentTestUtil.startFragment(fragment);
+ fragment.onAttach(ShadowApplication.getInstance().getApplicationContext());
// Verify: has metrics feature
assertThat(fragment.getMetricsFeatureProvider()).isNotNull();
diff --git a/tests/robotests/src/com/android/settings/core/instrumentation/SharedPreferenceLoggerTest.java b/tests/robotests/src/com/android/settings/core/instrumentation/SharedPreferenceLoggerTest.java
index 11f2784..a3e0e45 100644
--- a/tests/robotests/src/com/android/settings/core/instrumentation/SharedPreferenceLoggerTest.java
+++ b/tests/robotests/src/com/android/settings/core/instrumentation/SharedPreferenceLoggerTest.java
@@ -16,6 +16,7 @@
package com.android.settings.core.instrumentation;
import android.content.Context;
+import android.content.SharedPreferences;
import com.android.settings.TestConfig;
import com.android.settings.overlay.FeatureFactory;
@@ -32,7 +33,7 @@
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@RunWith(RobolectricTestRunner.class)
@@ -62,27 +63,53 @@
}
@Test
- public void putInt_shouldLogCount() {
- mSharedPrefLogger.edit().putInt(TEST_KEY, 1);
- verify(mLogWriter).count(any(Context.class), anyString(), anyInt());
+ public void putInt_shouldNotLogInitialPut() {
+ final SharedPreferences.Editor editor = mSharedPrefLogger.edit();
+ editor.putInt(TEST_KEY, 1);
+ editor.putInt(TEST_KEY, 1);
+ editor.putInt(TEST_KEY, 1);
+ editor.putInt(TEST_KEY, 2);
+ editor.putInt(TEST_KEY, 2);
+ editor.putInt(TEST_KEY, 2);
+ editor.putInt(TEST_KEY, 2);
+
+ verify(mLogWriter, times(6)).count(any(Context.class), anyString(), anyInt());
}
@Test
- public void putBoolean_shouldLogCount() {
- mSharedPrefLogger.edit().putBoolean(TEST_KEY, true);
- verify(mLogWriter).count(any(Context.class), anyString(), anyInt());
+ public void putBoolean_shouldNotLogInitialPut() {
+ final SharedPreferences.Editor editor = mSharedPrefLogger.edit();
+ editor.putBoolean(TEST_KEY, true);
+ editor.putBoolean(TEST_KEY, true);
+ editor.putBoolean(TEST_KEY, false);
+ editor.putBoolean(TEST_KEY, false);
+ editor.putBoolean(TEST_KEY, false);
+
+ verify(mLogWriter, times(4)).count(any(Context.class), anyString(), anyInt());
}
@Test
- public void putLong_shouldLogCount() {
- mSharedPrefLogger.edit().putLong(TEST_KEY, 1);
- verify(mLogWriter).count(any(Context.class), anyString(), anyInt());
+ public void putLong_shouldNotLogInitialPut() {
+ final SharedPreferences.Editor editor = mSharedPrefLogger.edit();
+ editor.putLong(TEST_KEY, 1);
+ editor.putLong(TEST_KEY, 1);
+ editor.putLong(TEST_KEY, 1);
+ editor.putLong(TEST_KEY, 1);
+ editor.putLong(TEST_KEY, 2);
+
+ verify(mLogWriter, times(4)).count(any(Context.class), anyString(), anyInt());
}
@Test
- public void putFloat_shouldLogCount() {
- mSharedPrefLogger.edit().putInt(TEST_KEY, 1);
- verify(mLogWriter).count(any(Context.class), anyString(), anyInt());
+ public void putFloat_shouldNotLogInitialPut() {
+ final SharedPreferences.Editor editor = mSharedPrefLogger.edit();
+ editor.putFloat(TEST_KEY, 1);
+ editor.putFloat(TEST_KEY, 1);
+ editor.putFloat(TEST_KEY, 1);
+ editor.putFloat(TEST_KEY, 1);
+ editor.putFloat(TEST_KEY, 2);
+
+ verify(mLogWriter, times(4)).count(any(Context.class), anyString(), anyInt());
}
}
diff --git a/tests/robotests/src/com/android/settings/datausage/BillingCycleSettingsTest.java b/tests/robotests/src/com/android/settings/datausage/BillingCycleSettingsTest.java
new file mode 100644
index 0000000..9ebb580
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/datausage/BillingCycleSettingsTest.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+package com.android.settings.datausage;
+
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.support.v7.preference.PreferenceManager;
+
+import com.android.settings.TestConfig;
+
+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;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class BillingCycleSettingsTest {
+
+ private static final int LIMIT_BYTES = 123;
+
+ @Mock
+ BillingCycleSettings mMockBillingCycleSettings;
+ BillingCycleSettings.ConfirmLimitFragment mConfirmLimitFragment;
+ @Mock
+ PreferenceManager mMockPreferenceManager;
+ SharedPreferences mSharedPreferences;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mConfirmLimitFragment = new BillingCycleSettings.ConfirmLimitFragment();
+ mConfirmLimitFragment.setTargetFragment(mMockBillingCycleSettings, 0);
+ mSharedPreferences = RuntimeEnvironment.application.getSharedPreferences(
+ "testSharedPreferences", Context.MODE_PRIVATE);
+ when(mMockBillingCycleSettings.getPreferenceManager()).thenReturn(mMockPreferenceManager);
+ when(mMockPreferenceManager.getSharedPreferences()).thenReturn(mSharedPreferences);
+ final Bundle args = new Bundle();
+ args.putLong(BillingCycleSettings.ConfirmLimitFragment.EXTRA_LIMIT_BYTES, LIMIT_BYTES);
+ mConfirmLimitFragment.setArguments(args);
+ mSharedPreferences.edit().putBoolean(
+ BillingCycleSettings.KEY_SET_DATA_LIMIT, false).apply();
+ }
+
+ @Test
+ public void testDataUsageLimit_shouldNotBeSetOnCancel() {
+ mConfirmLimitFragment.onClick(null, DialogInterface.BUTTON_NEGATIVE);
+
+ assertFalse(mSharedPreferences.getBoolean(BillingCycleSettings.KEY_SET_DATA_LIMIT, true));
+ verify(mMockBillingCycleSettings, never()).setPolicyLimitBytes(anyLong());
+ }
+
+ @Test
+ public void testDataUsageLimit_shouldBeSetOnConfirmation() {
+ mConfirmLimitFragment.onClick(null, DialogInterface.BUTTON_POSITIVE);
+
+ assertTrue(mSharedPreferences.getBoolean(BillingCycleSettings.KEY_SET_DATA_LIMIT, false));
+ verify(mMockBillingCycleSettings).setPolicyLimitBytes(LIMIT_BYTES);
+ }
+}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/password/SetNewPasswordControllerTest.java b/tests/robotests/src/com/android/settings/password/SetNewPasswordControllerTest.java
new file mode 100644
index 0000000..61dbe08
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/password/SetNewPasswordControllerTest.java
@@ -0,0 +1,183 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.password;
+
+import static android.content.pm.PackageManager.FEATURE_FINGERPRINT;
+import static com.android.settings.ChooseLockGeneric.ChooseLockGenericFragment.HIDE_DISABLED_PREFS;
+import static com.android.settings.ChooseLockGeneric.ChooseLockGenericFragment.MINIMUM_QUALITY_KEY;
+import static com.android.settings.ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE;
+import static com.android.settings.ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT;
+import static com.android.settings.ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.admin.DevicePolicyManager;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.hardware.fingerprint.FingerprintManager;
+import android.os.Bundle;
+
+import com.android.settings.TestConfig;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.Config;
+
+/**
+ * Tests for {@link SetNewPasswordController}.
+ */
+@RunWith(RobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public final class SetNewPasswordControllerTest {
+ private static final int CURRENT_UID = 101;
+ private static final long FINGERPRINT_CHALLENGE = -9876512313131L;
+
+ @Mock PackageManager mPackageManager;
+ @Mock FingerprintManager mFingerprintManager;
+ @Mock DevicePolicyManager mDevicePolicyManager;
+
+ @Mock private SetNewPasswordController.Ui mUi;
+ private SetNewPasswordController mSetNewPasswordController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mSetNewPasswordController = new SetNewPasswordController(
+ CURRENT_UID, mPackageManager, mFingerprintManager, mDevicePolicyManager, mUi);
+
+ when(mFingerprintManager.preEnroll()).thenReturn(FINGERPRINT_CHALLENGE);
+ when(mPackageManager.hasSystemFeature(eq(FEATURE_FINGERPRINT))).thenReturn(true);
+ }
+
+ @Test
+ public void launchChooseLockWithFingerprint() {
+ // GIVEN the device supports fingerprint.
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
+ // GIVEN there are no enrolled fingerprints.
+ when(mFingerprintManager.hasEnrolledFingerprints()).thenReturn(false);
+ // GIVEN DPC does not disallow fingerprint for keyguard usage.
+ when(mDevicePolicyManager.getKeyguardDisabledFeatures(any(ComponentName.class)))
+ .thenReturn(0);
+
+ // WHEN the controller dispatches a set new password intent.
+ mSetNewPasswordController.dispatchSetNewPasswordIntent();
+
+ // THEN the choose lock activity is launched with fingerprint extras.
+ ArgumentCaptor<Bundle> bundleArgumentCaptor = ArgumentCaptor.forClass(Bundle.class);
+ verify(mUi).launchChooseLock(bundleArgumentCaptor.capture());
+ // THEN the extras have all values for fingerprint setup.
+ compareFingerprintExtras(bundleArgumentCaptor.getValue());
+ }
+
+ @Test
+ public void launchChooseLockWithoutFingerprint_noFingerprintFeature() {
+ // GIVEN the device does NOT support fingerprint feature.
+ when(mPackageManager.hasSystemFeature(eq(FEATURE_FINGERPRINT))).thenReturn(false);
+
+ // WHEN the controller dispatches a set new password intent.
+ mSetNewPasswordController.dispatchSetNewPasswordIntent();
+
+ // THEN the choose lock activity is launched without fingerprint extras.
+ verify(mUi).launchChooseLock(null);
+ }
+
+ @Test
+ public void launchChooseLockWithoutFingerprint_noFingerprintSensor() {
+ // GIVEN the device does NOT support fingerprint.
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
+ // GIVEN there are no enrolled fingerprints.
+ when(mFingerprintManager.hasEnrolledFingerprints()).thenReturn(false);
+ // GIVEN DPC does not disallow fingerprint for keyguard usage.
+ when(mDevicePolicyManager.getKeyguardDisabledFeatures(any(ComponentName.class)))
+ .thenReturn(0);
+
+ // WHEN the controller dispatches a set new password intent.
+ mSetNewPasswordController.dispatchSetNewPasswordIntent();
+
+ // THEN the choose lock activity is launched without fingerprint extras.
+ verify(mUi).launchChooseLock(null);
+ }
+
+ @Test
+ public void launchChooseLockWithoutFingerprint_hasFingerprintEnrolled() {
+ // GIVEN the device supports fingerprint.
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
+ // GIVEN there are no enrolled fingerprints.
+ when(mFingerprintManager.hasEnrolledFingerprints()).thenReturn(true);
+ // GIVEN DPC does not disallow fingerprint for keyguard usage.
+ when(mDevicePolicyManager.getKeyguardDisabledFeatures(any(ComponentName.class)))
+ .thenReturn(0);
+
+ // WHEN the controller dispatches a set new password intent.
+ mSetNewPasswordController.dispatchSetNewPasswordIntent();
+
+ // THEN the choose lock activity is launched without fingerprint extras.
+ verify(mUi).launchChooseLock(null);
+ }
+
+ @Test
+ public void launchChooseLockWithoutFingerprint_deviceAdminDisallowFingerprintForKeyguard() {
+ // GIVEN the device supports fingerprint.
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
+ // GIVEN there is an enrolled fingerprint.
+ when(mFingerprintManager.hasEnrolledFingerprints()).thenReturn(true);
+ // GIVEN DPC disallows fingerprint for keyguard usage.
+ when(mDevicePolicyManager.getKeyguardDisabledFeatures(any(ComponentName.class)))
+ .thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT);
+
+ // WHEN the controller dispatches a set new password intent.
+ mSetNewPasswordController.dispatchSetNewPasswordIntent();
+
+ // THEN the choose lock activity is launched without fingerprint extras.
+ verify(mUi).launchChooseLock(null);
+ }
+
+ private void compareFingerprintExtras(Bundle actualBundle) {
+ assertEquals(
+ "Password quality must be something in order to config fingerprint.",
+ DevicePolicyManager.PASSWORD_QUALITY_SOMETHING,
+ actualBundle.getInt(MINIMUM_QUALITY_KEY));
+ assertTrue(
+ "All disabled preference should be removed.",
+ actualBundle.getBoolean(HIDE_DISABLED_PREFS));
+ assertTrue(
+ "There must be a fingerprint challenge.",
+ actualBundle.getBoolean(EXTRA_KEY_HAS_CHALLENGE));
+ assertEquals(
+ "The fingerprint challenge must come from the FingerprintManager",
+ FINGERPRINT_CHALLENGE,
+ actualBundle.getLong(EXTRA_KEY_CHALLENGE));
+ assertTrue(
+ "The request must be a fingerprint set up request.",
+ actualBundle.getBoolean(EXTRA_KEY_FOR_FINGERPRINT));
+ assertEquals(
+ "User id must be equaled to the input one.",
+ CURRENT_UID,
+ actualBundle.getInt(Intent.EXTRA_USER_ID));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/widget/RtlCompatibleViewPagerTest.java b/tests/robotests/src/com/android/settings/widget/RtlCompatibleViewPagerTest.java
index 2b3613f..b5213f1 100644
--- a/tests/robotests/src/com/android/settings/widget/RtlCompatibleViewPagerTest.java
+++ b/tests/robotests/src/com/android/settings/widget/RtlCompatibleViewPagerTest.java
@@ -16,47 +16,46 @@
package com.android.settings.widget;
-import android.annotation.Nullable;
-import android.app.Activity;
-import android.os.Bundle;
import android.os.Parcelable;
+import android.support.v4.view.PagerAdapter;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
+
import com.android.settings.TestConfig;
import com.android.settings.shadow.ShadowTextUtils;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-
-import static com.google.common.truth.Truth.assertThat;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
import java.util.Locale;
-import android.support.v4.view.PagerAdapter;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.annotation.Config;
-import org.robolectric.Robolectric;
+import static com.google.common.truth.Truth.assertThat;
@RunWith(RobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class RtlCompatibleViewPagerTest {
- private ViewPagerTestActivity mTestActivity;
- private RtlCompatibleViewPager mTestViewPager;
+
private Locale mLocaleEn;
private Locale mLocaleHe;
+ private RtlCompatibleViewPager mViewPager;
@Before
public void setUp() {
- mTestActivity = Robolectric.setupActivity(ViewPagerTestActivity.class);
- mTestViewPager = mTestActivity.getViewPager();
+ mViewPager = new RtlCompatibleViewPager(
+ ShadowApplication.getInstance().getApplicationContext());
+ mViewPager.setAdapter(new ViewPagerAdapter());
mLocaleEn = new Locale("en");
mLocaleHe = new Locale("he");
}
@Test
@Config(shadows = {ShadowTextUtils.class})
- public void testRtlCompatible() {
+ public void testGetCurrentItem_shouldMaintainIndexDuringLocaleChange() {
testRtlCompatibleInner(0);
testRtlCompatibleInner(1);
}
@@ -64,41 +63,20 @@
private void testRtlCompatibleInner(int currentItem) {
// Set up the environment
Locale.setDefault(mLocaleEn);
+ mViewPager.setCurrentItem(currentItem);
+
assertThat(TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()))
.isEqualTo(View.LAYOUT_DIRECTION_LTR);
- mTestViewPager.setCurrentItem(currentItem);
- assertThat(mTestViewPager.getCurrentItem()).isEqualTo(currentItem);
+ assertThat(mViewPager.getCurrentItem()).isEqualTo(currentItem);
// Simulate to change the language to RTL
- Parcelable savedInstance = mTestViewPager.onSaveInstanceState();
+ Parcelable savedInstance = mViewPager.onSaveInstanceState();
Locale.setDefault(mLocaleHe);
+ mViewPager.onRestoreInstanceState(savedInstance);
+
assertThat(TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()))
.isEqualTo(View.LAYOUT_DIRECTION_RTL);
- mTestViewPager.onRestoreInstanceState(savedInstance);
-
- assertThat(mTestViewPager.getCurrentItem()).isEqualTo(currentItem);
- }
-
-
- /**
- * Test activity that contains RTL viewpager
- */
- private static class ViewPagerTestActivity extends Activity {
- private RtlCompatibleViewPager mViewPager;
-
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- mViewPager = new RtlCompatibleViewPager(ViewPagerTestActivity.this);
- mViewPager.setAdapter(new ViewPagerAdapter());
-
- setContentView(mViewPager);
- }
-
- public RtlCompatibleViewPager getViewPager() {
- return mViewPager;
- }
+ assertThat(mViewPager.getCurrentItem()).isEqualTo(currentItem);
}
/**
@@ -122,11 +100,6 @@
}
@Override
- public void destroyItem(ViewGroup collection, int position, Object view) {
- collection.removeView((View) view);
- }
-
- @Override
public Object instantiateItem(ViewGroup container, int position) {
return null;
}