Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 45e9c560 authored by Lifu Tang's avatar Lifu Tang Committed by Android (Google) Code Review
Browse files

Merge changes from topic "location settings"

* changes:
  Display app stats for location permission
  Display recent location access in the widget
parents 9dbc0405 3da8f8d3
Loading
Loading
Loading
Loading
+29 −9
Original line number Diff line number Diff line
@@ -827,8 +827,15 @@
    <string name="location_settings_title">Location</string>
    <!-- Used in the location settings to control turning on/off the feature entirely -->
    <string name="location_settings_master_switch_title">Use location</string>
    <!-- Summary for Location settings, explaining a few important settings under it [CHAR LIMIT=NONE]-->
    <string name="location_settings_summary">Scanning, location history</string>
    <!-- Summary for Location settings when location is off [CHAR LIMIT=NONE] -->
    <string name="location_settings_summary_location_off">Off</string>
    <!-- Summary for Location settings when location is on, explaining how many apps have location permission [CHAR LIMIT=NONE]-->
    <plurals name="location_settings_summary_location_on">
        <item quantity="one">On - <xliff:g id="count">%1$d</xliff:g> app can access location</item>
        <item quantity="other">On - <xliff:g id="count">%1$d</xliff:g> apps can access location</item>
    </plurals>
    <!-- Location settings, loading the number of apps which have location permission [CHAR LIMIT=30] -->
    <string name="location_settings_loading_app_permission_stats">Loading\u2026</string>
    <!-- Main Settings screen setting option title for the item to take you to the accounts screen [CHAR LIMIT=22] -->
    <string name="account_settings_title">Accounts</string>
@@ -3630,15 +3637,28 @@
    <string name="managed_profile_location_switch_title">Location for work profile</string>
    <!-- [CHAR LIMIT=30] Location settings screen. It's a link that directs the user to a page that
      shows the location permission setting for each installed app -->
    <string name="location_app_level_permissions">App-level permissions</string>
    <!-- [CHAR LIMIT=42] Location settings screen, sub category for recent location requests -->
    <string name="location_category_recent_location_requests">Recent location requests</string>
    <!-- Location settings screen, displayed when there're more than three recent location requests -->
    <string name="location_recent_location_requests_see_all">See all</string>
    <string name="location_app_level_permissions">App permission</string>
    <!-- Summary for app permission on Location settings page when location is off [CHAR LIMIT=NONE] -->
    <string name="location_app_permission_summary_location_off">Location is off</string>
    <!-- Summary for Location settings when location is on, explaining how many apps have location permission [CHAR LIMIT=NONE]-->
    <plurals name="location_app_permission_summary_location_on">
        <item quantity="one">
            <xliff:g id="background_location_app_count">%1$d</xliff:g>
            of
            <xliff:g id="total_location_app_count">%2$d</xliff:g>
            app has unlimited access</item>
        <item quantity="other">
            <xliff:g id="background_location_app_count">%1$d</xliff:g>
            of
            <xliff:g id="total_location_app_count">%2$d</xliff:g>
            apps have unlimited access</item>
    </plurals>
    <!-- [CHAR LIMIT=50] Location settings screen, sub category for recent location access -->
    <string name="location_category_recent_location_access">Recent location access</string>
    <!-- [CHAR LIMIT=30] Location settings screen, button to bring the user to view the details of recent location access -->
    <string name="location_recent_location_access_view_details">View details</string>
    <!-- Location settings screen, displayed when there's no recent app accessing location -->
    <string name="location_no_recent_apps">No apps have requested location recently</string>
    <!-- [CHAR LIMIT=30] Location settings screen, sub category for location services -->
    <string name="location_category_location_services">Location services</string>
    <!-- [CHAR LIMIT=30] Location settings screen, recent location requests high battery use-->
    <string name="location_high_battery_use">High battery use</string>
    <!-- [CHAR LIMIT=30] Location settings screen, recent location requests low battery use-->
+0 −24
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>
 No newline at end of file
+6 −14
Original line number Diff line number Diff line
@@ -20,21 +20,14 @@
        android:title="@string/location_settings_title"
        settings:keywords="@string/keywords_location">

        <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:selectable="true"
            android:fragment="com.android.settings.location.RecentLocationRequestSeeAllFragment"
            settings:searchable="false"/>
        <com.android.settingslib.widget.LayoutPreference
            android:key="apps_dashboard"
            android:layout="@layout/app_entities_header"
            settings:allowDividerBelow="true" />

        <PreferenceCategory
            android:key="location_advanced_settings"
            settings:initialExpandedChildrenCount="1">
            settings:initialExpandedChildrenCount="0">

            <!-- This preference category gets removed if new_recent_location_ui is disabled -->
            <Preference
@@ -60,8 +53,7 @@
                android:selectable="true" />

            <PreferenceCategory
                android:key="location_services"
                android:title="@string/location_category_location_services"/>
                android:key="location_services" />
        </PreferenceCategory>

        <PreferenceCategory
+4 −3
Original line number Diff line number Diff line
@@ -93,10 +93,11 @@
    <Preference
        android:key="top_level_location"
        android:title="@string/location_settings_title"
        android:summary="@string/location_settings_summary"
        android:summary="@string/location_settings_loading_app_permission_stats"
        android:icon="@drawable/ic_homepage_location"
        android:order="-50"
        android:fragment="com.android.settings.location.LocationSettings"/>
        android:fragment="com.android.settings.location.LocationSettings"
        settings:controller="com.android.settings.location.TopLevelLocationPreferenceController"/>

    <Preference
        android:key="top_level_security"
+73 −4
Original line number Diff line number Diff line
package com.android.settings.location;

import static android.Manifest.permission.ACCESS_BACKGROUND_LOCATION;
import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
import static android.Manifest.permission.ACCESS_FINE_LOCATION;

import android.content.Context;
import android.location.LocationManager;
import android.permission.RuntimePermissionPresenter;
import android.provider.Settings;

import androidx.preference.Preference;

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 java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.atomic.AtomicInteger;

public class AppLocationPermissionPreferenceController extends
        AbstractPreferenceController implements PreferenceControllerMixin {
        LocationBasePreferenceController implements PreferenceControllerMixin {

    private static final String KEY_APP_LEVEL_PERMISSIONS = "app_level_permissions";
    /** Total number of apps that has location permission. */
    private int mNumTotal = -1;
    /** Total number of apps that has background location permission. */
    private int mNumBackground = -1;
    private final LocationManager mLocationManager;
    private Preference mPreference;

    public AppLocationPermissionPreferenceController(Context context) {
        super(context);
    public AppLocationPermissionPreferenceController(Context context, Lifecycle lifecycle) {
        super(context, lifecycle);
        mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    }

    @Override
@@ -25,4 +45,53 @@ public class AppLocationPermissionPreferenceController extends
        return Settings.Global.getInt(mContext.getContentResolver(),
                Settings.Global.LOCATION_SETTINGS_LINK_TO_PERMISSIONS_ENABLED, 1) == 1;
    }

    @Override
    public CharSequence getSummary() {
        if (mLocationManager.isLocationEnabled()) {
            if (mNumTotal == -1 || mNumBackground == -1) {
                return mContext.getString(R.string.location_settings_loading_app_permission_stats);
            }
            return mContext.getResources().getQuantityString(
                    R.plurals.location_app_permission_summary_location_on, mNumBackground,
                    mNumBackground, mNumTotal);
        } else {
            return mContext.getString(R.string.location_app_permission_summary_location_off);
        }
    }

    @Override
    public void updateState(Preference preference) {
        super.updateState(preference);
        mPreference = preference;
        final AtomicInteger loadingInProgress = new AtomicInteger(2);
        refreshSummary(preference);
        // Bail out if location has been disabled.
        if (!mLocationManager.isLocationEnabled()) {
            return;
        }
        RuntimePermissionPresenter.getInstance(mContext).countPermissionApps(
                Arrays.asList(ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION), false, false,
                (numApps) -> {
                    mNumTotal = numApps;
                    if (loadingInProgress.decrementAndGet() == 0) {
                        refreshSummary(preference);
                    }
                }, null);

        RuntimePermissionPresenter.getInstance(mContext).countPermissionApps(
                Collections.singletonList(ACCESS_BACKGROUND_LOCATION), true, false,
                (numApps) -> {
                    mNumBackground = numApps;
                    if (loadingInProgress.decrementAndGet() == 0) {
                        refreshSummary(preference);
                    }
                }, null);
    }

    @Override
    public void onLocationModeChanged(int mode, boolean restricted) {
        // 'null' is checked inside updateState(), so no need to check here.
        updateState(mPreference);
    }
}
Loading