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

Commit ec281b1e authored by Wei Wang's avatar Wei Wang
Browse files

Extend Location setting to show location usage within 24 hours.

Bug: 79089524

Test: manual, unit test.
Change-Id: I0058479a3b8e139c68c688e6e14f837a335bba6f
parent 715b5be1
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@ import android.os.Process;
import android.os.UserHandle;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManager;
import androidx.annotation.VisibleForTesting;
import androidx.annotation.VisibleForTesting;
import android.text.format.DateUtils;
import android.util.IconDrawableFactory;
import android.util.IconDrawableFactory;
import android.util.Log;
import android.util.Log;
import java.util.ArrayList;
import java.util.ArrayList;
@@ -41,7 +42,8 @@ public class RecentLocationApps {
    @VisibleForTesting
    @VisibleForTesting
    static final String ANDROID_SYSTEM_PACKAGE_NAME = "android";
    static final String ANDROID_SYSTEM_PACKAGE_NAME = "android";


    private static final int RECENT_TIME_INTERVAL_MILLIS = 15 * 60 * 1000;
    // Keep last 24 hours of location app information.
    private static final long RECENT_TIME_INTERVAL_MILLIS = DateUtils.DAY_IN_MILLIS;


    @VisibleForTesting
    @VisibleForTesting
    static final int[] LOCATION_OPS = new int[] {
    static final int[] LOCATION_OPS = new int[] {
+6 −6
Original line number Original line Diff line number Diff line
@@ -37,8 +37,8 @@ public class RecentLocationAppsTest {
    // App running duration in milliseconds
    // App running duration in milliseconds
    private static final int DURATION = 10;
    private static final int DURATION = 10;
    private static final long ONE_MIN_AGO = NOW - TimeUnit.MINUTES.toMillis(1);
    private static final long ONE_MIN_AGO = NOW - TimeUnit.MINUTES.toMillis(1);
    private static final long FOURTEEN_MIN_AGO = NOW - TimeUnit.MINUTES.toMillis(14);
    private static final long TWENTY_THREE_HOURS_AGO = NOW - TimeUnit.HOURS.toMillis(23);
    private static final long TWENTY_MIN_AGO = NOW - TimeUnit.MINUTES.toMillis(20);
    private static final long TWO_DAYS_AGO = NOW - TimeUnit.DAYS.toMillis(2);
    private static final String[] TEST_PACKAGE_NAMES =
    private static final String[] TEST_PACKAGE_NAMES =
            {"package_1MinAgo", "package_14MinAgo", "package_20MinAgo"};
            {"package_1MinAgo", "package_14MinAgo", "package_20MinAgo"};


@@ -74,7 +74,7 @@ public class RecentLocationAppsTest {
        when(mUserManager.getUserProfiles())
        when(mUserManager.getUserProfiles())
                .thenReturn(Collections.singletonList(new UserHandle(mTestUserId)));
                .thenReturn(Collections.singletonList(new UserHandle(mTestUserId)));


        long[] testRequestTime = {ONE_MIN_AGO, FOURTEEN_MIN_AGO, TWENTY_MIN_AGO};
        long[] testRequestTime = {ONE_MIN_AGO, TWENTY_THREE_HOURS_AGO, TWO_DAYS_AGO};
        List<PackageOps> appOps = createTestPackageOpsList(TEST_PACKAGE_NAMES, testRequestTime);
        List<PackageOps> appOps = createTestPackageOpsList(TEST_PACKAGE_NAMES, testRequestTime);
        when(mAppOpsManager.getPackagesForOps(RecentLocationApps.LOCATION_OPS)).thenReturn(appOps);
        when(mAppOpsManager.getPackagesForOps(RecentLocationApps.LOCATION_OPS)).thenReturn(appOps);
        mockTestApplicationInfos(mTestUserId, TEST_PACKAGE_NAMES);
        mockTestApplicationInfos(mTestUserId, TEST_PACKAGE_NAMES);
@@ -91,7 +91,7 @@ public class RecentLocationAppsTest {
        assertThat(requests.get(0).packageName).isEqualTo(TEST_PACKAGE_NAMES[0]);
        assertThat(requests.get(0).packageName).isEqualTo(TEST_PACKAGE_NAMES[0]);
        assertThat(requests.get(0).requestFinishTime).isEqualTo(ONE_MIN_AGO + DURATION);
        assertThat(requests.get(0).requestFinishTime).isEqualTo(ONE_MIN_AGO + DURATION);
        assertThat(requests.get(1).packageName).isEqualTo(TEST_PACKAGE_NAMES[1]);
        assertThat(requests.get(1).packageName).isEqualTo(TEST_PACKAGE_NAMES[1]);
        assertThat(requests.get(1).requestFinishTime).isEqualTo(FOURTEEN_MIN_AGO + DURATION);
        assertThat(requests.get(1).requestFinishTime).isEqualTo(TWENTY_THREE_HOURS_AGO + DURATION);
    }
    }


    @Test
    @Test
@@ -105,7 +105,7 @@ public class RecentLocationAppsTest {
                        ONE_MIN_AGO,
                        ONE_MIN_AGO,
                        DURATION);
                        DURATION);
        long[] testRequestTime =
        long[] testRequestTime =
                {ONE_MIN_AGO, FOURTEEN_MIN_AGO, TWENTY_MIN_AGO, ONE_MIN_AGO};
                {ONE_MIN_AGO, TWENTY_THREE_HOURS_AGO, TWO_DAYS_AGO, ONE_MIN_AGO};
        List<PackageOps> appOps = createTestPackageOpsList(TEST_PACKAGE_NAMES, testRequestTime);
        List<PackageOps> appOps = createTestPackageOpsList(TEST_PACKAGE_NAMES, testRequestTime);
        appOps.add(androidSystemPackageOps);
        appOps.add(androidSystemPackageOps);
        when(mAppOpsManager.getPackagesForOps(RecentLocationApps.LOCATION_OPS)).thenReturn(appOps);
        when(mAppOpsManager.getPackagesForOps(RecentLocationApps.LOCATION_OPS)).thenReturn(appOps);
@@ -119,7 +119,7 @@ public class RecentLocationAppsTest {
        assertThat(requests.get(0).packageName).isEqualTo(TEST_PACKAGE_NAMES[0]);
        assertThat(requests.get(0).packageName).isEqualTo(TEST_PACKAGE_NAMES[0]);
        assertThat(requests.get(0).requestFinishTime).isEqualTo(ONE_MIN_AGO + DURATION);
        assertThat(requests.get(0).requestFinishTime).isEqualTo(ONE_MIN_AGO + DURATION);
        assertThat(requests.get(1).packageName).isEqualTo(TEST_PACKAGE_NAMES[1]);
        assertThat(requests.get(1).packageName).isEqualTo(TEST_PACKAGE_NAMES[1]);
        assertThat(requests.get(1).requestFinishTime).isEqualTo(FOURTEEN_MIN_AGO + DURATION);
        assertThat(requests.get(1).requestFinishTime).isEqualTo(TWENTY_THREE_HOURS_AGO + DURATION);
    }
    }


    private void mockTestApplicationInfos(int userId, String... packageNameList)
    private void mockTestApplicationInfos(int userId, String... packageNameList)