Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Make openPairingWindow accept a device pointer #10590

Merged
merged 1 commit into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,23 @@ class MultiAdminClientFragment : Fragment() {
scope.cancel()
}

private fun sendBasicCommissioningCommandClick() {
private suspend fun sendBasicCommissioningCommandClick() {
val testDuration = 100
deviceController.openPairingWindow(addressUpdateFragment.deviceId, testDuration)
deviceController.openPairingWindow(
ChipClient.getConnectedDevicePointer(
requireContext(),
addressUpdateFragment.deviceId
), testDuration
)
}

private fun sendEnhancedCommissioningCommandClick() {
private suspend fun sendEnhancedCommissioningCommandClick() {
val testDuration = 100
val testIteration = 800
val devicePointer =
ChipClient.getConnectedDevicePointer(requireContext(), addressUpdateFragment.deviceId)
deviceController.openPairingWindowWithPIN(
addressUpdateFragment.deviceId, testDuration, testIteration,
devicePointer, testDuration, testIteration,
discriminatorEd.text.toString().toInt(), setupPinCodeEd.text.toString().toULong().toLong()
)
}
Expand Down
24 changes: 16 additions & 8 deletions src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,18 @@ JNI_METHOD(void, updateDevice)(JNIEnv * env, jobject self, jlong handle, jlong f
}
}

JNI_METHOD(jboolean, openPairingWindow)(JNIEnv * env, jobject self, jlong handle, jlong deviceId, jint duration)
JNI_METHOD(jboolean, openPairingWindow)(JNIEnv * env, jobject self, jlong handle, jlong devicePtr, jint duration)
{
chip::DeviceLayer::StackLock lock;
CHIP_ERROR err = CHIP_NO_ERROR;
Device * chipDevice = nullptr;
CHIP_ERROR err = CHIP_NO_ERROR;
chip::SetupPayload setupPayload;

GetCHIPDevice(env, handle, deviceId, &chipDevice);
Device * chipDevice = reinterpret_cast<Device *>(devicePtr);
if (chipDevice == nullptr)
{
ChipLogProgress(Controller, "Could not cast device pointer to Device object");
return false;
}

err = chipDevice->OpenPairingWindow(duration, chip::Controller::Device::CommissioningWindowOption::kOriginalSetupCode,
setupPayload);
Expand All @@ -427,16 +431,20 @@ JNI_METHOD(jboolean, openPairingWindow)(JNIEnv * env, jobject self, jlong handle
}

JNI_METHOD(jboolean, openPairingWindowWithPIN)
(JNIEnv * env, jobject self, jlong handle, jlong deviceId, jint duration, jint iteration, jint discriminator, jlong setupPinCode)
(JNIEnv * env, jobject self, jlong handle, jlong devicePtr, jint duration, jint iteration, jint discriminator, jlong setupPinCode)
{
chip::DeviceLayer::StackLock lock;
CHIP_ERROR err = CHIP_NO_ERROR;
Device * chipDevice = nullptr;
CHIP_ERROR err = CHIP_NO_ERROR;
chip::SetupPayload setupPayload;
setupPayload.discriminator = discriminator;
setupPayload.setUpPINCode = setupPinCode;

GetCHIPDevice(env, handle, deviceId, &chipDevice);
Device * chipDevice = reinterpret_cast<Device *>(devicePtr);
if (chipDevice == nullptr)
{
ChipLogProgress(Controller, "Could not cast device pointer to Device object");
return false;
}

err = chipDevice->OpenPairingWindow(duration, chip::Controller::Device::CommissioningWindowOption::kTokenWithRandomPIN,
setupPayload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,14 @@ public void updateDevice(long fabricId, long deviceId) {
updateDevice(deviceControllerPtr, fabricId, deviceId);
}

public boolean openPairingWindow(long deviceId, int duration) {
return openPairingWindow(deviceControllerPtr, deviceId, duration);
public boolean openPairingWindow(long devicePtr, int duration) {
return openPairingWindow(deviceControllerPtr, devicePtr, duration);
}

public boolean openPairingWindowWithPIN(
long deviceId, int duration, int iteration, int discriminator, long setupPinCode) {
long devicePtr, int duration, int iteration, int discriminator, long setupPinCode) {
return openPairingWindowWithPIN(
deviceControllerPtr, deviceId, duration, iteration, discriminator, setupPinCode);
deviceControllerPtr, devicePtr, duration, iteration, discriminator, setupPinCode);
}

public boolean isActive(long deviceId) {
Expand Down Expand Up @@ -257,11 +257,11 @@ private native void getConnectedDevicePointer(

private native void updateDevice(long deviceControllerPtr, long fabricId, long deviceId);

private native boolean openPairingWindow(long deviceControllerPtr, long deviceId, int duration);
private native boolean openPairingWindow(long deviceControllerPtr, long devicePtr, int duration);

private native boolean openPairingWindowWithPIN(
long deviceControllerPtr,
long deviceId,
long devicePtr,
int duration,
int iteration,
int discriminator,
Expand Down