1616
1717package com .android .server .hdmi ;
1818
19- import android .hardware .hdmi .HdmiDeviceInfo ;
2019import android .hardware .hdmi .HdmiControlManager ;
20+ import android .hardware .hdmi .HdmiDeviceInfo ;
2121import android .hardware .hdmi .IHdmiControlCallback ;
2222import android .os .RemoteException ;
2323import android .os .SystemProperties ;
@@ -137,28 +137,73 @@ void markActiveSource() {
137137 protected boolean handleActiveSource (HdmiCecMessage message ) {
138138 assertRunOnServiceThread ();
139139 int physicalAddress = HdmiUtils .twoBytesToInt (message .getParams ());
140+ mayResetActiveSource (physicalAddress );
141+ return true ; // Broadcast message.
142+ }
143+
144+ private void mayResetActiveSource (int physicalAddress ) {
140145 if (physicalAddress != mService .getPhysicalAddress ()) {
141146 mIsActiveSource = false ;
142- if (mService .isPowerOnOrTransient ()) {
143- mService .nap ();
144- }
145- return true ;
146147 }
147- return false ;
148148 }
149149
150150 @ Override
151151 @ ServiceThreadOnly
152152 protected boolean handleSetStreamPath (HdmiCecMessage message ) {
153153 assertRunOnServiceThread ();
154154 int physicalAddress = HdmiUtils .twoBytesToInt (message .getParams ());
155+ maySetActiveSource (physicalAddress );
156+ maySendActiveSource ();
157+ wakeUpIfActiveSource ();
158+ return true ; // Broadcast message.
159+ }
160+
161+ // Samsung model, we tested, sends <RoutingChange> and <RequestActiveSource> consecutively,
162+ // Then if there is no <ActiveSource> response, it will change the input to
163+ // the internal source. To handle this, we'll set ActiveSource aggressively.
164+ @ Override
165+ @ ServiceThreadOnly
166+ protected boolean handleRoutingChange (HdmiCecMessage message ) {
167+ assertRunOnServiceThread ();
168+ int newPath = HdmiUtils .twoBytesToInt (message .getParams (), 2 );
169+ maySetActiveSource (newPath );
170+ return true ; // Broadcast message.
171+ }
172+
173+ @ Override
174+ @ ServiceThreadOnly
175+ protected boolean handleRoutingInformation (HdmiCecMessage message ) {
176+ assertRunOnServiceThread ();
177+ int physicalAddress = HdmiUtils .twoBytesToInt (message .getParams ());
178+ maySetActiveSource (physicalAddress );
179+ return true ; // Broadcast message.
180+ }
181+
182+ private void maySetActiveSource (int physicalAddress ) {
155183 if (physicalAddress == mService .getPhysicalAddress ()) {
156- if (mService .isPowerStandbyOrTransient ()) {
157- mService .wakeUp ();
158- }
159- return true ;
184+ mIsActiveSource = true ;
185+ }
186+ }
187+
188+ private void wakeUpIfActiveSource () {
189+ if (mIsActiveSource && mService .isPowerStandbyOrTransient ()) {
190+ mService .wakeUp ();
160191 }
161- return false ;
192+ }
193+
194+ private void maySendActiveSource () {
195+ if (mIsActiveSource ) {
196+ mService .sendCecCommand (HdmiCecMessageBuilder .buildActiveSource (
197+ mAddress , mService .getPhysicalAddress ()));
198+ }
199+ }
200+
201+ @ Override
202+ @ ServiceThreadOnly
203+ protected boolean handleRequestActiveSource (HdmiCecMessage message ) {
204+ assertRunOnServiceThread ();
205+ maySendActiveSource ();
206+ return true ; // Broadcast message.
162207 }
163208
164209 @ Override
@@ -174,4 +219,4 @@ protected void disableDevice(boolean initiatedByCec, PendingActionClearedCallbac
174219 mIsActiveSource = false ;
175220 checkIfPendingActionsCleared ();
176221 }
177- }
222+ }
0 commit comments