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

Commit f8dcae57 authored by Yu-Han Yang's avatar Yu-Han Yang Committed by Automerger Merge Worker
Browse files

Merge "Add showSystem in RecentLocationAccess (SettingsLib)" into sc-dev am: 1fd830ff

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13743400

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I14883f6ec037b634ff8779f2783aad4f353d9660
parents 78fc0bca 1fd830ff
Loading
Loading
Loading
Loading
+31 −19
Original line number Diff line number Diff line
@@ -80,7 +80,8 @@ public class RecentLocationAccesses {
     * Fills a list of applications which queried location recently within specified time.
     * Apps are sorted by recency. Apps with more recent location accesses are in the front.
     */
    public List<Access> getAppList() {
    @VisibleForTesting
    List<Access> getAppList(boolean showSystemApps) {
        // Retrieve a location usage list from AppOps
        PackageManager pm = mContext.getPackageManager();
        AppOpsManager aoManager =
@@ -108,14 +109,17 @@ public class RecentLocationAccesses {

            // Don't show apps that do not have user sensitive location permissions
            boolean showApp = true;
            if (!showSystemApps) {
                for (int op : LOCATION_OPS) {
                    final String permission = AppOpsManager.opToPermission(op);
                final int permissionFlags = pm.getPermissionFlags(permission, packageName, user);
                    final int permissionFlags = pm.getPermissionFlags(permission, packageName,
                            user);
                    if (PermissionChecker.checkPermissionForPreflight(mContext, permission,
                            PermissionChecker.PID_UNKNOWN, uid, packageName)
                            == PermissionChecker.PERMISSION_GRANTED) {
                        if ((permissionFlags
                            & PackageManager.FLAG_PERMISSION_USER_SENSITIVE_WHEN_GRANTED) == 0) {
                                & PackageManager.FLAG_PERMISSION_USER_SENSITIVE_WHEN_GRANTED)
                                == 0) {
                            showApp = false;
                            break;
                        }
@@ -127,6 +131,7 @@ public class RecentLocationAccesses {
                        }
                    }
                }
            }
            if (showApp) {
                Access access = getAccessFromOps(now, ops);
                if (access != null) {
@@ -137,8 +142,15 @@ public class RecentLocationAccesses {
        return accesses;
    }

    public List<Access> getAppListSorted() {
        List<Access> accesses = getAppList();

    /**
     * Gets a list of apps that accessed location recently, sorting by recency.
     *
     * @param showSystemApps whether includes system apps in the list.
     * @return the list of apps that recently accessed location.
     */
    public List<Access> getAppListSorted(boolean showSystemApps) {
        List<Access> accesses = getAppList(showSystemApps);
        // Sort the list of Access by recency. Most recent accesses first.
        Collections.sort(accesses, Collections.reverseOrder(new Comparator<Access>() {
            @Override
+2 −2
Original line number Diff line number Diff line
@@ -86,7 +86,7 @@ public class RecentLocationAccessesTest {
    @Test
    @Ignore
    public void testGetAppList_shouldFilterRecentAccesses() {
        List<RecentLocationAccesses.Access> requests = mRecentLocationAccesses.getAppList();
        List<RecentLocationAccesses.Access> requests = mRecentLocationAccesses.getAppList(false);
        // Only two of the apps have requested location within 15 min.
        assertThat(requests).hasSize(2);
        // Make sure apps are ordered by recency
@@ -115,7 +115,7 @@ public class RecentLocationAccessesTest {
        mockTestApplicationInfos(
                Process.SYSTEM_UID, RecentLocationAccesses.ANDROID_SYSTEM_PACKAGE_NAME);

        List<RecentLocationAccesses.Access> requests = mRecentLocationAccesses.getAppList();
        List<RecentLocationAccesses.Access> requests = mRecentLocationAccesses.getAppList(true);
        // Android OS shouldn't show up in the list of apps.
        assertThat(requests).hasSize(2);
        // Make sure apps are ordered by recency