Check EnforcedAdmin to see if location is locked down by device policy.

Bug: 78563793
Test: m -j RunSettingsRoboTests
and manually via TestDPC

Change-Id: Iad2f11bde51bf6c321beb3c4709d53971a8e40c7
This commit is contained in:
yuemingw
2018-06-01 17:11:31 +01:00
parent eec3faea44
commit a2a593dd3b
3 changed files with 78 additions and 10 deletions

View File

@@ -25,6 +25,7 @@ import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import android.util.Log;
import com.android.settings.Utils;
import com.android.settings.widget.RestrictedAppPreference;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
@@ -130,8 +131,11 @@ public class LocationServicePreferenceController extends LocationBasePreferenceC
private List<Preference> getLocationServices() {
// If location access is locked down by device policy then we only show injected settings
// for the primary profile.
final int profileUserId = Utils.getManagedProfileId(mUserManager, UserHandle.myUserId());
return mInjector.getInjectedSettings(mFragment.getPreferenceManager().getContext(),
mLocationEnabler.isManagedProfileRestrictedByBase()
(profileUserId != UserHandle.USER_NULL
&& mLocationEnabler.getShareLocationEnforcedAdmin(profileUserId) != null)
? UserHandle.myUserId() : UserHandle.USER_CURRENT);
}
}