From 6237247d9663ab13d759b2c288ac6c5551005560 Mon Sep 17 00:00:00 2001 From: Sudheer Shanka Date: Mon, 29 Mar 2021 16:07:10 +0000 Subject: Rename MediaSessionConfig to MediaSessionDeviceConfig. Bug: 174699413 Test: treehugger Change-Id: Icd3c9556f04cccc376c294978a9c6bc301f284d7 --- .../android/server/media/MediaSessionConfig.java | 101 --------------------- .../server/media/MediaSessionDeviceConfig.java | 101 +++++++++++++++++++++ .../android/server/media/MediaSessionService.java | 8 +- 3 files changed, 105 insertions(+), 105 deletions(-) delete mode 100644 services/core/java/com/android/server/media/MediaSessionConfig.java create mode 100644 services/core/java/com/android/server/media/MediaSessionDeviceConfig.java diff --git a/services/core/java/com/android/server/media/MediaSessionConfig.java b/services/core/java/com/android/server/media/MediaSessionConfig.java deleted file mode 100644 index a866b0d4a38b..000000000000 --- a/services/core/java/com/android/server/media/MediaSessionConfig.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.server.media; - -import android.content.Context; -import android.provider.DeviceConfig; -import android.text.TextUtils; - -import java.io.PrintWriter; -import java.util.Set; - -class MediaSessionConfig { - /** - * Denotes the duration for which a media button receiver will be exempted from - * FGS-from-BG restriction and so will be allowed to start an FGS even if it is in the - * background state while it receives a media key event. - */ - private static final String KEY_MEDIA_BUTTON_RECEIVER_FGS_ALLOWLIST_DURATION_MS = - "media_button_receiver_fgs_allowlist_duration_ms"; - private static final long DEFAULT_MEDIA_BUTTON_RECEIVER_FGS_ALLOWLIST_DURATION_MS = 10_000; - private static volatile long sMediaButtonReceiverFgsAllowlistDurationMs = - DEFAULT_MEDIA_BUTTON_RECEIVER_FGS_ALLOWLIST_DURATION_MS; - - /** - * Denotes the duration for which an app receiving a media session callback will be - * exempted from FGS-from-BG restriction and so will be allowed to start an FGS even if - * it is in the background state while it receives a media session callback. - */ - private static final String KEY_MEDIA_SESSION_CALLBACK_FGS_ALLOWLIST_DURATION_MS = - "media_session_calback_fgs_allowlist_duration_ms"; - private static final long DEFAULT_MEDIA_SESSION_CALLBACK_FGS_ALLOWLIST_DURATION_MS = 10_000; - private static volatile long sMediaSessionCallbackFgsAllowlistDurationMs = - DEFAULT_MEDIA_SESSION_CALLBACK_FGS_ALLOWLIST_DURATION_MS; - - private static void refresh(DeviceConfig.Properties properties) { - final Set keys = properties.getKeyset(); - properties.getKeyset().forEach(key -> { - switch (key) { - case KEY_MEDIA_BUTTON_RECEIVER_FGS_ALLOWLIST_DURATION_MS: - sMediaButtonReceiverFgsAllowlistDurationMs = properties.getLong(key, - DEFAULT_MEDIA_BUTTON_RECEIVER_FGS_ALLOWLIST_DURATION_MS); - break; - case KEY_MEDIA_SESSION_CALLBACK_FGS_ALLOWLIST_DURATION_MS: - sMediaSessionCallbackFgsAllowlistDurationMs = properties.getLong(key, - DEFAULT_MEDIA_SESSION_CALLBACK_FGS_ALLOWLIST_DURATION_MS); - break; - } - }); - } - - public static void initialize(Context context) { - DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_MEDIA, - context.getMainExecutor(), properties -> refresh(properties)); - refresh(DeviceConfig.getProperties(DeviceConfig.NAMESPACE_MEDIA)); - } - - /** - * Returns the duration for which a media button receiver will be exempted from - * FGS-from-BG restriction and so will be allowed to start an FGS even if it is in the - * background state while it receives a media key event. - */ - public static long getMediaButtonReceiverFgsAllowlistDurationMs() { - return sMediaButtonReceiverFgsAllowlistDurationMs; - } - - /** - * Returns the duration for which an app receiving a media session callback will be - * exempted from FGS-from-BG restriction and so will be allowed to start an FGS even if - * it is in the background state while it receives a media session callback. - */ - public static long getMediaSessionCallbackFgsAllowlistDurationMs() { - return sMediaSessionCallbackFgsAllowlistDurationMs; - } - - public static void dump(PrintWriter pw, String prefix) { - pw.println("Media session config:"); - final String dumpFormat = prefix + " %s: [cur: %s, def: %s]"; - pw.println(TextUtils.formatSimple(dumpFormat, - KEY_MEDIA_BUTTON_RECEIVER_FGS_ALLOWLIST_DURATION_MS, - sMediaButtonReceiverFgsAllowlistDurationMs, - DEFAULT_MEDIA_BUTTON_RECEIVER_FGS_ALLOWLIST_DURATION_MS)); - pw.println(TextUtils.formatSimple(dumpFormat, - KEY_MEDIA_SESSION_CALLBACK_FGS_ALLOWLIST_DURATION_MS, - sMediaSessionCallbackFgsAllowlistDurationMs, - DEFAULT_MEDIA_SESSION_CALLBACK_FGS_ALLOWLIST_DURATION_MS)); - } -} diff --git a/services/core/java/com/android/server/media/MediaSessionDeviceConfig.java b/services/core/java/com/android/server/media/MediaSessionDeviceConfig.java new file mode 100644 index 000000000000..9bb8e2e93746 --- /dev/null +++ b/services/core/java/com/android/server/media/MediaSessionDeviceConfig.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.media; + +import android.content.Context; +import android.provider.DeviceConfig; +import android.text.TextUtils; + +import java.io.PrintWriter; +import java.util.Set; + +class MediaSessionDeviceConfig { + /** + * Denotes the duration for which a media button receiver will be exempted from + * FGS-from-BG restriction and so will be allowed to start an FGS even if it is in the + * background state while it receives a media key event. + */ + private static final String KEY_MEDIA_BUTTON_RECEIVER_FGS_ALLOWLIST_DURATION_MS = + "media_button_receiver_fgs_allowlist_duration_ms"; + private static final long DEFAULT_MEDIA_BUTTON_RECEIVER_FGS_ALLOWLIST_DURATION_MS = 10_000; + private static volatile long sMediaButtonReceiverFgsAllowlistDurationMs = + DEFAULT_MEDIA_BUTTON_RECEIVER_FGS_ALLOWLIST_DURATION_MS; + + /** + * Denotes the duration for which an app receiving a media session callback will be + * exempted from FGS-from-BG restriction and so will be allowed to start an FGS even if + * it is in the background state while it receives a media session callback. + */ + private static final String KEY_MEDIA_SESSION_CALLBACK_FGS_ALLOWLIST_DURATION_MS = + "media_session_calback_fgs_allowlist_duration_ms"; + private static final long DEFAULT_MEDIA_SESSION_CALLBACK_FGS_ALLOWLIST_DURATION_MS = 10_000; + private static volatile long sMediaSessionCallbackFgsAllowlistDurationMs = + DEFAULT_MEDIA_SESSION_CALLBACK_FGS_ALLOWLIST_DURATION_MS; + + private static void refresh(DeviceConfig.Properties properties) { + final Set keys = properties.getKeyset(); + properties.getKeyset().forEach(key -> { + switch (key) { + case KEY_MEDIA_BUTTON_RECEIVER_FGS_ALLOWLIST_DURATION_MS: + sMediaButtonReceiverFgsAllowlistDurationMs = properties.getLong(key, + DEFAULT_MEDIA_BUTTON_RECEIVER_FGS_ALLOWLIST_DURATION_MS); + break; + case KEY_MEDIA_SESSION_CALLBACK_FGS_ALLOWLIST_DURATION_MS: + sMediaSessionCallbackFgsAllowlistDurationMs = properties.getLong(key, + DEFAULT_MEDIA_SESSION_CALLBACK_FGS_ALLOWLIST_DURATION_MS); + break; + } + }); + } + + public static void initialize(Context context) { + DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_MEDIA, + context.getMainExecutor(), properties -> refresh(properties)); + refresh(DeviceConfig.getProperties(DeviceConfig.NAMESPACE_MEDIA)); + } + + /** + * Returns the duration for which a media button receiver will be exempted from + * FGS-from-BG restriction and so will be allowed to start an FGS even if it is in the + * background state while it receives a media key event. + */ + public static long getMediaButtonReceiverFgsAllowlistDurationMs() { + return sMediaButtonReceiverFgsAllowlistDurationMs; + } + + /** + * Returns the duration for which an app receiving a media session callback will be + * exempted from FGS-from-BG restriction and so will be allowed to start an FGS even if + * it is in the background state while it receives a media session callback. + */ + public static long getMediaSessionCallbackFgsAllowlistDurationMs() { + return sMediaSessionCallbackFgsAllowlistDurationMs; + } + + public static void dump(PrintWriter pw, String prefix) { + pw.println("Media session config:"); + final String dumpFormat = prefix + " %s: [cur: %s, def: %s]"; + pw.println(TextUtils.formatSimple(dumpFormat, + KEY_MEDIA_BUTTON_RECEIVER_FGS_ALLOWLIST_DURATION_MS, + sMediaButtonReceiverFgsAllowlistDurationMs, + DEFAULT_MEDIA_BUTTON_RECEIVER_FGS_ALLOWLIST_DURATION_MS)); + pw.println(TextUtils.formatSimple(dumpFormat, + KEY_MEDIA_SESSION_CALLBACK_FGS_ALLOWLIST_DURATION_MS, + sMediaSessionCallbackFgsAllowlistDurationMs, + DEFAULT_MEDIA_SESSION_CALLBACK_FGS_ALLOWLIST_DURATION_MS)); + } +} diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java index aefdbca779e6..50cfe1fbc333 100644 --- a/services/core/java/com/android/server/media/MediaSessionService.java +++ b/services/core/java/com/android/server/media/MediaSessionService.java @@ -238,7 +238,7 @@ public class MediaSessionService extends SystemService implements Monitor { mSession2TokenCallback); break; case PHASE_ACTIVITY_MANAGER_READY: - MediaSessionConfig.initialize(mContext); + MediaSessionDeviceConfig.initialize(mContext); break; } } @@ -560,7 +560,7 @@ public class MediaSessionService extends SystemService implements Monitor { PowerExemptionManager.class); powerExemptionManager.addToTemporaryAllowList(targetPackage, PowerExemptionManager.REASON_MEDIA_SESSION_CALLBACK, reason, - MediaSessionConfig.getMediaSessionCallbackFgsAllowlistDurationMs()); + MediaSessionDeviceConfig.getMediaSessionCallbackFgsAllowlistDurationMs()); } } finally { Binder.restoreCallingIdentity(token); @@ -1975,7 +1975,7 @@ public class MediaSessionService extends SystemService implements Monitor { } mAudioPlayerStateMonitor.dump(mContext, pw, ""); } - MediaSessionConfig.dump(pw, ""); + MediaSessionDeviceConfig.dump(pw, ""); } /** @@ -2260,7 +2260,7 @@ public class MediaSessionService extends SystemService implements Monitor { mContext, keyEvent, callingPackageName, needWakeLock ? mKeyEventReceiver.mLastTimeoutId : -1, mKeyEventReceiver, mHandler, - MediaSessionConfig.getMediaButtonReceiverFgsAllowlistDurationMs()); + MediaSessionDeviceConfig.getMediaButtonReceiverFgsAllowlistDurationMs()); if (sent) { String pkgName = mediaButtonReceiverHolder.getPackageName(); for (FullUserRecord.OnMediaKeyEventDispatchedListenerRecord cr -- cgit v1.2.3-59-g8ed1b