Move LocationSettings to top level page.
- Create some location icons for different scenario. - Remove Location in Security page. - Move Location Setting to top level page. Test: robotest, visual Bug: 116628158 Change-Id: I3f57ef49a396877bfbeaefea7dc4f4051e0ccc65
This commit is contained in:
@@ -1,111 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.location.LocationManager;
|
||||
import android.provider.Settings.Secure;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnPause;
|
||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
|
||||
public class LocationPreferenceController extends AbstractPreferenceController
|
||||
implements PreferenceControllerMixin, LifecycleObserver, OnResume, OnPause {
|
||||
|
||||
private static final String KEY_LOCATION = "location";
|
||||
private Context mContext;
|
||||
private Preference mPreference;
|
||||
|
||||
@VisibleForTesting
|
||||
BroadcastReceiver mLocationProvidersChangedReceiver;
|
||||
|
||||
public LocationPreferenceController(Context context, Lifecycle lifecycle) {
|
||||
super(context);
|
||||
mContext = context;
|
||||
mLocationProvidersChangedReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(LocationManager.PROVIDERS_CHANGED_ACTION)) {
|
||||
updateSummary();
|
||||
}
|
||||
}
|
||||
};
|
||||
if (lifecycle != null) {
|
||||
lifecycle.addObserver(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(KEY_LOCATION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
if (mLocationProvidersChangedReceiver != null) {
|
||||
mContext.registerReceiver(mLocationProvidersChangedReceiver, new IntentFilter(
|
||||
LocationManager.PROVIDERS_CHANGED_ACTION));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
if (mLocationProvidersChangedReceiver != null) {
|
||||
mContext.unregisterReceiver(mLocationProvidersChangedReceiver);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
preference.setSummary(getLocationSummary(mContext));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_LOCATION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void updateSummary() {
|
||||
updateState(mPreference);
|
||||
}
|
||||
|
||||
public static String getLocationSummary(Context context) {
|
||||
int mode = Secure.getInt(context.getContentResolver(),
|
||||
Secure.LOCATION_MODE, Secure.LOCATION_MODE_OFF);
|
||||
if (mode != Secure.LOCATION_MODE_OFF) {
|
||||
return context.getString(R.string.location_on_summary);
|
||||
}
|
||||
return context.getString(R.string.location_off_summary);
|
||||
}
|
||||
}
|
@@ -133,34 +133,6 @@ public class LocationSettings extends DashboardFragment {
|
||||
return controllers;
|
||||
}
|
||||
|
||||
private static class SummaryProvider implements SummaryLoader.SummaryProvider {
|
||||
|
||||
private final Context mContext;
|
||||
private final SummaryLoader mSummaryLoader;
|
||||
|
||||
public SummaryProvider(Context context, SummaryLoader summaryLoader) {
|
||||
mContext = context;
|
||||
mSummaryLoader = summaryLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setListening(boolean listening) {
|
||||
if (listening) {
|
||||
mSummaryLoader.setSummary(
|
||||
this, LocationPreferenceController.getLocationSummary(mContext));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
|
||||
= new SummaryLoader.SummaryProviderFactory() {
|
||||
@Override
|
||||
public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
|
||||
SummaryLoader summaryLoader) {
|
||||
return new SummaryProvider(activity, summaryLoader);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
|
@@ -29,7 +29,6 @@ import com.android.settings.biometrics.fingerprint.FingerprintProfileStatusPrefe
|
||||
import com.android.settings.biometrics.fingerprint.FingerprintStatusPreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.enterprise.EnterprisePrivacyPreferenceController;
|
||||
import com.android.settings.location.LocationPreferenceController;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.security.trustagent.ManageTrustAgentsPreferenceController;
|
||||
import com.android.settings.security.trustagent.TrustAgentListPreferenceController;
|
||||
@@ -105,7 +104,6 @@ public class SecuritySettings extends DashboardFragment {
|
||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
||||
Lifecycle lifecycle, SecuritySettings host) {
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new LocationPreferenceController(context, lifecycle));
|
||||
controllers.add(new EnterprisePrivacyPreferenceController(context));
|
||||
controllers.add(new ManageTrustAgentsPreferenceController(context));
|
||||
controllers.add(new ScreenPinningPreferenceController(context));
|
||||
|
@@ -450,7 +450,7 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
|
||||
private void addLocationAppRestrictionsPreference(AppRestrictionsHelper.SelectableAppInfo app,
|
||||
AppRestrictionsPreference p) {
|
||||
String packageName = app.packageName;
|
||||
p.setIcon(R.drawable.ic_settings_location);
|
||||
p.setIcon(R.drawable.ic_preference_location);
|
||||
p.setKey(getKeyForPackage(packageName));
|
||||
ArrayList<RestrictionEntry> restrictions = RestrictionUtils.getRestrictions(
|
||||
getActivity(), mUser);
|
||||
|
Reference in New Issue
Block a user