Loading services/core/java/com/android/server/audio/AudioService.java +2 −1 Original line number Diff line number Diff line Loading @@ -10809,7 +10809,8 @@ public class AudioService extends IAudioService.Stub //TODO move inside HardeningEnforcer after refactor that moves permission checks // in the blockFocusMethod if (permissionOverridesCheck) { mHardeningEnforcer.metricsLogFocusReq(/*blocked*/false, focusReqType, uid); mHardeningEnforcer.metricsLogFocusReq(/*blocked*/ false, focusReqType, uid, /*unblockedBySdk*/ false); } if (!permissionOverridesCheck && mHardeningEnforcer.blockFocusMethod(uid, HardeningEnforcer.METHOD_AUDIO_MANAGER_REQUEST_AUDIO_FOCUS, Loading services/core/java/com/android/server/audio/HardeningEnforcer.java +20 −2 Original line number Diff line number Diff line Loading @@ -168,6 +168,8 @@ public class HardeningEnforcer { } boolean blocked = true; // indicates the focus request was not blocked because of the SDK version boolean unblockedBySdk = false; if (noteOp(AppOpsManager.OP_TAKE_AUDIO_FOCUS, callingUid, packageName, attributionTag)) { if (DEBUG) { Slog.i(TAG, "blockFocusMethod pack:" + packageName + " NOT blocking"); Loading @@ -179,9 +181,10 @@ public class HardeningEnforcer { + targetSdk); } blocked = false; unblockedBySdk = true; } metricsLogFocusReq(blocked, focusReqType, callingUid); metricsLogFocusReq(blocked, focusReqType, callingUid, unblockedBySdk); if (!blocked) { return false; Loading @@ -195,7 +198,16 @@ public class HardeningEnforcer { return true; } /*package*/ void metricsLogFocusReq(boolean blocked, int focusReq, int callingUid) { /** * Log metrics for the focus request * @param blocked true if the call blocked * @param focusReq the type of focus request * @param callingUid the UID of the caller * @param unblockedBySdk if blocked is false, * true indicates it was unblocked thanks to an older SDK */ /*package*/ void metricsLogFocusReq(boolean blocked, int focusReq, int callingUid, boolean unblockedBySdk) { final String metricId = blocked ? METRIC_COUNTERS_FOCUS_DENIAL.get(focusReq) : METRIC_COUNTERS_FOCUS_GRANT.get(focusReq); if (TextUtils.isEmpty(metricId)) { Loading @@ -204,6 +216,12 @@ public class HardeningEnforcer { } try { Counter.logIncrementWithUid(metricId, callingUid); if (!blocked && unblockedBySdk) { // additional metric to capture focus requests that are currently granted // because the app is on an older SDK, but would have been blocked otherwise Counter.logIncrementWithUid( "media_audio.value_audio_focus_grant_hardening_waived_by_sdk", callingUid); } } catch (Exception e) { Slog.e(TAG, "Counter error metricId:" + metricId + " for focus req:" + focusReq + " from uid:" + callingUid, e); Loading Loading
services/core/java/com/android/server/audio/AudioService.java +2 −1 Original line number Diff line number Diff line Loading @@ -10809,7 +10809,8 @@ public class AudioService extends IAudioService.Stub //TODO move inside HardeningEnforcer after refactor that moves permission checks // in the blockFocusMethod if (permissionOverridesCheck) { mHardeningEnforcer.metricsLogFocusReq(/*blocked*/false, focusReqType, uid); mHardeningEnforcer.metricsLogFocusReq(/*blocked*/ false, focusReqType, uid, /*unblockedBySdk*/ false); } if (!permissionOverridesCheck && mHardeningEnforcer.blockFocusMethod(uid, HardeningEnforcer.METHOD_AUDIO_MANAGER_REQUEST_AUDIO_FOCUS, Loading
services/core/java/com/android/server/audio/HardeningEnforcer.java +20 −2 Original line number Diff line number Diff line Loading @@ -168,6 +168,8 @@ public class HardeningEnforcer { } boolean blocked = true; // indicates the focus request was not blocked because of the SDK version boolean unblockedBySdk = false; if (noteOp(AppOpsManager.OP_TAKE_AUDIO_FOCUS, callingUid, packageName, attributionTag)) { if (DEBUG) { Slog.i(TAG, "blockFocusMethod pack:" + packageName + " NOT blocking"); Loading @@ -179,9 +181,10 @@ public class HardeningEnforcer { + targetSdk); } blocked = false; unblockedBySdk = true; } metricsLogFocusReq(blocked, focusReqType, callingUid); metricsLogFocusReq(blocked, focusReqType, callingUid, unblockedBySdk); if (!blocked) { return false; Loading @@ -195,7 +198,16 @@ public class HardeningEnforcer { return true; } /*package*/ void metricsLogFocusReq(boolean blocked, int focusReq, int callingUid) { /** * Log metrics for the focus request * @param blocked true if the call blocked * @param focusReq the type of focus request * @param callingUid the UID of the caller * @param unblockedBySdk if blocked is false, * true indicates it was unblocked thanks to an older SDK */ /*package*/ void metricsLogFocusReq(boolean blocked, int focusReq, int callingUid, boolean unblockedBySdk) { final String metricId = blocked ? METRIC_COUNTERS_FOCUS_DENIAL.get(focusReq) : METRIC_COUNTERS_FOCUS_GRANT.get(focusReq); if (TextUtils.isEmpty(metricId)) { Loading @@ -204,6 +216,12 @@ public class HardeningEnforcer { } try { Counter.logIncrementWithUid(metricId, callingUid); if (!blocked && unblockedBySdk) { // additional metric to capture focus requests that are currently granted // because the app is on an older SDK, but would have been blocked otherwise Counter.logIncrementWithUid( "media_audio.value_audio_focus_grant_hardening_waived_by_sdk", callingUid); } } catch (Exception e) { Slog.e(TAG, "Counter error metricId:" + metricId + " for focus req:" + focusReq + " from uid:" + callingUid, e); Loading