Merge "Separate personal/work tab in LocationSettings"

This commit is contained in:
Raff Tsai
2019-11-27 16:42:03 +00:00
committed by Android (Google) Code Review
14 changed files with 403 additions and 41 deletions

View File

@@ -0,0 +1,61 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.location;
import android.app.settings.SettingsEnums;
import android.content.Context;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
/**
* Location Setting page for personal profile.
*/
public class LocationPersonalSettings extends DashboardFragment {
private static final String TAG = "LocationPersonal";
@Override
public int getMetricsCategory() {
return SettingsEnums.LOCATION;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.location_settings_personal;
}
@Override
protected String getLogTag() {
return TAG;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
use(AppLocationPermissionPreferenceController.class).init(this);
use(RecentLocationRequestPreferenceController.class).init(this);
use(LocationServicePreferenceController.class).init(this);
use(LocationFooterPreferenceController.class).init(this);
}
@Override
public int getHelpResource() {
return R.string.help_url_location_access;
}
}

View File

@@ -0,0 +1,59 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.location;
import android.content.Context;
import android.os.UserHandle;
import androidx.preference.Preference;
import com.android.settings.widget.RestrictedAppPreference;
import java.util.List;
import java.util.Map;
/**
* Retrieve the Location Services used in profile user.
*/
public class LocationServiceForWorkPreferenceController extends
LocationServicePreferenceController {
private static final String TAG = "LocationWorkPrefCtrl";
public LocationServiceForWorkPreferenceController(Context context, String key) {
super(context, key);
}
@Override
public void updateState(Preference preference) {
mCategoryLocationServices.removeAll();
final Map<Integer, List<Preference>> prefs = getLocationServices();
boolean show = false;
for (Map.Entry<Integer, List<Preference>> entry : prefs.entrySet()) {
for (Preference pref : entry.getValue()) {
if (pref instanceof RestrictedAppPreference) {
((RestrictedAppPreference) pref).checkRestrictionAndSetDisabled();
}
}
if (entry.getKey() != UserHandle.myUserId()) {
LocationSettings.addPreferencesSorted(entry.getValue(),
mCategoryLocationServices);
show = true;
}
}
mCategoryLocationServices.setVisible(show);
}
}

View File

@@ -39,19 +39,12 @@ import java.util.Map;
public class LocationServicePreferenceController extends LocationBasePreferenceController
implements LifecycleObserver, OnResume, OnPause {
private static final String TAG = "LocationServicePrefCtrl";
/** Key for preference category "Location services" */
@VisibleForTesting
static final String KEY_LOCATION_SERVICES = "location_services";
/** Key for preference category "Location services for work" */
@VisibleForTesting
static final String KEY_LOCATION_SERVICES_MANAGED = "location_services_managed_profile";
private static final String TAG = "LocationPrefCtrl";
@VisibleForTesting
static final IntentFilter INTENT_FILTER_INJECTED_SETTING_CHANGED =
new IntentFilter(SettingInjectorService.ACTION_INJECTED_SETTING_CHANGED);
private PreferenceCategory mCategoryLocationServices;
private PreferenceCategory mCategoryLocationServicesManaged;
protected PreferenceCategory mCategoryLocationServices;
@VisibleForTesting
AppSettingsInjector mInjector;
/** Receives UPDATE_INTENT */
@@ -71,21 +64,14 @@ public class LocationServicePreferenceController extends LocationBasePreferenceC
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mCategoryLocationServices = screen.findPreference(KEY_LOCATION_SERVICES);
mCategoryLocationServicesManaged = screen.findPreference(KEY_LOCATION_SERVICES_MANAGED);
mCategoryLocationServices = screen.findPreference(getPreferenceKey());
}
@Override
public void updateState(Preference preference) {
if (mCategoryLocationServices != null) {
mCategoryLocationServices.removeAll();
}
if (mCategoryLocationServicesManaged != null) {
mCategoryLocationServicesManaged.removeAll();
}
mCategoryLocationServices.removeAll();
final Map<Integer, List<Preference>> prefs = getLocationServices();
boolean showPrimary = false;
boolean showManaged = false;
boolean show = false;
for (Map.Entry<Integer, List<Preference>> entry : prefs.entrySet()) {
for (Preference pref : entry.getValue()) {
if (pref instanceof RestrictedAppPreference) {
@@ -97,21 +83,10 @@ public class LocationServicePreferenceController extends LocationBasePreferenceC
LocationSettings.addPreferencesSorted(entry.getValue(),
mCategoryLocationServices);
}
showPrimary = true;
} else {
if (mCategoryLocationServicesManaged != null) {
LocationSettings.addPreferencesSorted(entry.getValue(),
mCategoryLocationServicesManaged);
}
showManaged = true;
show = true;
}
}
if (mCategoryLocationServices != null) {
mCategoryLocationServices.setVisible(showPrimary);
}
if (mCategoryLocationServicesManaged != null) {
mCategoryLocationServicesManaged.setVisible(showManaged);
}
mCategoryLocationServices.setVisible(show);
}
@Override
@@ -143,7 +118,7 @@ public class LocationServicePreferenceController extends LocationBasePreferenceC
mContext.unregisterReceiver(mInjectedSettingsReceiver);
}
private Map<Integer, List<Preference>> getLocationServices() {
protected Map<Integer, 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());

View File

@@ -87,6 +87,7 @@ public class LocationSettings extends DashboardFragment {
use(LocationServicePreferenceController.class).init(this);
use(LocationFooterPreferenceController.class).init(this);
use(LocationForWorkPreferenceController.class).init(this);
use(LocationServiceForWorkPreferenceController.class).init(this);
}
@Override

View File

@@ -0,0 +1,62 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.location;
import android.app.settings.SettingsEnums;
import android.content.Context;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
/**
* Location Setting page for managed profile.
*/
public class LocationWorkProfileSettings extends DashboardFragment {
private static final String TAG = "LocationWorkProfile";
@Override
public int getMetricsCategory() {
return SettingsEnums.LOCATION_WORK;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.location_settings_workprofile;
}
@Override
protected String getLogTag() {
return TAG;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
use(AppLocationPermissionPreferenceController.class).init(this);
use(RecentLocationRequestPreferenceController.class).init(this);
use(LocationServiceForWorkPreferenceController.class).init(this);
use(LocationFooterPreferenceController.class).init(this);
use(LocationForWorkPreferenceController.class).init(this);
}
@Override
public int getHelpResource() {
return R.string.help_url_location_access;
}
}