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
This commit is contained in:
Yu-Han Yang
2021-03-16 22:56:56 -07:00
parent d8df0d97e2
commit 9e0f9b1dda
11 changed files with 64 additions and 27 deletions

View File

@@ -4035,7 +4035,7 @@
apps have access to location</item> apps have access to location</item>
</plurals> </plurals>
<!-- [CHAR LIMIT=50] Location settings screen, sub category for recent location access --> <!-- [CHAR LIMIT=50] Location settings screen, sub category for recent location access -->
<string name="location_category_recent_location_access">Past 24 hour access</string> <string name="location_category_recent_location_access">Recent access</string>
<!-- Location settings screen, displayed when there're more than three recent location access apps [CHAR LIMIT=30] --> <!-- Location settings screen, displayed when there're more than three recent location access apps [CHAR LIMIT=30] -->
<string name="location_recent_location_access_see_all">See all</string> <string name="location_recent_location_access_see_all">See all</string>
<!-- [CHAR LIMIT=30] Location settings screen, button to bring the user to view the details of recent location access --> <!-- [CHAR LIMIT=30] Location settings screen, button to bring the user to view the details of recent location access -->

View File

@@ -32,6 +32,7 @@
android:title="@string/location_recent_location_access_see_all" android:title="@string/location_recent_location_access_see_all"
android:icon="@drawable/ic_chevron_right_24dp" android:icon="@drawable/ic_chevron_right_24dp"
android:fragment="com.android.settings.location.RecentLocationAccessSeeAllFragment" android:fragment="com.android.settings.location.RecentLocationAccessSeeAllFragment"
settings:controller="com.android.settings.location.RecentLocationAccessSeeAllButtonPreferenceController"
settings:searchable="false"/> settings:searchable="false"/>
<PreferenceCategory <PreferenceCategory

View File

@@ -33,6 +33,7 @@
android:title="@string/location_recent_location_access_see_all" android:title="@string/location_recent_location_access_see_all"
android:icon="@drawable/ic_chevron_right_24dp" android:icon="@drawable/ic_chevron_right_24dp"
android:fragment="com.android.settings.location.RecentLocationAccessSeeAllFragment" android:fragment="com.android.settings.location.RecentLocationAccessSeeAllFragment"
settings:controller="com.android.settings.location.RecentLocationAccessSeeAllButtonPreferenceController"
settings:searchable="false"/> settings:searchable="false"/>
<!-- This preference category gets removed if new_recent_location_ui is disabled --> <!-- This preference category gets removed if new_recent_location_ui is disabled -->

View File

@@ -33,7 +33,7 @@
android:title="@string/location_recent_location_access_see_all" android:title="@string/location_recent_location_access_see_all"
android:icon="@drawable/ic_chevron_right_24dp" android:icon="@drawable/ic_chevron_right_24dp"
android:fragment="com.android.settings.location.RecentLocationAccessSeeAllFragment" 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:forWork="true"
settings:searchable="false"/> settings:searchable="false"/>

View File

@@ -53,6 +53,7 @@ public class LocationPersonalSettings extends DashboardFragment {
// STOPSHIP(b/180533061): resolve the personal/work location services issue before we can // STOPSHIP(b/180533061): resolve the personal/work location services issue before we can
// ship. // ship.
use(LocationFooterPreferenceController.class).init(this); use(LocationFooterPreferenceController.class).init(this);
use(RecentLocationAccessSeeAllButtonPreferenceController.class).init(this);
final int profileType = getArguments().getInt(ProfileSelectFragment.EXTRA_PROFILE); final int profileType = getArguments().getInt(ProfileSelectFragment.EXTRA_PROFILE);
final RecentLocationAccessPreferenceController controller = use( final RecentLocationAccessPreferenceController controller = use(

View File

@@ -17,8 +17,6 @@
package com.android.settings.location; package com.android.settings.location;
import android.content.Context; import android.content.Context;
import android.net.wifi.WifiManager;
import android.provider.Settings;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.core.BasePreferenceController; import com.android.settings.core.BasePreferenceController;
@@ -28,29 +26,8 @@ import com.android.settings.core.BasePreferenceController;
*/ */
public class LocationServicesPreferenceController extends BasePreferenceController { public class LocationServicesPreferenceController extends BasePreferenceController {
private final WifiManager mWifiManager;
public LocationServicesPreferenceController(Context context, String key) { public LocationServicesPreferenceController(Context context, String key) {
super(context, 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 @AvailabilityStatus

View File

@@ -83,6 +83,7 @@ public class LocationSettings extends DashboardFragment {
use(AppLocationPermissionPreferenceController.class).init(this); use(AppLocationPermissionPreferenceController.class).init(this);
use(RecentLocationAccessPreferenceController.class).init(this); use(RecentLocationAccessPreferenceController.class).init(this);
use(RecentLocationAccessSeeAllButtonPreferenceController.class).init(this);
use(LocationFooterPreferenceController.class).init(this); use(LocationFooterPreferenceController.class).init(this);
use(LocationForWorkPreferenceController.class).init(this); use(LocationForWorkPreferenceController.class).init(this);
use(LocationInjectedServicesForWorkPreferenceController.class).init(this); use(LocationInjectedServicesForWorkPreferenceController.class).init(this);

View File

@@ -52,6 +52,7 @@ public class LocationWorkProfileSettings extends DashboardFragment {
use(AppLocationPermissionPreferenceController.class).init(this); use(AppLocationPermissionPreferenceController.class).init(this);
use(LocationFooterPreferenceController.class).init(this); use(LocationFooterPreferenceController.class).init(this);
use(LocationForWorkPreferenceController.class).init(this); use(LocationForWorkPreferenceController.class).init(this);
use(RecentLocationAccessSeeAllButtonPreferenceController.class).init(this);
final int profileType = getArguments().getInt(ProfileSelectFragment.EXTRA_PROFILE); final int profileType = getArguments().getInt(ProfileSelectFragment.EXTRA_PROFILE);
final RecentLocationAccessPreferenceController controller = use( final RecentLocationAccessPreferenceController controller = use(

View File

@@ -17,6 +17,7 @@ import static android.Manifest.permission_group.LOCATION;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.icu.text.RelativeDateTimeFormatter;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
@@ -29,6 +30,7 @@ import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment; import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.profileselector.ProfileSelectFragment; import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
import com.android.settingslib.location.RecentLocationAccesses; import com.android.settingslib.location.RecentLocationAccesses;
import com.android.settingslib.utils.StringUtil;
import com.android.settingslib.widget.AppPreference; import com.android.settingslib.widget.AppPreference;
import java.util.ArrayList; import java.util.ArrayList;
@@ -113,7 +115,8 @@ public class RecentLocationAccessPreferenceController extends LocationBasePrefer
@Override @Override
public void onLocationModeChanged(int mode, boolean restricted) { 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); final AppPreference pref = new AppPreference(prefContext);
pref.setIcon(access.icon); pref.setIcon(access.icon);
pref.setTitle(access.label); pref.setTitle(access.label);
pref.setSummary(StringUtil.formatRelativeTime(prefContext,
System.currentTimeMillis() - access.accessFinishTime, false,
RelativeDateTimeFormatter.Style.SHORT));
pref.setOnPreferenceClickListener(new PackageEntryClickedListener( pref.setOnPreferenceClickListener(new PackageEntryClickedListener(
fragment.getContext(), access.packageName, access.userHandle)); fragment.getContext(), access.packageName, access.userHandle));
return pref; return pref;

View File

@@ -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);
}
}

View File

@@ -37,7 +37,7 @@ public class RecentLocationAccessSeeAllPreferenceController
extends LocationBasePreferenceController { extends LocationBasePreferenceController {
private PreferenceScreen mCategoryAllRecentLocationAccess; private PreferenceScreen mCategoryAllRecentLocationAccess;
private RecentLocationAccesses mRecentLocationAccesses; private final RecentLocationAccesses mRecentLocationAccesses;
private boolean mShowSystem = false; private boolean mShowSystem = false;
private Preference mPreference; private Preference mPreference;
private int mType = ProfileSelectFragment.ProfileType.ALL; private int mType = ProfileSelectFragment.ProfileType.ALL;