diff options
| -rw-r--r-- | services/core/java/com/android/server/media/MediaFeatureFlagManager.java | 94 | ||||
| -rw-r--r-- | services/core/java/com/android/server/media/MediaRouter2ServiceImpl.java | 26 |
2 files changed, 5 insertions, 115 deletions
diff --git a/services/core/java/com/android/server/media/MediaFeatureFlagManager.java b/services/core/java/com/android/server/media/MediaFeatureFlagManager.java deleted file mode 100644 index f90f64a19301..000000000000 --- a/services/core/java/com/android/server/media/MediaFeatureFlagManager.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2023 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.annotation.StringDef; -import android.app.ActivityThread; -import android.app.Application; -import android.provider.DeviceConfig; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/* package */ class MediaFeatureFlagManager { - - /** - * Namespace for media better together features. - */ - private static final String NAMESPACE_MEDIA_BETTER_TOGETHER = "media_better_together"; - - @StringDef( - prefix = "FEATURE_", - value = { - FEATURE_SCANNING_MINIMUM_PACKAGE_IMPORTANCE - }) - @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) - @Retention(RetentionPolicy.SOURCE) - /* package */ @interface MediaFeatureFlag {} - - /** - * Whether to use IMPORTANCE_FOREGROUND (i.e. 100) or IMPORTANCE_FOREGROUND_SERVICE (i.e. 125) - * as the minimum package importance for scanning. - */ - /* package */ static final @MediaFeatureFlag String - FEATURE_SCANNING_MINIMUM_PACKAGE_IMPORTANCE = "scanning_package_minimum_importance"; - - private static final MediaFeatureFlagManager sInstance = new MediaFeatureFlagManager(); - - private MediaFeatureFlagManager() { - // Empty to prevent instantiation. - } - - /* package */ static MediaFeatureFlagManager getInstance() { - return sInstance; - } - - /** - * Returns a boolean value from {@link DeviceConfig} from the system_time namespace, or - * {@code defaultValue} if there is no explicit value set. - */ - public boolean getBoolean(@MediaFeatureFlag String key, boolean defaultValue) { - return DeviceConfig.getBoolean(NAMESPACE_MEDIA_BETTER_TOGETHER, key, defaultValue); - } - - /** - * Returns an int value from {@link DeviceConfig} from the system_time namespace, or {@code - * defaultValue} if there is no explicit value set. - */ - public int getInt(@MediaFeatureFlag String key, int defaultValue) { - return DeviceConfig.getInt(NAMESPACE_MEDIA_BETTER_TOGETHER, key, defaultValue); - } - - /** - * Adds a listener to react for changes in media feature flags values. Future calls to this - * method with the same listener will replace the old namespace and executor. - * - * @param onPropertiesChangedListener The listener to add. - */ - public void addOnPropertiesChangedListener( - DeviceConfig.OnPropertiesChangedListener onPropertiesChangedListener) { - Application currentApplication = ActivityThread.currentApplication(); - if (currentApplication != null) { - DeviceConfig.addOnPropertiesChangedListener( - NAMESPACE_MEDIA_BETTER_TOGETHER, - currentApplication.getMainExecutor(), - onPropertiesChangedListener); - } - } -} diff --git a/services/core/java/com/android/server/media/MediaRouter2ServiceImpl.java b/services/core/java/com/android/server/media/MediaRouter2ServiceImpl.java index e048522eee53..527200484832 100644 --- a/services/core/java/com/android/server/media/MediaRouter2ServiceImpl.java +++ b/services/core/java/com/android/server/media/MediaRouter2ServiceImpl.java @@ -16,7 +16,7 @@ package com.android.server.media; -import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND_SERVICE; +import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND; import static android.content.Intent.ACTION_SCREEN_OFF; import static android.content.Intent.ACTION_SCREEN_ON; import static android.media.MediaRoute2ProviderService.REASON_UNKNOWN_ERROR; @@ -24,7 +24,6 @@ import static android.media.MediaRouter2Utils.getOriginalId; import static android.media.MediaRouter2Utils.getProviderId; import static com.android.internal.util.function.pooled.PooledLambda.obtainMessage; -import static com.android.server.media.MediaFeatureFlagManager.FEATURE_SCANNING_MINIMUM_PACKAGE_IMPORTANCE; import android.Manifest; import android.annotation.NonNull; @@ -55,7 +54,6 @@ import android.os.Looper; import android.os.PowerManager; import android.os.RemoteException; import android.os.UserHandle; -import android.provider.DeviceConfig; import android.text.TextUtils; import android.util.ArrayMap; import android.util.Log; @@ -97,11 +95,7 @@ class MediaRouter2ServiceImpl { // in MediaRouter2, remove this constant and replace the usages with the real request IDs. private static final long DUMMY_REQUEST_ID = -1; - private static int sPackageImportanceForScanning = - MediaFeatureFlagManager.getInstance() - .getInt( - FEATURE_SCANNING_MINIMUM_PACKAGE_IMPORTANCE, - IMPORTANCE_FOREGROUND_SERVICE); + private static final int REQUIRED_PACKAGE_IMPORTANCE_FOR_SCANNING = IMPORTANCE_FOREGROUND; /** * Contains the list of bluetooth permissions that are required to do system routing. @@ -159,7 +153,7 @@ class MediaRouter2ServiceImpl { mContext = context; mActivityManager = mContext.getSystemService(ActivityManager.class); mActivityManager.addOnUidImportanceListener(mOnUidImportanceListener, - sPackageImportanceForScanning); + REQUIRED_PACKAGE_IMPORTANCE_FOR_SCANNING); mPowerManager = mContext.getSystemService(PowerManager.class); mUserManagerInternal = LocalServices.getService(UserManagerInternal.class); @@ -171,9 +165,6 @@ class MediaRouter2ServiceImpl { } mContext.getPackageManager().addOnPermissionsChangeListener(this::onPermissionsChanged); - - MediaFeatureFlagManager.getInstance() - .addOnPropertiesChangedListener(this::onDeviceConfigChange); } /** @@ -1725,13 +1716,6 @@ class MediaRouter2ServiceImpl { // End of locked methods that are used by both MediaRouter2 and MediaRouter2Manager. - private void onDeviceConfigChange(@NonNull DeviceConfig.Properties properties) { - sPackageImportanceForScanning = - properties.getInt( - /* name */ FEATURE_SCANNING_MINIMUM_PACKAGE_IMPORTANCE, - /* defaultValue */ IMPORTANCE_FOREGROUND_SERVICE); - } - static long toUniqueRequestId(int requesterId, int originalRequestId) { return ((long) requesterId << 32) | originalRequestId; } @@ -3170,7 +3154,7 @@ class MediaRouter2ServiceImpl { record -> service.mActivityManager.getPackageImportance( record.mPackageName) - <= sPackageImportanceForScanning) + <= REQUIRED_PACKAGE_IMPORTANCE_FOR_SCANNING) .collect(Collectors.toList()); } @@ -3187,7 +3171,7 @@ class MediaRouter2ServiceImpl { manager.mIsScanning && service.mActivityManager.getPackageImportance( manager.mOwnerPackageName) - <= sPackageImportanceForScanning); + <= REQUIRED_PACKAGE_IMPORTANCE_FOR_SCANNING); } private MediaRoute2Provider findProvider(@Nullable String providerId) { |