Add padlock to location for work profile when disabled by admin.

Change-Id: Iee930c9340436cc68ee432ad15ec182ccc6fb0a1
This commit is contained in:
Sudheer Shanka
2016-01-25 23:34:20 +00:00
parent 20c9817713
commit 0d9ac3469b
3 changed files with 25 additions and 44 deletions

View File

@@ -2827,8 +2827,6 @@
<string name="location_title">My Location</string> <string name="location_title">My Location</string>
<!-- [CHAR LIMIT=30] Title for managed profile location switch --> <!-- [CHAR LIMIT=30] Title for managed profile location switch -->
<string name="managed_profile_location_switch_title">Location for work profile</string> <string name="managed_profile_location_switch_title">Location for work profile</string>
<!-- [CHAR LIMIT=30] Text to show on managed profile location switch if MDM has locked down location access for managed profile-->
<string name="managed_profile_location_switch_lockdown">Turned off by your company</string>
<!-- [CHAR LIMIT=30] Location settings screen, setting preference screen box label for location mode --> <!-- [CHAR LIMIT=30] Location settings screen, setting preference screen box label for location mode -->
<string name="location_mode_title">Mode</string> <string name="location_mode_title">Mode</string>
<!-- [CHAR LIMIT=30] Location settings screen, high accuracy location mode --> <!-- [CHAR LIMIT=30] Location settings screen, high accuracy location mode -->

View File

@@ -27,10 +27,10 @@
android:summary="@string/location_mode_location_off_title" /> android:summary="@string/location_mode_location_off_title" />
<!-- This preference category gets removed if there is no managed profile --> <!-- This preference category gets removed if there is no managed profile -->
<SwitchPreference <com.android.settingslib.RestrictedSwitchPreference
android:key="managed_profile_location_switch" android:key="managed_profile_location_switch"
android:title="@string/managed_profile_location_switch_title" android:title="@string/managed_profile_location_switch_title"
android:summary="@string/managed_profile_location_switch_lockdown" settings:useAdminDisabledSummary="true"
android:persistent="false" android:persistent="false"
android:enabled="false" android:enabled="false"
android:selectable="true" /> android:selectable="true" />

View File

@@ -32,7 +32,6 @@ import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceCategory; import android.support.v7.preference.PreferenceCategory;
import android.support.v7.preference.PreferenceGroup; import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceScreen; import android.support.v7.preference.PreferenceScreen;
import android.support.v14.preference.SwitchPreference;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
@@ -47,6 +46,7 @@ import com.android.settings.applications.InstalledAppDetails;
import com.android.settings.dashboard.SummaryLoader; import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.widget.SwitchBar; import com.android.settings.widget.SwitchBar;
import com.android.settingslib.RestrictedLockUtils; import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
import com.android.settingslib.location.RecentLocationApps; import com.android.settingslib.location.RecentLocationApps;
import java.util.ArrayList; import java.util.ArrayList;
@@ -104,7 +104,7 @@ public class LocationSettings extends LocationSettingsBase
private Switch mSwitch; private Switch mSwitch;
private boolean mValidListener = false; private boolean mValidListener = false;
private UserHandle mManagedProfile; private UserHandle mManagedProfile;
private SwitchPreference mManagedProfileSwitch; private RestrictedSwitchPreference mManagedProfileSwitch;
private Preference mLocationMode; private Preference mLocationMode;
private PreferenceCategory mCategoryRecentLocationRequests; private PreferenceCategory mCategoryRecentLocationRequests;
/** Receives UPDATE_INTENT */ /** Receives UPDATE_INTENT */
@@ -253,7 +253,7 @@ public class LocationSettings extends LocationSettingsBase
root.removePreference(root.findPreference(KEY_MANAGED_PROFILE_SWITCH)); root.removePreference(root.findPreference(KEY_MANAGED_PROFILE_SWITCH));
mManagedProfileSwitch = null; mManagedProfileSwitch = null;
} else { } else {
mManagedProfileSwitch = (SwitchPreference)root mManagedProfileSwitch = (RestrictedSwitchPreference)root
.findPreference(KEY_MANAGED_PROFILE_SWITCH); .findPreference(KEY_MANAGED_PROFILE_SWITCH);
mManagedProfileSwitch.setOnPreferenceClickListener(null); mManagedProfileSwitch.setOnPreferenceClickListener(null);
} }
@@ -263,26 +263,30 @@ public class LocationSettings extends LocationSettingsBase
if (mManagedProfileSwitch == null) { if (mManagedProfileSwitch == null) {
return; return;
} }
boolean enabled = mainSwitchOn;
int summaryResId = R.string.switch_off_text;
if (mUm.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION, mManagedProfile)
&& getAdminRestrictingManagedProfile() != null) {
summaryResId = R.string.managed_profile_location_switch_lockdown;
enabled = false;
}
mManagedProfileSwitch.setEnabled(enabled);
mManagedProfileSwitch.setOnPreferenceClickListener(null); mManagedProfileSwitch.setOnPreferenceClickListener(null);
if (!enabled) { final EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(getActivity(),
UserManager.DISALLOW_SHARE_LOCATION, mManagedProfile.getIdentifier());
if (mUm.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION, mManagedProfile)
&& admin != null) {
mManagedProfileSwitch.setDisabledByAdmin(admin);
mManagedProfileSwitch.setChecked(false); mManagedProfileSwitch.setChecked(false);
} else { } else {
final boolean isRestricted = isManagedProfileRestrictedByBase(); boolean enabled = mainSwitchOn;
mManagedProfileSwitch.setChecked(!isRestricted); mManagedProfileSwitch.setEnabled(enabled);
summaryResId = (isRestricted ?
R.string.switch_off_text : R.string.switch_on_text); int summaryResId = R.string.switch_off_text;
mManagedProfileSwitch.setOnPreferenceClickListener(mManagedProfileSwitchClickListener); if (!enabled) {
mManagedProfileSwitch.setChecked(false);
} else {
final boolean isRestricted = isManagedProfileRestrictedByBase();
mManagedProfileSwitch.setChecked(!isRestricted);
summaryResId = (isRestricted ?
R.string.switch_off_text : R.string.switch_on_text);
mManagedProfileSwitch.setOnPreferenceClickListener(
mManagedProfileSwitchClickListener);
}
mManagedProfileSwitch.setSummary(summaryResId);
} }
mManagedProfileSwitch.setSummary(summaryResId);
} }
/** /**
@@ -418,27 +422,6 @@ public class LocationSettings extends LocationSettingsBase
} }
} }
private ComponentName getAdminRestrictingManagedProfile() {
if (mManagedProfile == null) {
return null;
}
DevicePolicyManager dpm = (DevicePolicyManager)getActivity().getSystemService(
Context.DEVICE_POLICY_SERVICE);
if (dpm == null) {
return null;
}
List<ComponentName> admins = dpm.getActiveAdminsAsUser(mManagedProfile.getIdentifier());
for (int i = 0; i < admins.size(); ++i) {
final ComponentName admin = admins.get(i);
Bundle restrictions = dpm.getUserRestrictions(admin, mManagedProfile.getIdentifier());
if (restrictions != null && restrictions.getBoolean(UserManager.DISALLOW_SHARE_LOCATION,
false)) {
return admin;
}
}
return null;
}
private boolean isManagedProfileRestrictedByBase() { private boolean isManagedProfileRestrictedByBase() {
if (mManagedProfile == null) { if (mManagedProfile == null) {
return false; return false;