Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2806c822 authored by David Zhao's avatar David Zhao Committed by Automerger Merge Worker
Browse files

Merge changes from topic "TvInputJNISTE" into udc-dev am: cdd08d45

parents 84f99d1d cdd08d45
Loading
Loading
Loading
Loading
+21 −3
Original line number Diff line number Diff line
@@ -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) {
+39 −3
Original line number Diff line number Diff line
@@ -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) {
+7 −1
Original line number Diff line number Diff line
@@ -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);
        }

        /**
+14 −11
Original line number Diff line number Diff line
@@ -84,6 +84,12 @@ 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;
@@ -91,16 +97,13 @@ static void nativeClose(JNIEnv* env, jclass clazz, jlong ptr) {

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 },
        {"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 },
        {"nativeSetTvMessageEnabled", "(JIIIZ)I", (void*)nativeSetTvMessageEnabled},
        {"nativeClose", "(J)V", (void*)nativeClose},
};

#define FIND_CLASS(var, className) \
+22 −0
Original line number Diff line number Diff line
@@ -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
Loading