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

Commit ffe8d252 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Hold location indicator for 10s rather than 5s." into main

parents 5bfce90a 447f0faa
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -101,7 +101,11 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis

    private static final String SYSTEM_PKG = "android";

    // LINT.IfChange
    private static final long DEFAULT_RUNNING_TIME_MS = 5000L;
    private static final long ADDITIONAL_RUNNING_TIME_LOCATION_ONLY_MS =
            10_000L - DEFAULT_RUNNING_TIME_MS;
    // LINT.ThenChange(/packages/SystemUI/src/com/android/systemui/privacy/PrivacyItemController.kt)
    private static final long DEFAULT_RECENT_TIME_MS = 15000L;

    private static boolean shouldShowIndicators() {
@@ -597,8 +601,15 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis
                        continue;
                    }

                    boolean isRunning = attrOpEntry.isRunning()
                            || lastAccessTime >= runningThreshold;
                    String permGroupName = getGroupForOp(op);
                    boolean isLocationOp =
                            android.location.flags.Flags.locationIndicatorsEnabled()
                                    && LOCATION.equals(permGroupName);
                    long currentRunningThreshold =
                            runningThreshold
                                    - (isLocationOp ? ADDITIONAL_RUNNING_TIME_LOCATION_ONLY_MS : 0);
                    boolean isRunning =
                            attrOpEntry.isRunning() || lastAccessTime >= currentRunningThreshold;

                    OpUsage proxyUsage = null;
                    AppOpsManager.OpEventProxyInfo proxy = attrOpEntry.getLastProxyInfo(opFlags);
@@ -607,8 +618,7 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis
                                op, proxy.getUid(), lastAccessTime, isRunning, null);
                    }

                    String permGroupName = getGroupForOp(op);
                    if (LOCATION.equals(permGroupName)) {
                    if (isLocationOp) {
                        // Only non-system, non-background apps should trigger location indicator.
                        // But if the location indicator is already visible (e.g. an app
                        // transitioned from foreground to background), we should not filter it out
+15 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.privacy

import android.location.flags.Flags.locationIndicatorsEnabled
import com.android.internal.annotations.VisibleForTesting
import com.android.systemui.Dumpable
import com.android.systemui.appops.AppOpsController
@@ -47,7 +48,10 @@ class PrivacyItemController @Inject constructor(
    @VisibleForTesting
    internal companion object {
        const val TAG = "PrivacyItemController"
        @VisibleForTesting const val TIME_TO_HOLD_INDICATORS = 5000L
        // LINT.IfChange
        @VisibleForTesting const val TIME_TO_HOLD_INDICATORS = 5_000L
        @VisibleForTesting const val TIME_TO_HOLD_INDICATORS_FOR_LOCATION = 10_000L
        // LINT.ThenChange(/core/java/android/permission/PermissionUsageHelper.java)
    }

    @VisibleForTesting
@@ -181,10 +185,19 @@ class PrivacyItemController @Inject constructor(
     * @return a list that may have added items that should be kept for some time.
     */
    private fun processNewList(list: List<PrivacyItem>): List<PrivacyItem> {
        val allPrivacyItemsAreLocation =
            locationIndicatorsEnabled() &&
                PrivacyConfig.Companion.privacyItemsAreLocationOnly((list + privacyList).distinct())
        val timeToHold =
            if (allPrivacyItemsAreLocation) {
                TIME_TO_HOLD_INDICATORS_FOR_LOCATION
            } else {
                TIME_TO_HOLD_INDICATORS
            }
        logger.logRetrievedPrivacyItemsList(list)

        // Anything earlier than this timestamp can be removed
        val removeBeforeTime = systemClock.elapsedRealtime() - TIME_TO_HOLD_INDICATORS
        val removeBeforeTime = systemClock.elapsedRealtime() - timeToHold
        val mustKeep = privacyList.filter {
            it.timeStampElapsed > removeBeforeTime && !(it isIn list)
        }
+42 −3
Original line number Diff line number Diff line
@@ -267,7 +267,7 @@ class PrivacyItemControllerTest : SysuiTestCase() {
    }

    @Test
    fun testPassageOfTimeDoesNotRemoveIndicators() {
    fun testPassageOfTimeDoesNotRemoveCameraIndicators() {
        doReturn(listOf(
                PrivacyItem(PrivacyType.TYPE_CAMERA,
                        PrivacyApplication(TEST_PACKAGE_NAME, TEST_UID), 0)
@@ -283,7 +283,7 @@ class PrivacyItemControllerTest : SysuiTestCase() {
    }

    @Test
    fun testNotHeldAfterTimeIsOff() {
    fun testCameraPrivacyItemNotHeldAfterTimeIsOff() {
        // Start with some element at time 0
        doReturn(listOf(
                PrivacyItem(PrivacyType.TYPE_CAMERA,
@@ -306,7 +306,46 @@ class PrivacyItemControllerTest : SysuiTestCase() {
    }

    @Test
    fun testElementNotRemovedBeforeHoldTime() {
    fun testPassageOfTimeDoesNotRemoveLocationIndicators() {
        // Start with some element at time 0
        doReturn(listOf(
                PrivacyItem(PrivacyType.TYPE_LOCATION,
                        PrivacyApplication(TEST_PACKAGE_NAME, TEST_UID), 0)
        )).`when`(privacyItemMonitor).getActivePrivacyItems()
        privacyItemController.addCallback(callback)
        executor.runAllReady()
        doReturn(emptyList<PrivacyItem>()).`when`(privacyItemMonitor).getActivePrivacyItems()

        fakeClock.advanceTime(PrivacyItemController.TIME_TO_HOLD_INDICATORS + 1)
                executor.runAllReady()
        // Verify that LOCATION items are not removed after TIME_TO_HOLD_INDICATORS
        assertTrue(privacyItemController.privacyList.isNotEmpty())
    }

    @Test
    fun testLocationPrivacyItemsNotHeldAfterTimeIsOff() {
        // Start with some element at time 0
        doReturn(listOf(
                PrivacyItem(PrivacyType.TYPE_LOCATION,
                        PrivacyApplication(TEST_PACKAGE_NAME, TEST_UID), 0)
        )).`when`(privacyItemMonitor).getActivePrivacyItems()
        privacyItemController.addCallback(callback)
        executor.runAllReady()
        doReturn(emptyList<PrivacyItem>()).`when`(privacyItemMonitor).getActivePrivacyItems()

        fakeClock.advanceTime(PrivacyItemController.TIME_TO_HOLD_INDICATORS_FOR_LOCATION + 1)
        verify(privacyItemMonitor).startListening(capture(argCaptorCallback))
        argCaptorCallback.value.onPrivacyItemsChanged()
        executor.runAllReady()

        // See it's not there
        verify(callback).onPrivacyItemsChanged(emptyList())
        assertTrue(privacyItemController.privacyList.isEmpty())
    }


    @Test
    fun testCameraElementNotRemovedBeforeHoldTime() {
        // Start with some element at current time
        doReturn(listOf(
                PrivacyItem(PrivacyType.TYPE_CAMERA,