Merge changes from topic "TvInputJNISTE" into udc-dev
* changes: Update TvInputJNI for setTvMessageEnabled Fix connection enumeration not accounting for discontinuous IDs
This commit is contained in:
@@ -27,9 +27,6 @@ import android.util.SparseArray;
|
||||
import android.util.SparseIntArray;
|
||||
import android.view.Surface;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
/**
|
||||
* Provides access to the low-level TV input hardware abstraction layer.
|
||||
*/
|
||||
@@ -64,6 +61,8 @@ final class TvInputHal implements Handler.Callback {
|
||||
private static native TvStreamConfig[] nativeGetStreamConfigs(long ptr, int deviceId,
|
||||
int generation);
|
||||
private static native void nativeClose(long ptr);
|
||||
private static native int nativeSetTvMessageEnabled(long ptr, int deviceId, int streamId,
|
||||
int type, boolean enabled);
|
||||
|
||||
private final Object mLock = new Object();
|
||||
private long mPtr = 0;
|
||||
@@ -100,6 +99,25 @@ final class TvInputHal implements Handler.Callback {
|
||||
}
|
||||
}
|
||||
|
||||
public int setTvMessageEnabled(int deviceId, TvStreamConfig streamConfig, int type,
|
||||
boolean enabled) {
|
||||
synchronized (mLock) {
|
||||
if (mPtr == 0) {
|
||||
return ERROR_NO_INIT;
|
||||
}
|
||||
int generation = mStreamConfigGenerations.get(deviceId, 0);
|
||||
if (generation != streamConfig.getGeneration()) {
|
||||
return ERROR_STALE_CONFIG;
|
||||
}
|
||||
if (nativeSetTvMessageEnabled(mPtr, deviceId, streamConfig.getStreamId(), type,
|
||||
enabled) == 0) {
|
||||
return SUCCESS;
|
||||
} else {
|
||||
return ERROR_UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int removeStream(int deviceId, TvStreamConfig streamConfig) {
|
||||
synchronized (mLock) {
|
||||
if (mPtr == 0) {
|
||||
|
||||
@@ -459,9 +459,11 @@ class TvInputHardwareManager implements TvInputHal.Callback {
|
||||
|
||||
private int findDeviceIdForInputIdLocked(String inputId) {
|
||||
for (int i = 0; i < mConnections.size(); ++i) {
|
||||
Connection connection = mConnections.get(i);
|
||||
if (connection.getInfoLocked().getId().equals(inputId)) {
|
||||
return i;
|
||||
int key = mConnections.keyAt(i);
|
||||
Connection connection = mConnections.get(key);
|
||||
if (connection != null && connection.getInfoLocked() != null
|
||||
&& connection.getInfoLocked().getId().equals(inputId)) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
@@ -489,6 +491,27 @@ class TvInputHardwareManager implements TvInputHal.Callback {
|
||||
return configsList;
|
||||
}
|
||||
|
||||
public boolean setTvMessageEnabled(String inputId, int type,
|
||||
boolean enabled) {
|
||||
synchronized (mLock) {
|
||||
int deviceId = findDeviceIdForInputIdLocked(inputId);
|
||||
if (deviceId < 0) {
|
||||
Slog.e(TAG, "Invalid inputId : " + inputId);
|
||||
return false;
|
||||
}
|
||||
|
||||
Connection connection = mConnections.get(deviceId);
|
||||
boolean success = true;
|
||||
for (TvStreamConfig config : connection.getConfigsLocked()) {
|
||||
success = success
|
||||
&& mHal.setTvMessageEnabled(deviceId, config, type, enabled)
|
||||
== TvInputHal.SUCCESS;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a snapshot of the given TV input into the provided Surface.
|
||||
*/
|
||||
@@ -764,6 +787,7 @@ class TvInputHardwareManager implements TvInputHal.Callback {
|
||||
+ " mHardwareInfo: " + mHardwareInfo
|
||||
+ ", mInfo: " + mInfo
|
||||
+ ", mCallback: " + mCallback
|
||||
+ ", mHardware: " + mHardware
|
||||
+ ", mConfigs: " + Arrays.toString(mConfigs)
|
||||
+ ", mCallingUid: " + mCallingUid
|
||||
+ ", mResolvedUserId: " + mResolvedUserId
|
||||
@@ -1100,6 +1124,18 @@ class TvInputHardwareManager implements TvInputHal.Callback {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean setTvMessageEnabled(int deviceId, TvStreamConfig streamConfig, int type,
|
||||
boolean enabled) {
|
||||
synchronized (mImplLock) {
|
||||
if (mReleased) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return mHal.setTvMessageEnabled(deviceId, streamConfig, type, enabled)
|
||||
== TvInputHal.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean startCapture(Surface surface, TvStreamConfig config) {
|
||||
synchronized (mImplLock) {
|
||||
if (mReleased) {
|
||||
|
||||
@@ -2154,6 +2154,9 @@ public final class TvInputManagerService extends SystemService {
|
||||
try {
|
||||
synchronized (mLock) {
|
||||
try {
|
||||
final String inputId =
|
||||
getSessionStateLocked(sessionToken, callingUid, userId).inputId;
|
||||
mTvInputHardwareManager.setTvMessageEnabled(inputId, type, enabled);
|
||||
getSessionLocked(sessionToken, callingUid, resolvedUserId)
|
||||
.setTvMessageEnabled(type, enabled);
|
||||
} catch (RemoteException | SessionNotFoundException e) {
|
||||
@@ -2711,7 +2714,10 @@ public final class TvInputManagerService extends SystemService {
|
||||
.audioAddress("0")
|
||||
.hdmiPortId(0)
|
||||
.build();
|
||||
mTvInputHardwareManager.onDeviceAvailable(info, null);
|
||||
TvStreamConfig[] configs = {
|
||||
new TvStreamConfig.Builder().streamId(19001)
|
||||
.generation(1).maxHeight(600).maxWidth(800).type(1).build()};
|
||||
mTvInputHardwareManager.onDeviceAvailable(info, configs);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -84,23 +84,26 @@ static jobjectArray nativeGetStreamConfigs(JNIEnv* env, jclass clazz,
|
||||
return result;
|
||||
}
|
||||
|
||||
static int nativeSetTvMessageEnabled(JNIEnv* env, jclass clazz, jlong ptr, jint deviceId,
|
||||
jint streamId, jint type, jboolean enabled) {
|
||||
JTvInputHal* tvInputHal = (JTvInputHal*)ptr;
|
||||
return tvInputHal->setTvMessageEnabled(deviceId, streamId, type, enabled);
|
||||
}
|
||||
|
||||
static void nativeClose(JNIEnv* env, jclass clazz, jlong ptr) {
|
||||
JTvInputHal* tvInputHal = (JTvInputHal*)ptr;
|
||||
delete tvInputHal;
|
||||
}
|
||||
|
||||
static const JNINativeMethod gTvInputHalMethods[] = {
|
||||
/* name, signature, funcPtr */
|
||||
{ "nativeOpen", "(Landroid/os/MessageQueue;)J",
|
||||
(void*) nativeOpen },
|
||||
{ "nativeAddOrUpdateStream", "(JIILandroid/view/Surface;)I",
|
||||
(void*) nativeAddOrUpdateStream },
|
||||
{ "nativeRemoveStream", "(JII)I",
|
||||
(void*) nativeRemoveStream },
|
||||
{ "nativeGetStreamConfigs", "(JII)[Landroid/media/tv/TvStreamConfig;",
|
||||
(void*) nativeGetStreamConfigs },
|
||||
{ "nativeClose", "(J)V",
|
||||
(void*) nativeClose },
|
||||
/* name, signature, funcPtr */
|
||||
{"nativeOpen", "(Landroid/os/MessageQueue;)J", (void*)nativeOpen},
|
||||
{"nativeAddOrUpdateStream", "(JIILandroid/view/Surface;)I", (void*)nativeAddOrUpdateStream},
|
||||
{"nativeRemoveStream", "(JII)I", (void*)nativeRemoveStream},
|
||||
{"nativeGetStreamConfigs", "(JII)[Landroid/media/tv/TvStreamConfig;",
|
||||
(void*)nativeGetStreamConfigs},
|
||||
{"nativeSetTvMessageEnabled", "(JIIIZ)I", (void*)nativeSetTvMessageEnabled},
|
||||
{"nativeClose", "(J)V", (void*)nativeClose},
|
||||
};
|
||||
|
||||
#define FIND_CLASS(var, className) \
|
||||
|
||||
@@ -144,6 +144,17 @@ int JTvInputHal::removeStream(int deviceId, int streamId) {
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int JTvInputHal::setTvMessageEnabled(int deviceId, int streamId, int type, bool enabled) {
|
||||
Mutex::Autolock autoLock(&mLock);
|
||||
if (!mTvInput->setTvMessageEnabled(deviceId, streamId,
|
||||
static_cast<AidlTvMessageEventType>(type), enabled)
|
||||
.isOk()) {
|
||||
ALOGE("Error in setTvMessageEnabled. device id:%d stream id:%d", deviceId, streamId);
|
||||
return BAD_VALUE;
|
||||
}
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
const std::vector<AidlTvStreamConfig> JTvInputHal::getStreamConfigs(int deviceId) {
|
||||
std::vector<AidlTvStreamConfig> list;
|
||||
::ndk::ScopedAStatus status = mTvInput->getStreamConfigurations(deviceId, &list);
|
||||
@@ -384,4 +395,15 @@ JTvInputHal::ITvInputWrapper::ITvInputWrapper(std::shared_ptr<AidlITvInput>& aid
|
||||
}
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus JTvInputHal::ITvInputWrapper::setTvMessageEnabled(int32_t deviceId,
|
||||
int32_t streamId,
|
||||
TvMessageEventType in_type,
|
||||
bool enabled) {
|
||||
if (mIsHidl) {
|
||||
return ::ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
|
||||
} else {
|
||||
return mAidlTvInput->setTvMessageEnabled(deviceId, streamId, in_type, enabled);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
||||
@@ -44,6 +44,8 @@ using ::aidl::android::hardware::tv::input::BnTvInputCallback;
|
||||
using ::aidl::android::hardware::tv::input::CableConnectionStatus;
|
||||
using ::aidl::android::hardware::tv::input::TvInputEventType;
|
||||
using ::aidl::android::hardware::tv::input::TvInputType;
|
||||
using ::aidl::android::hardware::tv::input::TvMessageEvent;
|
||||
using ::aidl::android::hardware::tv::input::TvMessageEventType;
|
||||
|
||||
using AidlAudioDevice = ::aidl::android::media::audio::common::AudioDevice;
|
||||
using AidlAudioDeviceAddress = ::aidl::android::media::audio::common::AudioDeviceAddress;
|
||||
@@ -53,6 +55,7 @@ using AidlNativeHandle = ::aidl::android::hardware::common::NativeHandle;
|
||||
using AidlTvInputDeviceInfo = ::aidl::android::hardware::tv::input::TvInputDeviceInfo;
|
||||
using AidlTvInputEvent = ::aidl::android::hardware::tv::input::TvInputEvent;
|
||||
using AidlTvMessageEvent = ::aidl::android::hardware::tv::input::TvMessageEvent;
|
||||
using AidlTvMessageEventType = ::aidl::android::hardware::tv::input::TvMessageEventType;
|
||||
using AidlTvStreamConfig = ::aidl::android::hardware::tv::input::TvStreamConfig;
|
||||
|
||||
extern gTvInputHalClassInfoType gTvInputHalClassInfo;
|
||||
@@ -69,6 +72,7 @@ public:
|
||||
static JTvInputHal* createInstance(JNIEnv* env, jobject thiz, const sp<Looper>& looper);
|
||||
|
||||
int addOrUpdateStream(int deviceId, int streamId, const sp<Surface>& surface);
|
||||
int setTvMessageEnabled(int deviceId, int streamId, int type, bool enabled);
|
||||
int removeStream(int deviceId, int streamId);
|
||||
const std::vector<AidlTvStreamConfig> getStreamConfigs(int deviceId);
|
||||
|
||||
@@ -150,6 +154,8 @@ private:
|
||||
::ndk::ScopedAStatus openStream(int32_t in_deviceId, int32_t in_streamId,
|
||||
AidlNativeHandle* _aidl_return);
|
||||
::ndk::ScopedAStatus closeStream(int32_t in_deviceId, int32_t in_streamId);
|
||||
::ndk::ScopedAStatus setTvMessageEnabled(int32_t deviceId, int32_t streamId,
|
||||
TvMessageEventType in_type, bool enabled);
|
||||
|
||||
private:
|
||||
::ndk::ScopedAStatus hidlSetCallback(const std::shared_ptr<TvInputCallback>& in_callback);
|
||||
|
||||
Reference in New Issue
Block a user