Merge "Ask the user to unlock the work profile before adding a work account." into nyc-dev

am: 74777cc

* commit '74777ccd90e8b94614ae29beb7a7e1dbadae77f0':
  Ask the user to unlock the work profile before adding a work account.

Change-Id: I2c2eb6a1117e95079ac3923368d7715e90457880
This commit is contained in:
Nicolas Prevot
2016-04-07 09:30:19 +00:00
committed by android-build-merger
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
* @see Activity#onActivityResult(int, int, android.content.Intent)
*/
boolean launchConfirmationActivity(int request, CharSequence title, boolean returnCredentials,
int userId) {
public boolean launchConfirmationActivity(int request, CharSequence title,
boolean returnCredentials, int userId) {
return launchConfirmationActivity(request, title, null, null,
returnCredentials, false, false, 0, Utils.enforceSameOwner(mActivity, userId));
}

View File

@@ -32,6 +32,7 @@ import android.os.UserManager;
import android.util.Log;
import android.widget.Toast;
import com.android.settings.ChooseLockSettingsHelper;
import com.android.settings.R;
import com.android.settings.Utils;
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 ADD_ACCOUNT_REQUEST = 2;
private static final int UNLOCK_WORK_PROFILE_REQUEST = 3;
private PendingIntent mPendingIntent;
@@ -154,24 +156,27 @@ public class AddAccountSettings extends Activity {
finish();
return;
}
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 the profile is locked, we must ask the user to unlock it first.
ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(this);
if (!helper.launchConfirmationActivity(UNLOCK_WORK_PROFILE_REQUEST,
getString(R.string.unlock_set_unlock_launch_picker_title),
false,
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
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case UNLOCK_WORK_PROFILE_REQUEST:
if (resultCode == Activity.RESULT_OK) {
requestChooseAccount();
} else {
finish();
}
break;
case CHOOSE_ACCOUNT_REQUEST:
if (resultCode == RESULT_CANCELED) {
if (data != null) {
@@ -202,6 +207,22 @@ public class AddAccountSettings extends Activity {
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) {
Bundle addAccountOptions = new Bundle();
/*