Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0d9ac346 authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

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

Change-Id: Iee930c9340436cc68ee432ad15ec182ccc6fb0a1
parent 20c98177
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -2827,8 +2827,6 @@
    <string name="location_title">My Location</string>
    <!-- [CHAR LIMIT=30] Title for managed profile location switch  -->
    <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 -->
    <string name="location_mode_title">Mode</string>
    <!-- [CHAR LIMIT=30] Location settings screen, high accuracy location mode -->
+2 −2
Original line number Diff line number Diff line
@@ -27,10 +27,10 @@
            android:summary="@string/location_mode_location_off_title" />

        <!-- This preference category gets removed if there is no managed profile -->
        <SwitchPreference
        <com.android.settingslib.RestrictedSwitchPreference
            android:key="managed_profile_location_switch"
            android:title="@string/managed_profile_location_switch_title"
            android:summary="@string/managed_profile_location_switch_lockdown"
            settings:useAdminDisabledSummary="true"
            android:persistent="false"
            android:enabled="false"
            android:selectable="true" />
+23 −40
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceCategory;
import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceScreen;
import android.support.v14.preference.SwitchPreference;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
@@ -47,6 +46,7 @@ import com.android.settings.applications.InstalledAppDetails;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.widget.SwitchBar;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
import com.android.settingslib.location.RecentLocationApps;

import java.util.ArrayList;
@@ -104,7 +104,7 @@ public class LocationSettings extends LocationSettingsBase
    private Switch mSwitch;
    private boolean mValidListener = false;
    private UserHandle mManagedProfile;
    private SwitchPreference mManagedProfileSwitch;
    private RestrictedSwitchPreference mManagedProfileSwitch;
    private Preference mLocationMode;
    private PreferenceCategory mCategoryRecentLocationRequests;
    /** Receives UPDATE_INTENT  */
@@ -253,7 +253,7 @@ public class LocationSettings extends LocationSettingsBase
            root.removePreference(root.findPreference(KEY_MANAGED_PROFILE_SWITCH));
            mManagedProfileSwitch = null;
        } else {
            mManagedProfileSwitch = (SwitchPreference)root
            mManagedProfileSwitch = (RestrictedSwitchPreference)root
                    .findPreference(KEY_MANAGED_PROFILE_SWITCH);
            mManagedProfileSwitch.setOnPreferenceClickListener(null);
        }
@@ -263,16 +263,18 @@ public class LocationSettings extends LocationSettingsBase
        if (mManagedProfileSwitch == null) {
            return;
        }
        boolean enabled = mainSwitchOn;
        int summaryResId = R.string.switch_off_text;
        mManagedProfileSwitch.setOnPreferenceClickListener(null);
        final EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(getActivity(),
                UserManager.DISALLOW_SHARE_LOCATION, mManagedProfile.getIdentifier());
        if (mUm.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION, mManagedProfile)
                && getAdminRestrictingManagedProfile() != null) {
                    summaryResId = R.string.managed_profile_location_switch_lockdown;
                    enabled = false;
        }

                && admin != null) {
            mManagedProfileSwitch.setDisabledByAdmin(admin);
            mManagedProfileSwitch.setChecked(false);
        } else {
            boolean enabled = mainSwitchOn;
            mManagedProfileSwitch.setEnabled(enabled);
        mManagedProfileSwitch.setOnPreferenceClickListener(null);

            int summaryResId = R.string.switch_off_text;
            if (!enabled) {
                mManagedProfileSwitch.setChecked(false);
            } else {
@@ -280,10 +282,12 @@ public class LocationSettings extends LocationSettingsBase
                mManagedProfileSwitch.setChecked(!isRestricted);
                summaryResId = (isRestricted ?
                        R.string.switch_off_text : R.string.switch_on_text);
            mManagedProfileSwitch.setOnPreferenceClickListener(mManagedProfileSwitchClickListener);
                mManagedProfileSwitch.setOnPreferenceClickListener(
                        mManagedProfileSwitchClickListener);
            }
            mManagedProfileSwitch.setSummary(summaryResId);
        }
    }

    /**
     * Add the settings injected by external apps into the "App Settings" category. Hides the
@@ -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() {
        if (mManagedProfile == null) {
            return false;