Skip to content
Snippets Groups Projects
Commit a6f572f9 authored by Chavi Weingarten's avatar Chavi Weingarten
Browse files

Add native InputTransferToken

Added a native class that corresponds to the Java InputTransferToken.

Test: SurfaceControlInputReceiverTests
Test: AInputTransferTokenTest
Bug: 324271765
Change-Id: Ida2a7b34338560dfed9af7f510d64372e41384af
parent 25cf7faf
No related branches found
No related tags found
No related merge requests found
/*
* Copyright 2024 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.
*/
/**
* @addtogroup NativeActivity Native Activity
* @{
*/
/**
* @file input_transfer_token_jni.h
*/
#ifndef ANDROID_INPUT_TRANSFER_TOKEN_JNI_H
#define ANDROID_INPUT_TRANSFER_TOKEN_JNI_H
#include <sys/cdefs.h>
#include <jni.h>
__BEGIN_DECLS
struct AInputTransferToken;
/**
* AInputTransferToken can be used to request focus on or to transfer touch gesture to and from
* an embedded SurfaceControl
*/
typedef struct AInputTransferToken AInputTransferToken;
/**
* Return the AInputTransferToken wrapped by a Java InputTransferToken object. This must be released
* using AInputTransferToken_release
*
* inputTransferTokenObj must be a non-null instance of android.window.InputTransferToken.
*
* Available since API level 35.
*/
AInputTransferToken* _Nonnull AInputTransferToken_fromJava(JNIEnv* _Nonnull env,
jobject _Nonnull inputTransferTokenObj) __INTRODUCED_IN(__ANDROID_API_V__);
/**
* Return the Java InputTransferToken object that wraps AInputTransferToken
*
* aInputTransferToken must be non null and the returned value is an object of instance
* android.window.InputTransferToken.
*
* Available since API level 35.
*/
jobject _Nonnull AInputTransferToken_toJava(JNIEnv* _Nonnull env,
const AInputTransferToken* _Nonnull aInputTransferToken) __INTRODUCED_IN(__ANDROID_API_V__);
/**
* Removes a reference that was previously acquired in native.
*
* Available since API level 35.
*/
void AInputTransferToken_release(AInputTransferToken* _Nonnull aInputTransferToken)
__INTRODUCED_IN(__ANDROID_API_V__);
__END_DECLS
#endif // ANDROID_INPUT_TRANSFER_TOKEN_JNI_H
/** @} */
/*
* Copyright (C) 2024 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.
*/
#pragma once
#include <binder/Binder.h>
#include <binder/IBinder.h>
#include <binder/Parcel.h>
#include <private/gui/ParcelUtils.h>
#include <utils/Errors.h>
namespace android {
struct InputTransferToken : public RefBase, Parcelable {
public:
InputTransferToken() { mToken = new BBinder(); }
InputTransferToken(const sp<IBinder>& token) { mToken = token; }
status_t writeToParcel(Parcel* parcel) const override {
SAFE_PARCEL(parcel->writeStrongBinder, mToken);
return NO_ERROR;
}
status_t readFromParcel(const Parcel* parcel) {
SAFE_PARCEL(parcel->readStrongBinder, &mToken);
return NO_ERROR;
};
sp<IBinder> mToken;
};
static inline bool operator==(const sp<InputTransferToken>& token1,
const sp<InputTransferToken>& token2) {
if (token1.get() == token2.get()) {
return true;
}
return token1->mToken == token2->mToken;
}
} // namespace android
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment