diff options
| author | 2021-07-07 10:29:43 -0700 | |
|---|---|---|
| committer | 2021-07-08 10:33:05 -0700 | |
| commit | 16bfded1a54465cb54c76b486aa70d24e0fbaa56 (patch) | |
| tree | b8fc64d051f338feccec7344a2df6c7963adc69b | |
| parent | 96e7cae3996873f00b4df8256136019eb1fb2227 (diff) | |
Log duration privacy toggle was in previous state
Test: statsd_testdrive
Bug: 192269258
Change-Id: If8da2ae56f2c82b96f0035d4955ac39787299098
| -rw-r--r-- | services/core/java/com/android/server/SensorPrivacyService.java | 55 |
1 files changed, 33 insertions, 22 deletions
diff --git a/services/core/java/com/android/server/SensorPrivacyService.java b/services/core/java/com/android/server/SensorPrivacyService.java index b54d9866c7a3..53ff8ff768de 100644 --- a/services/core/java/com/android/server/SensorPrivacyService.java +++ b/services/core/java/com/android/server/SensorPrivacyService.java @@ -148,6 +148,8 @@ import java.util.Objects; public final class SensorPrivacyService extends SystemService { private static final String TAG = SensorPrivacyService.class.getSimpleName(); + private static final boolean DEBUG = false; + private static final boolean DEBUG_LOGGING = false; /** Version number indicating compatibility parsing the persisted file */ private static final int CURRENT_PERSISTENCE_VERSION = 1; @@ -290,14 +292,6 @@ public final class SensorPrivacyService extends SystemService { } return false; } - - private long getCurrentTimeMillis() { - try { - return SystemClock.currentNetworkTimeMillis(); - } catch (Exception e) { - return System.currentTimeMillis(); - } - } } private class SensorUseReminderDialogInfo { @@ -364,11 +358,11 @@ public final class SensorPrivacyService extends SystemService { // Reset sensor privacy when restriction is added if (!prevRestrictions.getBoolean(UserManager.DISALLOW_CAMERA_TOGGLE) && newRestrictions.getBoolean(UserManager.DISALLOW_CAMERA_TOGGLE)) { - setIndividualSensorPrivacyUnchecked(userId, CAMERA, false); + setIndividualSensorPrivacyUnchecked(userId, OTHER, CAMERA, false); } if (!prevRestrictions.getBoolean(UserManager.DISALLOW_MICROPHONE_TOGGLE) && newRestrictions.getBoolean(UserManager.DISALLOW_MICROPHONE_TOGGLE)) { - setIndividualSensorPrivacyUnchecked(userId, MICROPHONE, false); + setIndividualSensorPrivacyUnchecked(userId, OTHER, MICROPHONE, false); } } @@ -709,29 +703,33 @@ public final class SensorPrivacyService extends SystemService { return; } - if (userId == mUserManagerInternal.getProfileParentId(userId)) { - logSensorPrivacyToggle(source, sensor, enable); - } - - setIndividualSensorPrivacyUnchecked(userId, sensor, enable); + setIndividualSensorPrivacyUnchecked(userId, source, sensor, enable); } - private void setIndividualSensorPrivacyUnchecked(int userId, int sensor, boolean enable) { + private void setIndividualSensorPrivacyUnchecked(int userId, int source, int sensor, + boolean enable) { synchronized (mLock) { SparseArray<SensorState> userIndividualEnabled = mIndividualEnabled.get(userId, new SparseArray<>()); SensorState sensorState = userIndividualEnabled.get(sensor); + long lastChange; if (sensorState != null) { + lastChange = sensorState.mLastChange; if (!sensorState.setEnabled(enable)) { // State not changing return; } } else { sensorState = new SensorState(enable); + lastChange = sensorState.mLastChange; userIndividualEnabled.put(sensor, sensorState); } mIndividualEnabled.put(userId, userIndividualEnabled); + if (userId == mUserManagerInternal.getProfileParentId(userId)) { + logSensorPrivacyToggle(source, sensor, sensorState.mEnabled, lastChange); + } + if (!enable) { long token = Binder.clearCallingIdentity(); try { @@ -775,12 +773,12 @@ public final class SensorPrivacyService extends SystemService { return true; } - private void logSensorPrivacyToggle(int source, int sensor, boolean enable) { - long logMins = 0L; - //(TODO:pyuli) : Add timestamp after persistent storage for timestamp is done. + private void logSensorPrivacyToggle(int source, int sensor, boolean enabled, + long lastChange) { + long logMins = Math.max(0, (getCurrentTimeMillis() - lastChange) / (1000 * 60)); int logAction = -1; - if (enable) { + if (enabled) { logAction = PRIVACY_SENSOR_TOGGLE_INTERACTION__ACTION__TOGGLE_OFF; } else { logAction = PRIVACY_SENSOR_TOGGLE_INTERACTION__ACTION__TOGGLE_ON; @@ -813,6 +811,11 @@ public final class SensorPrivacyService extends SystemService { logSource = PRIVACY_SENSOR_TOGGLE_INTERACTION__SOURCE__SOURCE_UNKNOWN; } + if (DEBUG || DEBUG_LOGGING) { + Log.d(TAG, "Logging sensor toggle interaction:" + " logSensor=" + logSensor + + " logAction=" + logAction + " logSource=" + logSource + " logMins=" + + logMins); + } write(PRIVACY_SENSOR_TOGGLE_INTERACTION, logSensor, logAction, logSource, logMins); } @@ -1741,7 +1744,7 @@ public final class SensorPrivacyService extends SystemService { if (mSensorPrivacyServiceImpl .isIndividualSensorPrivacyEnabled(getCurrentUser(), MICROPHONE)) { mSensorPrivacyServiceImpl.setIndividualSensorPrivacyUnchecked( - getCurrentUser(), MICROPHONE, false); + getCurrentUser(), OTHER, MICROPHONE, false); mMicUnmutedForEmergencyCall = true; } else { mMicUnmutedForEmergencyCall = false; @@ -1756,11 +1759,19 @@ public final class SensorPrivacyService extends SystemService { mIsInEmergencyCall = false; if (mMicUnmutedForEmergencyCall) { mSensorPrivacyServiceImpl.setIndividualSensorPrivacyUnchecked( - getCurrentUser(), MICROPHONE, true); + getCurrentUser(), OTHER, MICROPHONE, true); mMicUnmutedForEmergencyCall = false; } } } } } + + private static long getCurrentTimeMillis() { + try { + return SystemClock.currentNetworkTimeMillis(); + } catch (Exception e) { + return System.currentTimeMillis(); + } + } } |