Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.hdmi; |
| 18 | |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 19 | import android.hardware.hdmi.HdmiControlManager; |
Yuncheol Heo | 64bafd9 | 2014-08-11 11:17:54 +0900 | [diff] [blame] | 20 | import android.hardware.hdmi.HdmiDeviceInfo; |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 21 | import android.hardware.hdmi.IHdmiControlCallback; |
Amy | 23be681 | 2019-01-25 17:04:07 -0800 | [diff] [blame] | 22 | import android.hardware.tv.cec.V1_0.SendMessageResult; |
Jinsuk Kim | e26d833 | 2015-01-09 08:55:41 +0900 | [diff] [blame] | 23 | import android.os.PowerManager; |
| 24 | import android.os.PowerManager.WakeLock; |
Jinsuk Kim | af2acf0 | 2014-07-11 18:43:04 +0900 | [diff] [blame] | 25 | import android.os.SystemProperties; |
Jinsuk Kim | e6e8f3d | 2015-05-11 14:17:04 +0900 | [diff] [blame] | 26 | import android.provider.Settings.Global; |
Nick Chalko | bfb3076 | 2019-10-15 16:06:50 -0700 | [diff] [blame] | 27 | import android.sysprop.HdmiProperties; |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 28 | import android.util.Slog; |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 29 | |
Amy | aefab64 | 2018-08-22 19:10:14 -0700 | [diff] [blame] | 30 | import com.android.internal.annotations.VisibleForTesting; |
Terry Heo | 795415b | 2014-10-01 15:03:53 +0900 | [diff] [blame] | 31 | import com.android.internal.app.LocalePicker; |
| 32 | import com.android.internal.app.LocalePicker.LocaleInfo; |
Terry Heo | 959d2db | 2014-08-28 16:45:41 +0900 | [diff] [blame] | 33 | import com.android.internal.util.IndentingPrintWriter; |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 34 | import com.android.server.hdmi.HdmiAnnotations.ServiceThreadOnly; |
Amy | 23be681 | 2019-01-25 17:04:07 -0800 | [diff] [blame] | 35 | import com.android.server.hdmi.HdmiControlService.SendMessageCallback; |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 36 | |
Terry Heo | 795415b | 2014-10-01 15:03:53 +0900 | [diff] [blame] | 37 | import java.io.UnsupportedEncodingException; |
| 38 | import java.util.List; |
Jinsuk Kim | 8ea452e | 2015-07-10 13:01:06 +0900 | [diff] [blame] | 39 | import java.util.Locale; |
Terry Heo | 795415b | 2014-10-01 15:03:53 +0900 | [diff] [blame] | 40 | |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 41 | /** |
| 42 | * Represent a logical device of type Playback residing in Android system. |
| 43 | */ |
Amy | 645c361 | 2018-09-25 10:48:19 -0700 | [diff] [blame] | 44 | public class HdmiCecLocalDevicePlayback extends HdmiCecLocalDeviceSource { |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 45 | private static final String TAG = "HdmiCecLocalDevicePlayback"; |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 46 | |
Donghyun Cho | a09256c | 2016-03-11 17:35:37 +0900 | [diff] [blame] | 47 | private static final boolean SET_MENU_LANGUAGE = |
Nick Chalko | bfb3076 | 2019-10-15 16:06:50 -0700 | [diff] [blame] | 48 | HdmiProperties.set_menu_language().orElse(false); |
Donghyun Cho | a09256c | 2016-03-11 17:35:37 +0900 | [diff] [blame] | 49 | |
Jinsuk Kim | e26d833 | 2015-01-09 08:55:41 +0900 | [diff] [blame] | 50 | // Used to keep the device awake while it is the active source. For devices that |
| 51 | // cannot wake up via CEC commands, this address the inconvenience of having to |
Jinsuk Kim | bad8393 | 2015-02-10 07:10:40 +0900 | [diff] [blame] | 52 | // turn them on. True by default, and can be disabled (i.e. device can go to sleep |
| 53 | // in active device status) by explicitly setting the system property |
| 54 | // persist.sys.hdmi.keep_awake to false. |
Jinsuk Kim | e26d833 | 2015-01-09 08:55:41 +0900 | [diff] [blame] | 55 | // Lazily initialized - should call getWakeLock() to get the instance. |
Jinsuk Kim | bad8393 | 2015-02-10 07:10:40 +0900 | [diff] [blame] | 56 | private ActiveWakeLock mWakeLock; |
Jinsuk Kim | e26d833 | 2015-01-09 08:55:41 +0900 | [diff] [blame] | 57 | |
Jinsuk Kim | e6e8f3d | 2015-05-11 14:17:04 +0900 | [diff] [blame] | 58 | // If true, turn off TV upon standby. False by default. |
| 59 | private boolean mAutoTvOff; |
| 60 | |
Amy | aefab64 | 2018-08-22 19:10:14 -0700 | [diff] [blame] | 61 | // Local active port number used for Routing Control. |
| 62 | // Default 0 means HOME is the current active path. Temp solution only. |
| 63 | // TODO(amyjojo): adding system constants for input ports to TIF mapping. |
| 64 | private int mLocalActivePath = 0; |
| 65 | |
Jungshik Jang | 3ee6572 | 2014-06-03 16:22:30 +0900 | [diff] [blame] | 66 | HdmiCecLocalDevicePlayback(HdmiControlService service) { |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 67 | super(service, HdmiDeviceInfo.DEVICE_PLAYBACK); |
Jinsuk Kim | e6e8f3d | 2015-05-11 14:17:04 +0900 | [diff] [blame] | 68 | |
| 69 | mAutoTvOff = mService.readBooleanSetting(Global.HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED, false); |
| 70 | |
| 71 | // The option is false by default. Update settings db as well to have the right |
| 72 | // initial setting on UI. |
| 73 | mService.writeBooleanSetting(Global.HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED, mAutoTvOff); |
Jungshik Jang | 8b308d9 | 2014-05-29 21:52:28 +0900 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | @Override |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 77 | @ServiceThreadOnly |
Yuncheol Heo | fc44e4e | 2014-08-04 19:41:09 +0900 | [diff] [blame] | 78 | protected void onAddressAllocated(int logicalAddress, int reason) { |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 79 | assertRunOnServiceThread(); |
Amy | b9d7f43 | 2018-11-30 15:08:30 -0800 | [diff] [blame] | 80 | if (reason == mService.INITIATED_BY_ENABLE_CEC) { |
| 81 | mService.setAndBroadcastActiveSource(mService.getPhysicalAddress(), |
| 82 | getDeviceInfo().getDeviceType(), Constants.ADDR_BROADCAST); |
| 83 | } |
Jungshik Jang | 3ee6572 | 2014-06-03 16:22:30 +0900 | [diff] [blame] | 84 | mService.sendCecCommand(HdmiCecMessageBuilder.buildReportPhysicalAddressCommand( |
| 85 | mAddress, mService.getPhysicalAddress(), mDeviceType)); |
Jinsuk Kim | ad515e8 | 2014-10-07 07:43:44 +0900 | [diff] [blame] | 86 | mService.sendCecCommand(HdmiCecMessageBuilder.buildDeviceVendorIdCommand( |
| 87 | mAddress, mService.getVendorId())); |
Amy | 3af63c3 | 2019-05-10 18:32:50 -0700 | [diff] [blame] | 88 | // Actively send out an OSD name to the TV to update the TV panel in case the TV |
| 89 | // does not query the OSD name on time. This is not a required behavior by the spec. |
| 90 | // It is used for some TVs that need the OSD name update but don't query it themselves. |
| 91 | buildAndSendSetOsdName(Constants.ADDR_TV); |
Amy | 23be681 | 2019-01-25 17:04:07 -0800 | [diff] [blame] | 92 | if (mService.audioSystem() == null) { |
| 93 | // If current device is not a functional audio system device, |
| 94 | // send message to potential audio system device in the system to get the system |
| 95 | // audio mode status. If no response, set to false. |
| 96 | mService.sendCecCommand(HdmiCecMessageBuilder.buildGiveSystemAudioModeStatus( |
| 97 | mAddress, Constants.ADDR_AUDIO_SYSTEM), new SendMessageCallback() { |
| 98 | @Override |
| 99 | public void onSendCompleted(int error) { |
| 100 | if (error != SendMessageResult.SUCCESS) { |
| 101 | HdmiLogger.debug( |
| 102 | "AVR did not respond to <Give System Audio Mode Status>"); |
| 103 | mService.setSystemAudioActivated(false); |
| 104 | } |
| 105 | } |
| 106 | }); |
| 107 | } |
Jinsuk Kim | 6f87b4e | 2014-10-10 14:40:29 +0900 | [diff] [blame] | 108 | startQueuedActions(); |
Jinsuk Kim | 2918e9e | 2014-05-20 16:45:45 +0900 | [diff] [blame] | 109 | } |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 110 | |
Jinsuk Kim | af2acf0 | 2014-07-11 18:43:04 +0900 | [diff] [blame] | 111 | @Override |
| 112 | @ServiceThreadOnly |
| 113 | protected int getPreferredAddress() { |
| 114 | assertRunOnServiceThread(); |
| 115 | return SystemProperties.getInt(Constants.PROPERTY_PREFERRED_ADDRESS_PLAYBACK, |
| 116 | Constants.ADDR_UNREGISTERED); |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | @ServiceThreadOnly |
| 121 | protected void setPreferredAddress(int addr) { |
| 122 | assertRunOnServiceThread(); |
Amy | 59c06c1 | 2019-01-18 15:35:15 -0800 | [diff] [blame] | 123 | mService.writeStringSystemProperty(Constants.PROPERTY_PREFERRED_ADDRESS_PLAYBACK, |
Jinsuk Kim | af2acf0 | 2014-07-11 18:43:04 +0900 | [diff] [blame] | 124 | String.valueOf(addr)); |
| 125 | } |
| 126 | |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 127 | @ServiceThreadOnly |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 128 | void queryDisplayStatus(IHdmiControlCallback callback) { |
| 129 | assertRunOnServiceThread(); |
Jinsuk Kim | cb80287 | 2015-10-13 08:22:09 +0900 | [diff] [blame] | 130 | List<DevicePowerStatusAction> actions = getActions(DevicePowerStatusAction.class); |
| 131 | if (!actions.isEmpty()) { |
| 132 | Slog.i(TAG, "queryDisplayStatus already in progress"); |
| 133 | actions.get(0).addCallback(callback); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 134 | return; |
| 135 | } |
Jinsuk Kim | cb80287 | 2015-10-13 08:22:09 +0900 | [diff] [blame] | 136 | DevicePowerStatusAction action = DevicePowerStatusAction.create(this, Constants.ADDR_TV, |
| 137 | callback); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 138 | if (action == null) { |
| 139 | Slog.w(TAG, "Cannot initiate queryDisplayStatus"); |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 140 | invokeCallback(callback, HdmiControlManager.RESULT_EXCEPTION); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 141 | return; |
| 142 | } |
| 143 | addAndStartAction(action); |
| 144 | } |
| 145 | |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 146 | @Override |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 147 | @ServiceThreadOnly |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 148 | void onHotplug(int portId, boolean connected) { |
Jungshik Jang | a5b7414 | 2014-06-23 18:03:10 +0900 | [diff] [blame] | 149 | assertRunOnServiceThread(); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 150 | mCecMessageCache.flushAll(); |
Yuncheol Heo | 89ec14e | 2014-09-16 15:53:59 +0900 | [diff] [blame] | 151 | // We'll not clear mIsActiveSource on the hotplug event to pass CETC 11.2.2-2 ~ 3. |
Jinsuk Kim | e26d833 | 2015-01-09 08:55:41 +0900 | [diff] [blame] | 152 | if (!connected) { |
| 153 | getWakeLock().release(); |
| 154 | } |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 155 | } |
| 156 | |
Jinsuk Kim | e6e8f3d | 2015-05-11 14:17:04 +0900 | [diff] [blame] | 157 | @Override |
| 158 | @ServiceThreadOnly |
| 159 | protected void onStandby(boolean initiatedByCec, int standbyAction) { |
| 160 | assertRunOnServiceThread(); |
Amy | c556aa3 | 2019-02-13 17:17:31 -0800 | [diff] [blame] | 161 | if (!mService.isControlEnabled()) { |
| 162 | return; |
| 163 | } |
| 164 | if (mIsActiveSource) { |
| 165 | mService.sendCecCommand(HdmiCecMessageBuilder.buildInactiveSource( |
| 166 | mAddress, mService.getPhysicalAddress())); |
| 167 | } |
Amy | 8ecb001 | 2019-05-09 19:06:42 -0700 | [diff] [blame] | 168 | // Invalidate the internal active source record when goes to standby |
| 169 | // This set will also update mIsActiveSource |
| 170 | mService.setActiveSource(Constants.ADDR_INVALID, Constants.INVALID_PHYSICAL_ADDRESS); |
Amy | c556aa3 | 2019-02-13 17:17:31 -0800 | [diff] [blame] | 171 | if (initiatedByCec || !mAutoTvOff) { |
Jinsuk Kim | e6e8f3d | 2015-05-11 14:17:04 +0900 | [diff] [blame] | 172 | return; |
| 173 | } |
| 174 | switch (standbyAction) { |
| 175 | case HdmiControlService.STANDBY_SCREEN_OFF: |
Donghyun Cho | 9ccff51 | 2016-04-01 14:31:11 +0900 | [diff] [blame] | 176 | mService.sendCecCommand( |
| 177 | HdmiCecMessageBuilder.buildStandby(mAddress, Constants.ADDR_TV)); |
Jinsuk Kim | e6e8f3d | 2015-05-11 14:17:04 +0900 | [diff] [blame] | 178 | break; |
| 179 | case HdmiControlService.STANDBY_SHUTDOWN: |
| 180 | // ACTION_SHUTDOWN is taken as a signal to power off all the devices. |
| 181 | mService.sendCecCommand( |
| 182 | HdmiCecMessageBuilder.buildStandby(mAddress, Constants.ADDR_BROADCAST)); |
| 183 | break; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | @Override |
| 188 | @ServiceThreadOnly |
| 189 | void setAutoDeviceOff(boolean enabled) { |
| 190 | assertRunOnServiceThread(); |
| 191 | mAutoTvOff = enabled; |
| 192 | } |
| 193 | |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 194 | @ServiceThreadOnly |
Amy | 645c361 | 2018-09-25 10:48:19 -0700 | [diff] [blame] | 195 | @VisibleForTesting |
Amy | 9a59d9c | 2018-08-31 13:47:24 -0700 | [diff] [blame] | 196 | void setIsActiveSource(boolean on) { |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 197 | assertRunOnServiceThread(); |
Jinsuk Kim | e26d833 | 2015-01-09 08:55:41 +0900 | [diff] [blame] | 198 | mIsActiveSource = on; |
| 199 | if (on) { |
| 200 | getWakeLock().acquire(); |
Jinsuk Kim | e26d833 | 2015-01-09 08:55:41 +0900 | [diff] [blame] | 201 | } else { |
| 202 | getWakeLock().release(); |
Jinsuk Kim | e26d833 | 2015-01-09 08:55:41 +0900 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | |
| 206 | @ServiceThreadOnly |
Jinsuk Kim | bad8393 | 2015-02-10 07:10:40 +0900 | [diff] [blame] | 207 | private ActiveWakeLock getWakeLock() { |
Jinsuk Kim | e26d833 | 2015-01-09 08:55:41 +0900 | [diff] [blame] | 208 | assertRunOnServiceThread(); |
| 209 | if (mWakeLock == null) { |
Jinsuk Kim | bad8393 | 2015-02-10 07:10:40 +0900 | [diff] [blame] | 210 | if (SystemProperties.getBoolean(Constants.PROPERTY_KEEP_AWAKE, true)) { |
| 211 | mWakeLock = new SystemWakeLock(); |
| 212 | } else { |
| 213 | // Create a dummy lock object that doesn't do anything about wake lock, |
| 214 | // hence allows the device to go to sleep even if it's the active source. |
| 215 | mWakeLock = new ActiveWakeLock() { |
| 216 | @Override |
| 217 | public void acquire() { } |
| 218 | @Override |
| 219 | public void release() { } |
| 220 | @Override |
| 221 | public boolean isHeld() { return false; } |
| 222 | }; |
| 223 | HdmiLogger.debug("No wakelock is used to keep the display on."); |
| 224 | } |
Jinsuk Kim | e26d833 | 2015-01-09 08:55:41 +0900 | [diff] [blame] | 225 | } |
| 226 | return mWakeLock; |
| 227 | } |
| 228 | |
| 229 | @Override |
| 230 | protected boolean canGoToStandby() { |
| 231 | return !getWakeLock().isHeld(); |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 232 | } |
| 233 | |
Jinsuk Kim | 9b8507c | 2015-03-24 16:55:01 +0900 | [diff] [blame] | 234 | @ServiceThreadOnly |
| 235 | protected boolean handleUserControlPressed(HdmiCecMessage message) { |
| 236 | assertRunOnServiceThread(); |
| 237 | wakeUpIfActiveSource(); |
| 238 | return super.handleUserControlPressed(message); |
| 239 | } |
| 240 | |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 241 | @Override |
Amy | 3403742 | 2018-09-06 13:21:08 -0700 | [diff] [blame] | 242 | protected void wakeUpIfActiveSource() { |
Jinsuk Kim | 9b8507c | 2015-03-24 16:55:01 +0900 | [diff] [blame] | 243 | if (!mIsActiveSource) { |
| 244 | return; |
| 245 | } |
| 246 | // Wake up the device if the power is in standby mode, or its screen is off - |
| 247 | // which can happen if the device is holding a partial lock. |
| 248 | if (mService.isPowerStandbyOrTransient() || !mService.getPowerManager().isScreenOn()) { |
Yuncheol Heo | 64bafd9 | 2014-08-11 11:17:54 +0900 | [diff] [blame] | 249 | mService.wakeUp(); |
| 250 | } |
| 251 | } |
| 252 | |
Amy | 225d55a | 2018-09-06 11:03:51 -0700 | [diff] [blame] | 253 | @Override |
| 254 | protected void maySendActiveSource(int dest) { |
Yuncheol Heo | 64bafd9 | 2014-08-11 11:17:54 +0900 | [diff] [blame] | 255 | if (mIsActiveSource) { |
| 256 | mService.sendCecCommand(HdmiCecMessageBuilder.buildActiveSource( |
| 257 | mAddress, mService.getPhysicalAddress())); |
Yuncheol Heo | 8ecb721 | 2014-10-27 17:29:42 +0900 | [diff] [blame] | 258 | // Always reports menu-status active to receive RCP. |
| 259 | mService.sendCecCommand(HdmiCecMessageBuilder.buildReportMenuStatus( |
| 260 | mAddress, dest, Constants.MENU_STATE_ACTIVATED)); |
Yuncheol Heo | 64bafd9 | 2014-08-11 11:17:54 +0900 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | |
Terry Heo | 795415b | 2014-10-01 15:03:53 +0900 | [diff] [blame] | 264 | @ServiceThreadOnly |
| 265 | protected boolean handleSetMenuLanguage(HdmiCecMessage message) { |
| 266 | assertRunOnServiceThread(); |
Donghyun Cho | a09256c | 2016-03-11 17:35:37 +0900 | [diff] [blame] | 267 | if (!SET_MENU_LANGUAGE) { |
| 268 | return false; |
| 269 | } |
Terry Heo | 795415b | 2014-10-01 15:03:53 +0900 | [diff] [blame] | 270 | |
| 271 | try { |
| 272 | String iso3Language = new String(message.getParams(), 0, 3, "US-ASCII"); |
Jinsuk Kim | 8ea452e | 2015-07-10 13:01:06 +0900 | [diff] [blame] | 273 | Locale currentLocale = mService.getContext().getResources().getConfiguration().locale; |
| 274 | if (currentLocale.getISO3Language().equals(iso3Language)) { |
| 275 | // Do not switch language if the new language is the same as the current one. |
| 276 | // This helps avoid accidental country variant switching from en_US to en_AU |
| 277 | // due to the limitation of CEC. See the warning below. |
| 278 | return true; |
| 279 | } |
Terry Heo | 795415b | 2014-10-01 15:03:53 +0900 | [diff] [blame] | 280 | |
| 281 | // Don't use Locale.getAvailableLocales() since it returns a locale |
| 282 | // which is not available on Settings. |
| 283 | final List<LocaleInfo> localeInfos = LocalePicker.getAllAssetLocales( |
| 284 | mService.getContext(), false); |
| 285 | for (LocaleInfo localeInfo : localeInfos) { |
| 286 | if (localeInfo.getLocale().getISO3Language().equals(iso3Language)) { |
| 287 | // WARNING: CEC adopts ISO/FDIS-2 for language code, while Android requires |
| 288 | // additional country variant to pinpoint the locale. This keeps the right |
| 289 | // locale from being chosen. 'eng' in the CEC command, for instance, |
| 290 | // will always be mapped to en-AU among other variants like en-US, en-GB, |
| 291 | // an en-IN, which may not be the expected one. |
| 292 | LocalePicker.updateLocale(localeInfo.getLocale()); |
| 293 | return true; |
| 294 | } |
| 295 | } |
| 296 | Slog.w(TAG, "Can't handle <Set Menu Language> of " + iso3Language); |
| 297 | return false; |
| 298 | } catch (UnsupportedEncodingException e) { |
Donghyun Cho | a09256c | 2016-03-11 17:35:37 +0900 | [diff] [blame] | 299 | Slog.w(TAG, "Can't handle <Set Menu Language>", e); |
Terry Heo | 795415b | 2014-10-01 15:03:53 +0900 | [diff] [blame] | 300 | return false; |
| 301 | } |
| 302 | } |
| 303 | |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 304 | @Override |
Amy | 25e2338 | 2019-01-25 14:47:06 -0800 | [diff] [blame] | 305 | protected boolean handleSetSystemAudioMode(HdmiCecMessage message) { |
| 306 | // System Audio Mode only turns on/off when Audio System broadcasts on/off message. |
| 307 | // For device with type 4 and 5, it can set system audio mode on/off |
| 308 | // when there is another audio system device connected into the system first. |
| 309 | if (message.getDestination() != Constants.ADDR_BROADCAST |
| 310 | || message.getSource() != Constants.ADDR_AUDIO_SYSTEM |
| 311 | || mService.audioSystem() != null) { |
| 312 | return true; |
| 313 | } |
| 314 | boolean setSystemAudioModeOn = HdmiUtils.parseCommandParamSystemAudioStatus(message); |
| 315 | if (mService.isSystemAudioActivated() != setSystemAudioModeOn) { |
| 316 | mService.setSystemAudioActivated(setSystemAudioModeOn); |
| 317 | } |
| 318 | return true; |
| 319 | } |
| 320 | |
| 321 | @Override |
Amy | 23be681 | 2019-01-25 17:04:07 -0800 | [diff] [blame] | 322 | protected boolean handleSystemAudioModeStatus(HdmiCecMessage message) { |
| 323 | // Only directly addressed System Audio Mode Status message can change internal |
| 324 | // system audio mode status. |
| 325 | if (message.getDestination() == mAddress |
| 326 | && message.getSource() == Constants.ADDR_AUDIO_SYSTEM) { |
| 327 | boolean setSystemAudioModeOn = HdmiUtils.parseCommandParamSystemAudioStatus(message); |
| 328 | if (mService.isSystemAudioActivated() != setSystemAudioModeOn) { |
| 329 | mService.setSystemAudioActivated(setSystemAudioModeOn); |
| 330 | } |
| 331 | } |
| 332 | return true; |
| 333 | } |
| 334 | |
| 335 | @Override |
Donghyun Cho | 7609bc3 | 2016-12-02 15:31:52 +0900 | [diff] [blame] | 336 | protected int findKeyReceiverAddress() { |
| 337 | return Constants.ADDR_TV; |
| 338 | } |
| 339 | |
| 340 | @Override |
Amy | 53b8cb0 | 2019-01-29 17:22:03 -0800 | [diff] [blame] | 341 | protected int findAudioReceiverAddress() { |
| 342 | if (mService.isSystemAudioActivated()) { |
| 343 | return Constants.ADDR_AUDIO_SYSTEM; |
| 344 | } |
| 345 | return Constants.ADDR_TV; |
| 346 | } |
| 347 | |
| 348 | @Override |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 349 | @ServiceThreadOnly |
Jungshik Jang | 4fc1d10 | 2014-07-09 19:24:50 +0900 | [diff] [blame] | 350 | protected void disableDevice(boolean initiatedByCec, PendingActionClearedCallback callback) { |
| 351 | super.disableDevice(initiatedByCec, callback); |
| 352 | |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 353 | assertRunOnServiceThread(); |
Yuncheol Heo | 38db629 | 2014-07-01 14:15:14 +0900 | [diff] [blame] | 354 | checkIfPendingActionsCleared(); |
Jungshik Jang | 79c58a4 | 2014-06-16 16:45:36 +0900 | [diff] [blame] | 355 | } |
Terry Heo | 959d2db | 2014-08-28 16:45:41 +0900 | [diff] [blame] | 356 | |
Amy | aefab64 | 2018-08-22 19:10:14 -0700 | [diff] [blame] | 357 | private void routeToPort(int portId) { |
| 358 | // TODO(AMYJOJO): route to specific input of the port |
| 359 | mLocalActivePath = portId; |
| 360 | } |
| 361 | |
| 362 | @VisibleForTesting |
| 363 | protected int getLocalActivePath() { |
| 364 | return mLocalActivePath; |
| 365 | } |
| 366 | |
Terry Heo | 959d2db | 2014-08-28 16:45:41 +0900 | [diff] [blame] | 367 | @Override |
| 368 | protected void dump(final IndentingPrintWriter pw) { |
| 369 | super.dump(pw); |
| 370 | pw.println("mIsActiveSource: " + mIsActiveSource); |
Jinsuk Kim | e6e8f3d | 2015-05-11 14:17:04 +0900 | [diff] [blame] | 371 | pw.println("mAutoTvOff:" + mAutoTvOff); |
Terry Heo | 959d2db | 2014-08-28 16:45:41 +0900 | [diff] [blame] | 372 | } |
Jinsuk Kim | bad8393 | 2015-02-10 07:10:40 +0900 | [diff] [blame] | 373 | |
| 374 | // Wrapper interface over PowerManager.WakeLock |
| 375 | private interface ActiveWakeLock { |
| 376 | void acquire(); |
| 377 | void release(); |
| 378 | boolean isHeld(); |
| 379 | } |
| 380 | |
| 381 | private class SystemWakeLock implements ActiveWakeLock { |
| 382 | private final WakeLock mWakeLock; |
| 383 | public SystemWakeLock() { |
| 384 | mWakeLock = mService.getPowerManager().newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); |
| 385 | mWakeLock.setReferenceCounted(false); |
| 386 | } |
| 387 | |
| 388 | @Override |
| 389 | public void acquire() { |
| 390 | mWakeLock.acquire(); |
| 391 | HdmiLogger.debug("active source: %b. Wake lock acquired", mIsActiveSource); |
| 392 | } |
| 393 | |
| 394 | @Override |
| 395 | public void release() { |
| 396 | mWakeLock.release(); |
| 397 | HdmiLogger.debug("Wake lock released"); |
| 398 | } |
| 399 | |
| 400 | @Override |
| 401 | public boolean isHeld() { |
| 402 | return mWakeLock.isHeld(); |
| 403 | } |
| 404 | } |
Jinsuk Kim | 84659ed | 2014-10-06 23:48:19 +0000 | [diff] [blame] | 405 | } |