Skip to content

Commit d82e05e

Browse files
committed
Restyled
1 parent de3da7c commit d82e05e

File tree

9 files changed

+111
-72
lines changed

9 files changed

+111
-72
lines changed

examples/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/clusterclient/DiagnosticLogFragment.kt

+8-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import com.google.chip.chiptool.databinding.DiagnosticLogFragmentBinding
2121
import java.io.File
2222
import java.io.FileOutputStream
2323
import java.io.IOException
24-
import kotlinx.coroutines.*
24+
import kotlinx.coroutines.CoroutineScope
25+
import kotlinx.coroutines.launch
2526

2627
class DiagnosticLogFragment : Fragment() {
2728
private val deviceController: ChipDeviceController
@@ -87,18 +88,18 @@ class DiagnosticLogFragment : Fragment() {
8788
mDownloadFile?.let { showNotification(it) } ?: return
8889
}
8990

90-
override fun onTransferData(
91-
fabricIndex: Int,
92-
nodeId: Long,
93-
data: ByteArray
94-
): Boolean {
91+
override fun onTransferData(fabricIndex: Int, nodeId: Long, data: ByteArray): Boolean {
9592
Log.d(TAG, "onTransferData : ${data.size}")
9693
if (mDownloadFileOutputStream == null) {
9794
Log.d(TAG, "mDownloadFileOutputStream or mDownloadFile is null")
9895
return false
9996
}
97+
return addData(mDownloadFileOutputStream!!, data)
98+
}
99+
100+
private fun addData(outputStream: FileOutputStream, data: ByteArray): Boolean {
100101
try {
101-
mDownloadFileOutputStream!!.write(data)
102+
outputStream.write(data)
102103
} catch (e: IOException) {
103104
Log.d(TAG, "IOException", e)
104105
return false

kotlin-detect-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ exceptions:
231231
- "**/examples/java-matter-controller/java/src/com/matter/controller/commands/common/Argument.kt"
232232
TooGenericExceptionThrown:
233233
excludes:
234+
- "**/examples/java-matter-controller/java/src/com/matter/controller/commands/bdx/DownloadLogCommand.kt"
234235
- "**/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommissionablesCommand.kt"
235236
- "**/src/controller/java/generated/java/**/*"
236237
ThrowingExceptionsWithoutMessageOrCause:

src/controller/java/AndroidLogDownloadFromNode.cpp

+43-30
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
#include "AndroidLogDownloadFromNode.h"
2020

21-
#include <controller/CHIPDeviceControllerFactory.h>
22-
#include <protocols/bdx/BdxUri.h>
2321
#include <app-common/zap-generated/cluster-enums.h>
2422
#include <app-common/zap-generated/cluster-objects.h>
23+
#include <controller/CHIPDeviceControllerFactory.h>
24+
#include <protocols/bdx/BdxUri.h>
2525

2626
using namespace chip::app::Clusters;
2727

@@ -30,8 +30,9 @@ namespace Controller {
3030

3131
// Max Length is below 8
3232
CharSpan toIntentCharSpan(DiagnosticLogs::IntentEnum intent)
33-
{
34-
switch (intent) {
33+
{
34+
switch (intent)
35+
{
3536
case DiagnosticLogs::IntentEnum::kEndUserSupport:
3637
return CharSpan::fromCharString("EndUser");
3738
case DiagnosticLogs::IntentEnum::kNetworkDiag:
@@ -43,16 +44,17 @@ CharSpan toIntentCharSpan(DiagnosticLogs::IntentEnum intent)
4344
}
4445
}
4546

46-
AndroidLogDownloadFromNode::AndroidLogDownloadFromNode(chip::Controller::DeviceController * controller, NodeId remoteNodeId, DiagnosticLogs::IntentEnum intent, uint16_t timeout, jobject jCallbackObject)
47-
: mController(controller), mOnDeviceConnectedCallback(&OnDeviceConnectedFn, this),
48-
mOnDeviceConnectionFailureCallback(&OnDeviceConnectionFailureFn, this),
49-
mOnBdxTransferCallback(&OnBdxTransferCallback, this),
50-
mOnBdxTransferSuccessCallback(&OnBdxTransferSuccessCallback, this),
47+
AndroidLogDownloadFromNode::AndroidLogDownloadFromNode(chip::Controller::DeviceController * controller, NodeId remoteNodeId,
48+
DiagnosticLogs::IntentEnum intent, uint16_t timeout,
49+
jobject jCallbackObject) :
50+
mController(controller),
51+
mOnDeviceConnectedCallback(&OnDeviceConnectedFn, this), mOnDeviceConnectionFailureCallback(&OnDeviceConnectionFailureFn, this),
52+
mOnBdxTransferCallback(&OnBdxTransferCallback, this), mOnBdxTransferSuccessCallback(&OnBdxTransferSuccessCallback, this),
5153
mOnBdxTransferFailureCallback(&OnBdxTransferFailureCallback, this)
5254
{
5355
mRemoteNodeId = remoteNodeId;
54-
mIntent = intent;
55-
mTimeout = timeout;
56+
mIntent = intent;
57+
mTimeout = timeout;
5658

5759
if (mJavaCallback.Init(jCallbackObject) != CHIP_NO_ERROR)
5860
{
@@ -61,9 +63,11 @@ AndroidLogDownloadFromNode::AndroidLogDownloadFromNode(chip::Controller::DeviceC
6163
}
6264
}
6365

64-
CHIP_ERROR AndroidLogDownloadFromNode::LogDownloadFromNode(DeviceController * controller, NodeId remoteNodeId, DiagnosticLogs::IntentEnum intent, uint16_t timeout, jobject jcallback)
66+
CHIP_ERROR AndroidLogDownloadFromNode::LogDownloadFromNode(DeviceController * controller, NodeId remoteNodeId,
67+
DiagnosticLogs::IntentEnum intent, uint16_t timeout, jobject jcallback)
6568
{
66-
VerifyOrReturnValue(controller != nullptr && jcallback != nullptr && remoteNodeId != kUndefinedNodeId, CHIP_ERROR_INVALID_ARGUMENT);
69+
VerifyOrReturnValue(controller != nullptr && jcallback != nullptr && remoteNodeId != kUndefinedNodeId,
70+
CHIP_ERROR_INVALID_ARGUMENT);
6771

6872
auto * logDownload = new AndroidLogDownloadFromNode(controller, remoteNodeId, intent, timeout, jcallback);
6973
VerifyOrReturnValue(logDownload != nullptr, CHIP_ERROR_NO_MEMORY);
@@ -84,10 +88,11 @@ CHIP_ERROR AndroidLogDownloadFromNode::GetConnectedDevice()
8488
return mController->GetConnectedDevice(mRemoteNodeId, &mOnDeviceConnectedCallback, &mOnDeviceConnectionFailureCallback);
8589
}
8690

87-
CHIP_ERROR AndroidLogDownloadFromNode::SendRetrieveLogsRequest(Messaging::ExchangeManager & exchangeMgr, const SessionHandle & sessionHandle)
91+
CHIP_ERROR AndroidLogDownloadFromNode::SendRetrieveLogsRequest(Messaging::ExchangeManager & exchangeMgr,
92+
const SessionHandle & sessionHandle)
8893
{
8994
DiagnosticLogs::Commands::RetrieveLogsRequest::Type request;
90-
request.intent = mIntent;
95+
request.intent = mIntent;
9196
request.requestedProtocol = DiagnosticLogs::TransferProtocolEnum::kBdx;
9297

9398
CHIP_ERROR err = chip::bdx::MakeURI(mRemoteNodeId, toIntentCharSpan(mIntent), mFileDesignator);
@@ -97,7 +102,9 @@ CHIP_ERROR AndroidLogDownloadFromNode::SendRetrieveLogsRequest(Messaging::Exchan
97102
FinishLogDownloadFromNode(err);
98103
}
99104

100-
mBdxReceiver = new BdxDiagnosticLogsReceiver(&mOnBdxTransferCallback, &mOnBdxTransferSuccessCallback, &mOnBdxTransferFailureCallback, mController->GetFabricIndex(), mRemoteNodeId, mFileDesignator);
105+
mBdxReceiver =
106+
new BdxDiagnosticLogsReceiver(&mOnBdxTransferCallback, &mOnBdxTransferSuccessCallback, &mOnBdxTransferFailureCallback,
107+
mController->GetFabricIndex(), mRemoteNodeId, mFileDesignator);
101108
VerifyOrReturnValue(mBdxReceiver != nullptr, CHIP_ERROR_NO_MEMORY);
102109

103110
auto systemState = DeviceControllerFactory::GetInstance().GetSystemState();
@@ -107,15 +114,15 @@ CHIP_ERROR AndroidLogDownloadFromNode::SendRetrieveLogsRequest(Messaging::Exchan
107114
{
108115
mBdxReceiver->StartBDXTransferTimeout(mTimeout);
109116
}
110-
117+
111118
request.transferFileDesignator = MakeOptional(mFileDesignator);
112119
ClusterBase cluster(exchangeMgr, sessionHandle, 0);
113120

114121
return cluster.InvokeCommand(request, this, OnResponseRetrieveLogs, OnCommandFailure);
115122
}
116123

117124
void AndroidLogDownloadFromNode::OnDeviceConnectedFn(void * context, Messaging::ExchangeManager & exchangeMgr,
118-
const SessionHandle & sessionHandle)
125+
const SessionHandle & sessionHandle)
119126
{
120127
CHIP_ERROR err = CHIP_NO_ERROR;
121128
auto * self = static_cast<AndroidLogDownloadFromNode *>(context);
@@ -139,7 +146,8 @@ void AndroidLogDownloadFromNode::OnDeviceConnectionFailureFn(void * context, con
139146
self->FinishLogDownloadFromNode(err);
140147
}
141148

142-
void AndroidLogDownloadFromNode::OnResponseRetrieveLogs(void * context, const DiagnosticLogs::Commands::RetrieveLogsResponse::DecodableType & data)
149+
void AndroidLogDownloadFromNode::OnResponseRetrieveLogs(void * context,
150+
const DiagnosticLogs::Commands::RetrieveLogsResponse::DecodableType & data)
143151
{
144152
auto * self = static_cast<AndroidLogDownloadFromNode *>(context);
145153
VerifyOrReturn(self != nullptr,
@@ -189,7 +197,7 @@ void AndroidLogDownloadFromNode::OnCommandFailure(void * context, CHIP_ERROR err
189197
void AndroidLogDownloadFromNode::FinishLogDownloadFromNode(CHIP_ERROR err)
190198
{
191199
CHIP_ERROR jniErr = CHIP_NO_ERROR;
192-
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
200+
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
193201
JniLocalReferenceScope scope(env);
194202

195203
if (err == CHIP_NO_ERROR)
@@ -201,7 +209,8 @@ void AndroidLogDownloadFromNode::FinishLogDownloadFromNode(CHIP_ERROR err)
201209

202210
VerifyOrReturn(jniErr == CHIP_NO_ERROR, ChipLogError(Controller, "Could not find onSuccess method"));
203211

204-
env->CallVoidMethod(mJavaCallback.ObjectRef(), onSuccessMethod, static_cast<jint>(mController->GetFabricIndex()), static_cast<jlong>(mRemoteNodeId));
212+
env->CallVoidMethod(mJavaCallback.ObjectRef(), onSuccessMethod, static_cast<jint>(mController->GetFabricIndex()),
213+
static_cast<jlong>(mRemoteNodeId));
205214
return;
206215
}
207216

@@ -222,18 +231,21 @@ void AndroidLogDownloadFromNode::FinishLogDownloadFromNode(CHIP_ERROR err)
222231
jniErr = JniReferences::GetInstance().FindMethod(env, mJavaCallback.ObjectRef(), "onError", "(IJJ)V", &onErrorMethod);
223232
VerifyOrReturn(jniErr == CHIP_NO_ERROR, ChipLogError(Controller, "Could not find onError method"));
224233

225-
env->CallVoidMethod(mJavaCallback.ObjectRef(), onErrorMethod, static_cast<jint>(mController->GetFabricIndex()), static_cast<jlong>(mRemoteNodeId), static_cast<jlong>(err.AsInteger()));
234+
env->CallVoidMethod(mJavaCallback.ObjectRef(), onErrorMethod, static_cast<jint>(mController->GetFabricIndex()),
235+
static_cast<jlong>(mRemoteNodeId), static_cast<jlong>(err.AsInteger()));
226236
}
227237

228-
void AndroidLogDownloadFromNode::OnBdxTransferCallback(void * context, FabricIndex fabricIndex, NodeId remoteNodeId, const chip::ByteSpan & data, CHIP_ERROR *errInfoOnFailure)
238+
void AndroidLogDownloadFromNode::OnBdxTransferCallback(void * context, FabricIndex fabricIndex, NodeId remoteNodeId,
239+
const chip::ByteSpan & data, CHIP_ERROR * errInfoOnFailure)
229240
{
230241
auto * self = static_cast<AndroidLogDownloadFromNode *>(context);
231242
VerifyOrReturn(self != nullptr, ChipLogProgress(Controller, "Send command failure callback with null context. Ignoring"));
232243

233244
self->OnTransferCallback(fabricIndex, remoteNodeId, data, errInfoOnFailure);
234245
}
235246

236-
void AndroidLogDownloadFromNode::OnTransferCallback(FabricIndex fabricIndex, NodeId remoteNodeId, const chip::ByteSpan & data, CHIP_ERROR *errInfoOnFailure)
247+
void AndroidLogDownloadFromNode::OnTransferCallback(FabricIndex fabricIndex, NodeId remoteNodeId, const chip::ByteSpan & data,
248+
CHIP_ERROR * errInfoOnFailure)
237249
{
238250
VerifyOrReturn(mJavaCallback.HasValidObjectRef(), ChipLogError(Controller, "mJavaCallback is invalid"));
239251

@@ -242,17 +254,17 @@ void AndroidLogDownloadFromNode::OnTransferCallback(FabricIndex fabricIndex, Nod
242254

243255
jmethodID onTransferDataMethod;
244256
// Java method signature : boolean onTransferData(int fabricIndex, long nodeId, byte[] data)
245-
*errInfoOnFailure = JniReferences::GetInstance().FindMethod(env, mJavaCallback.ObjectRef(), "onTransferData",
246-
"(IJ[B)Z", &onTransferDataMethod);
257+
*errInfoOnFailure =
258+
JniReferences::GetInstance().FindMethod(env, mJavaCallback.ObjectRef(), "onTransferData", "(IJ[B)Z", &onTransferDataMethod);
247259
VerifyOrReturn(*errInfoOnFailure == CHIP_NO_ERROR, ChipLogError(Controller, "Could not find onTransferData method"));
248260
chip::ByteArray dataByteArray(env, data);
249261

250-
jboolean ret = env->CallBooleanMethod(mJavaCallback.ObjectRef(), onTransferDataMethod, static_cast<jint>(fabricIndex), static_cast<jlong>(remoteNodeId), dataByteArray.jniValue());
262+
jboolean ret = env->CallBooleanMethod(mJavaCallback.ObjectRef(), onTransferDataMethod, static_cast<jint>(fabricIndex),
263+
static_cast<jlong>(remoteNodeId), dataByteArray.jniValue());
251264

252265
if (ret != JNI_TRUE)
253266
{
254-
ChipLogError(Controller, "Transfer will be rejected.")
255-
*errInfoOnFailure = CHIP_ERROR_INTERNAL;
267+
ChipLogError(Controller, "Transfer will be rejected.") * errInfoOnFailure = CHIP_ERROR_INTERNAL;
256268
}
257269
}
258270

@@ -266,7 +278,8 @@ void AndroidLogDownloadFromNode::OnBdxTransferSuccessCallback(void * context, Fa
266278
self->FinishLogDownloadFromNode(CHIP_NO_ERROR);
267279
}
268280

269-
void AndroidLogDownloadFromNode::OnBdxTransferFailureCallback(void * context, FabricIndex fabricIndex, NodeId remoteNodeId, CHIP_ERROR status)
281+
void AndroidLogDownloadFromNode::OnBdxTransferFailureCallback(void * context, FabricIndex fabricIndex, NodeId remoteNodeId,
282+
CHIP_ERROR status)
270283
{
271284
ChipLogProgress(Controller, "OnBdxTransferFailureCallback: %" CHIP_ERROR_FORMAT, status.Format());
272285

src/controller/java/AndroidLogDownloadFromNode.h

+13-7
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@ class AndroidLogDownloadFromNode
4646
* @param[in] timeout Download log timeout value. If this value is 0, controller does not handle timeouts.
4747
* @param[in] callback The callback to call when Log Download data is received and when an error occurs
4848
*/
49-
static CHIP_ERROR LogDownloadFromNode(DeviceController * controller, NodeId remoteNodeId, app::Clusters::DiagnosticLogs::IntentEnum intent, uint16_t timeout, jobject jCallbackObject);
49+
static CHIP_ERROR LogDownloadFromNode(DeviceController * controller, NodeId remoteNodeId,
50+
app::Clusters::DiagnosticLogs::IntentEnum intent, uint16_t timeout,
51+
jobject jCallbackObject);
5052

5153
private:
52-
AndroidLogDownloadFromNode(DeviceController * controller, NodeId remoteNodeId, app::Clusters::DiagnosticLogs::IntentEnum intent, uint16_t timeout, jobject javaCallback);
54+
AndroidLogDownloadFromNode(DeviceController * controller, NodeId remoteNodeId, app::Clusters::DiagnosticLogs::IntentEnum intent,
55+
uint16_t timeout, jobject javaCallback);
5356

5457
DeviceController * mController;
5558

@@ -67,20 +70,23 @@ class AndroidLogDownloadFromNode
6770
char mFileDesignatorBuffer[bdx::DiagnosticLogs::kMaxFileDesignatorLen];
6871
MutableCharSpan mFileDesignator = MutableCharSpan(mFileDesignatorBuffer, bdx::DiagnosticLogs::kMaxFileDesignatorLen);
6972

70-
BdxDiagnosticLogsReceiver *mBdxReceiver = nullptr;
71-
73+
BdxDiagnosticLogsReceiver * mBdxReceiver = nullptr;
74+
7275
CHIP_ERROR GetConnectedDevice();
7376
CHIP_ERROR SendRetrieveLogsRequest(Messaging::ExchangeManager & exchangeMgr, const SessionHandle & sessionHandle);
74-
void OnTransferCallback(FabricIndex fabricIndex, NodeId remoteNodeId, const chip::ByteSpan & data, CHIP_ERROR *errInfoOnFailure);
77+
void OnTransferCallback(FabricIndex fabricIndex, NodeId remoteNodeId, const chip::ByteSpan & data,
78+
CHIP_ERROR * errInfoOnFailure);
7579
void FinishLogDownloadFromNode(CHIP_ERROR err);
7680

7781
static void OnDeviceConnectedFn(void * context, Messaging::ExchangeManager & exchangeMgr, const SessionHandle & sessionHandle);
7882
static void OnDeviceConnectionFailureFn(void * context, const ScopedNodeId & peerId, CHIP_ERROR error);
7983

80-
static void OnResponseRetrieveLogs(void * context, const app::Clusters::DiagnosticLogs::Commands::RetrieveLogsResponse::DecodableType & data);
84+
static void OnResponseRetrieveLogs(void * context,
85+
const app::Clusters::DiagnosticLogs::Commands::RetrieveLogsResponse::DecodableType & data);
8186
static void OnCommandFailure(void * context, CHIP_ERROR err);
8287

83-
static void OnBdxTransferCallback(void * context, FabricIndex fabricIndex, NodeId remoteNodeId, const chip::ByteSpan & data, CHIP_ERROR *errInfoOnFailure);
88+
static void OnBdxTransferCallback(void * context, FabricIndex fabricIndex, NodeId remoteNodeId, const chip::ByteSpan & data,
89+
CHIP_ERROR * errInfoOnFailure);
8490
static void OnBdxTransferSuccessCallback(void * context, FabricIndex fabricIndex, NodeId remoteNodeId);
8591
static void OnBdxTransferFailureCallback(void * context, FabricIndex fabricIndex, NodeId remoteNodeId, CHIP_ERROR status);
8692
};

src/controller/java/BUILD.gn

+1-1
Original file line numberDiff line numberDiff line change
@@ -642,8 +642,8 @@ android_library("java") {
642642
"src/chip/devicecontroller/DeviceAttestation.java",
643643
"src/chip/devicecontroller/DeviceAttestationDelegate.java",
644644
"src/chip/devicecontroller/DiagnosticLogType.java",
645-
"src/chip/devicecontroller/DownloadLogCallback.java",
646645
"src/chip/devicecontroller/DiscoveredDevice.java",
646+
"src/chip/devicecontroller/DownloadLogCallback.java",
647647
"src/chip/devicecontroller/GroupKeySecurityPolicy.java",
648648
"src/chip/devicecontroller/ICDCheckInDelegate.java",
649649
"src/chip/devicecontroller/ICDCheckInDelegateWrapper.java",

0 commit comments

Comments
 (0)