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

Commit cb142de5 authored by Rocky Fang's avatar Rocky Fang
Browse files

Skip AppOps call from system UID

This is not needed since system UID should always have permission.

Bug: 334110086
Test: Presubmit
Change-Id: I327fed5587e40cce96f196561f80bad954dbb3be
parent 991e1925
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -463,14 +463,16 @@ bool SensorService::SensorEventConnection::noteOpIfRequired(const sensors_event_
        if ((event.type == SENSOR_TYPE_STEP_COUNTER || event.type == SENSOR_TYPE_STEP_DETECTOR) &&
            mTargetSdk > 0 && mTargetSdk <= __ANDROID_API_P__) {
            success = true;
        } else if (mUid == AID_SYSTEM) {
            // Allow access if it is requested from system.
            success = true;
        } else {
            int32_t sensorHandle = event.sensor;
            String16 noteMsg("Sensor event (");
            noteMsg.append(String16(mService->getSensorStringType(sensorHandle)));
            noteMsg.append(String16(")"));
            int32_t appOpMode = mService->sAppOpsManager.noteOp(iter->second, mUid,
                                                                mOpPackageName, mAttributionTag,
                                                                noteMsg);
            int32_t appOpMode = mService->sAppOpsManager.noteOp(iter->second, mUid, mOpPackageName,
                                                                mAttributionTag, noteMsg);
            success = (appOpMode == AppOpsManager::MODE_ALLOWED);
        }
    }
+8 −3
Original line number Diff line number Diff line
@@ -2302,11 +2302,16 @@ bool SensorService::canAccessSensor(const Sensor& sensor, const char* operation,
        // requirement to hold the AR permission to access Step Counter and Step Detector events
        // was introduced.
        canAccess = true;
    } else if (IPCThreadState::self()->getCallingUid() == AID_SYSTEM) {
        // Allow access if it is requested from system.
        canAccess = true;
    } else if (hasPermissionForSensor(sensor)) {
        // Ensure that the AppOp is allowed, or that there is no necessary app op for the sensor
        // Ensure that the AppOp is allowed, or that there is no necessary app op
        // for the sensor
        if (opCode >= 0) {
            const int32_t appOpMode = sAppOpsManager.checkOp(opCode,
                    IPCThreadState::self()->getCallingUid(), opPackageName);
            const int32_t appOpMode =
                    sAppOpsManager.checkOp(opCode, IPCThreadState::self()->getCallingUid(),
                                           opPackageName);
            canAccess = (appOpMode == AppOpsManager::MODE_ALLOWED);
        } else {
            canAccess = true;