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

Commit f6146093 authored by Jay Thomas Sullivan's avatar Jay Thomas Sullivan Committed by Jay Sullivan
Browse files

Improve logging of ignored setUidMode

If we ignore a setUidMode call that would have changed the op mode,
then:

- Log as an error
- Log the stack trace
- Use the phrase "Blocked setUidMode"

Otherwise:

- Log as a warning
- Don't log the stack trace
- Use the phrase "Ignored setUidMode"

The reason for this is that the former is much more concerning, so we
want to know where it's coming from and to be able to easily search
bugreports for this specific situation.

FLAG: android.permission.flags.runtime_permission_appops_mapping_enabled
Bug: 341219398
Test: presubmit
Change-Id: Ia27838c680ace39adf9221df953fecdf5a40ae1d
parent 5b0af123
Loading
Loading
Loading
Loading
+18 −10
Original line number Diff line number Diff line
@@ -246,24 +246,32 @@ class AppOpService(private val service: AccessCheckingService) : AppOpsCheckingS
        }

    override fun setUidMode(uid: Int, deviceId: String, code: Int, mode: Int): Boolean {
        val appId = UserHandle.getAppId(uid)
        val userId = UserHandle.getUserId(uid)
        val appOpName = AppOpsManager.opToPublicName(code)

        if (
            Flags.runtimePermissionAppopsMappingEnabled() && code in runtimeAppOpToPermissionNames
        ) {
            Slog.w(
                LOG_TAG,
                "Cannot set UID mode for runtime permission app op, " +
                    " callingUid = ${Binder.getCallingUid()}, " +
            val oldMode =
                service.getState { with(appIdPolicy) { getAppOpMode(appId, userId, appOpName) } }
            val wouldHaveChanged = oldMode != mode
            val logMessage =
                (if (wouldHaveChanged) "Blocked" else "Ignored") +
                    " setUidMode call for runtime permission app op:" +
                    " uid = $uid," +
                    " code = ${AppOpsManager.opToName(code)}," +
                    " mode = ${AppOpsManager.modeToName(mode)}",
                RuntimeException()
            )
                    " mode = ${AppOpsManager.modeToName(mode)}," +
                    " callingUid = ${Binder.getCallingUid()}," +
                    " oldMode = ${AppOpsManager.modeToName(oldMode)}"
            if (wouldHaveChanged) {
                Slog.e(LOG_TAG, logMessage, RuntimeException())
            } else {
                Slog.w(LOG_TAG, logMessage)
            }
            return false
        }

        val appId = UserHandle.getAppId(uid)
        val userId = UserHandle.getUserId(uid)
        val appOpName = AppOpsManager.opToPublicName(code)
        var wasChanged: Boolean
        service.mutateState {
            wasChanged = with(appIdPolicy) { setAppOpMode(appId, userId, appOpName, mode) }