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

Commit 811d95c3 authored by Lifu Tang's avatar Lifu Tang
Browse files

Display recent location access in the widget

Bug: 120239674
Test: manually
Change-Id: Iaf899486bf27c55189eea4c0e913ff1baaf529e5
parent bc0bfe84
Loading
Loading
Loading
Loading
+4 −6
Original line number Original line Diff line number Diff line
@@ -3631,14 +3631,12 @@
    <!-- [CHAR LIMIT=30] Location settings screen. It's a link that directs the user to a page that
    <!-- [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 -->
      shows the location permission setting for each installed app -->
    <string name="location_app_level_permissions">App-level permissions</string>
    <string name="location_app_level_permissions">App-level permissions</string>
    <!-- [CHAR LIMIT=42] Location settings screen, sub category for recent location requests -->
    <!-- [CHAR LIMIT=50] Location settings screen, sub category for recent location access -->
    <string name="location_category_recent_location_requests">Recent location requests</string>
    <string name="location_category_recent_location_access">Recent location access</string>
    <!-- Location settings screen, displayed when there're more than three recent location requests -->
    <!-- [CHAR LIMIT=30] Location settings screen, button to bring the user to view the details of recent location access -->
    <string name="location_recent_location_requests_see_all">See all</string>
    <string name="location_recent_location_access_view_details">View details</string>
    <!-- Location settings screen, displayed when there's no recent app accessing location -->
    <!-- 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>
    <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-->
    <!-- [CHAR LIMIT=30] Location settings screen, recent location requests high battery use-->
    <string name="location_high_battery_use">High battery use</string>
    <string name="location_high_battery_use">High battery use</string>
    <!-- [CHAR LIMIT=30] Location settings screen, recent location requests low battery use-->
    <!-- [CHAR LIMIT=30] Location settings screen, recent location requests low battery use-->
+0 −24
Original line number Original line 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 Original line Diff line number Diff line
@@ -20,21 +20,14 @@
        android:title="@string/location_settings_title"
        android:title="@string/location_settings_title"
        settings:keywords="@string/keywords_location">
        settings:keywords="@string/keywords_location">


        <PreferenceCategory
        <com.android.settingslib.widget.LayoutPreference
            android:key="recent_location_requests"
            android:key="apps_dashboard"
            android:title="@string/location_category_recent_location_requests"/>
            android:layout="@layout/app_entities_header"

            settings:allowDividerBelow="true" />
        <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"/>


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


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


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


        <PreferenceCategory
        <PreferenceCategory
+4 −6
Original line number Original line Diff line number Diff line
@@ -35,7 +35,7 @@ import com.android.settings.search.Indexable;
import com.android.settings.widget.SwitchBar;
import com.android.settings.widget.SwitchBar;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.location.RecentLocationApps;
import com.android.settingslib.location.RecentLocationAccesses;
import com.android.settingslib.search.SearchIndexable;
import com.android.settingslib.search.SearchIndexable;


import java.util.ArrayList;
import java.util.ArrayList;
@@ -52,7 +52,7 @@ import java.util.List;
 *         <li>In switch bar: location master switch. Used to toggle location on and off.
 *         <li>In switch bar: location master switch. Used to toggle location on and off.
 *         </li>
 *         </li>
 *     </ul>
 *     </ul>
 *     <li>Recent location requests: automatically populated by {@link RecentLocationApps}</li>
 *     <li>Recent location requests: automatically populated by {@link RecentLocationAccesses}</li>
 *     <li>Location services: multi-app settings provided from outside the Android framework. Each
 *     <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>
 *     is injected by a system-partition app via the {@link SettingInjectorService} API.</li>
 * </ul>
 * </ul>
@@ -124,11 +124,9 @@ public class LocationSettings extends DashboardFragment {
        final List<AbstractPreferenceController> controllers = new ArrayList<>();
        final List<AbstractPreferenceController> controllers = new ArrayList<>();
        controllers.add(new AppLocationPermissionPreferenceController(context));
        controllers.add(new AppLocationPermissionPreferenceController(context));
        controllers.add(new LocationForWorkPreferenceController(context, lifecycle));
        controllers.add(new LocationForWorkPreferenceController(context, lifecycle));
        controllers.add(
        controllers.add(new RecentLocationAccessPreferenceController(context));
                new RecentLocationRequestPreferenceController(context, fragment, lifecycle));
        controllers.add(new LocationScanningPreferenceController(context));
        controllers.add(new LocationScanningPreferenceController(context));
        controllers.add(
        controllers.add(new LocationServicePreferenceController(context, fragment, lifecycle));
                new LocationServicePreferenceController(context, fragment, lifecycle));
        controllers.add(new LocationFooterPreferenceController(context, lifecycle));
        controllers.add(new LocationFooterPreferenceController(context, lifecycle));
        return controllers;
        return controllers;
    }
    }
+103 −0
Original line number Original line 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.Manifest;
import android.content.Context;
import android.content.Intent;
import android.view.View;

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.location.RecentLocationAccesses;
import com.android.settingslib.widget.AppEntitiesHeaderController;
import com.android.settingslib.widget.LayoutPreference;

import java.util.List;

public class RecentLocationAccessPreferenceController extends AbstractPreferenceController
        implements PreferenceControllerMixin {
    /** Key for the recent location apps dashboard */
    private static final String KEY_APPS_DASHBOARD = "apps_dashboard";
    private final RecentLocationAccesses mRecentLocationAccesses;
    private AppEntitiesHeaderController mController;
    private static final int MAXIMUM_APP_COUNT = 3;

    public RecentLocationAccessPreferenceController(Context context) {
        this(context, new RecentLocationAccesses(context));
    }

    @VisibleForTesting
    RecentLocationAccessPreferenceController(Context context,
            RecentLocationAccesses recentAccesses) {
        super(context);
        mRecentLocationAccesses = recentAccesses;
    }

    @Override
    public String getPreferenceKey() {
        return KEY_APPS_DASHBOARD;
    }

    @Override
    public boolean isAvailable() {
        return true;
    }

    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);
        final LayoutPreference preference = (LayoutPreference) screen.findPreference(
                KEY_APPS_DASHBOARD);
        final View view = preference.findViewById(R.id.app_entities_header);
        mController = AppEntitiesHeaderController.newInstance(mContext, view)
                .setHeaderTitleRes(R.string.location_category_recent_location_access)
                .setHeaderDetailsRes(R.string.location_recent_location_access_view_details)
                .setHeaderDetailsClickListener((View v) -> {
                    final Intent intent = new Intent(Intent.ACTION_REVIEW_PERMISSION_USAGE);
                    intent.putExtra(Intent.EXTRA_PERMISSION_NAME,
                            Manifest.permission.ACCESS_FINE_LOCATION);
                    mContext.startActivity(intent);
                });
    }

    @Override
    public void updateState(Preference preference) {
        updateRecentApps();
    }

    private void updateRecentApps() {
        final List<RecentLocationAccesses.Access> recentLocationAccesses =
                mRecentLocationAccesses.getAppListSorted();
        if (recentLocationAccesses.size() > 0) {
            // Display the top 3 preferences to container in original order.
            int i = 0;
            for (; i < Math.min(recentLocationAccesses.size(), MAXIMUM_APP_COUNT); i++) {
                final RecentLocationAccesses.Access access = recentLocationAccesses.get(i);
                mController.setAppEntity(i, access.icon, access.label, access.contentDescription);
            }
            for (; i < MAXIMUM_APP_COUNT; i++) {
                mController.removeAppEntity(i);
            }
        } else {
            // If there's no item to display, add a "No recent apps" item.
        }
        mController.apply();
    }
}
Loading