diff options
| -rw-r--r-- | core/res/res/values/config_tv_external_input_logging.xml | 50 | ||||
| -rw-r--r-- | core/res/res/values/symbols.xml | 5 | ||||
| -rw-r--r-- | services/core/java/com/android/server/tv/TvInputManagerService.java | 43 |
3 files changed, 98 insertions, 0 deletions
diff --git a/core/res/res/values/config_tv_external_input_logging.xml b/core/res/res/values/config_tv_external_input_logging.xml new file mode 100644 index 000000000000..72e30be00a02 --- /dev/null +++ b/core/res/res/values/config_tv_external_input_logging.xml @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* +** 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. +*/ +--> + +<!-- These resources are around just to allow their values to be customized + for different hardware and product builds. Do not translate. + + NOTE: The naming convention is "config_camelCaseValue". Some legacy + entries do not follow the convention, but all new entries should. --> + +<resources> + <bool name="config_tvExternalInputLoggingDisplayNameFilterEnabled">false</bool> + + <string-array name="config_tvExternalInputLoggingDeviceOnScreenDisplayNames"> + <item>Chromecast</item> + <item>Chromecast HD</item> + <item>SHIELD</item> + <item>Roku</item> + <item>Roku Express 4</item> + <item>Home Theater</item> + <item>Fire TV Stick</item> + <item>PlayStation 5</item> + <item>NintendoSwitch</item> + </string-array> + + <string-array name="config_tvExternalInputLoggingDeviceBrandNames"> + <item>Chromecast</item> + <item>SHIELD</item> + <item>Roku</item> + <item>Apple</item> + <item>Fire TV</item> + <item>PlayStation</item> + <item>Nintendo</item> + </string-array> +</resources> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index e2fc837b9a64..ee0563b5d7cd 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -5220,4 +5220,9 @@ <!-- Whether we order unlocking and waking --> <java-symbol type="bool" name="config_orderUnlockAndWake" /> + + <!-- External TV Input Logging Configs --> + <java-symbol type="bool" name="config_tvExternalInputLoggingDisplayNameFilterEnabled" /> + <java-symbol type="array" name="config_tvExternalInputLoggingDeviceOnScreenDisplayNames" /> + <java-symbol type="array" name="config_tvExternalInputLoggingDeviceBrandNames" /> </resources> diff --git a/services/core/java/com/android/server/tv/TvInputManagerService.java b/services/core/java/com/android/server/tv/TvInputManagerService.java index 6a2b824201cc..234e3f4c4b54 100644 --- a/services/core/java/com/android/server/tv/TvInputManagerService.java +++ b/services/core/java/com/android/server/tv/TvInputManagerService.java @@ -41,6 +41,7 @@ import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.content.pm.UserInfo; +import android.content.res.Resources; import android.graphics.Rect; import android.hardware.hdmi.HdmiControlManager; import android.hardware.hdmi.HdmiDeviceInfo; @@ -94,6 +95,7 @@ import android.util.SparseArray; import android.view.InputChannel; import android.view.Surface; +import com.android.internal.R; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.content.PackageMonitor; @@ -177,6 +179,11 @@ public final class TvInputManagerService extends SystemService { private final ActivityManager mActivityManager; + private boolean mExternalInputLoggingDisplayNameFilterEnabled = false; + private final HashSet<String> mExternalInputLoggingDeviceOnScreenDisplayNames = + new HashSet<String>(); + private final List<String> mExternalInputLoggingDeviceBrandNames = new ArrayList<String>(); + public TvInputManagerService(Context context) { super(context); @@ -192,6 +199,8 @@ public final class TvInputManagerService extends SystemService { synchronized (mLock) { getOrCreateUserStateLocked(mCurrentUserId); } + + initExternalInputLoggingConfigs(); } @Override @@ -224,6 +233,21 @@ public final class TvInputManagerService extends SystemService { } } + private void initExternalInputLoggingConfigs() { + mExternalInputLoggingDisplayNameFilterEnabled = mContext.getResources().getBoolean( + R.bool.config_tvExternalInputLoggingDisplayNameFilterEnabled); + if (!mExternalInputLoggingDisplayNameFilterEnabled) { + return; + } + final String[] deviceOnScreenDisplayNames = mContext.getResources().getStringArray( + R.array.config_tvExternalInputLoggingDeviceOnScreenDisplayNames); + final String[] deviceBrandNames = mContext.getResources().getStringArray( + R.array.config_tvExternalInputLoggingDeviceBrandNames); + mExternalInputLoggingDeviceOnScreenDisplayNames.addAll( + Arrays.asList(deviceOnScreenDisplayNames)); + mExternalInputLoggingDeviceBrandNames.addAll(Arrays.asList(deviceBrandNames)); + } + private void registerBroadcastReceivers() { PackageMonitor monitor = new PackageMonitor() { private void buildTvInputList(String[] packages) { @@ -3073,6 +3097,9 @@ public final class TvInputManagerService extends SystemService { hdmiPort = hdmiDeviceInfo.getPortId(); if (hdmiDeviceInfo.isCecDevice()) { displayName = hdmiDeviceInfo.getDisplayName(); + if (mExternalInputLoggingDisplayNameFilterEnabled) { + displayName = filterExternalInputLoggingDisplayName(displayName); + } vendorId = hdmiDeviceInfo.getVendorId(); } } @@ -3082,6 +3109,22 @@ public final class TvInputManagerService extends SystemService { inputType, vendorId, hdmiPort, tifSessionId, displayName); } + private String filterExternalInputLoggingDisplayName(String displayName) { + String nullDisplayName = "NULL_DISPLAY_NAME", filteredDisplayName = "FILTERED_DISPLAY_NAME"; + if (displayName == null) { + return nullDisplayName; + } + if (mExternalInputLoggingDeviceOnScreenDisplayNames.contains(displayName)) { + return displayName; + } + for (String brandName : mExternalInputLoggingDeviceBrandNames) { + if (displayName.toUpperCase().contains(brandName.toUpperCase())) { + return brandName; + } + } + return filteredDisplayName; + } + private static final class UserState { // A mapping from the TV input id to its TvInputState. private Map<String, TvInputState> inputMap = new HashMap<>(); |