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] Support random pincode #25511

Merged
merged 5 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -107,9 +107,14 @@ class MultiAdminClientFragment : Fragment() {
val testIteration = 1000
val devicePointer =
ChipClient.getConnectedDevicePointer(requireContext(), addressUpdateFragment.deviceId)

var setupPinCode: Long? = null
if (!binding.setupPinCodeEd.text.toString().isEmpty()) {
setupPinCode = binding.setupPinCodeEd.text.toString().toULong().toLong()
}
deviceController.openPairingWindowWithPINCallback(
devicePointer, testDuration, testIteration.toLong(),
binding.discriminatorEd.text.toString().toInt(), binding.setupPinCodeEd.text.toString().toULong().toLong(),
binding.discriminatorEd.text.toString().toInt(), setupPinCode,
object:OpenCommissioningCallback {
override fun onError(status: Int, deviceId: Long) {
showMessage("OpenCommissioning Fail! \nDevice ID : $deviceId\nErrorCode : $status")
Expand Down
25 changes: 20 additions & 5 deletions src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,8 @@ JNI_METHOD(jboolean, openPairingWindow)(JNIEnv * env, jobject self, jlong handle
}

JNI_METHOD(jboolean, openPairingWindowWithPIN)
(JNIEnv * env, jobject self, jlong handle, jlong devicePtr, jint duration, jlong iteration, jint discriminator, jlong setupPinCode)
(JNIEnv * env, jobject self, jlong handle, jlong devicePtr, jint duration, jlong iteration, jint discriminator,
jobject setupPinCode)
{
VerifyOrReturnValue(chip::CanCastTo<uint32_t>(iteration), false);

Expand All @@ -1149,10 +1150,17 @@ JNI_METHOD(jboolean, openPairingWindowWithPIN)

AndroidDeviceControllerWrapper * wrapper = AndroidDeviceControllerWrapper::FromJNIHandle(handle);

Optional<uint32_t> pinCode = Optional<uint32_t>();
if (setupPinCode != nullptr)
{
jlong jsetupPinCode = chip::JniReferences::GetInstance().LongToPrimitive(setupPinCode);
pinCode = MakeOptional(static_cast<uint32_t>(jsetupPinCode));
}

chip::SetupPayload setupPayload;
err = AutoCommissioningWindowOpener::OpenCommissioningWindow(
wrapper->Controller(), chipDevice->GetDeviceId(), System::Clock::Seconds16(duration), static_cast<uint32_t>(iteration),
discriminator, MakeOptional(static_cast<uint32_t>(setupPinCode)), NullOptional, setupPayload);
discriminator, pinCode, NullOptional, setupPayload);

if (err != CHIP_NO_ERROR)
{
Expand Down Expand Up @@ -1191,8 +1199,8 @@ JNI_METHOD(jboolean, openPairingWindowCallback)
}

JNI_METHOD(jboolean, openPairingWindowWithPINCallback)
(JNIEnv * env, jobject self, jlong handle, jlong devicePtr, jint duration, jlong iteration, jint discriminator, jlong setupPinCode,
jobject jcallback)
(JNIEnv * env, jobject self, jlong handle, jlong devicePtr, jint duration, jlong iteration, jint discriminator,
jobject setupPinCode, jobject jcallback)
{
VerifyOrReturnValue(chip::CanCastTo<uint32_t>(iteration), false);

Expand All @@ -1208,10 +1216,17 @@ JNI_METHOD(jboolean, openPairingWindowWithPINCallback)

AndroidDeviceControllerWrapper * wrapper = AndroidDeviceControllerWrapper::FromJNIHandle(handle);

Optional<uint32_t> pinCode = Optional<uint32_t>();
if (setupPinCode != nullptr)
{
jlong jsetupPinCode = chip::JniReferences::GetInstance().LongToPrimitive(setupPinCode);
pinCode = MakeOptional(static_cast<uint32_t>(jsetupPinCode));
}

chip::SetupPayload setupPayload;
err = AndroidCommissioningWindowOpener::OpenCommissioningWindow(
wrapper->Controller(), chipDevice->GetDeviceId(), System::Clock::Seconds16(duration), static_cast<uint32_t>(iteration),
discriminator, MakeOptional(static_cast<uint32_t>(setupPinCode)), NullOptional, jcallback, setupPayload);
discriminator, pinCode, NullOptional, jcallback, setupPayload);

if (err != CHIP_NO_ERROR)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ public boolean openPairingWindow(long devicePtr, int duration) {
}

public boolean openPairingWindowWithPIN(
long devicePtr, int duration, long iteration, int discriminator, long setupPinCode) {
long devicePtr, int duration, long iteration, int discriminator, Long setupPinCode) {
return openPairingWindowWithPIN(
deviceControllerPtr, devicePtr, duration, iteration, discriminator, setupPinCode);
}
Expand All @@ -482,7 +482,7 @@ public boolean openPairingWindowWithPINCallback(
int duration,
long iteration,
int discriminator,
long setupPinCode,
Long setupPinCode,
OpenCommissioningCallback callback) {
return openPairingWindowWithPINCallback(
deviceControllerPtr, devicePtr, duration, iteration, discriminator, setupPinCode, callback);
Expand Down Expand Up @@ -809,7 +809,7 @@ private native boolean openPairingWindowWithPIN(
int duration,
long iteration,
int discriminator,
long setupPinCode);
Long setupPinCode);
joonhaengHeo marked this conversation as resolved.
Show resolved Hide resolved

private native boolean openPairingWindowCallback(
long deviceControllerPtr, long devicePtr, int duration, OpenCommissioningCallback callback);
Expand All @@ -820,7 +820,7 @@ private native boolean openPairingWindowWithPINCallback(
int duration,
long iteration,
int discriminator,
long setupPinCode,
Long setupPinCode,
OpenCommissioningCallback callback);

private native byte[] getAttestationChallenge(long deviceControllerPtr, long devicePtr);
Expand Down