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

Commit 4627fa2e authored by Nate Myren's avatar Nate Myren
Browse files

Wait for non-stale app ops, add logs, remove useless code

Ensure the ReviewOngoingUsageFragment waits for non-stale phone call
ops, add logs to ops, logging state, remove unneeded accept method

Bug: 166837151
Test: Make a phone call, click the privacy chip, then leave the call,
wait 10 seconds, and go to another app that uses camera/mic, click the
chip- phone call should not be there.

Change-Id: I3a5362a8a5061c8373c2cec6fd73f9d9d11d4c18
Merged-In: I2837d48b3e0c985d3023bf75f3876e0e97a0d9ae
parent 356193b2
Loading
Loading
Loading
Loading
+11 −25
Original line number Diff line number Diff line
@@ -20,9 +20,9 @@ import android.app.AppOpsManager
import android.app.AppOpsManager.OP_FLAGS_ALL_TRUSTED
import android.app.Application
import android.os.UserHandle
import android.util.Log
import com.android.permissioncontroller.PermissionControllerApplication
import kotlinx.coroutines.Job
import java.util.function.Consumer

/**
 * LiveData that loads the last usage of each of a list of app ops for every package.
@@ -38,8 +38,7 @@ class OpUsageLiveData(
    private val app: Application,
    private val opNames: List<String>,
    private val usageDurationMs: Long
) : SmartAsyncMediatorLiveData<@JvmSuppressWildcards Map<String, List<OpAccess>>>(),
        Consumer<AppOpsManager.HistoricalOps> {
) : SmartAsyncMediatorLiveData<@JvmSuppressWildcards Map<String, List<OpAccess>>>() {
    val appOpsManager = app.getSystemService(AppOpsManager::class.java)!!

    override suspend fun loadDataAndPostValue(job: Job) {
@@ -73,6 +72,15 @@ class OpUsageLiveData(
                        lastAccessTime
                    }
                    accessList.add(OpAccess(packageOp.packageName, user, accessTime))
                    // TODO ntmyren: remove logs once b/160724034 is fixed
                    Log.i("OpUsageLiveData", "adding ${opEntry.opStr} for " +
                        "${packageOp.packageName}, access time of $lastAccessTime, isRunning: " +
                        "${opEntry.isRunning} current time $now, duration $lastAccessDuration")
                } else {
                    // TODO ntmyren: remove logs once b/160724034 is fixed
                    Log.i("OpUsageLiveData", "NOT adding ${opEntry.opStr} for " +
                        "${packageOp.packageName}, access time of $lastAccessTime, isRunning: " +
                        "${opEntry.isRunning} current time $now, duration $lastAccessDuration")
                }
            }
        }
@@ -80,28 +88,6 @@ class OpUsageLiveData(
        postValue(opMap)
    }

    override fun accept(historicalOps: AppOpsManager.HistoricalOps) {
        val opMap = mutableMapOf<String, MutableList<OpAccess>>()
        for (i in 0 until historicalOps.uidCount) {
            val historicalUidOps = historicalOps.getUidOpsAt(i)
            val user = UserHandle.getUserHandleForUid(historicalUidOps.uid)
            for (j in 0 until historicalUidOps.packageCount) {
                val historicalPkgOps = historicalUidOps.getPackageOpsAt(j)
                val pkgName = historicalPkgOps.packageName
                for (k in 0 until historicalPkgOps.opCount) {
                    val historicalAttributedOps = historicalPkgOps.getAttributedOpsAt(k)
                    for (l in 0 until historicalAttributedOps.opCount) {
                        val historicalOp = historicalAttributedOps.getOpAt(l)
                        val opName = historicalOp.opName

                        val accessList = opMap.getOrPut(opName) { mutableListOf() }
                        accessList.add(OpAccess(pkgName, user, -1))
                    }
                }
            }
        }
    }

    override fun onActive() {
        super.onActive()
        updateAsync()
+3 −0
Original line number Diff line number Diff line
@@ -110,6 +110,9 @@ public class ReviewOngoingUsageFragment extends PreferenceFragmentCompat {
        mOpUsageLiveData.observe(this, new Observer<Map<String, List<OpAccess>>>() {
            @Override
            public void onChanged(Map<String, List<OpAccess>> opUsage) {
                if (mOpUsageLiveData.isStale()) {
                    return;
                }
                mOpUsage = opUsage;
                mOpUsageLiveData.removeObserver(this);