Show location settings for managed profiles

Location settings for managed profiles are managed by user restriction DISALLOW_SHARE_LOCATION

Change-Id: I76a64def18de7502ee118e03a699d1a05d9a6ce9
This commit is contained in:
Chirayu Desai
2022-02-15 22:54:45 +05:30
committed by Michael Bestas
parent 6059326b6d
commit 8e8329a05c
2 changed files with 20 additions and 4 deletions

View File

@@ -21,6 +21,10 @@
wizard:firstAction="welcome">
<WizardAction wizard:uri="intent:#Intent;action=org.lineageos.setupwizard.LINEAGE_WELCOME;end" id="welcome">
<result wizard:action="location_settings" />
</WizardAction>
<WizardAction wizard:uri="intent:#Intent;action=org.lineageos.setupwizard.LINEAGE_LOCATION_SETTINGS;end" id="location_settings">
<result wizard:action="restore" />
</WizardAction>

View File

@@ -19,7 +19,8 @@ package org.lineageos.setupwizard;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.Process;
import android.os.UserManager;
import android.view.View;
import android.widget.CheckBox;
@@ -32,6 +33,8 @@ public class LocationSettingsActivity extends BaseSetupWizardActivity {
private LocationManager mLocationManager;
private UserManager mUserManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -39,18 +42,27 @@ public class LocationSettingsActivity extends BaseSetupWizardActivity {
mLocationAccess = (CheckBox) findViewById(R.id.location_checkbox);
mLocationManager = getSystemService(LocationManager.class);
mUserManager = getSystemService(UserManager.class);
View locationAccessView = findViewById(R.id.location);
locationAccessView.setOnClickListener(v -> {
mLocationManager.setLocationEnabledForUser(!mLocationAccess.isChecked(),
new UserHandle(UserHandle.USER_CURRENT));
mLocationAccess.setChecked(!mLocationAccess.isChecked());
mLocationManager.setLocationEnabledForUser(mLocationAccess.isChecked(),
Process.myUserHandle());
if (mUserManager.isManagedProfile()) {
mUserManager.setUserRestriction(UserManager.DISALLOW_SHARE_LOCATION,
!mLocationAccess.isChecked());
}
});
}
@Override
public void onResume() {
super.onResume();
mLocationAccess.setChecked(mLocationManager.isLocationEnabled());
boolean checked = mLocationManager.isLocationEnabled();
if (mUserManager.isManagedProfile()) {
checked &= mUserManager.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION);
}
mLocationAccess.setChecked(checked);
}
@Override