Skip to content

Commit 3ecfb6c

Browse files
[Android] Implement Establish PASE Connection for SetupCode (#34971)
* Implement Establish PASE Connection for SetupCode * Restyled by google-java-format * Restyled by clang-format --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 2dc166f commit 3ecfb6c

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/controller/java/CHIPDeviceController-JNI.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,31 @@ JNI_METHOD(void, establishPaseConnectionByAddress)
852852
}
853853
}
854854

855+
JNI_METHOD(void, establishPaseConnectionByCode)
856+
(JNIEnv * env, jobject self, jlong handle, jlong deviceId, jstring setUpCode, jboolean useOnlyOnNetworkDiscovery)
857+
{
858+
chip::DeviceLayer::StackLock lock;
859+
CHIP_ERROR err = CHIP_NO_ERROR;
860+
AndroidDeviceControllerWrapper * wrapper = AndroidDeviceControllerWrapper::FromJNIHandle(handle);
861+
862+
auto discoveryType = DiscoveryType::kAll;
863+
if (useOnlyOnNetworkDiscovery)
864+
{
865+
discoveryType = DiscoveryType::kDiscoveryNetworkOnly;
866+
}
867+
868+
JniUtfString setUpCodeJniString(env, setUpCode);
869+
870+
err = wrapper->Controller()->EstablishPASEConnection(static_cast<chip::NodeId>(deviceId), setUpCodeJniString.c_str(),
871+
discoveryType);
872+
873+
if (err != CHIP_NO_ERROR)
874+
{
875+
ChipLogError(Controller, "Failed to establish PASE connection.");
876+
JniReferences::GetInstance().ThrowError(env, sChipDeviceControllerExceptionCls, err);
877+
}
878+
}
879+
855880
JNI_METHOD(void, continueCommissioning)
856881
(JNIEnv * env, jobject self, jlong handle, jlong devicePtr, jboolean ignoreAttestationFailure)
857882
{

src/controller/java/src/chip/devicecontroller/ChipDeviceController.java

+18
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,21 @@ public void establishPaseConnection(long deviceId, String address, int port, lon
470470
establishPaseConnectionByAddress(deviceControllerPtr, deviceId, address, port, setupPincode);
471471
}
472472

473+
/**
474+
* Establish a secure PASE connection using the scanned QR code or manual entry code.
475+
*
476+
* @param deviceId the ID of the node to connect to
477+
* @param setupCode the scanned QR code or manual entry code
478+
* @param useOnlyOnNetworkDiscovery the flag to indicate the commissionable device is available on
479+
* the network
480+
*/
481+
public void establishPaseConnection(
482+
long deviceId, String setupCode, boolean useOnlyOnNetworkDiscovery) {
483+
Log.d(TAG, "Establishing PASE connection using Code: " + setupCode);
484+
establishPaseConnectionByCode(
485+
deviceControllerPtr, deviceId, setupCode, useOnlyOnNetworkDiscovery);
486+
}
487+
473488
/**
474489
* Initiates the automatic commissioning flow using the specified network credentials. It is
475490
* expected that a secure session has already been established via {@link
@@ -1624,6 +1639,9 @@ private native void establishPaseConnection(
16241639
private native void establishPaseConnectionByAddress(
16251640
long deviceControllerPtr, long deviceId, String address, int port, long setupPincode);
16261641

1642+
private native void establishPaseConnectionByCode(
1643+
long deviceControllerPtr, long deviceId, String setupCode, boolean useOnlyOnNetworkDiscovery);
1644+
16271645
private native void commissionDevice(
16281646
long deviceControllerPtr,
16291647
long deviceId,

0 commit comments

Comments
 (0)