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