From 9e0f9b1ddaaa55a8b3697451e8f5b4f95d5a53e4 Mon Sep 17 00:00:00 2001 From: Yu-Han Yang Date: Tue, 16 Mar 2021 22:56:56 -0700 Subject: [PATCH] Hide "recent access" and "see all" when location off This CL also does the following: - Change "past 24 hour access" to "recent access" - Add timestamp to recent access app - Remove the summary of "Location Services" button Bug: 180533061 Test: on device Change-Id: I0405cb6f363243db9f2c9ccf8ab8788b633d1564 --- res/values/strings.xml | 2 +- res/xml/location_settings.xml | 1 + res/xml/location_settings_personal.xml | 1 + res/xml/location_settings_workprofile.xml | 2 +- .../location/LocationPersonalSettings.java | 1 + .../LocationServicesPreferenceController.java | 23 --------- .../settings/location/LocationSettings.java | 1 + .../location/LocationWorkProfileSettings.java | 1 + ...entLocationAccessPreferenceController.java | 8 ++- ...ccessSeeAllButtonPreferenceController.java | 49 +++++++++++++++++++ ...ationAccessSeeAllPreferenceController.java | 2 +- 11 files changed, 64 insertions(+), 27 deletions(-) create mode 100644 src/com/android/settings/location/RecentLocationAccessSeeAllButtonPreferenceController.java diff --git a/res/values/strings.xml b/res/values/strings.xml index a2f1aa879d0..ddb362fa9b2 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -4035,7 +4035,7 @@ apps have access to location - Past 24 hour access + Recent access See all diff --git a/res/xml/location_settings.xml b/res/xml/location_settings.xml index 1646b1d810d..93f30e58d56 100644 --- a/res/xml/location_settings.xml +++ b/res/xml/location_settings.xml @@ -32,6 +32,7 @@ android:title="@string/location_recent_location_access_see_all" android:icon="@drawable/ic_chevron_right_24dp" android:fragment="com.android.settings.location.RecentLocationAccessSeeAllFragment" + settings:controller="com.android.settings.location.RecentLocationAccessSeeAllButtonPreferenceController" settings:searchable="false"/> diff --git a/res/xml/location_settings_workprofile.xml b/res/xml/location_settings_workprofile.xml index 40a822cc6b0..c3efcbe2af5 100644 --- a/res/xml/location_settings_workprofile.xml +++ b/res/xml/location_settings_workprofile.xml @@ -33,7 +33,7 @@ android:title="@string/location_recent_location_access_see_all" android:icon="@drawable/ic_chevron_right_24dp" android:fragment="com.android.settings.location.RecentLocationAccessSeeAllFragment" - settings:controller="com.android.settings.core.WorkPreferenceController" + settings:controller="com.android.settings.location.RecentLocationAccessSeeAllButtonPreferenceController" settings:forWork="true" settings:searchable="false"/> diff --git a/src/com/android/settings/location/LocationPersonalSettings.java b/src/com/android/settings/location/LocationPersonalSettings.java index 38b7c4a9e92..bdf2d2b8e89 100644 --- a/src/com/android/settings/location/LocationPersonalSettings.java +++ b/src/com/android/settings/location/LocationPersonalSettings.java @@ -53,6 +53,7 @@ public class LocationPersonalSettings extends DashboardFragment { // STOPSHIP(b/180533061): resolve the personal/work location services issue before we can // ship. use(LocationFooterPreferenceController.class).init(this); + use(RecentLocationAccessSeeAllButtonPreferenceController.class).init(this); final int profileType = getArguments().getInt(ProfileSelectFragment.EXTRA_PROFILE); final RecentLocationAccessPreferenceController controller = use( diff --git a/src/com/android/settings/location/LocationServicesPreferenceController.java b/src/com/android/settings/location/LocationServicesPreferenceController.java index f7a338840f2..53150a827b3 100644 --- a/src/com/android/settings/location/LocationServicesPreferenceController.java +++ b/src/com/android/settings/location/LocationServicesPreferenceController.java @@ -17,8 +17,6 @@ package com.android.settings.location; import android.content.Context; -import android.net.wifi.WifiManager; -import android.provider.Settings; import com.android.settings.R; import com.android.settings.core.BasePreferenceController; @@ -28,29 +26,8 @@ import com.android.settings.core.BasePreferenceController; */ public class LocationServicesPreferenceController extends BasePreferenceController { - private final WifiManager mWifiManager; - public LocationServicesPreferenceController(Context context, String key) { super(context, key); - mWifiManager = context.getSystemService(WifiManager.class); - } - - @Override - public CharSequence getSummary() { - final boolean wifiScanOn = mWifiManager.isScanAlwaysAvailable(); - final boolean bleScanOn = Settings.Global.getInt(mContext.getContentResolver(), - Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0) == 1; - int resId; - if (wifiScanOn && bleScanOn) { - resId = R.string.scanning_status_text_wifi_on_ble_on; - } else if (wifiScanOn && !bleScanOn) { - resId = R.string.scanning_status_text_wifi_on_ble_off; - } else if (!wifiScanOn && bleScanOn) { - resId = R.string.scanning_status_text_wifi_off_ble_on; - } else { - resId = R.string.scanning_status_text_wifi_off_ble_off; - } - return mContext.getString(resId); } @AvailabilityStatus diff --git a/src/com/android/settings/location/LocationSettings.java b/src/com/android/settings/location/LocationSettings.java index d58ad5b5ca2..bb971bff057 100644 --- a/src/com/android/settings/location/LocationSettings.java +++ b/src/com/android/settings/location/LocationSettings.java @@ -83,6 +83,7 @@ public class LocationSettings extends DashboardFragment { use(AppLocationPermissionPreferenceController.class).init(this); use(RecentLocationAccessPreferenceController.class).init(this); + use(RecentLocationAccessSeeAllButtonPreferenceController.class).init(this); use(LocationFooterPreferenceController.class).init(this); use(LocationForWorkPreferenceController.class).init(this); use(LocationInjectedServicesForWorkPreferenceController.class).init(this); diff --git a/src/com/android/settings/location/LocationWorkProfileSettings.java b/src/com/android/settings/location/LocationWorkProfileSettings.java index 18936fd4897..67830758007 100644 --- a/src/com/android/settings/location/LocationWorkProfileSettings.java +++ b/src/com/android/settings/location/LocationWorkProfileSettings.java @@ -52,6 +52,7 @@ public class LocationWorkProfileSettings extends DashboardFragment { use(AppLocationPermissionPreferenceController.class).init(this); use(LocationFooterPreferenceController.class).init(this); use(LocationForWorkPreferenceController.class).init(this); + use(RecentLocationAccessSeeAllButtonPreferenceController.class).init(this); final int profileType = getArguments().getInt(ProfileSelectFragment.EXTRA_PROFILE); final RecentLocationAccessPreferenceController controller = use( diff --git a/src/com/android/settings/location/RecentLocationAccessPreferenceController.java b/src/com/android/settings/location/RecentLocationAccessPreferenceController.java index 383fbeaafd9..97de4a7f9a4 100644 --- a/src/com/android/settings/location/RecentLocationAccessPreferenceController.java +++ b/src/com/android/settings/location/RecentLocationAccessPreferenceController.java @@ -17,6 +17,7 @@ import static android.Manifest.permission_group.LOCATION; import android.content.Context; import android.content.Intent; +import android.icu.text.RelativeDateTimeFormatter; import android.os.UserHandle; import android.os.UserManager; @@ -29,6 +30,7 @@ import com.android.settings.R; import com.android.settings.dashboard.DashboardFragment; import com.android.settings.dashboard.profileselector.ProfileSelectFragment; import com.android.settingslib.location.RecentLocationAccesses; +import com.android.settingslib.utils.StringUtil; import com.android.settingslib.widget.AppPreference; import java.util.ArrayList; @@ -113,7 +115,8 @@ public class RecentLocationAccessPreferenceController extends LocationBasePrefer @Override public void onLocationModeChanged(int mode, boolean restricted) { - mCategoryRecentLocationRequests.setEnabled(mLocationEnabler.isEnabled(mode)); + boolean enabled = mLocationEnabler.isEnabled(mode); + mCategoryRecentLocationRequests.setVisible(enabled); } /** @@ -133,6 +136,9 @@ public class RecentLocationAccessPreferenceController extends LocationBasePrefer final AppPreference pref = new AppPreference(prefContext); pref.setIcon(access.icon); pref.setTitle(access.label); + pref.setSummary(StringUtil.formatRelativeTime(prefContext, + System.currentTimeMillis() - access.accessFinishTime, false, + RelativeDateTimeFormatter.Style.SHORT)); pref.setOnPreferenceClickListener(new PackageEntryClickedListener( fragment.getContext(), access.packageName, access.userHandle)); return pref; diff --git a/src/com/android/settings/location/RecentLocationAccessSeeAllButtonPreferenceController.java b/src/com/android/settings/location/RecentLocationAccessSeeAllButtonPreferenceController.java new file mode 100644 index 00000000000..68cde637eeb --- /dev/null +++ b/src/com/android/settings/location/RecentLocationAccessSeeAllButtonPreferenceController.java @@ -0,0 +1,49 @@ +/* + * Copyright 2021 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 androidx.preference.Preference; +import androidx.preference.PreferenceScreen; + +/** + * Preference controller that handles the "See All" button for recent location access. + */ +public class RecentLocationAccessSeeAllButtonPreferenceController extends + LocationBasePreferenceController { + + private Preference mPreference; + + /** + * Constructor of {@link RecentLocationAccessSeeAllButtonPreferenceController}. + */ + public RecentLocationAccessSeeAllButtonPreferenceController(Context context, String key) { + super(context, key); + } + + @Override + public void displayPreference(PreferenceScreen screen) { + super.displayPreference(screen); + mPreference = screen.findPreference(getPreferenceKey()); + } + + @Override + public void onLocationModeChanged(int mode, boolean restricted) { + boolean enabled = mLocationEnabler.isEnabled(mode); + mPreference.setVisible(enabled); + } +} diff --git a/src/com/android/settings/location/RecentLocationAccessSeeAllPreferenceController.java b/src/com/android/settings/location/RecentLocationAccessSeeAllPreferenceController.java index c147ee7722d..a05092dcdbd 100644 --- a/src/com/android/settings/location/RecentLocationAccessSeeAllPreferenceController.java +++ b/src/com/android/settings/location/RecentLocationAccessSeeAllPreferenceController.java @@ -37,7 +37,7 @@ public class RecentLocationAccessSeeAllPreferenceController extends LocationBasePreferenceController { private PreferenceScreen mCategoryAllRecentLocationAccess; - private RecentLocationAccesses mRecentLocationAccesses; + private final RecentLocationAccesses mRecentLocationAccesses; private boolean mShowSystem = false; private Preference mPreference; private int mType = ProfileSelectFragment.ProfileType.ALL;