Loading services/core/java/com/android/server/hdmi/DeviceDiscoveryAction.java +10 −2 Original line number Diff line number Diff line Loading @@ -115,12 +115,12 @@ final class DeviceDiscoveryAction extends FeatureAction { @Override public void onPollingFinished(List<Integer> ackedAddress) { if (ackedAddress.isEmpty()) { Slog.i(TAG, "No device is detected."); Slog.v(TAG, "No device is detected."); finish(); return; } Slog.i(TAG, "Device detected: " + ackedAddress); Slog.v(TAG, "Device detected: " + ackedAddress); allocateDevices(ackedAddress); startPhysicalAddressStage(); } Loading @@ -136,6 +136,7 @@ final class DeviceDiscoveryAction extends FeatureAction { } private void startPhysicalAddressStage() { Slog.v(TAG, "Start [Physical Address Stage]:" + mDevices.size()); mProcessedDeviceCount = 0; mState = STATE_WAITING_FOR_PHYSICAL_ADDRESS; Loading @@ -158,6 +159,7 @@ final class DeviceDiscoveryAction extends FeatureAction { } private void startOsdNameStage() { Slog.v(TAG, "Start [Osd Name Stage]:" + mDevices.size()); mProcessedDeviceCount = 0; mState = STATE_WAITING_FOR_OSD_NAME; Loading @@ -176,6 +178,8 @@ final class DeviceDiscoveryAction extends FeatureAction { } private void startVendorIdStage() { Slog.v(TAG, "Start [Vendor Id Stage]:" + mDevices.size()); mProcessedDeviceCount = 0; mState = STATE_WAITING_FOR_VENDOR_ID; Loading Loading @@ -301,11 +305,14 @@ final class DeviceDiscoveryAction extends FeatureAction { } private void wrapUpAndFinish() { Slog.v(TAG, "---------Wrap up Device Discovery:[" + mDevices.size() + "]---------"); ArrayList<HdmiCecDeviceInfo> result = new ArrayList<>(); for (DeviceInfo info : mDevices) { HdmiCecDeviceInfo cecDeviceInfo = info.toHdmiCecDeviceInfo(); Slog.v(TAG, " DeviceInfo: " + cecDeviceInfo); result.add(cecDeviceInfo); } Slog.v(TAG, "--------------------------------------------"); mCallback.onDeviceDiscoveryDone(result); finish(); } Loading Loading @@ -355,6 +362,7 @@ final class DeviceDiscoveryAction extends FeatureAction { return; } Slog.v(TAG, "Timeout[State=" + mState + ", Processed=" + mProcessedDeviceCount); removeDevice(mProcessedDeviceCount); checkAndProceedStage(); } Loading services/core/java/com/android/server/hdmi/HdmiCecController.java +3 −2 Original line number Diff line number Diff line Loading @@ -121,10 +121,11 @@ final class HdmiCecController { * * @param deviceTypes array of device types */ void initializeLocalDevices(int[] deviceTypes) { void initializeLocalDevices(int[] deviceTypes, HdmiCecLocalDevice.AddressAllocationCallback callback) { assertRunOnServiceThread(); for (int type : deviceTypes) { HdmiCecLocalDevice device = HdmiCecLocalDevice.create(this, type); HdmiCecLocalDevice device = HdmiCecLocalDevice.create(this, type, callback); if (device == null) { continue; } Loading services/core/java/com/android/server/hdmi/HdmiCecLocalDevice.java +32 −4 Original line number Diff line number Diff line Loading @@ -29,23 +29,41 @@ abstract class HdmiCecLocalDevice { protected final HdmiCecController mController; protected final int mDeviceType; protected final AddressAllocationCallback mAllocationCallback; protected int mAddress; protected int mPreferredAddress; protected HdmiCecDeviceInfo mDeviceInfo; protected HdmiCecLocalDevice(HdmiCecController controller, int deviceType) { /** * Callback interface to notify newly allocated logical address of the given * local device. */ interface AddressAllocationCallback { /** * Called when a logical address of the given device is allocated. * * @param deviceType original device type * @param logicalAddress newly allocated logical address */ void onAddressAllocated(int deviceType, int logicalAddress); } protected HdmiCecLocalDevice(HdmiCecController controller, int deviceType, AddressAllocationCallback callback) { mController = controller; mDeviceType = deviceType; mAllocationCallback = callback; mAddress = HdmiCec.ADDR_UNREGISTERED; } // Factory method that returns HdmiCecLocalDevice of corresponding type. static HdmiCecLocalDevice create(HdmiCecController controller, int deviceType) { static HdmiCecLocalDevice create(HdmiCecController controller, int deviceType, AddressAllocationCallback callback) { switch (deviceType) { case HdmiCec.DEVICE_TV: return new HdmiCecLocalDeviceTv(controller); return new HdmiCecLocalDeviceTv(controller, callback); case HdmiCec.DEVICE_PLAYBACK: return new HdmiCecLocalDevicePlayback(controller); return new HdmiCecLocalDevicePlayback(controller, callback); default: return null; } Loading @@ -53,6 +71,12 @@ abstract class HdmiCecLocalDevice { abstract void init(); /** * Called when a logical address of the local device is allocated. * Note that internal variables are updated before it's called. */ protected abstract void onAddressAllocated(int logicalAddress); protected void allocateAddress(int type) { mController.allocateLogicalAddress(type, mPreferredAddress, new AllocateLogicalAddressCallback() { Loading @@ -66,6 +90,10 @@ abstract class HdmiCecLocalDevice { mController.addDeviceInfo(deviceInfo); mController.addLogicalAddress(logicalAddress); onAddressAllocated(logicalAddress); if (mAllocationCallback != null) { mAllocationCallback.onAddressAllocated(deviceType, logicalAddress); } } }); } Loading services/core/java/com/android/server/hdmi/HdmiCecLocalDevicePlayback.java +6 −2 Original line number Diff line number Diff line Loading @@ -23,13 +23,17 @@ import android.hardware.hdmi.HdmiCec; */ final class HdmiCecLocalDevicePlayback extends HdmiCecLocalDevice { HdmiCecLocalDevicePlayback(HdmiCecController controller) { super(controller, HdmiCec.DEVICE_PLAYBACK); HdmiCecLocalDevicePlayback(HdmiCecController controller, AddressAllocationCallback callback) { super(controller, HdmiCec.DEVICE_PLAYBACK, callback); } @Override void init() { allocateAddress(mDeviceType); } @Override protected void onAddressAllocated(int logicalAddress) { mController.sendCommand(HdmiCecMessageBuilder.buildReportPhysicalAddressCommand( mAddress, mController.getPhysicalAddress(), mDeviceType)); } Loading services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java +5 −2 Original line number Diff line number Diff line Loading @@ -23,14 +23,17 @@ import android.hardware.hdmi.HdmiCec; */ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice { HdmiCecLocalDeviceTv(HdmiCecController controller) { super(controller, HdmiCec.DEVICE_TV); HdmiCecLocalDeviceTv(HdmiCecController controller, AddressAllocationCallback callback) { super(controller, HdmiCec.DEVICE_TV, callback); } @Override void init() { allocateAddress(mDeviceType); } @Override protected void onAddressAllocated(int logicalAddress) { // TODO: vendor-specific initialization here. mController.sendCommand(HdmiCecMessageBuilder.buildReportPhysicalAddressCommand( Loading Loading
services/core/java/com/android/server/hdmi/DeviceDiscoveryAction.java +10 −2 Original line number Diff line number Diff line Loading @@ -115,12 +115,12 @@ final class DeviceDiscoveryAction extends FeatureAction { @Override public void onPollingFinished(List<Integer> ackedAddress) { if (ackedAddress.isEmpty()) { Slog.i(TAG, "No device is detected."); Slog.v(TAG, "No device is detected."); finish(); return; } Slog.i(TAG, "Device detected: " + ackedAddress); Slog.v(TAG, "Device detected: " + ackedAddress); allocateDevices(ackedAddress); startPhysicalAddressStage(); } Loading @@ -136,6 +136,7 @@ final class DeviceDiscoveryAction extends FeatureAction { } private void startPhysicalAddressStage() { Slog.v(TAG, "Start [Physical Address Stage]:" + mDevices.size()); mProcessedDeviceCount = 0; mState = STATE_WAITING_FOR_PHYSICAL_ADDRESS; Loading @@ -158,6 +159,7 @@ final class DeviceDiscoveryAction extends FeatureAction { } private void startOsdNameStage() { Slog.v(TAG, "Start [Osd Name Stage]:" + mDevices.size()); mProcessedDeviceCount = 0; mState = STATE_WAITING_FOR_OSD_NAME; Loading @@ -176,6 +178,8 @@ final class DeviceDiscoveryAction extends FeatureAction { } private void startVendorIdStage() { Slog.v(TAG, "Start [Vendor Id Stage]:" + mDevices.size()); mProcessedDeviceCount = 0; mState = STATE_WAITING_FOR_VENDOR_ID; Loading Loading @@ -301,11 +305,14 @@ final class DeviceDiscoveryAction extends FeatureAction { } private void wrapUpAndFinish() { Slog.v(TAG, "---------Wrap up Device Discovery:[" + mDevices.size() + "]---------"); ArrayList<HdmiCecDeviceInfo> result = new ArrayList<>(); for (DeviceInfo info : mDevices) { HdmiCecDeviceInfo cecDeviceInfo = info.toHdmiCecDeviceInfo(); Slog.v(TAG, " DeviceInfo: " + cecDeviceInfo); result.add(cecDeviceInfo); } Slog.v(TAG, "--------------------------------------------"); mCallback.onDeviceDiscoveryDone(result); finish(); } Loading Loading @@ -355,6 +362,7 @@ final class DeviceDiscoveryAction extends FeatureAction { return; } Slog.v(TAG, "Timeout[State=" + mState + ", Processed=" + mProcessedDeviceCount); removeDevice(mProcessedDeviceCount); checkAndProceedStage(); } Loading
services/core/java/com/android/server/hdmi/HdmiCecController.java +3 −2 Original line number Diff line number Diff line Loading @@ -121,10 +121,11 @@ final class HdmiCecController { * * @param deviceTypes array of device types */ void initializeLocalDevices(int[] deviceTypes) { void initializeLocalDevices(int[] deviceTypes, HdmiCecLocalDevice.AddressAllocationCallback callback) { assertRunOnServiceThread(); for (int type : deviceTypes) { HdmiCecLocalDevice device = HdmiCecLocalDevice.create(this, type); HdmiCecLocalDevice device = HdmiCecLocalDevice.create(this, type, callback); if (device == null) { continue; } Loading
services/core/java/com/android/server/hdmi/HdmiCecLocalDevice.java +32 −4 Original line number Diff line number Diff line Loading @@ -29,23 +29,41 @@ abstract class HdmiCecLocalDevice { protected final HdmiCecController mController; protected final int mDeviceType; protected final AddressAllocationCallback mAllocationCallback; protected int mAddress; protected int mPreferredAddress; protected HdmiCecDeviceInfo mDeviceInfo; protected HdmiCecLocalDevice(HdmiCecController controller, int deviceType) { /** * Callback interface to notify newly allocated logical address of the given * local device. */ interface AddressAllocationCallback { /** * Called when a logical address of the given device is allocated. * * @param deviceType original device type * @param logicalAddress newly allocated logical address */ void onAddressAllocated(int deviceType, int logicalAddress); } protected HdmiCecLocalDevice(HdmiCecController controller, int deviceType, AddressAllocationCallback callback) { mController = controller; mDeviceType = deviceType; mAllocationCallback = callback; mAddress = HdmiCec.ADDR_UNREGISTERED; } // Factory method that returns HdmiCecLocalDevice of corresponding type. static HdmiCecLocalDevice create(HdmiCecController controller, int deviceType) { static HdmiCecLocalDevice create(HdmiCecController controller, int deviceType, AddressAllocationCallback callback) { switch (deviceType) { case HdmiCec.DEVICE_TV: return new HdmiCecLocalDeviceTv(controller); return new HdmiCecLocalDeviceTv(controller, callback); case HdmiCec.DEVICE_PLAYBACK: return new HdmiCecLocalDevicePlayback(controller); return new HdmiCecLocalDevicePlayback(controller, callback); default: return null; } Loading @@ -53,6 +71,12 @@ abstract class HdmiCecLocalDevice { abstract void init(); /** * Called when a logical address of the local device is allocated. * Note that internal variables are updated before it's called. */ protected abstract void onAddressAllocated(int logicalAddress); protected void allocateAddress(int type) { mController.allocateLogicalAddress(type, mPreferredAddress, new AllocateLogicalAddressCallback() { Loading @@ -66,6 +90,10 @@ abstract class HdmiCecLocalDevice { mController.addDeviceInfo(deviceInfo); mController.addLogicalAddress(logicalAddress); onAddressAllocated(logicalAddress); if (mAllocationCallback != null) { mAllocationCallback.onAddressAllocated(deviceType, logicalAddress); } } }); } Loading
services/core/java/com/android/server/hdmi/HdmiCecLocalDevicePlayback.java +6 −2 Original line number Diff line number Diff line Loading @@ -23,13 +23,17 @@ import android.hardware.hdmi.HdmiCec; */ final class HdmiCecLocalDevicePlayback extends HdmiCecLocalDevice { HdmiCecLocalDevicePlayback(HdmiCecController controller) { super(controller, HdmiCec.DEVICE_PLAYBACK); HdmiCecLocalDevicePlayback(HdmiCecController controller, AddressAllocationCallback callback) { super(controller, HdmiCec.DEVICE_PLAYBACK, callback); } @Override void init() { allocateAddress(mDeviceType); } @Override protected void onAddressAllocated(int logicalAddress) { mController.sendCommand(HdmiCecMessageBuilder.buildReportPhysicalAddressCommand( mAddress, mController.getPhysicalAddress(), mDeviceType)); } Loading
services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java +5 −2 Original line number Diff line number Diff line Loading @@ -23,14 +23,17 @@ import android.hardware.hdmi.HdmiCec; */ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice { HdmiCecLocalDeviceTv(HdmiCecController controller) { super(controller, HdmiCec.DEVICE_TV); HdmiCecLocalDeviceTv(HdmiCecController controller, AddressAllocationCallback callback) { super(controller, HdmiCec.DEVICE_TV, callback); } @Override void init() { allocateAddress(mDeviceType); } @Override protected void onAddressAllocated(int logicalAddress) { // TODO: vendor-specific initialization here. mController.sendCommand(HdmiCecMessageBuilder.buildReportPhysicalAddressCommand( Loading