HdmiConfig class holding constants that may need customization
Put in one place some constants used in HdmiControlService that
may need customization. This makes it easy to do the job.
Bug: 16160911
Change-Id: I59786a48d336cfca722daa82c1f0dceb88c5e5e4
diff --git a/services/core/java/com/android/server/hdmi/DeviceDiscoveryAction.java b/services/core/java/com/android/server/hdmi/DeviceDiscoveryAction.java
index 3c699bc..a75b485 100644
--- a/services/core/java/com/android/server/hdmi/DeviceDiscoveryAction.java
+++ b/services/core/java/com/android/server/hdmi/DeviceDiscoveryAction.java
@@ -51,8 +51,6 @@
// State in which the action is waiting for gathering vendor id of non-local devices.
private static final int STATE_WAITING_FOR_VENDOR_ID = 4;
- private static final int DEVICE_POLLING_RETRY = 1;
-
/**
* Interface used to report result of device discovery.
*/
@@ -118,7 +116,7 @@
startPhysicalAddressStage();
}
}, Constants.POLL_ITERATION_REVERSE_ORDER
- | Constants.POLL_STRATEGY_REMOTES_DEVICES, DEVICE_POLLING_RETRY);
+ | Constants.POLL_STRATEGY_REMOTES_DEVICES, HdmiConfig.DEVICE_POLLING_RETRY);
return true;
}
@@ -154,7 +152,7 @@
return;
}
sendCommand(HdmiCecMessageBuilder.buildGivePhysicalAddress(getSourceAddress(), address));
- addTimer(mState, TIMEOUT_MS);
+ addTimer(mState, HdmiConfig.TIMEOUT_MS);
}
private void startOsdNameStage() {
@@ -177,7 +175,7 @@
return;
}
sendCommand(HdmiCecMessageBuilder.buildGiveOsdNameCommand(getSourceAddress(), address));
- addTimer(mState, TIMEOUT_MS);
+ addTimer(mState, HdmiConfig.TIMEOUT_MS);
}
private void startVendorIdStage() {
@@ -202,7 +200,7 @@
}
sendCommand(
HdmiCecMessageBuilder.buildGiveDeviceVendorIdCommand(getSourceAddress(), address));
- addTimer(mState, TIMEOUT_MS);
+ addTimer(mState, HdmiConfig.TIMEOUT_MS);
}
private boolean mayProcessMessageIfCached(int address, int opcode) {
diff --git a/services/core/java/com/android/server/hdmi/DevicePowerStatusAction.java b/services/core/java/com/android/server/hdmi/DevicePowerStatusAction.java
index 87c8d92..1106810 100644
--- a/services/core/java/com/android/server/hdmi/DevicePowerStatusAction.java
+++ b/services/core/java/com/android/server/hdmi/DevicePowerStatusAction.java
@@ -59,7 +59,7 @@
boolean start() {
queryDevicePowerStatus();
mState = STATE_WAITING_FOR_REPORT_POWER_STATUS;
- addTimer(mState, FeatureAction.TIMEOUT_MS);
+ addTimer(mState, HdmiConfig.TIMEOUT_MS);
return true;
}
diff --git a/services/core/java/com/android/server/hdmi/DeviceSelectAction.java b/services/core/java/com/android/server/hdmi/DeviceSelectAction.java
index 9767d21..d4fffcf 100644
--- a/services/core/java/com/android/server/hdmi/DeviceSelectAction.java
+++ b/services/core/java/com/android/server/hdmi/DeviceSelectAction.java
@@ -111,7 +111,7 @@
}
});
mState = STATE_WAIT_FOR_REPORT_POWER_STATUS;
- addTimer(mState, TIMEOUT_MS);
+ addTimer(mState, HdmiConfig.TIMEOUT_MS);
}
@Override
diff --git a/services/core/java/com/android/server/hdmi/FeatureAction.java b/services/core/java/com/android/server/hdmi/FeatureAction.java
index f8ebed2..7d15f4c 100644
--- a/services/core/java/com/android/server/hdmi/FeatureAction.java
+++ b/services/core/java/com/android/server/hdmi/FeatureAction.java
@@ -47,10 +47,6 @@
// Timer handler message used for timeout event
protected static final int MSG_TIMEOUT = 100;
- // Default timeout for the incoming command to arrive in response to a request.
- // TODO: Consider reading this value from configuration to allow customization.
- protected static final int TIMEOUT_MS = 2000;
-
// Default state used in common by all the feature actions.
protected static final int STATE_NONE = 0;
diff --git a/services/core/java/com/android/server/hdmi/HdmiCecController.java b/services/core/java/com/android/server/hdmi/HdmiCecController.java
index a5a502a..6ed2364 100644
--- a/services/core/java/com/android/server/hdmi/HdmiCecController.java
+++ b/services/core/java/com/android/server/hdmi/HdmiCecController.java
@@ -77,8 +77,6 @@
private static final int NUM_LOGICAL_ADDRESS = 16;
- private static final int RETRY_COUNT_FOR_LOGICAL_ADDRESS_ALLOCATION = 3;
-
// Predicate for whether the given logical address is remote device's one or not.
private final Predicate<Integer> mRemoteDeviceAddressPredicate = new Predicate<Integer>() {
@Override
@@ -198,8 +196,7 @@
int curAddress = (startAddress + i) % NUM_LOGICAL_ADDRESS;
if (curAddress != Constants.ADDR_UNREGISTERED
&& deviceType == HdmiUtils.getTypeFromAddress(curAddress)) {
- if (!sendPollMessage(curAddress, curAddress,
- RETRY_COUNT_FOR_LOGICAL_ADDRESS_ALLOCATION)) {
+ if (!sendPollMessage(curAddress, curAddress, HdmiConfig.ADDRESS_ALLOCATION_RETRY)) {
logicalAddress = curAddress;
break;
}
diff --git a/services/core/java/com/android/server/hdmi/HdmiConfig.java b/services/core/java/com/android/server/hdmi/HdmiConfig.java
new file mode 100644
index 0000000..8ae76b5
--- /dev/null
+++ b/services/core/java/com/android/server/hdmi/HdmiConfig.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.hdmi;
+
+/**
+ * Class that holds together the constants that may require per-product configuration.
+ */
+final class HdmiConfig {
+
+ // Default timeout for the incoming command to arrive in response to a request.
+ static final int TIMEOUT_MS = 2000;
+
+ // IRT(Initiator Repetition Time) in millisecond as recommended in the standard.
+ // Outgoing UCP commands, when in 'Press and Hold' mode, should be this much apart
+ // from the adjacent one so as not to place unnecessarily heavy load on the CEC line.
+ static final int IRT_MS = 300;
+
+ // Number of retries for polling each device in device discovery phase after TV powers on
+ // or HDMI control is enabled.
+ static final int DEVICE_POLLING_RETRY = 1;
+
+ // Number of retries for polling each device in periodic check (hotplug detection).
+ static final int HOTPLUG_DETECTION_RETRY = 2;
+
+ // Number of retries for polling each device in address allocation mechanism.
+ static final int ADDRESS_ALLOCATION_RETRY = 3;
+
+ private HdmiConfig() { /* cannot be instantiated */ }
+}
diff --git a/services/core/java/com/android/server/hdmi/HotplugDetectionAction.java b/services/core/java/com/android/server/hdmi/HotplugDetectionAction.java
index e3d8ee2..bd919e2 100644
--- a/services/core/java/com/android/server/hdmi/HotplugDetectionAction.java
+++ b/services/core/java/com/android/server/hdmi/HotplugDetectionAction.java
@@ -38,7 +38,6 @@
private static final int POLLING_INTERVAL_MS = 5000;
private static final int TIMEOUT_COUNT = 3;
- private static final int POLL_RETRY_COUNT = 2;
// State in which waits for next polling
private static final int STATE_WAIT_FOR_NEXT_POLLING = 1;
@@ -126,7 +125,7 @@
checkHotplug(ackedAddress, false);
}
}, Constants.POLL_ITERATION_IN_ORDER
- | Constants.POLL_STRATEGY_REMOTES_DEVICES, POLL_RETRY_COUNT);
+ | Constants.POLL_STRATEGY_REMOTES_DEVICES, HdmiConfig.HOTPLUG_DETECTION_RETRY);
}
private void pollAudioSystem() {
@@ -138,7 +137,7 @@
checkHotplug(ackedAddress, true);
}
}, Constants.POLL_ITERATION_IN_ORDER
- | Constants.POLL_STRATEGY_SYSTEM_AUDIO, POLL_RETRY_COUNT);
+ | Constants.POLL_STRATEGY_SYSTEM_AUDIO, HdmiConfig.HOTPLUG_DETECTION_RETRY);
}
private void checkHotplug(List<Integer> ackedAddress, boolean audioOnly) {
diff --git a/services/core/java/com/android/server/hdmi/NewDeviceAction.java b/services/core/java/com/android/server/hdmi/NewDeviceAction.java
index a950afb..80deaab 100644
--- a/services/core/java/com/android/server/hdmi/NewDeviceAction.java
+++ b/services/core/java/com/android/server/hdmi/NewDeviceAction.java
@@ -87,7 +87,7 @@
sendCommand(HdmiCecMessageBuilder.buildGiveOsdNameCommand(getSourceAddress(),
mDeviceLogicalAddress));
- addTimer(mState, TIMEOUT_MS);
+ addTimer(mState, HdmiConfig.TIMEOUT_MS);
return true;
}
@@ -161,7 +161,7 @@
}
sendCommand(HdmiCecMessageBuilder.buildGiveDeviceVendorIdCommand(getSourceAddress(),
mDeviceLogicalAddress));
- addTimer(mState, TIMEOUT_MS);
+ addTimer(mState, HdmiConfig.TIMEOUT_MS);
}
private void addDeviceInfo() {
diff --git a/services/core/java/com/android/server/hdmi/OneTouchPlayAction.java b/services/core/java/com/android/server/hdmi/OneTouchPlayAction.java
index 40ce7ed..6299b99 100644
--- a/services/core/java/com/android/server/hdmi/OneTouchPlayAction.java
+++ b/services/core/java/com/android/server/hdmi/OneTouchPlayAction.java
@@ -76,7 +76,7 @@
broadcastActiveSource();
queryDevicePowerStatus();
mState = STATE_WAITING_FOR_REPORT_POWER_STATUS;
- addTimer(mState, FeatureAction.TIMEOUT_MS);
+ addTimer(mState, HdmiConfig.TIMEOUT_MS);
return true;
}
@@ -116,7 +116,7 @@
if (state == STATE_WAITING_FOR_REPORT_POWER_STATUS) {
if (mPowerStatusCounter++ < LOOP_COUNTER_MAX) {
queryDevicePowerStatus();
- addTimer(mState, FeatureAction.TIMEOUT_MS);
+ addTimer(mState, HdmiConfig.TIMEOUT_MS);
} else {
// Couldn't wake up the TV for whatever reason. Report failure.
invokeCallback(HdmiControlManager.RESULT_TIMEOUT);
diff --git a/services/core/java/com/android/server/hdmi/RequestArcInitiationAction.java b/services/core/java/com/android/server/hdmi/RequestArcInitiationAction.java
index 692f961..f25363d 100644
--- a/services/core/java/com/android/server/hdmi/RequestArcInitiationAction.java
+++ b/services/core/java/com/android/server/hdmi/RequestArcInitiationAction.java
@@ -42,7 +42,7 @@
public void onSendCompleted(int error) {
if (error == Constants.SEND_RESULT_SUCCESS) {
mState = STATE_WATING_FOR_REQUEST_ARC_REQUEST_RESPONSE;
- addTimer(mState, TIMEOUT_MS);
+ addTimer(mState, HdmiConfig.TIMEOUT_MS);
} else {
// If failed to send <Request ARC Initiation>, start "Disabled"
// ARC transmission action.
diff --git a/services/core/java/com/android/server/hdmi/RequestArcTerminationAction.java b/services/core/java/com/android/server/hdmi/RequestArcTerminationAction.java
index 31cbe32..1491c72 100644
--- a/services/core/java/com/android/server/hdmi/RequestArcTerminationAction.java
+++ b/services/core/java/com/android/server/hdmi/RequestArcTerminationAction.java
@@ -42,7 +42,7 @@
public void onSendCompleted(int error) {
if (error == Constants.SEND_RESULT_SUCCESS) {
mState = STATE_WATING_FOR_REQUEST_ARC_REQUEST_RESPONSE;
- addTimer(mState, TIMEOUT_MS);
+ addTimer(mState, HdmiConfig.TIMEOUT_MS);
} else {
// If failed to send <Request ARC Termination>, start "Disabled" ARC
// transmission action.
diff --git a/services/core/java/com/android/server/hdmi/SetArcTransmissionStateAction.java b/services/core/java/com/android/server/hdmi/SetArcTransmissionStateAction.java
index 15375f3..e0c1ad5 100644
--- a/services/core/java/com/android/server/hdmi/SetArcTransmissionStateAction.java
+++ b/services/core/java/com/android/server/hdmi/SetArcTransmissionStateAction.java
@@ -17,7 +17,6 @@
package com.android.server.hdmi;
import android.hardware.hdmi.HdmiCecDeviceInfo;
-
import android.util.Slog;
/**
@@ -80,7 +79,7 @@
// If succeeds to send <Report ARC Initiated>, wait general timeout
// to check whether there is no <Feature Abort> for <Report ARC Initiated>.
mState = STATE_WAITING_TIMEOUT;
- addTimer(mState, TIMEOUT_MS);
+ addTimer(mState, HdmiConfig.TIMEOUT_MS);
} else {
// If fails to send <Report ARC Initiated>, disable ARC and
// send <Report ARC Terminated> directly.
diff --git a/services/core/java/com/android/server/hdmi/SystemAudioAction.java b/services/core/java/com/android/server/hdmi/SystemAudioAction.java
index dab8ae9..969eeae 100644
--- a/services/core/java/com/android/server/hdmi/SystemAudioAction.java
+++ b/services/core/java/com/android/server/hdmi/SystemAudioAction.java
@@ -35,7 +35,7 @@
private static final int MAX_SEND_RETRY_COUNT = 2;
private static final int ON_TIMEOUT_MS = 5000;
- private static final int OFF_TIMEOUT_MS = TIMEOUT_MS;
+ private static final int OFF_TIMEOUT_MS = HdmiConfig.TIMEOUT_MS;
// Logical address of AV Receiver.
protected final int mAvrLogicalAddress;
diff --git a/services/core/java/com/android/server/hdmi/SystemAudioAutoInitiationAction.java b/services/core/java/com/android/server/hdmi/SystemAudioAutoInitiationAction.java
index a2b4beb..7c25040 100644
--- a/services/core/java/com/android/server/hdmi/SystemAudioAutoInitiationAction.java
+++ b/services/core/java/com/android/server/hdmi/SystemAudioAutoInitiationAction.java
@@ -37,7 +37,7 @@
boolean start() {
mState = STATE_WAITING_FOR_SYSTEM_AUDIO_MODE_STATUS;
- addTimer(mState, TIMEOUT_MS);
+ addTimer(mState, HdmiConfig.TIMEOUT_MS);
sendGiveSystemAudioModeStatus();
return true;
}
diff --git a/services/core/java/com/android/server/hdmi/SystemAudioStatusAction.java b/services/core/java/com/android/server/hdmi/SystemAudioStatusAction.java
index ce9cc5c..91805c5 100644
--- a/services/core/java/com/android/server/hdmi/SystemAudioStatusAction.java
+++ b/services/core/java/com/android/server/hdmi/SystemAudioStatusAction.java
@@ -46,7 +46,7 @@
@Override
boolean start() {
mState = STATE_WAIT_FOR_REPORT_AUDIO_STATUS;
- addTimer(mState, TIMEOUT_MS);
+ addTimer(mState, HdmiConfig.TIMEOUT_MS);
sendGiveAudioStatus();
return true;
}