Skip to content

Commit 61daf6b

Browse files
committed
Hook up device power status change to TIF
Instead of introducing new api update existing IDeviceEventListener Bug: 16445063 Change-Id: I93bfc736a06a78e83c95877a53f4f241b51ed9c0
1 parent 3d1232f commit 61daf6b

6 files changed

Lines changed: 61 additions & 25 deletions

File tree

core/java/android/hardware/hdmi/HdmiControlManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ public final class HdmiControlManager {
6969
public static final int RESULT_INCORRECT_MODE = 6;
7070
public static final int RESULT_COMMUNICATION_FAILED = 7;
7171

72+
public static final int DEVICE_EVENT_ADD_DEVICE = 1;
73+
public static final int DEVICE_EVENT_REMOVE_DEVICE = 2;
74+
public static final int DEVICE_EVENT_UPDATE_DEVICE = 3;
75+
7276
// --- One Touch Recording success result
7377
/** Recording currently selected source. Indicates the status of a recording. */
7478
public static final int ONE_TOUCH_RECORD_RECORDING_CURRENTLY_SELECTED_SOURCE = 0x01;

core/java/android/hardware/hdmi/IHdmiDeviceEventListener.aidl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ oneway interface IHdmiDeviceEventListener {
2929
/**
3030
* @param deviceInfo {@link HdmiDeviceInfo} of the logical device whose
3131
* status has changed
32-
* @param activated true if the device gets activated
32+
* @param status device status. It should be one of the following values
33+
* <ul>
34+
* <li>{@link HdmiControlManager#DEVICE_EVENT_ADD_DEVICE}
35+
* <li>{@link HdmiControlManager#DEVICE_EVENT_REMOVE_DEVICE}
36+
* <li>{@link HdmiControlManager#DEVICE_EVENT_UPDATE_DEVICE}
37+
* </ul>
3338
*/
34-
void onStatusChanged(in HdmiDeviceInfo deviceInfo, in boolean activated);
39+
void onStatusChanged(in HdmiDeviceInfo deviceInfo, in int status);
3540
}

services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ public void onDeviceDiscoveryDone(List<HdmiDeviceInfo> deviceInfos) {
640640
private void clearDeviceInfoList() {
641641
assertRunOnServiceThread();
642642
for (HdmiDeviceInfo info : mSafeExternalInputs) {
643-
invokeDeviceEventListener(info, false);
643+
invokeDeviceEventListener(info, HdmiControlManager.DEVICE_EVENT_REMOVE_DEVICE);
644644
}
645645
mDeviceInfos.clear();
646646
updateSafeDeviceInfoList();
@@ -1070,9 +1070,9 @@ private static boolean isParentPath(int parentPath, int childPath) {
10701070
return false;
10711071
}
10721072

1073-
private void invokeDeviceEventListener(HdmiDeviceInfo info, boolean activated) {
1073+
private void invokeDeviceEventListener(HdmiDeviceInfo info, int status) {
10741074
if (!hideDevicesBehindLegacySwitch(info)) {
1075-
mService.invokeDeviceEventListeners(info, activated);
1075+
mService.invokeDeviceEventListeners(info, status);
10761076
}
10771077
}
10781078

@@ -1144,7 +1144,7 @@ final void addCecDevice(HdmiDeviceInfo info) {
11441144
// The addition of TV device itself should not be notified.
11451145
return;
11461146
}
1147-
invokeDeviceEventListener(info, true);
1147+
invokeDeviceEventListener(info, HdmiControlManager.DEVICE_EVENT_ADD_DEVICE);
11481148
}
11491149

11501150
/**
@@ -1158,7 +1158,7 @@ final void removeCecDevice(int address) {
11581158
HdmiDeviceInfo info = removeDeviceInfo(address);
11591159

11601160
mCecMessageCache.flushMessagesFrom(address);
1161-
invokeDeviceEventListener(info, false);
1161+
invokeDeviceEventListener(info, HdmiControlManager.DEVICE_EVENT_REMOVE_DEVICE);
11621162
}
11631163

11641164
@ServiceThreadOnly
@@ -1537,6 +1537,6 @@ void updateDevicePowerStatus(int logicalAddress, int newPowerStatus) {
15371537
// addDeviceInfo replaces old device info with new one if exists.
15381538
addDeviceInfo(newInfo);
15391539

1540-
// TODO: notify this update to others.
1540+
invokeDeviceEventListener(newInfo, HdmiControlManager.DEVICE_EVENT_UPDATE_DEVICE);
15411541
}
15421542
}

services/core/java/com/android/server/hdmi/HdmiControlService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,11 +1254,11 @@ private void addDeviceEventListener(IHdmiDeviceEventListener listener) {
12541254
}
12551255
}
12561256

1257-
void invokeDeviceEventListeners(HdmiDeviceInfo device, boolean activated) {
1257+
void invokeDeviceEventListeners(HdmiDeviceInfo device, int status) {
12581258
synchronized (mLock) {
12591259
for (IHdmiDeviceEventListener listener : mDeviceEventListeners) {
12601260
try {
1261-
listener.onStatusChanged(device, activated);
1261+
listener.onStatusChanged(device, status);
12621262
} catch (RemoteException e) {
12631263
Slog.e(TAG, "Failed to report device event:" + e);
12641264
}

services/core/java/com/android/server/tv/TvInputHardwareManager.java

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import android.content.Context;
2323
import android.content.Intent;
24+
import android.hardware.hdmi.HdmiControlManager;
2425
import android.hardware.hdmi.HdmiDeviceInfo;
2526
import android.hardware.hdmi.HdmiHotplugEvent;
2627
import android.hardware.hdmi.IHdmiControlService;
@@ -862,6 +863,7 @@ interface Listener {
862863
public void onHardwareDeviceRemoved(TvInputHardwareInfo info);
863864
public void onHdmiDeviceAdded(HdmiDeviceInfo device);
864865
public void onHdmiDeviceRemoved(HdmiDeviceInfo device);
866+
public void onHdmiDeviceUpdated(HdmiDeviceInfo device);
865867
}
866868

867869
private class ListenerHandler extends Handler {
@@ -870,6 +872,7 @@ private class ListenerHandler extends Handler {
870872
private static final int HARDWARE_DEVICE_REMOVED = 3;
871873
private static final int HDMI_DEVICE_ADDED = 4;
872874
private static final int HDMI_DEVICE_REMOVED = 5;
875+
private static final int HDMI_DEVICE_UPDATED = 6;
873876

874877
@Override
875878
public final void handleMessage(Message msg) {
@@ -900,6 +903,10 @@ public final void handleMessage(Message msg) {
900903
mListener.onHdmiDeviceRemoved(info);
901904
break;
902905
}
906+
case HDMI_DEVICE_UPDATED: {
907+
HdmiDeviceInfo info = (HdmiDeviceInfo) msg.obj;
908+
mListener.onHdmiDeviceUpdated(info);
909+
}
903910
default: {
904911
Slog.w(TAG, "Unhandled message: " + msg);
905912
break;
@@ -932,25 +939,40 @@ public void onReceived(HdmiHotplugEvent event) {
932939

933940
private final class HdmiDeviceEventListener extends IHdmiDeviceEventListener.Stub {
934941
@Override
935-
public void onStatusChanged(HdmiDeviceInfo deviceInfo, boolean activated) {
942+
public void onStatusChanged(HdmiDeviceInfo deviceInfo, int status) {
936943
synchronized (mLock) {
937-
if (activated) {
938-
if (!mHdmiDeviceList.contains(deviceInfo)) {
939-
mHdmiDeviceList.add(deviceInfo);
940-
} else {
941-
Slog.w(TAG, "The list already contains " + deviceInfo + "; ignoring.");
942-
return;
944+
int messageType = 0;
945+
switch (status) {
946+
case HdmiControlManager.DEVICE_EVENT_ADD_DEVICE: {
947+
if (!mHdmiDeviceList.contains(deviceInfo)) {
948+
mHdmiDeviceList.add(deviceInfo);
949+
} else {
950+
Slog.w(TAG, "The list already contains " + deviceInfo + "; ignoring.");
951+
return;
952+
}
953+
messageType = ListenerHandler.HDMI_DEVICE_ADDED;
954+
break;
943955
}
944-
} else {
945-
if (!mHdmiDeviceList.remove(deviceInfo)) {
946-
Slog.w(TAG, "The list doesn't contain " + deviceInfo + "; ignoring.");
947-
return;
956+
case HdmiControlManager.DEVICE_EVENT_REMOVE_DEVICE: {
957+
if (!mHdmiDeviceList.remove(deviceInfo)) {
958+
Slog.w(TAG, "The list doesn't contain " + deviceInfo + "; ignoring.");
959+
return;
960+
}
961+
messageType = ListenerHandler.HDMI_DEVICE_REMOVED;
962+
break;
963+
}
964+
case HdmiControlManager.DEVICE_EVENT_UPDATE_DEVICE: {
965+
if (!mHdmiDeviceList.remove(deviceInfo)) {
966+
Slog.w(TAG, "The list doesn't contain " + deviceInfo + "; ignoring.");
967+
return;
968+
}
969+
mHdmiDeviceList.add(deviceInfo);
970+
messageType = ListenerHandler.HDMI_DEVICE_UPDATED;
971+
break;
948972
}
949973
}
950-
Message msg = mHandler.obtainMessage(
951-
activated ? ListenerHandler.HDMI_DEVICE_ADDED
952-
: ListenerHandler.HDMI_DEVICE_REMOVED,
953-
0, 0, deviceInfo);
974+
975+
Message msg = mHandler.obtainMessage(messageType, 0, 0, deviceInfo);
954976
if (findHardwareInfoForHdmiPortLocked(deviceInfo.getPortId()) != null) {
955977
msg.sendToTarget();
956978
} else {

services/core/java/com/android/server/tv/TvInputManagerService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,5 +2174,10 @@ public void onHdmiDeviceRemoved(HdmiDeviceInfo deviceInfo) {
21742174
}
21752175
}
21762176
}
2177+
2178+
@Override
2179+
public void onHdmiDeviceUpdated(HdmiDeviceInfo deviceInfo) {
2180+
// TODO: implement here.
2181+
}
21772182
}
21782183
}

0 commit comments

Comments
 (0)