Use Activity.getActivityToken to align with mr2

Context.getActivityToken is introduced since O.
To align with MR2 and avoid unnecessary merge conflict,
pass the activity token from activity to controller.

Test: 1. make RunSettingsRoboTests
      2. Manual Test
      	a. Start SET_NEW_PASSWORD intent in user 0, set password.
         	User 0 password is set.
      	b. Start SET_NEW_PASSWORD intent in work profile, set password.
         	work profile password is set.

Bug: 32959373
Change-Id: I8577752d446a7c395ad30417f8c0c832f951d7b3
This commit is contained in:
Tony Mak
2016-12-14 02:57:14 +00:00
parent 1ff0a53529
commit e0405fc4f2
2 changed files with 6 additions and 3 deletions

View File

@@ -50,7 +50,8 @@ public class SetNewPasswordActivity extends Activity implements SetNewPasswordCo
finish(); finish();
return; return;
} }
mSetNewPasswordController = SetNewPasswordController.create(this, this, getIntent()); mSetNewPasswordController = SetNewPasswordController.create(
this, this, getIntent(), getActivityToken());
mSetNewPasswordController.dispatchSetNewPasswordIntent(); mSetNewPasswordController.dispatchSetNewPasswordIntent();
} }

View File

@@ -29,6 +29,7 @@ import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.hardware.fingerprint.FingerprintManager; import android.hardware.fingerprint.FingerprintManager;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder;
import android.os.UserManager; import android.os.UserManager;
import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting;
@@ -60,14 +61,15 @@ final class SetNewPasswordController {
private final DevicePolicyManager mDevicePolicyManager; private final DevicePolicyManager mDevicePolicyManager;
private final Ui mUi; private final Ui mUi;
public static SetNewPasswordController create(Context context, Ui ui, Intent intent) { public static SetNewPasswordController create(Context context, Ui ui, Intent intent,
IBinder activityToken) {
// Trying to figure out which user is setting new password. If it is // Trying to figure out which user is setting new password. If it is
// ACTION_SET_NEW_PARENT_PROFILE_PASSWORD or the calling user is not allowed to set // ACTION_SET_NEW_PARENT_PROFILE_PASSWORD or the calling user is not allowed to set
// separate profile challenge, it is the current user to set new password. Otherwise, // separate profile challenge, it is the current user to set new password. Otherwise,
// it is the user who starts this activity setting new password. // it is the user who starts this activity setting new password.
int userId = ActivityManager.getCurrentUser(); int userId = ActivityManager.getCurrentUser();
if (ACTION_SET_NEW_PASSWORD.equals(intent.getAction())) { if (ACTION_SET_NEW_PASSWORD.equals(intent.getAction())) {
final int callingUserId = Utils.getSecureTargetUser(context.getActivityToken(), final int callingUserId = Utils.getSecureTargetUser(activityToken,
UserManager.get(context), null, intent.getExtras()).getIdentifier(); UserManager.get(context), null, intent.getExtras()).getIdentifier();
final LockPatternUtils lockPatternUtils = new LockPatternUtils(context); final LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
if (lockPatternUtils.isSeparateProfileChallengeAllowed(callingUserId)) { if (lockPatternUtils.isSeparateProfileChallengeAllowed(callingUserId)) {