-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android] Fix handling optional values + UI fix. (#19237)
* [nrf noup] [android] Use ScrollView in main screen Some buttons were not visible on low-resolution devices. Signed-off-by: Damian Krolik <[email protected]> * [nrf noup] [android] Fix crash on DoorLock.lockDoor command Cluster Interaction Tool screen would crash when trying to send a command that takes an optional argument. The reason was that optional arguments were incorrectly converted in the application and the underlying JNI layer. Signed-off-by: Damian Krolik <[email protected]> * Add IDL tests
- Loading branch information
1 parent
47e7a12
commit fbf2d25
Showing
15 changed files
with
719 additions
and
592 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
client cluster MyCluster = 1 { | ||
request struct FooRequest { | ||
optional OCTET_STRING argument = 0; | ||
} | ||
|
||
command Foo(FooRequest): DefaultSuccess = 0; | ||
} |
79 changes: 79 additions & 0 deletions
79
scripts/idl/tests/outputs/optional_argument/jni/MyClusterClient-InvokeSubscribeImpl.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include <controller/java/zap-generated/CHIPCallbackTypes.h> | ||
#include <controller/java/zap-generated/CHIPInvokeCallbacks.h> | ||
#include <controller/java/zap-generated/CHIPReadCallbacks.h> | ||
|
||
#include <app-common/zap-generated/cluster-objects.h> | ||
#include <zap-generated/CHIPClientCallbacks.h> | ||
#include <zap-generated/CHIPClusters.h> | ||
|
||
#include <controller/java/AndroidCallbacks.h> | ||
#include <controller/java/AndroidClusterExceptions.h> | ||
#include <controller/java/CHIPDefaultCallbacks.h> | ||
#include <jni.h> | ||
#include <lib/support/CHIPListUtils.h> | ||
#include <lib/support/CodeUtils.h> | ||
#include <lib/support/JniReferences.h> | ||
#include <lib/support/JniTypeWrappers.h> | ||
#include <lib/support/Span.h> | ||
#include <platform/PlatformManager.h> | ||
#include <vector> | ||
|
||
#define JNI_METHOD(RETURN, CLASS_NAME, METHOD_NAME) \ | ||
extern "C" JNIEXPORT RETURN JNICALL Java_chip_devicecontroller_ChipClusters_00024##CLASS_NAME##_##METHOD_NAME | ||
|
||
using namespace chip; | ||
using namespace chip::Controller; | ||
|
||
JNI_METHOD(jlong, MyClusterCluster, initWithDevice)(JNIEnv * env, jobject self, jlong devicePtr, jint endpointId) | ||
{ | ||
chip::DeviceLayer::StackLock lock; | ||
MyClusterCluster * cppCluster = new MyClusterCluster(); | ||
|
||
cppCluster->Associate(reinterpret_cast<DeviceProxy *>(devicePtr), endpointId); | ||
return reinterpret_cast<jlong>(cppCluster); | ||
} | ||
|
||
JNI_METHOD(void, MyClusterCluster, | ||
foo)(JNIEnv * env, jobject self, jlong clusterPtr, jobject callback,jobject argument,jobject timedInvokeTimeoutMs) | ||
{ | ||
chip::DeviceLayer::StackLock lock; | ||
CHIP_ERROR err = CHIP_NO_ERROR; | ||
MyClusterCluster * cppCluster; | ||
|
||
ListFreer listFreer; | ||
chip::app::Clusters::MyCluster::Commands::Foo::Type request; | ||
|
||
std::vector<Platform::UniquePtr<JniByteArray>> cleanupByteArrays; | ||
std::vector<Platform::UniquePtr<JniUtfString>> cleanupStrings;{ | ||
jobject optionalValue_0 = nullptr; | ||
chip::JniReferences::GetInstance().GetOptionalValue(argument, optionalValue_0); | ||
if (optionalValue_0) { | ||
auto & definedValue_0 = request.argument.Emplace(); | ||
cleanupByteArrays.push_back(chip::Platform::MakeUnique<chip::JniByteArray>(env, static_cast<jbyteArray>(optionalValue_0))); | ||
definedValue_0 = cleanupByteArrays.back()->byteSpan(); | ||
} | ||
} | ||
|
||
|
||
std::unique_ptr<CHIPDefaultSuccessCallback, void (*)(CHIPDefaultSuccessCallback *)> onSuccess( | ||
Platform::New<CHIPDefaultSuccessCallback>(callback), Platform::Delete<CHIPDefaultSuccessCallback>); | ||
std::unique_ptr<CHIPDefaultFailureCallback, void (*)(CHIPDefaultFailureCallback *)> onFailure(Platform::New<CHIPDefaultFailureCallback>(callback), Platform::Delete<CHIPDefaultFailureCallback>); | ||
VerifyOrReturn(onSuccess.get() != nullptr, AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); | ||
VerifyOrReturn(onFailure.get() != nullptr, AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error creating native callback", CHIP_ERROR_NO_MEMORY)); | ||
|
||
cppCluster = reinterpret_cast<MyClusterCluster *>(clusterPtr); | ||
VerifyOrReturn(cppCluster != nullptr, AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error getting native cluster", CHIP_ERROR_INCORRECT_STATE)); | ||
|
||
auto successFn = chip::Callback::Callback<CHIPDefaultSuccessCallbackType>::FromCancelable(onSuccess->Cancel()); | ||
auto failureFn = chip::Callback::Callback<CHIPDefaultFailureCallbackType>::FromCancelable(onFailure->Cancel()); | ||
|
||
if (timedInvokeTimeoutMs == nullptr) { | ||
err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall); | ||
} else { | ||
err = cppCluster->InvokeCommand(request, onSuccess->mContext, successFn->mCall, failureFn->mCall, chip::JniReferences::GetInstance().IntegerToPrimitive(timedInvokeTimeoutMs)); | ||
} | ||
VerifyOrReturn(err == CHIP_NO_ERROR, AndroidClusterExceptions::GetInstance().ReturnIllegalStateException(env, callback, "Error invoking command", CHIP_ERROR_INCORRECT_STATE)); | ||
|
||
onSuccess.release(); | ||
onFailure.release(); | ||
} |
14 changes: 14 additions & 0 deletions
14
scripts/idl/tests/outputs/optional_argument/jni/MyClusterClient-ReadImpl.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
#include <controller/java/zap-generated/CHIPReadCallbacks.h> | ||
|
||
#include <app-common/zap-generated/cluster-objects.h> | ||
#include <zap-generated/CHIPClusters.h> | ||
|
||
#include <controller/java/AndroidClusterExceptions.h> | ||
#include <controller/java/CHIPDefaultCallbacks.h> | ||
#include <jni.h> | ||
#include <lib/support/CodeUtils.h> | ||
#include <platform/PlatformManager.h> | ||
|
||
#define JNI_METHOD(RETURN, CLASS_NAME, METHOD_NAME) \ | ||
extern "C" JNIEXPORT RETURN JNICALL Java_chip_devicecontroller_ChipClusters_00024##CLASS_NAME##_##METHOD_NAME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
182 changes: 94 additions & 88 deletions
182
src/android/CHIPTool/app/src/main/res/layout/select_action_fragment.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,109 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" android:layout_width="match_parent" | ||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<Button | ||
android:id="@+id/scanQrBtn" | ||
android:layout_height="wrap_content" | ||
android:layout_width="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:text="@string/scan_qr_code_btn_text" /> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<Button | ||
android:id="@+id/provisionWiFiCredentialsBtn" | ||
android:layout_height="wrap_content" | ||
android:layout_width="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:text="@string/provision_wifi_credentials_btn_text" /> | ||
<Button | ||
android:id="@+id/scanQrBtn" | ||
android:layout_height="wrap_content" | ||
android:layout_width="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:text="@string/scan_qr_code_btn_text" /> | ||
|
||
<Button | ||
android:id="@+id/provisionThreadCredentialsBtn" | ||
android:layout_height="wrap_content" | ||
android:layout_width="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:text="@string/provision_thread_credentials_btn_text" /> | ||
<Button | ||
android:id="@+id/provisionWiFiCredentialsBtn" | ||
android:layout_height="wrap_content" | ||
android:layout_width="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:text="@string/provision_wifi_credentials_btn_text" /> | ||
|
||
<Button | ||
android:id="@+id/provisionCustomFlowBtn" | ||
android:layout_height="wrap_content" | ||
android:layout_width="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:text="@string/provision_custom_flow_btn_text" /> | ||
<Button | ||
android:id="@+id/provisionThreadCredentialsBtn" | ||
android:layout_height="wrap_content" | ||
android:layout_width="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:text="@string/provision_thread_credentials_btn_text" /> | ||
|
||
<Button | ||
android:id="@+id/onOffClusterBtn" | ||
android:layout_height="wrap_content" | ||
android:layout_width="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:text="@string/on_off_level_btn_text" /> | ||
<Button | ||
android:id="@+id/provisionCustomFlowBtn" | ||
android:layout_height="wrap_content" | ||
android:layout_width="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:text="@string/provision_custom_flow_btn_text" /> | ||
|
||
<Button | ||
android:id="@+id/sensorClustersBtn" | ||
android:layout_height="wrap_content" | ||
android:layout_width="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:text="@string/sensor_client_btn_text" /> | ||
<Button | ||
android:id="@+id/onOffClusterBtn" | ||
android:layout_height="wrap_content" | ||
android:layout_width="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:text="@string/on_off_level_btn_text" /> | ||
|
||
<Button | ||
android:id="@+id/multiAdminClusterBtn" | ||
android:layout_height="wrap_content" | ||
android:layout_width="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:text="@string/multi_admin_client_btn_text" /> | ||
<Button | ||
android:id="@+id/sensorClustersBtn" | ||
android:layout_height="wrap_content" | ||
android:layout_width="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:text="@string/sensor_client_btn_text" /> | ||
|
||
<Button | ||
android:id="@+id/opCredClustersBtn" | ||
android:layout_height="wrap_content" | ||
android:layout_width="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:text="@string/op_cred_client_btn_text" /> | ||
<Button | ||
android:id="@+id/multiAdminClusterBtn" | ||
android:layout_height="wrap_content" | ||
android:layout_width="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:text="@string/multi_admin_client_btn_text" /> | ||
|
||
<Button | ||
android:id="@+id/basicClusterBtn" | ||
android:layout_height="wrap_content" | ||
android:layout_width="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:text="@string/basic_cluster_btn_text" /> | ||
<Button | ||
android:id="@+id/opCredClustersBtn" | ||
android:layout_height="wrap_content" | ||
android:layout_width="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:text="@string/op_cred_client_btn_text" /> | ||
|
||
<Button | ||
android:id="@+id/attestationTestBtn" | ||
android:layout_height="wrap_content" | ||
android:layout_width="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:visibility="gone" | ||
android:text="@string/attestation_test_btn_text" /> | ||
<Button | ||
android:id="@+id/basicClusterBtn" | ||
android:layout_height="wrap_content" | ||
android:layout_width="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:text="@string/basic_cluster_btn_text" /> | ||
|
||
<Button | ||
android:id="@+id/wildcardBtn" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:text="@string/wildcard_btn_text" /> | ||
<Button | ||
android:id="@+id/attestationTestBtn" | ||
android:layout_height="wrap_content" | ||
android:layout_width="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:visibility="gone" | ||
android:text="@string/attestation_test_btn_text" /> | ||
|
||
<Button | ||
android:id="@+id/clusterInteractionBtn" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:text="@string/cluster_interaction_tool" /> | ||
<Button | ||
android:id="@+id/wildcardBtn" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:text="@string/wildcard_btn_text" /> | ||
|
||
</LinearLayout> | ||
<Button | ||
android:id="@+id/clusterInteractionBtn" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:text="@string/cluster_interaction_tool" /> | ||
|
||
</LinearLayout> | ||
|
||
</ScrollView> |
Oops, something went wrong.