From 4fb8a97b21741a3cd89b0c84184b7a35bb215c73 Mon Sep 17 00:00:00 2001 From: Anh Pham Date: Wed, 14 Apr 2021 11:27:35 +0200 Subject: [PATCH] Move isChangeEnabled() to end of the if statement. Bug: 185207500 Test: Build, locally tested a simple app that calls SensorManager.registerListener() and observed that the log CompatibilityChangeReporter: Compat change id reported: 136069189 is no longer printed out in logcat. Change-Id: I8ef197b650bb07638300045d42de96ba3bcd20e2 --- core/java/android/hardware/SystemSensorManager.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/java/android/hardware/SystemSensorManager.java b/core/java/android/hardware/SystemSensorManager.java index 3c11d8ed97b1b..bc2dcb3b4e624 100644 --- a/core/java/android/hardware/SystemSensorManager.java +++ b/core/java/android/hardware/SystemSensorManager.java @@ -571,10 +571,10 @@ public class SystemSensorManager extends SensorManager { } int sensorHandle = (sensor == null) ? -1 : sensor.getHandle(); - if (Compatibility.isChangeEnabled(CHANGE_ID_SAMPLING_RATE_SENSORS_PERMISSION) - && rate > CAPPED_SAMPLING_RATE_LEVEL + if (rate > CAPPED_SAMPLING_RATE_LEVEL && mIsPackageDebuggable - && !mHasHighSamplingRateSensorsPermission) { + && !mHasHighSamplingRateSensorsPermission + && Compatibility.isChangeEnabled(CHANGE_ID_SAMPLING_RATE_SENSORS_PERMISSION)) { throw new SecurityException("To use the sampling rate level " + rate + ", app needs to declare the normal permission" + " HIGH_SAMPLING_RATE_SENSORS."); @@ -782,10 +782,10 @@ public class SystemSensorManager extends SensorManager { Sensor sensor, int rateUs, int maxBatchReportLatencyUs) { if (mNativeSensorEventQueue == 0) throw new NullPointerException(); if (sensor == null) throw new NullPointerException(); - if (Compatibility.isChangeEnabled(CHANGE_ID_SAMPLING_RATE_SENSORS_PERMISSION) - && rateUs < CAPPED_SAMPLING_PERIOD_US + if (rateUs < CAPPED_SAMPLING_PERIOD_US && mManager.mIsPackageDebuggable - && !mManager.mHasHighSamplingRateSensorsPermission) { + && !mManager.mHasHighSamplingRateSensorsPermission + && Compatibility.isChangeEnabled(CHANGE_ID_SAMPLING_RATE_SENSORS_PERMISSION)) { throw new SecurityException("To use the sampling rate of " + rateUs + " microseconds, app needs to declare the normal permission" + " HIGH_SAMPLING_RATE_SENSORS.");