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 group message #29244

Merged
merged 28 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5445f81
Implement Android Group message
joonhaengHeo Sep 10, 2023
3bafe21
Add Android if_nameindex
joonhaengHeo Sep 14, 2023
42d8945
Add groupsetting API
joonhaengHeo Sep 14, 2023
45f9076
remove test code
joonhaengHeo Sep 14, 2023
6f169eb
Restyled by whitespace
restyled-commits Sep 14, 2023
bbc24a2
Restyled by google-java-format
restyled-commits Sep 14, 2023
3410310
Restyled by clang-format
restyled-commits Sep 14, 2023
38ad57e
Merge branch 'master' of github.com:joonhaengHeo/connectedhomeip into…
joonhaengHeo Sep 18, 2023
ff17937
Merge branch 'add_group_message' of github.com:joonhaengHeo/connected…
joonhaengHeo Sep 20, 2023
8db4f2a
Implement Group Setting UI
joonhaengHeo Sep 21, 2023
9f66423
restyle kotlin
joonhaengHeo Sep 21, 2023
fa32628
Merge branch 'master' into add_group_message
joonhaengHeo Sep 21, 2023
ebb365c
Merge branch 'master' into add_group_message
joonhaengHeo Sep 21, 2023
77ccbc6
Fix kotlin static code analysis
joonhaengHeo Sep 21, 2023
7baf985
Modify from comments.
joonhaengHeo Sep 25, 2023
4b9a3a0
Restyled by whitespace
restyled-commits Sep 25, 2023
f91a898
Restyled by google-java-format
restyled-commits Sep 25, 2023
b818d54
Restyled by clang-format
restyled-commits Sep 25, 2023
328dafb
kotlin restyle
joonhaengHeo Sep 25, 2023
e5af233
Merge branch 'master' into add_group_message
joonhaengHeo Sep 25, 2023
e8e32b3
Merge branch 'master' into add_group_message
joonhaengHeo Sep 25, 2023
cca6090
Modify return value
joonhaengHeo Sep 25, 2023
bb84169
Update group id in commandpath
joonhaengHeo Sep 26, 2023
09e3a9e
Update kotlin codestyle
joonhaengHeo Sep 26, 2023
b816916
Restyled by google-java-format
restyled-commits Sep 26, 2023
9e210d1
Restyled by clang-format
restyled-commits Sep 26, 2023
ef5f2ee
Update from comments
joonhaengHeo Sep 26, 2023
b7ccd42
Modify write path in group session
joonhaengHeo Sep 27, 2023
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 @@ -39,6 +39,7 @@ import com.google.chip.chiptool.setuppayloadscanner.BarcodeFragment
import com.google.chip.chiptool.setuppayloadscanner.CHIPDeviceDetailsFragment
import com.google.chip.chiptool.setuppayloadscanner.CHIPDeviceInfo
import com.google.chip.chiptool.setuppayloadscanner.CHIPLedgerDetailsFragment
import com.google.chip.chiptool.util.DeviceIdUtil
import org.json.JSONObject

class CHIPToolActivity :
Expand Down Expand Up @@ -94,11 +95,12 @@ class CHIPToolActivity :
}
}

override fun onCommissioningComplete(code: Int) {
override fun onCommissioningComplete(code: Int, nodeId: Long) {
runOnUiThread {
Toast.makeText(this, getString(R.string.commissioning_completed, code), Toast.LENGTH_SHORT)
.show()
}
DeviceIdUtil.setCommissionedNodeId(this, nodeId)
ChipClient.getDeviceController(this).close()
showFragment(SelectActionFragment.newInstance(), false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.google.chip.chiptool.attestation.AttestationTestFragment
import com.google.chip.chiptool.clusterclient.*
import com.google.chip.chiptool.clusterclient.GroupSettingFragment
import com.google.chip.chiptool.clusterclient.clusterinteraction.ClusterInteractionFragment
import com.google.chip.chiptool.databinding.SelectActionFragmentBinding
import com.google.chip.chiptool.provisioning.ProvisionNetworkType
Expand Down Expand Up @@ -71,6 +72,7 @@ class SelectActionFragment : Fragment() {
binding.provisionCustomFlowBtn.setOnClickListener { handleProvisionCustomFlowClicked() }
binding.wildcardBtn.setOnClickListener { handleWildcardClicked() }
binding.unpairDeviceBtn.setOnClickListener { handleUnpairDeviceClicked() }
binding.groupSettingBtn.setOnClickListener { handleGroupSettingClicked() }

return binding.root
}
Expand Down Expand Up @@ -233,6 +235,10 @@ class SelectActionFragment : Fragment() {
showFragment(BarcodeFragment.newInstance(), false)
}

private fun handleGroupSettingClicked() {
showFragment(GroupSettingFragment.newInstance())
}

companion object {

@JvmStatic fun newInstance() = SelectActionFragment()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.google.chip.chiptool.clusterclient

import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.AdapterView
import android.widget.ArrayAdapter
import androidx.fragment.app.Fragment
import chip.devicecontroller.ChipDeviceController
import com.google.chip.chiptool.ChipClient
Expand Down Expand Up @@ -41,13 +45,70 @@ class AddressUpdateFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)

val compressedFabricId = deviceController.compressedFabricId
binding.fabricIdEd.setText(compressedFabricId.toULong().toString(16).padStart(16, '0'))
binding.deviceIdEd.setText(DeviceIdUtil.getLastDeviceId(requireContext()).toString())
binding.fabricIdEd.setText(compressedFabricId.toULong().toString().padStart(16, '0'))
binding.deviceIdEd.setText(DeviceIdUtil.getLastDeviceId(requireContext()).toString(16))
binding.epIdEd.setText(endpointId.toString())

updateDeviceIdSpinner()
}

fun updateDeviceIdSpinner() {
val deviceIdList = DeviceIdUtil.getCommissionedNodeId(requireContext())
binding.deviceIdSpinner.adapter =
ArrayAdapter(requireContext(), android.R.layout.simple_spinner_dropdown_item, deviceIdList)
binding.deviceIdSpinner.onItemSelectedListener =
object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
binding.deviceIdEd.setText(deviceIdList[position].toULong(16).toString())
}

override fun onNothingSelected(parent: AdapterView<*>?) {
Log.d(TAG, "onNothingSelected")
}
}
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}

suspend fun getDevicePointer(context: Context): Long {
return if (isGroupId()) {
deviceController.getGroupDevicePointer(getGroupId().toInt())
} else {
ChipClient.getConnectedDevicePointer(context, getNodeId().toLong())
}
}

fun isGroupId(): Boolean {
return isGroupNodeId(getNodeId())
}

fun getGroupId(): UInt {
return getGroupIdFromNodeId(getNodeId())
}

fun getNodeId(): ULong {
return binding.deviceIdEd.text.toString().toULong()
}

companion object {
private const val TAG = "AddressUpdateFragment"
// Refer from NodeId.h (src/lib/core/NodeId.h)
private const val MIN_GROUP_NODE_ID = 0xFFFF_FFFF_FFFF_0000UL
private const val MASK_GROUP_ID = 0x0000_0000_0000_FFFFUL

fun isGroupNodeId(nodeId: ULong): Boolean {
return nodeId >= MIN_GROUP_NODE_ID
}

fun getNodeIdFromGroupId(groupId: UInt): ULong {
return groupId.toULong() or MIN_GROUP_NODE_ID
}

fun getGroupIdFromNodeId(nodeId: ULong): UInt {
return (nodeId and MASK_GROUP_ID).toUInt()
}
}
}
Loading