Loading res/values/strings.xml +7 −0 Original line number Diff line number Diff line Loading @@ -3847,6 +3847,13 @@ <!-- Ask user to connect to the internet [CHAR_ LIMIT=50]--> <string name="mobile_connect_to_internet" translatable="true">Please connect to the internet</string> <!-- Location settings screen, sub category for recent location requests [CHAR LIMIT=42] --> <string name="location_category_recent_location_requests">Recent location requests</string> <!-- Location settings screen, displayed when there're more than three recent location requests [CHAR LIMIT=30] --> <string name="location_recent_location_requests_see_all">See all</string> <!-- Location settings screen, sub category for location services [CHAR LIMIT=30] --> <string name="location_category_location_services">Location services</string> <!-- Security & location settings screen, section header for settings relating to location --> <string name="location_title">My Location</string> <!-- [CHAR LIMIT=30] Title for managed profile location switch --> Loading res/xml/location_recent_requests_see_all.xml 0 → 100644 +18 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2018 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. --> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:title="@string/location_category_recent_location_requests" android:key="recent_location_requests_see_all"> <PreferenceCategory android:key="all_recent_location_requests"/> </PreferenceScreen> res/xml/location_settings.xml +10 −5 Original line number Diff line number Diff line Loading @@ -20,11 +20,16 @@ android:title="@string/location_settings_title" settings:keywords="@string/keywords_location"> <com.android.settingslib.widget.LayoutPreference android:key="apps_dashboard" android:layout="@layout/app_entities_header" android:selectable="false" settings:allowDividerBelow="true" /> <PreferenceCategory android:key="recent_location_requests" android:title="@string/location_category_recent_location_requests"/> <Preference android:key="recent_location_requests_see_all_button" android:title="@string/location_recent_location_requests_see_all" android:icon="@drawable/ic_chevron_right_24dp" android:fragment="com.android.settings.location.RecentLocationRequestSeeAllFragment" settings:searchable="false"/> <PreferenceCategory android:key="location_advanced_settings" Loading src/com/android/settings/location/LocationSettings.java +3 −3 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ import com.android.settings.search.Indexable; import com.android.settings.widget.SwitchBar; import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.location.RecentLocationAccesses; import com.android.settingslib.location.RecentLocationApps; import com.android.settingslib.search.SearchIndexable; import java.util.ArrayList; Loading @@ -50,7 +50,7 @@ import java.util.List; * <li>In switch bar: location master switch. Used to toggle location on and off. * </li> * </ul> * <li>Recent location requests: automatically populated by {@link RecentLocationAccesses}</li> * <li>Recent location requests: automatically populated by {@link RecentLocationApps}</li> * <li>Location services: multi-app settings provided from outside the Android framework. Each * is injected by a system-partition app via the {@link SettingInjectorService} API.</li> * </ul> Loading Loading @@ -118,7 +118,7 @@ public class LocationSettings extends DashboardFragment { final List<AbstractPreferenceController> controllers = new ArrayList<>(); controllers.add(new AppLocationPermissionPreferenceController(context, lifecycle)); controllers.add(new LocationForWorkPreferenceController(context, lifecycle)); controllers.add(new RecentLocationAccessPreferenceController(context)); controllers.add(new RecentLocationRequestPreferenceController(context, fragment, lifecycle)); controllers.add(new LocationScanningPreferenceController(context)); controllers.add(new LocationServicePreferenceController(context, fragment, lifecycle)); controllers.add(new LocationFooterPreferenceController(context, lifecycle)); Loading src/com/android/settings/location/RecentLocationRequestPreferenceController.java 0 → 100644 +145 −0 Original line number Diff line number Diff line /* * 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.Context; import android.os.Bundle; import android.os.UserHandle; import androidx.annotation.VisibleForTesting; import androidx.preference.Preference; import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceScreen; import com.android.settings.R; import com.android.settings.applications.appinfo.AppInfoDashboardFragment; import com.android.settings.core.SubSettingLauncher; import com.android.settings.dashboard.DashboardFragment; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.location.RecentLocationApps; import com.android.settingslib.widget.apppreference.AppPreference; import java.util.List; public class RecentLocationRequestPreferenceController extends LocationBasePreferenceController { /** Key for preference category "Recent location requests" */ private static final String KEY_RECENT_LOCATION_REQUESTS = "recent_location_requests"; @VisibleForTesting static final String KEY_SEE_ALL_BUTTON = "recent_location_requests_see_all_button"; private final LocationSettings mFragment; private final RecentLocationApps mRecentLocationApps; private PreferenceCategory mCategoryRecentLocationRequests; /** Used in this class and {@link RecentLocationRequestSeeAllPreferenceController} */ static class PackageEntryClickedListener implements Preference.OnPreferenceClickListener { private final DashboardFragment mFragment; private final String mPackage; private final UserHandle mUserHandle; public PackageEntryClickedListener(DashboardFragment fragment, String packageName, UserHandle userHandle) { mFragment = fragment; mPackage = packageName; mUserHandle = userHandle; } @Override public boolean onPreferenceClick(Preference preference) { // start new fragment to display extended information final Bundle args = new Bundle(); args.putString(AppInfoDashboardFragment.ARG_PACKAGE_NAME, mPackage); new SubSettingLauncher(mFragment.getContext()) .setDestination(AppInfoDashboardFragment.class.getName()) .setArguments(args) .setTitleRes(R.string.application_info_label) .setUserHandle(mUserHandle) .setSourceMetricsCategory(mFragment.getMetricsCategory()) .launch(); return true; } } public RecentLocationRequestPreferenceController(Context context, LocationSettings fragment, Lifecycle lifecycle) { this(context, fragment, lifecycle, new RecentLocationApps(context)); } @VisibleForTesting RecentLocationRequestPreferenceController(Context context, LocationSettings fragment, Lifecycle lifecycle, RecentLocationApps recentApps) { super(context, lifecycle); mFragment = fragment; mRecentLocationApps = recentApps; } @Override public String getPreferenceKey() { return KEY_RECENT_LOCATION_REQUESTS; } @Override public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); mCategoryRecentLocationRequests = (PreferenceCategory) screen.findPreference(KEY_RECENT_LOCATION_REQUESTS); } @Override public void updateState(Preference preference) { mCategoryRecentLocationRequests.removeAll(); final Context prefContext = preference.getContext(); final List<RecentLocationApps.Request> recentLocationRequests = mRecentLocationApps.getAppListSorted(false); if (recentLocationRequests.size() > 3) { // Display the top 3 preferences to container in original order. for (int i = 0; i < 3; i++) { mCategoryRecentLocationRequests.addPreference( createAppPreference(prefContext, recentLocationRequests.get(i))); } } else if (recentLocationRequests.size() > 0) { // Add preferences to container in original order (already sorted by recency). for (RecentLocationApps.Request request : recentLocationRequests) { mCategoryRecentLocationRequests.addPreference( createAppPreference(prefContext, request)); } } else { // If there's no item to display, add a "No recent apps" item. final Preference banner = createAppPreference(prefContext); banner.setTitle(R.string.location_no_recent_apps); banner.setSelectable(false); mCategoryRecentLocationRequests.addPreference(banner); } } @Override public void onLocationModeChanged(int mode, boolean restricted) { mCategoryRecentLocationRequests.setEnabled(mLocationEnabler.isEnabled(mode)); } @VisibleForTesting AppPreference createAppPreference(Context prefContext) { return new AppPreference(prefContext); } @VisibleForTesting AppPreference createAppPreference(Context prefContext, RecentLocationApps.Request request) { final AppPreference pref = createAppPreference(prefContext); pref.setSummary(request.contentDescription); pref.setIcon(request.icon); pref.setTitle(request.label); pref.setOnPreferenceClickListener(new PackageEntryClickedListener( mFragment, request.packageName, request.userHandle)); return pref; } } Loading
res/values/strings.xml +7 −0 Original line number Diff line number Diff line Loading @@ -3847,6 +3847,13 @@ <!-- Ask user to connect to the internet [CHAR_ LIMIT=50]--> <string name="mobile_connect_to_internet" translatable="true">Please connect to the internet</string> <!-- Location settings screen, sub category for recent location requests [CHAR LIMIT=42] --> <string name="location_category_recent_location_requests">Recent location requests</string> <!-- Location settings screen, displayed when there're more than three recent location requests [CHAR LIMIT=30] --> <string name="location_recent_location_requests_see_all">See all</string> <!-- Location settings screen, sub category for location services [CHAR LIMIT=30] --> <string name="location_category_location_services">Location services</string> <!-- Security & location settings screen, section header for settings relating to location --> <string name="location_title">My Location</string> <!-- [CHAR LIMIT=30] Title for managed profile location switch --> Loading
res/xml/location_recent_requests_see_all.xml 0 → 100644 +18 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2018 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. --> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:title="@string/location_category_recent_location_requests" android:key="recent_location_requests_see_all"> <PreferenceCategory android:key="all_recent_location_requests"/> </PreferenceScreen>
res/xml/location_settings.xml +10 −5 Original line number Diff line number Diff line Loading @@ -20,11 +20,16 @@ android:title="@string/location_settings_title" settings:keywords="@string/keywords_location"> <com.android.settingslib.widget.LayoutPreference android:key="apps_dashboard" android:layout="@layout/app_entities_header" android:selectable="false" settings:allowDividerBelow="true" /> <PreferenceCategory android:key="recent_location_requests" android:title="@string/location_category_recent_location_requests"/> <Preference android:key="recent_location_requests_see_all_button" android:title="@string/location_recent_location_requests_see_all" android:icon="@drawable/ic_chevron_right_24dp" android:fragment="com.android.settings.location.RecentLocationRequestSeeAllFragment" settings:searchable="false"/> <PreferenceCategory android:key="location_advanced_settings" Loading
src/com/android/settings/location/LocationSettings.java +3 −3 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ import com.android.settings.search.Indexable; import com.android.settings.widget.SwitchBar; import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.location.RecentLocationAccesses; import com.android.settingslib.location.RecentLocationApps; import com.android.settingslib.search.SearchIndexable; import java.util.ArrayList; Loading @@ -50,7 +50,7 @@ import java.util.List; * <li>In switch bar: location master switch. Used to toggle location on and off. * </li> * </ul> * <li>Recent location requests: automatically populated by {@link RecentLocationAccesses}</li> * <li>Recent location requests: automatically populated by {@link RecentLocationApps}</li> * <li>Location services: multi-app settings provided from outside the Android framework. Each * is injected by a system-partition app via the {@link SettingInjectorService} API.</li> * </ul> Loading Loading @@ -118,7 +118,7 @@ public class LocationSettings extends DashboardFragment { final List<AbstractPreferenceController> controllers = new ArrayList<>(); controllers.add(new AppLocationPermissionPreferenceController(context, lifecycle)); controllers.add(new LocationForWorkPreferenceController(context, lifecycle)); controllers.add(new RecentLocationAccessPreferenceController(context)); controllers.add(new RecentLocationRequestPreferenceController(context, fragment, lifecycle)); controllers.add(new LocationScanningPreferenceController(context)); controllers.add(new LocationServicePreferenceController(context, fragment, lifecycle)); controllers.add(new LocationFooterPreferenceController(context, lifecycle)); Loading
src/com/android/settings/location/RecentLocationRequestPreferenceController.java 0 → 100644 +145 −0 Original line number Diff line number Diff line /* * 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.Context; import android.os.Bundle; import android.os.UserHandle; import androidx.annotation.VisibleForTesting; import androidx.preference.Preference; import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceScreen; import com.android.settings.R; import com.android.settings.applications.appinfo.AppInfoDashboardFragment; import com.android.settings.core.SubSettingLauncher; import com.android.settings.dashboard.DashboardFragment; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.location.RecentLocationApps; import com.android.settingslib.widget.apppreference.AppPreference; import java.util.List; public class RecentLocationRequestPreferenceController extends LocationBasePreferenceController { /** Key for preference category "Recent location requests" */ private static final String KEY_RECENT_LOCATION_REQUESTS = "recent_location_requests"; @VisibleForTesting static final String KEY_SEE_ALL_BUTTON = "recent_location_requests_see_all_button"; private final LocationSettings mFragment; private final RecentLocationApps mRecentLocationApps; private PreferenceCategory mCategoryRecentLocationRequests; /** Used in this class and {@link RecentLocationRequestSeeAllPreferenceController} */ static class PackageEntryClickedListener implements Preference.OnPreferenceClickListener { private final DashboardFragment mFragment; private final String mPackage; private final UserHandle mUserHandle; public PackageEntryClickedListener(DashboardFragment fragment, String packageName, UserHandle userHandle) { mFragment = fragment; mPackage = packageName; mUserHandle = userHandle; } @Override public boolean onPreferenceClick(Preference preference) { // start new fragment to display extended information final Bundle args = new Bundle(); args.putString(AppInfoDashboardFragment.ARG_PACKAGE_NAME, mPackage); new SubSettingLauncher(mFragment.getContext()) .setDestination(AppInfoDashboardFragment.class.getName()) .setArguments(args) .setTitleRes(R.string.application_info_label) .setUserHandle(mUserHandle) .setSourceMetricsCategory(mFragment.getMetricsCategory()) .launch(); return true; } } public RecentLocationRequestPreferenceController(Context context, LocationSettings fragment, Lifecycle lifecycle) { this(context, fragment, lifecycle, new RecentLocationApps(context)); } @VisibleForTesting RecentLocationRequestPreferenceController(Context context, LocationSettings fragment, Lifecycle lifecycle, RecentLocationApps recentApps) { super(context, lifecycle); mFragment = fragment; mRecentLocationApps = recentApps; } @Override public String getPreferenceKey() { return KEY_RECENT_LOCATION_REQUESTS; } @Override public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); mCategoryRecentLocationRequests = (PreferenceCategory) screen.findPreference(KEY_RECENT_LOCATION_REQUESTS); } @Override public void updateState(Preference preference) { mCategoryRecentLocationRequests.removeAll(); final Context prefContext = preference.getContext(); final List<RecentLocationApps.Request> recentLocationRequests = mRecentLocationApps.getAppListSorted(false); if (recentLocationRequests.size() > 3) { // Display the top 3 preferences to container in original order. for (int i = 0; i < 3; i++) { mCategoryRecentLocationRequests.addPreference( createAppPreference(prefContext, recentLocationRequests.get(i))); } } else if (recentLocationRequests.size() > 0) { // Add preferences to container in original order (already sorted by recency). for (RecentLocationApps.Request request : recentLocationRequests) { mCategoryRecentLocationRequests.addPreference( createAppPreference(prefContext, request)); } } else { // If there's no item to display, add a "No recent apps" item. final Preference banner = createAppPreference(prefContext); banner.setTitle(R.string.location_no_recent_apps); banner.setSelectable(false); mCategoryRecentLocationRequests.addPreference(banner); } } @Override public void onLocationModeChanged(int mode, boolean restricted) { mCategoryRecentLocationRequests.setEnabled(mLocationEnabler.isEnabled(mode)); } @VisibleForTesting AppPreference createAppPreference(Context prefContext) { return new AppPreference(prefContext); } @VisibleForTesting AppPreference createAppPreference(Context prefContext, RecentLocationApps.Request request) { final AppPreference pref = createAppPreference(prefContext); pref.setSummary(request.contentDescription); pref.setIcon(request.icon); pref.setTitle(request.label); pref.setOnPreferenceClickListener(new PackageEntryClickedListener( mFragment, request.packageName, request.userHandle)); return pref; } }