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

Commit 68381fe4 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Skip checking the app op for step sensors for legacy apps" into rvc-dev...

Merge "Skip checking the app op for step sensors for legacy apps" into rvc-dev am: a0758a8a am: 34cd2854

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/native/+/11934461

Change-Id: I28c8116a7231b013eafcf290010838e27978ac56
parents 3fe0384d 34cd2854
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ SensorService::SensorEventConnection::SensorEventConnection(
      mCacheSize(0), mMaxCacheSize(0), mTimeOfLastEventDrop(0), mEventsDropped(0),
      mPackageName(packageName), mOpPackageName(opPackageName), mDestroyed(false) {
    mChannel = new BitTube(mService->mSocketBufferSize);
    mTargetSdk = SensorService::getTargetSdkVersion(opPackageName);
#if DEBUG_CONNECTIONS
    mEventsReceived = mEventsSentFromCache = mEventsSent = 0;
    mTotalAcksNeeded = mTotalAcksReceived = 0;
@@ -439,9 +440,18 @@ bool SensorService::SensorEventConnection::noteOpIfRequired(const sensors_event_
    bool success = true;
    const auto iter = mHandleToAppOp.find(event.sensor);
    if (iter != mHandleToAppOp.end()) {
        int32_t appOpMode = mService->sAppOpsManager.noteOp((*iter).second, mUid, mOpPackageName);
        // Special handling for step count/detect backwards compatibility: if the app's target SDK
        // is pre-Q, still permit delivering events to the app even if permission isn't granted
        // (since this permission was only introduced in Q)
        if ((event.type == SENSOR_TYPE_STEP_COUNTER || event.type == SENSOR_TYPE_STEP_DETECTOR) &&
                mTargetSdk > 0 && mTargetSdk <= __ANDROID_API_P__) {
            success = true;
        } else {
            int32_t appOpMode = mService->sAppOpsManager.noteOp(iter->second, mUid,
                                                                mOpPackageName);
            success = (appOpMode == AppOpsManager::MODE_ALLOWED);
        }
    }
    return success;
}

+1 −0
Original line number Diff line number Diff line
@@ -175,6 +175,7 @@ private:
    int mEventsDropped;
    String8 mPackageName;
    const String16 mOpPackageName;
    int mTargetSdk;
#if DEBUG_CONNECTIONS
    int mEventsReceived, mEventsSent, mEventsSentFromCache;
    int mTotalAcksNeeded, mTotalAcksReceived;
+11 −19
Original line number Diff line number Diff line
@@ -1802,35 +1802,27 @@ bool SensorService::canAccessSensor(const Sensor& sensor, const char* operation,
    const int32_t appOpMode = sAppOpsManager.checkOp(opCode,
            IPCThreadState::self()->getCallingUid(), opPackageName);
    bool appOpAllowed = appOpMode == AppOpsManager::MODE_ALLOWED;
    int targetSdkVersion = getTargetSdkVersion(opPackageName);

    bool canAccess = false;
    if (hasPermissionForSensor(sensor)) {
    if (targetSdkVersion > 0 && targetSdkVersion <= __ANDROID_API_P__ &&
            (sensor.getType() == SENSOR_TYPE_STEP_COUNTER ||
             sensor.getType() == SENSOR_TYPE_STEP_DETECTOR)) {
        // Allow access to step sensors if the application targets pre-Q, which is before the
        // requirement to hold the AR permission to access Step Counter and Step Detector events
        // was introduced.
        canAccess = true;
    } else if (hasPermissionForSensor(sensor)) {
        // Ensure that the AppOp is allowed, or that there is no necessary app op for the sensor
        if (opCode < 0 || appOpAllowed) {
            canAccess = true;
        }
    } else if (sensor.getType() == SENSOR_TYPE_STEP_COUNTER ||
            sensor.getType() == SENSOR_TYPE_STEP_DETECTOR) {
        int targetSdkVersion = getTargetSdkVersion(opPackageName);
        // Allow access to the sensor if the application targets pre-Q, which is before the
        // requirement to hold the AR permission to access Step Counter and Step Detector events
        // was introduced, and the user hasn't revoked the app op.
        //
        // Verifying the app op is required to ensure that the user hasn't revoked the necessary
        // permissions to access the Step Detector and Step Counter when the application targets
        // pre-Q. Without this check, if the user revokes the pre-Q install-time GMS Core AR
        // permission, the app would still be able to receive Step Counter and Step Detector events.
        if (appOpAllowed &&
                targetSdkVersion > 0 &&
                targetSdkVersion <= __ANDROID_API_P__) {
            canAccess = true;
        }
    }

    if (canAccess) {
        sAppOpsManager.noteOp(opCode, IPCThreadState::self()->getCallingUid(), opPackageName);
    } else {
        ALOGE("%s a sensor (%s) without holding its required permission: %s",
        ALOGE("%s %s a sensor (%s) without holding %s", String8(opPackageName).string(),
              operation, sensor.getName().string(), sensor.getRequiredPermission().string());
    }