Ask the user to unlock the work profile before adding a work account.

If the work profile is locked, and the user tries to add a
work account from Settings:
Show the work profile security challenge.

BUG:28005200
Change-Id: I87ff25d9de94026b0d7ac307ea3a541e77989aa6
This commit is contained in:
Nicolas Prevot
2016-04-06 11:19:08 +01:00
parent 6452b84763
commit a599c8fd04
2 changed files with 35 additions and 14 deletions

View File

@@ -88,8 +88,8 @@ public final class ChooseLockSettingsHelper {
* @return true if one exists and we launched an activity to confirm it * @return true if one exists and we launched an activity to confirm it
* @see Activity#onActivityResult(int, int, android.content.Intent) * @see Activity#onActivityResult(int, int, android.content.Intent)
*/ */
boolean launchConfirmationActivity(int request, CharSequence title, boolean returnCredentials, public boolean launchConfirmationActivity(int request, CharSequence title,
int userId) { boolean returnCredentials, int userId) {
return launchConfirmationActivity(request, title, null, null, return launchConfirmationActivity(request, title, null, null,
returnCredentials, false, false, 0, Utils.enforceSameOwner(mActivity, userId)); returnCredentials, false, false, 0, Utils.enforceSameOwner(mActivity, userId));
} }

View File

@@ -32,6 +32,7 @@ import android.os.UserManager;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
import com.android.settings.ChooseLockSettingsHelper;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.Utils; import com.android.settings.Utils;
import com.android.settingslib.RestrictedLockUtils; import com.android.settingslib.RestrictedLockUtils;
@@ -83,6 +84,7 @@ public class AddAccountSettings extends Activity {
private static final int CHOOSE_ACCOUNT_REQUEST = 1; private static final int CHOOSE_ACCOUNT_REQUEST = 1;
private static final int ADD_ACCOUNT_REQUEST = 2; private static final int ADD_ACCOUNT_REQUEST = 2;
private static final int UNLOCK_WORK_PROFILE_REQUEST = 3;
private PendingIntent mPendingIntent; private PendingIntent mPendingIntent;
@@ -154,24 +156,27 @@ public class AddAccountSettings extends Activity {
finish(); finish();
return; return;
} }
final String[] authorities =
getIntent().getStringArrayExtra(AccountPreferenceBase.AUTHORITIES_FILTER_KEY); // If the profile is locked, we must ask the user to unlock it first.
final String[] accountTypes = ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(this);
getIntent().getStringArrayExtra(AccountPreferenceBase.ACCOUNT_TYPES_FILTER_KEY); if (!helper.launchConfirmationActivity(UNLOCK_WORK_PROFILE_REQUEST,
final Intent intent = new Intent(this, ChooseAccountActivity.class); getString(R.string.unlock_set_unlock_launch_picker_title),
if (authorities != null) { false,
intent.putExtra(AccountPreferenceBase.AUTHORITIES_FILTER_KEY, authorities); mUserHandle.getIdentifier())) {
requestChooseAccount();
} }
if (accountTypes != null) {
intent.putExtra(AccountPreferenceBase.ACCOUNT_TYPES_FILTER_KEY, accountTypes);
}
intent.putExtra(EXTRA_USER, mUserHandle);
startActivityForResult(intent, CHOOSE_ACCOUNT_REQUEST);
} }
@Override @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) { switch (requestCode) {
case UNLOCK_WORK_PROFILE_REQUEST:
if (resultCode == Activity.RESULT_OK) {
requestChooseAccount();
} else {
finish();
}
break;
case CHOOSE_ACCOUNT_REQUEST: case CHOOSE_ACCOUNT_REQUEST:
if (resultCode == RESULT_CANCELED) { if (resultCode == RESULT_CANCELED) {
if (data != null) { if (data != null) {
@@ -202,6 +207,22 @@ public class AddAccountSettings extends Activity {
if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "saved"); if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "saved");
} }
private void requestChooseAccount() {
final String[] authorities =
getIntent().getStringArrayExtra(AccountPreferenceBase.AUTHORITIES_FILTER_KEY);
final String[] accountTypes =
getIntent().getStringArrayExtra(AccountPreferenceBase.ACCOUNT_TYPES_FILTER_KEY);
final Intent intent = new Intent(this, ChooseAccountActivity.class);
if (authorities != null) {
intent.putExtra(AccountPreferenceBase.AUTHORITIES_FILTER_KEY, authorities);
}
if (accountTypes != null) {
intent.putExtra(AccountPreferenceBase.ACCOUNT_TYPES_FILTER_KEY, accountTypes);
}
intent.putExtra(EXTRA_USER, mUserHandle);
startActivityForResult(intent, CHOOSE_ACCOUNT_REQUEST);
}
private void addAccount(String accountType) { private void addAccount(String accountType) {
Bundle addAccountOptions = new Bundle(); Bundle addAccountOptions = new Bundle();
/* /*