Loading src/com/android/settings/ChooseLockGeneric.java +10 −13 Original line number Diff line number Diff line Loading @@ -186,22 +186,15 @@ public class ChooseLockGeneric extends SettingsActivity { ENCRYPT_REQUESTED_DISABLED); } int targetUser = Utils.getSecureTargetUser( // a) If this is started from other user, use that user id. // b) If this is started from the same user, read the extra if this is launched // from Settings app itself. // c) Otherwise, use UserHandle.myUserId(). mUserId = Utils.getSecureTargetUser( getActivity().getActivityToken(), UserManager.get(getActivity()), null, getArguments(), getActivity().getIntent().getExtras()).getIdentifier(); 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(); mUserId = Utils.getUserIdFromBundle(getContext(), arguments != null ? arguments : getActivity().getIntent().getExtras()); } else { mUserId = targetUser; } if (ACTION_SET_NEW_PASSWORD.equals(chooseLockAction) && Utils.isManagedProfile(UserManager.get(getActivity()), mUserId) && mLockPatternUtils.isSeparateProfileChallengeEnabled(mUserId)) { Loading Loading @@ -256,6 +249,8 @@ public class ChooseLockGeneric extends SettingsActivity { } else if (KEY_SKIP_FINGERPRINT.equals(key)) { Intent chooseLockGenericIntent = new Intent(getActivity(), ChooseLockGeneric.class); chooseLockGenericIntent.setAction(getIntent().getAction()); // Forward the target user id to ChooseLockGeneric. chooseLockGenericIntent.putExtra(Intent.EXTRA_USER_ID, mUserId); chooseLockGenericIntent.putExtra(PASSWORD_CONFIRMED, mPasswordConfirmed); startActivityForResult(chooseLockGenericIntent, SKIP_FINGERPRINT_REQUEST); return true; Loading Loading @@ -343,6 +338,8 @@ public class ChooseLockGeneric extends SettingsActivity { if (data != null) { intent.putExtras(data.getExtras()); } // Forward the target user id to fingerprint setup page. intent.putExtra(Intent.EXTRA_USER_ID, mUserId); startActivity(intent); finish(); } else if (requestCode == SKIP_FINGERPRINT_REQUEST) { Loading src/com/android/settings/Utils.java +33 −10 Original line number Diff line number Diff line Loading @@ -102,6 +102,7 @@ import java.util.List; import java.util.Locale; import static android.content.Intent.EXTRA_USER; import static android.content.Intent.EXTRA_USER_ID; import static android.text.format.DateUtils.FORMAT_ABBREV_MONTH; import static android.text.format.DateUtils.FORMAT_SHOW_DATE; Loading Loading @@ -651,10 +652,15 @@ public final class Utils extends com.android.settingslib.Utils { /** * Returns the target user for a Settings activity. * * The target user can be either the current user, the user that launched this activity or * the user contained as an extra in the arguments or intent extras. * * <p> * User would be retrieved in this order: * <ul> * <li> If this activity is launched from other user, return that user id. * <li> If this is launched from the Settings app in same user, return the user contained as an * extra in the arguments or intent extras. * <li> Otherwise, return UserHandle.myUserId(). * </ul> * <p> * Note: This is secure in the sense that it only returns a target user different to the current * one if the app launching this activity is the Settings app itself, running in the same user * or in one that is in the same profile group, or if the user id is provided by the system. Loading @@ -675,16 +681,14 @@ public final class Utils extends com.android.settingslib.Utils { return launchedFromUser; } } UserHandle extrasUser = intentExtras != null ? (UserHandle) intentExtras.getParcelable(EXTRA_USER) : null; UserHandle extrasUser = getUserHandleFromBundle(intentExtras); if (extrasUser != null && !extrasUser.equals(currentUser)) { // Check it's secure if (launchedFromSettingsApp && isProfileOf(um, extrasUser)) { return extrasUser; } } UserHandle argumentsUser = arguments != null ? (UserHandle) arguments.getParcelable(EXTRA_USER) : null; UserHandle argumentsUser = getUserHandleFromBundle(arguments); if (argumentsUser != null && !argumentsUser.equals(currentUser)) { // Check it's secure if (launchedFromSettingsApp && isProfileOf(um, argumentsUser)) { Loading @@ -698,6 +702,25 @@ public final class Utils extends com.android.settingslib.Utils { return currentUser; } /** * Lookup both {@link Intent#EXTRA_USER} and {@link Intent#EXTRA_USER_ID} in the bundle * and return the {@link UserHandle} object. Return {@code null} if nothing is found. */ private static @Nullable UserHandle getUserHandleFromBundle(Bundle bundle) { if (bundle == null) { return null; } final UserHandle user = bundle.getParcelable(EXTRA_USER); if (user != null) { return user; } final int userId = bundle.getInt(EXTRA_USER_ID, -1); if (userId != -1) { return UserHandle.of(userId); } return null; } /** * Returns the target user for a Settings activity. * Loading src/com/android/settings/password/FingerprintManagerWrapper.java 0 → 100644 +47 −0 Original line number Diff line number Diff line /* * 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.NonNull; import android.hardware.fingerprint.FingerprintManager; import com.android.internal.util.Preconditions; /** * Wrapper of {@link FingerprintManager}. Workaround for roboelectic testing. See * {@link IFingerprintManager} for details. */ public class FingerprintManagerWrapper implements IFingerprintManager { private @NonNull FingerprintManager mFingerprintManager; public FingerprintManagerWrapper(@NonNull FingerprintManager fingerprintManager) { Preconditions.checkNotNull(fingerprintManager); mFingerprintManager = fingerprintManager; } public boolean isHardwareDetected() { return mFingerprintManager.isHardwareDetected(); } public boolean hasEnrolledFingerprints(int userId) { return mFingerprintManager.hasEnrolledFingerprints(userId); } public long preEnroll() { return mFingerprintManager.preEnroll(); } } src/com/android/settings/password/IFingerprintManager.java 0 → 100644 +31 −0 Original line number Diff line number Diff line /* * 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; /** * This is the workaround to allow us test {@link SetNewPasswordController} which uses a new hidden * API {@link android.hardware.fingerprint.FingerprintManager#hasEnrolledFingerprints(int)} that * roboelectric does not support yet. Having roboelectic to support latest platform API is tracked * in b/30995831. */ public interface IFingerprintManager { boolean isHardwareDetected(); boolean hasEnrolledFingerprints(int userId); long preEnroll(); } src/com/android/settings/password/SetNewPasswordActivity.java +17 −6 Original line number Diff line number Diff line Loading @@ -16,13 +16,18 @@ package com.android.settings.password; import android.annotation.Nullable; import static android.app.admin.DevicePolicyManager.ACTION_SET_NEW_PARENT_PROFILE_PASSWORD; import static android.app.admin.DevicePolicyManager.ACTION_SET_NEW_PASSWORD; import android.app.Activity; import android.app.admin.DevicePolicyManager; import android.content.Intent; import android.os.Bundle; import android.util.Log; import com.android.settings.ChooseLockGeneric; import com.android.settings.SetupChooseLockGeneric; import com.android.settings.Utils; /** * Trampolines {@link DevicePolicyManager#ACTION_SET_NEW_PASSWORD} and Loading @@ -30,6 +35,7 @@ import com.android.settings.ChooseLockGeneric; * activity for handling set new password. */ public class SetNewPasswordActivity extends Activity implements SetNewPasswordController.Ui { private static final String TAG = "SetNewPasswordActivity"; private String mNewPasswordAction; private SetNewPasswordController mSetNewPasswordController; Loading @@ -38,17 +44,22 @@ public class SetNewPasswordActivity extends Activity implements SetNewPasswordCo super.onCreate(savedState); mNewPasswordAction = getIntent().getAction(); mSetNewPasswordController = new SetNewPasswordController(this, this); if (!ACTION_SET_NEW_PASSWORD.equals(mNewPasswordAction) && !ACTION_SET_NEW_PARENT_PROFILE_PASSWORD.equals(mNewPasswordAction)) { Log.e(TAG, "Unexpected action to launch this activity"); finish(); return; } mSetNewPasswordController = SetNewPasswordController.create( this, this, getIntent(), getActivityToken()); mSetNewPasswordController.dispatchSetNewPasswordIntent(); } @Override public void launchChooseLock(@Nullable Bundle chooseLockFingerprintExtras) { public void launchChooseLock(Bundle chooseLockFingerprintExtras) { Intent intent = new Intent(this, ChooseLockGeneric.class) .setAction(mNewPasswordAction); if (chooseLockFingerprintExtras != null) { intent.putExtras(chooseLockFingerprintExtras); } startActivity(intent); finish(); } Loading Loading
src/com/android/settings/ChooseLockGeneric.java +10 −13 Original line number Diff line number Diff line Loading @@ -186,22 +186,15 @@ public class ChooseLockGeneric extends SettingsActivity { ENCRYPT_REQUESTED_DISABLED); } int targetUser = Utils.getSecureTargetUser( // a) If this is started from other user, use that user id. // b) If this is started from the same user, read the extra if this is launched // from Settings app itself. // c) Otherwise, use UserHandle.myUserId(). mUserId = Utils.getSecureTargetUser( getActivity().getActivityToken(), UserManager.get(getActivity()), null, getArguments(), getActivity().getIntent().getExtras()).getIdentifier(); 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(); mUserId = Utils.getUserIdFromBundle(getContext(), arguments != null ? arguments : getActivity().getIntent().getExtras()); } else { mUserId = targetUser; } if (ACTION_SET_NEW_PASSWORD.equals(chooseLockAction) && Utils.isManagedProfile(UserManager.get(getActivity()), mUserId) && mLockPatternUtils.isSeparateProfileChallengeEnabled(mUserId)) { Loading Loading @@ -256,6 +249,8 @@ public class ChooseLockGeneric extends SettingsActivity { } else if (KEY_SKIP_FINGERPRINT.equals(key)) { Intent chooseLockGenericIntent = new Intent(getActivity(), ChooseLockGeneric.class); chooseLockGenericIntent.setAction(getIntent().getAction()); // Forward the target user id to ChooseLockGeneric. chooseLockGenericIntent.putExtra(Intent.EXTRA_USER_ID, mUserId); chooseLockGenericIntent.putExtra(PASSWORD_CONFIRMED, mPasswordConfirmed); startActivityForResult(chooseLockGenericIntent, SKIP_FINGERPRINT_REQUEST); return true; Loading Loading @@ -343,6 +338,8 @@ public class ChooseLockGeneric extends SettingsActivity { if (data != null) { intent.putExtras(data.getExtras()); } // Forward the target user id to fingerprint setup page. intent.putExtra(Intent.EXTRA_USER_ID, mUserId); startActivity(intent); finish(); } else if (requestCode == SKIP_FINGERPRINT_REQUEST) { Loading
src/com/android/settings/Utils.java +33 −10 Original line number Diff line number Diff line Loading @@ -102,6 +102,7 @@ import java.util.List; import java.util.Locale; import static android.content.Intent.EXTRA_USER; import static android.content.Intent.EXTRA_USER_ID; import static android.text.format.DateUtils.FORMAT_ABBREV_MONTH; import static android.text.format.DateUtils.FORMAT_SHOW_DATE; Loading Loading @@ -651,10 +652,15 @@ public final class Utils extends com.android.settingslib.Utils { /** * Returns the target user for a Settings activity. * * The target user can be either the current user, the user that launched this activity or * the user contained as an extra in the arguments or intent extras. * * <p> * User would be retrieved in this order: * <ul> * <li> If this activity is launched from other user, return that user id. * <li> If this is launched from the Settings app in same user, return the user contained as an * extra in the arguments or intent extras. * <li> Otherwise, return UserHandle.myUserId(). * </ul> * <p> * Note: This is secure in the sense that it only returns a target user different to the current * one if the app launching this activity is the Settings app itself, running in the same user * or in one that is in the same profile group, or if the user id is provided by the system. Loading @@ -675,16 +681,14 @@ public final class Utils extends com.android.settingslib.Utils { return launchedFromUser; } } UserHandle extrasUser = intentExtras != null ? (UserHandle) intentExtras.getParcelable(EXTRA_USER) : null; UserHandle extrasUser = getUserHandleFromBundle(intentExtras); if (extrasUser != null && !extrasUser.equals(currentUser)) { // Check it's secure if (launchedFromSettingsApp && isProfileOf(um, extrasUser)) { return extrasUser; } } UserHandle argumentsUser = arguments != null ? (UserHandle) arguments.getParcelable(EXTRA_USER) : null; UserHandle argumentsUser = getUserHandleFromBundle(arguments); if (argumentsUser != null && !argumentsUser.equals(currentUser)) { // Check it's secure if (launchedFromSettingsApp && isProfileOf(um, argumentsUser)) { Loading @@ -698,6 +702,25 @@ public final class Utils extends com.android.settingslib.Utils { return currentUser; } /** * Lookup both {@link Intent#EXTRA_USER} and {@link Intent#EXTRA_USER_ID} in the bundle * and return the {@link UserHandle} object. Return {@code null} if nothing is found. */ private static @Nullable UserHandle getUserHandleFromBundle(Bundle bundle) { if (bundle == null) { return null; } final UserHandle user = bundle.getParcelable(EXTRA_USER); if (user != null) { return user; } final int userId = bundle.getInt(EXTRA_USER_ID, -1); if (userId != -1) { return UserHandle.of(userId); } return null; } /** * Returns the target user for a Settings activity. * Loading
src/com/android/settings/password/FingerprintManagerWrapper.java 0 → 100644 +47 −0 Original line number Diff line number Diff line /* * 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.NonNull; import android.hardware.fingerprint.FingerprintManager; import com.android.internal.util.Preconditions; /** * Wrapper of {@link FingerprintManager}. Workaround for roboelectic testing. See * {@link IFingerprintManager} for details. */ public class FingerprintManagerWrapper implements IFingerprintManager { private @NonNull FingerprintManager mFingerprintManager; public FingerprintManagerWrapper(@NonNull FingerprintManager fingerprintManager) { Preconditions.checkNotNull(fingerprintManager); mFingerprintManager = fingerprintManager; } public boolean isHardwareDetected() { return mFingerprintManager.isHardwareDetected(); } public boolean hasEnrolledFingerprints(int userId) { return mFingerprintManager.hasEnrolledFingerprints(userId); } public long preEnroll() { return mFingerprintManager.preEnroll(); } }
src/com/android/settings/password/IFingerprintManager.java 0 → 100644 +31 −0 Original line number Diff line number Diff line /* * 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; /** * This is the workaround to allow us test {@link SetNewPasswordController} which uses a new hidden * API {@link android.hardware.fingerprint.FingerprintManager#hasEnrolledFingerprints(int)} that * roboelectric does not support yet. Having roboelectic to support latest platform API is tracked * in b/30995831. */ public interface IFingerprintManager { boolean isHardwareDetected(); boolean hasEnrolledFingerprints(int userId); long preEnroll(); }
src/com/android/settings/password/SetNewPasswordActivity.java +17 −6 Original line number Diff line number Diff line Loading @@ -16,13 +16,18 @@ package com.android.settings.password; import android.annotation.Nullable; import static android.app.admin.DevicePolicyManager.ACTION_SET_NEW_PARENT_PROFILE_PASSWORD; import static android.app.admin.DevicePolicyManager.ACTION_SET_NEW_PASSWORD; import android.app.Activity; import android.app.admin.DevicePolicyManager; import android.content.Intent; import android.os.Bundle; import android.util.Log; import com.android.settings.ChooseLockGeneric; import com.android.settings.SetupChooseLockGeneric; import com.android.settings.Utils; /** * Trampolines {@link DevicePolicyManager#ACTION_SET_NEW_PASSWORD} and Loading @@ -30,6 +35,7 @@ import com.android.settings.ChooseLockGeneric; * activity for handling set new password. */ public class SetNewPasswordActivity extends Activity implements SetNewPasswordController.Ui { private static final String TAG = "SetNewPasswordActivity"; private String mNewPasswordAction; private SetNewPasswordController mSetNewPasswordController; Loading @@ -38,17 +44,22 @@ public class SetNewPasswordActivity extends Activity implements SetNewPasswordCo super.onCreate(savedState); mNewPasswordAction = getIntent().getAction(); mSetNewPasswordController = new SetNewPasswordController(this, this); if (!ACTION_SET_NEW_PASSWORD.equals(mNewPasswordAction) && !ACTION_SET_NEW_PARENT_PROFILE_PASSWORD.equals(mNewPasswordAction)) { Log.e(TAG, "Unexpected action to launch this activity"); finish(); return; } mSetNewPasswordController = SetNewPasswordController.create( this, this, getIntent(), getActivityToken()); mSetNewPasswordController.dispatchSetNewPasswordIntent(); } @Override public void launchChooseLock(@Nullable Bundle chooseLockFingerprintExtras) { public void launchChooseLock(Bundle chooseLockFingerprintExtras) { Intent intent = new Intent(this, ChooseLockGeneric.class) .setAction(mNewPasswordAction); if (chooseLockFingerprintExtras != null) { intent.putExtras(chooseLockFingerprintExtras); } startActivity(intent); finish(); } Loading