Skip to content

Commit

Permalink
Implement remove ICD Client Info in Android platform
Browse files Browse the repository at this point in the history
  • Loading branch information
joonhaengHeo committed Jun 11, 2024
1 parent c158260 commit 4156766
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import chip.devicecontroller.ChipDeviceController
import chip.devicecontroller.ChipICDClient
import chip.devicecontroller.UnpairDeviceCallback
import com.google.chip.chiptool.ChipClient
import com.google.chip.chiptool.R
import com.google.chip.chiptool.clusterclient.AddressUpdateFragment
import com.google.chip.chiptool.databinding.UnpairDeviceFragmentBinding
import com.google.chip.chiptool.util.DeviceIdUtil
import kotlinx.coroutines.*

class UnpairDeviceFragment : Fragment() {
Expand Down Expand Up @@ -63,6 +65,21 @@ class UnpairDeviceFragment : Fragment() {
addressUpdateFragment.deviceId,
ChipUnpairDeviceCallback()
)

// Remove ICD Client info
if (addressUpdateFragment.isICDDevice()) {
ChipICDClient.removeICDClientInfo(
deviceController.fabricIndex,
addressUpdateFragment.deviceId
)

Log.d(TAG, "ICDClientInfo : ${ChipICDClient.getICDClientInfo(deviceController.fabricIndex)}")
}
requireActivity().runOnUiThread {
Log.d(TAG, "remove : ${addressUpdateFragment.deviceId}")
DeviceIdUtil.removeCommissionedNodeId(requireContext(), addressUpdateFragment.deviceId)
addressUpdateFragment.updateDeviceIdSpinner()
}
}

companion object {
Expand Down
13 changes: 13 additions & 0 deletions src/controller/java/AndroidICDClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ jobject getICDClientInfo(JNIEnv * env, const char * icdClientInfoSign, jint jFab
return jInfo;
}

jlong removeICDClientInfo(JNIEnv * env, jint jFabricIndex, jlong jNodeId)
{
CHIP_ERROR err = CHIP_NO_ERROR;

chip::ScopedNodeId scopedNodeId(static_cast<chip::NodeId>(jNodeId), static_cast<chip::FabricIndex>(jFabricIndex));
err = getICDClientStorage()->DeleteEntry(scopedNodeId);
if (err != CHIP_NO_ERROR)
{
ChipLogError(Controller, "removeICDClientInfo error!: %" CHIP_ERROR_FORMAT, err.Format());
}
return static_cast<jlong>(err.AsInteger());
}

chip::app::DefaultICDClientStorage * getICDClientStorage()
{
return &sICDClientStorage;
Expand Down
2 changes: 2 additions & 0 deletions src/controller/java/AndroidICDClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@

jobject getICDClientInfo(JNIEnv * env, const char * icdClientInfoSign, jint jFabricIndex);

jlong removeICDClientInfo(JNIEnv * env, jint jFabricIndex, jlong jNodeId);

chip::app::DefaultICDClientStorage * getICDClientStorage();
6 changes: 6 additions & 0 deletions src/controller/java/CHIPICDClient-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ JNI_METHOD(jobject, getICDClientInfo)(JNIEnv * env, jobject self, jint jFabricIn

return getICDClientInfo(env, "chip/devicecontroller/ICDClientInfo", jFabricIndex);
}

JNI_METHOD(void, removeICDClientInfo)(JNIEnv * env, jobject self, jint jFabricIndex, jlong jNodeId)
{
chip::DeviceLayer::StackLock lock;
removeICDClientInfo(env, jFabricIndex, jNodeId);
}
6 changes: 6 additions & 0 deletions src/controller/java/MatterICDClient-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ JNI_METHOD(jobject, getICDClientInfo)(JNIEnv * env, jobject self, jint jFabricIn

return getICDClientInfo(env, "matter/controller/ICDClientInfo", jFabricIndex);
}

JNI_METHOD(void, removeICDClientInfo)(JNIEnv * env, jobject self, jint jFabricIndex, jlong jNodeId)
{
chip::DeviceLayer::StackLock lock;
removeICDClientInfo(env, jFabricIndex, jNodeId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ public static boolean isPeerICDClient(int fabricIndex, long deviceId) {
return clientInfo.stream().anyMatch(info -> info.getPeerNodeId() == deviceId);
}

public static native void removeICDClientInfo(int fabricIndex, long deviceId);

public static native List<ICDClientInfo> getICDClientInfo(int fabricIndex);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ object MatterICDClientImpl {
}

external fun getICDClientInfo(fabricIndex: Int): List<ICDClientInfo>?

external fun removeICDClientInfo(fabricIndex: Int, deviceId: Long)
}

0 comments on commit 4156766

Please sign in to comment.