Skip to content

Commit ecfb786

Browse files
joonhaengHeobzbarsky-apple
authored andcommitted
[Android] Modify chiptool crash when skipCommissioningComplete flag enabled (project-chip#32807)
* Modify android chiptool crash * Update src/controller/CHIPDeviceController.cpp Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> * Change FindCommissionedDevice timing * Change CommissioningStageComplete call timing --------- Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
1 parent 180ee0d commit ecfb786

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/controller/CHIPDeviceController.cpp

+16-3
Original file line numberDiff line numberDiff line change
@@ -1844,13 +1844,25 @@ void DeviceCommissioner::CleanupCommissioning(DeviceProxy * proxy, NodeId nodeId
18441844

18451845
if (completionStatus.err == CHIP_NO_ERROR)
18461846
{
1847+
// CommissioningStageComplete uses mDeviceBeingCommissioned, which can
1848+
// be commissionee if we are cleaning up before we've gone operational. Normally
1849+
// that would not happen in this non-error case, _except_ if we were told to skip sending
1850+
// CommissioningComplete: in that case we do not have an operational DeviceProxy, so
1851+
// we're using our CommissioneeDeviceProxy to do a successful cleanup.
1852+
//
1853+
// This means we have to call CommissioningStageComplete() before we destroy commissionee.
1854+
//
1855+
// This should be safe, because CommissioningStageComplete() does not call CleanupCommissioning
1856+
// when called in the cleanup stage (which is where we are), and StopPairing does not directly release
1857+
// mDeviceBeingCommissioned.
1858+
CommissioningStageComplete(CHIP_NO_ERROR);
1859+
18471860
CommissioneeDeviceProxy * commissionee = FindCommissioneeDevice(nodeId);
18481861
if (commissionee != nullptr)
18491862
{
18501863
ReleaseCommissioneeDevice(commissionee);
18511864
}
18521865
// Send the callbacks, we're done.
1853-
CommissioningStageComplete(CHIP_NO_ERROR);
18541866
SendCommissioningCompleteCallbacks(nodeId, mCommissioningCompletionStatus);
18551867
}
18561868
else if (completionStatus.err == CHIP_ERROR_CANCELLED)
@@ -1929,12 +1941,13 @@ void DeviceCommissioner::CleanupDoneAfterError()
19291941
VerifyOrReturn(mDeviceBeingCommissioned != nullptr);
19301942

19311943
NodeId nodeId = mDeviceBeingCommissioned->GetDeviceId();
1932-
// At this point, we also want to close off the pase session so we need to re-establish
1933-
CommissioneeDeviceProxy * commissionee = FindCommissioneeDevice(nodeId);
19341944

19351945
// Signal completion - this will reset mDeviceBeingCommissioned.
19361946
CommissioningStageComplete(CHIP_NO_ERROR);
19371947

1948+
// At this point, we also want to close off the pase session so we need to re-establish
1949+
CommissioneeDeviceProxy * commissionee = FindCommissioneeDevice(nodeId);
1950+
19381951
// If we've disarmed the failsafe, it's because we're starting again, so kill the pase connection.
19391952
if (commissionee != nullptr)
19401953
{

0 commit comments

Comments
 (0)