Use the correct userId when checking if disabled by admin.
And when adding accounts if only one account type is possible and it is disabled by admin, show the admin support dialog. Bug: 26897250 Bug: 26767564 Change-Id: I5cca64491a100efc34307c45aa35c14412f043cd
This commit is contained in:
@@ -416,7 +416,7 @@ public class ChooseLockGeneric extends SettingsActivity {
|
|||||||
|
|
||||||
int adminEnforcedQuality = mDPM.getPasswordQuality(null);
|
int adminEnforcedQuality = mDPM.getPasswordQuality(null);
|
||||||
EnforcedAdmin enforcedAdmin = RestrictedLockUtils.checkIfPasswordQualityIsSet(
|
EnforcedAdmin enforcedAdmin = RestrictedLockUtils.checkIfPasswordQualityIsSet(
|
||||||
getActivity());
|
getActivity(), mUserId);
|
||||||
for (int i = entries.getPreferenceCount() - 1; i >= 0; --i) {
|
for (int i = entries.getPreferenceCount() - 1; i >= 0; --i) {
|
||||||
Preference pref = entries.getPreference(i);
|
Preference pref = entries.getPreference(i);
|
||||||
if (pref instanceof RestrictedPreference) {
|
if (pref instanceof RestrictedPreference) {
|
||||||
|
@@ -482,8 +482,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
boolean serviceAllowed =
|
boolean serviceAllowed =
|
||||||
permittedServices == null || permittedServices.contains(packageName);
|
permittedServices == null || permittedServices.contains(packageName);
|
||||||
if (!serviceAllowed && !serviceEnabled) {
|
if (!serviceAllowed && !serviceEnabled) {
|
||||||
EnforcedAdmin admin =
|
EnforcedAdmin admin = RestrictedLockUtils.checkIfAccessibilityServiceDisallowed(
|
||||||
RestrictedLockUtils.getProfileOrDeviceOwnerOnCallingUser(getActivity());
|
getActivity(), serviceInfo.packageName, UserHandle.myUserId());
|
||||||
if (admin != null) {
|
if (admin != null) {
|
||||||
preference.setDisabledByAdmin(admin);
|
preference.setDisabledByAdmin(admin);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -272,7 +272,7 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
mUserHandle.getIdentifier());
|
mUserHandle.getIdentifier());
|
||||||
if (admin == null) {
|
if (admin == null) {
|
||||||
admin = RestrictedLockUtils.checkIfAccountManagementDisabled(
|
admin = RestrictedLockUtils.checkIfAccountManagementDisabled(
|
||||||
getPrefContext(), mAccount.type);
|
getPrefContext(), mAccount.type, mUserHandle.getIdentifier());
|
||||||
}
|
}
|
||||||
RestrictedLockUtils.setMenuItemAsDisabledByAdmin(getPrefContext(),
|
RestrictedLockUtils.setMenuItemAsDisabledByAdmin(getPrefContext(),
|
||||||
removeAccount, admin);
|
removeAccount, admin);
|
||||||
|
@@ -34,11 +34,14 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
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 java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static android.content.Intent.EXTRA_USER;
|
import static android.content.Intent.EXTRA_USER;
|
||||||
|
|
||||||
|
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entry point Activity for account setup. Works as follows
|
* Entry point Activity for account setup. Works as follows
|
||||||
*
|
*
|
||||||
@@ -171,6 +174,9 @@ public class AddAccountSettings extends Activity {
|
|||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case CHOOSE_ACCOUNT_REQUEST:
|
case CHOOSE_ACCOUNT_REQUEST:
|
||||||
if (resultCode == RESULT_CANCELED) {
|
if (resultCode == RESULT_CANCELED) {
|
||||||
|
if (data != null) {
|
||||||
|
startActivityAsUser(data, mUserHandle);
|
||||||
|
}
|
||||||
setResult(resultCode);
|
setResult(resultCode);
|
||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
|
@@ -39,6 +39,7 @@ import com.android.internal.util.CharSequences;
|
|||||||
import com.android.settings.InstrumentedPreferenceActivity;
|
import com.android.settings.InstrumentedPreferenceActivity;
|
||||||
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 java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -48,6 +49,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
import static android.content.Intent.EXTRA_USER;
|
import static android.content.Intent.EXTRA_USER;
|
||||||
|
|
||||||
|
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Activity asking a user to select an account to be set up.
|
* Activity asking a user to select an account to be set up.
|
||||||
*
|
*
|
||||||
@@ -160,9 +163,19 @@ public class ChooseAccountActivity extends InstrumentedPreferenceActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Context context = getPreferenceScreen().getContext();
|
||||||
if (mProviderList.size() == 1) {
|
if (mProviderList.size() == 1) {
|
||||||
// If there's only one provider that matches, just run it.
|
// There's only one provider that matches. If it is disabled by admin show the
|
||||||
finishWithAccountType(mProviderList.get(0).type);
|
// support dialog otherwise run it.
|
||||||
|
EnforcedAdmin admin = RestrictedLockUtils.checkIfAccountManagementDisabled(
|
||||||
|
context, mProviderList.get(0).type, mUserHandle.getIdentifier());
|
||||||
|
if (admin != null) {
|
||||||
|
setResult(RESULT_CANCELED, RestrictedLockUtils.getShowAdminSupportDetailsIntent(
|
||||||
|
context, admin));
|
||||||
|
finish();
|
||||||
|
} else {
|
||||||
|
finishWithAccountType(mProviderList.get(0).type);
|
||||||
|
}
|
||||||
} else if (mProviderList.size() > 0) {
|
} else if (mProviderList.size() > 0) {
|
||||||
Collections.sort(mProviderList);
|
Collections.sort(mProviderList);
|
||||||
mAddAccountGroup.removeAll();
|
mAddAccountGroup.removeAll();
|
||||||
@@ -170,7 +183,7 @@ public class ChooseAccountActivity extends InstrumentedPreferenceActivity {
|
|||||||
Drawable drawable = getDrawableForType(pref.type);
|
Drawable drawable = getDrawableForType(pref.type);
|
||||||
ProviderPreference p = new ProviderPreference(getPreferenceScreen().getContext(),
|
ProviderPreference p = new ProviderPreference(getPreferenceScreen().getContext(),
|
||||||
pref.type, drawable, pref.name);
|
pref.type, drawable, pref.name);
|
||||||
p.checkAccountManagementAndSetDisabled();
|
p.checkAccountManagementAndSetDisabled(mUserHandle.getIdentifier());
|
||||||
mAddAccountGroup.addPreference(p);
|
mAddAccountGroup.addPreference(p);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@@ -46,9 +46,9 @@ public class ProviderPreference extends RestrictedPreference {
|
|||||||
return mAccountType;
|
return mAccountType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkAccountManagementAndSetDisabled() {
|
public void checkAccountManagementAndSetDisabled(int userId) {
|
||||||
EnforcedAdmin admin = RestrictedLockUtils.checkIfAccountManagementDisabled(
|
EnforcedAdmin admin = RestrictedLockUtils.checkIfAccountManagementDisabled(
|
||||||
getContext(), getAccountType());
|
getContext(), getAccountType(), userId);
|
||||||
setDisabledByAdmin(admin);
|
setDisabledByAdmin(admin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -21,6 +21,7 @@ import android.content.ActivityNotFoundException;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.UserHandle;
|
||||||
import android.support.v14.preference.SwitchPreference;
|
import android.support.v14.preference.SwitchPreference;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
|
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
|
||||||
@@ -121,11 +122,6 @@ class InputMethodPreference extends RestrictedSwitchPreference implements OnPref
|
|||||||
setOnPreferenceClickListener(this);
|
setOnPreferenceClickListener(this);
|
||||||
setOnPreferenceChangeListener(this);
|
setOnPreferenceChangeListener(this);
|
||||||
useAdminDisabledSummary(true);
|
useAdminDisabledSummary(true);
|
||||||
if (!isAllowedByOrganization) {
|
|
||||||
EnforcedAdmin admin =
|
|
||||||
RestrictedLockUtils.getProfileOrDeviceOwnerOnCallingUser(context);
|
|
||||||
setDisabledByAdmin(admin);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputMethodInfo getInputMethodInfo() {
|
public InputMethodInfo getInputMethodInfo() {
|
||||||
@@ -192,11 +188,23 @@ class InputMethodPreference extends RestrictedSwitchPreference implements OnPref
|
|||||||
void updatePreferenceViews() {
|
void updatePreferenceViews() {
|
||||||
final boolean isAlwaysChecked = mInputMethodSettingValues.isAlwaysCheckedIme(
|
final boolean isAlwaysChecked = mInputMethodSettingValues.isAlwaysCheckedIme(
|
||||||
mImi, getContext());
|
mImi, getContext());
|
||||||
// Only when this preference has a switch and an input method should be always enabled,
|
// When this preference has a switch and an input method should be always enabled,
|
||||||
// this preference should be disabled to prevent accidentally disabling an input method.
|
// this preference should be disabled to prevent accidentally disabling an input method.
|
||||||
setEnabled(!((isAlwaysChecked && isImeEnabler()) || (!mIsAllowedByOrganization)));
|
// This preference should also be disabled in case the admin does not allow this input
|
||||||
|
// method.
|
||||||
|
if (isAlwaysChecked && isImeEnabler()) {
|
||||||
|
setDisabledByAdmin(null);
|
||||||
|
setEnabled(false);
|
||||||
|
} else if (!mIsAllowedByOrganization) {
|
||||||
|
EnforcedAdmin admin =
|
||||||
|
RestrictedLockUtils.checkIfInputMethodDisallowed(getContext(),
|
||||||
|
mImi.getPackageName(), UserHandle.myUserId());
|
||||||
|
setDisabledByAdmin(admin);
|
||||||
|
} else {
|
||||||
|
setEnabled(true);
|
||||||
|
}
|
||||||
setChecked(mInputMethodSettingValues.isEnabledImi(mImi));
|
setChecked(mInputMethodSettingValues.isEnabledImi(mImi));
|
||||||
if (mIsAllowedByOrganization) {
|
if (!isDisabledByAdmin()) {
|
||||||
setSummary(getSummaryString());
|
setSummary(getSummaryString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user