16
16
*/
17
17
#include " AndroidCallbacks.h"
18
18
#include < controller/java/AndroidClusterExceptions.h>
19
- #include < controller/java/AndroidControllerExceptions.h>
20
19
#include < controller/java/CHIPAttributeTLVValueDecoder.h>
21
20
#include < controller/java/CHIPEventTLVValueDecoder.h>
22
21
#include < jni.h>
@@ -106,14 +105,16 @@ void GetConnectedDeviceCallback::OnDeviceConnectionFailureFn(void * context, con
106
105
JniReferences::GetInstance ().FindMethod (env, javaCallback, " onConnectionFailure" , " (JLjava/lang/Exception;)V" , &failureMethod);
107
106
VerifyOrReturn (failureMethod != nullptr , ChipLogError (Controller, " Could not find onConnectionFailure method" ));
108
107
109
- jthrowable exception ;
110
- CHIP_ERROR err = AndroidControllerExceptions::GetInstance ().CreateAndroidControllerException (env, ErrorStr (error),
111
- error.AsInteger (), exception );
112
- VerifyOrReturn (
113
- err == CHIP_NO_ERROR,
114
- ChipLogError (Controller,
115
- " Unable to create AndroidControllerException on GetConnectedDeviceCallback::OnDeviceConnectionFailureFn: %s" ,
116
- ErrorStr (err)));
108
+ // Create the exception to return.
109
+ jclass controllerExceptionCls;
110
+ CHIP_ERROR err = JniReferences::GetInstance ().GetClassRef (env, " chip/devicecontroller/ChipDeviceControllerException" ,
111
+ controllerExceptionCls);
112
+ VerifyOrReturn (err == CHIP_NO_ERROR, ChipLogError (Controller, " Could not find exception type for onConnectionFailure" ));
113
+ JniClass controllerExceptionJniCls (controllerExceptionCls);
114
+
115
+ jmethodID exceptionConstructor = env->GetMethodID (controllerExceptionCls, " <init>" , " (ILjava/lang/String;)V" );
116
+ jobject exception =
117
+ env->NewObject (controllerExceptionCls, exceptionConstructor, error.AsInteger (), env->NewStringUTF (ErrorStr (error)));
117
118
118
119
DeviceLayer::StackUnlock unlock;
119
120
env->CallVoidMethod (javaCallback, failureMethod, peerId.GetNodeId (), exception );
@@ -557,12 +558,12 @@ CHIP_ERROR ReportCallback::OnResubscriptionNeeded(app::ReadClient * apReadClient
557
558
558
559
jmethodID onResubscriptionAttemptMethod;
559
560
ReturnLogErrorOnFailure (JniReferences::GetInstance ().FindMethod (
560
- env, mResubscriptionAttemptCallbackRef , " onResubscriptionAttempt" , " (JJ )V" , &onResubscriptionAttemptMethod));
561
+ env, mResubscriptionAttemptCallbackRef , " onResubscriptionAttempt" , " (II )V" , &onResubscriptionAttemptMethod));
561
562
562
563
DeviceLayer::StackUnlock unlock;
563
564
env->CallVoidMethod (mResubscriptionAttemptCallbackRef , onResubscriptionAttemptMethod,
564
- static_cast <jlong >(aTerminationCause.AsInteger ()),
565
- static_cast <jlong >(apReadClient->ComputeTimeTillNextSubscription ()));
565
+ static_cast <jint >(aTerminationCause.AsInteger ()),
566
+ static_cast <jint >(apReadClient->ComputeTimeTillNextSubscription ()));
566
567
VerifyOrReturnError (!env->ExceptionCheck (), CHIP_JNI_ERROR_EXCEPTION_THROWN);
567
568
return CHIP_NO_ERROR;
568
569
}
@@ -584,10 +585,8 @@ void ReportCallback::ReportError(jobject attributePath, jobject eventPath, const
584
585
JNIEnv * env = JniReferences::GetInstance ().GetEnvForCurrentThread ();
585
586
586
587
jthrowable exception ;
587
- err = AndroidControllerExceptions::GetInstance ().CreateAndroidControllerException (env, message, errorCode, exception );
588
- VerifyOrReturn (
589
- err == CHIP_NO_ERROR,
590
- ChipLogError (Controller, " Unable to create AndroidControllerException on ReportCallback::ReportError: %s" , ErrorStr (err)));
588
+ err = AndroidClusterExceptions::GetInstance ().CreateIllegalStateException (env, message, errorCode, exception );
589
+ VerifyOrReturn (err == CHIP_NO_ERROR, ChipLogError (Controller, " Unable to create IllegalStateException: %s" , ErrorStr (err)));
591
590
592
591
jmethodID onErrorMethod;
593
592
err = JniReferences::GetInstance ().FindMethod (
@@ -814,12 +813,12 @@ CHIP_ERROR ReportEventCallback::OnResubscriptionNeeded(app::ReadClient * apReadC
814
813
815
814
jmethodID onResubscriptionAttemptMethod;
816
815
ReturnLogErrorOnFailure (JniReferences::GetInstance ().FindMethod (
817
- env, mResubscriptionAttemptCallbackRef , " onResubscriptionAttempt" , " (JJ )V" , &onResubscriptionAttemptMethod));
816
+ env, mResubscriptionAttemptCallbackRef , " onResubscriptionAttempt" , " (II )V" , &onResubscriptionAttemptMethod));
818
817
819
818
DeviceLayer::StackUnlock unlock;
820
819
env->CallVoidMethod (mResubscriptionAttemptCallbackRef , onResubscriptionAttemptMethod,
821
- static_cast <jlong >(aTerminationCause.AsInteger ()),
822
- static_cast <jlong >(apReadClient->ComputeTimeTillNextSubscription ()));
820
+ static_cast <jint >(aTerminationCause.AsInteger ()),
821
+ static_cast <jint >(apReadClient->ComputeTimeTillNextSubscription ()));
823
822
824
823
return CHIP_NO_ERROR;
825
824
}
@@ -840,10 +839,8 @@ void ReportEventCallback::ReportError(jobject eventPath, const char * message, C
840
839
JNIEnv * env = JniReferences::GetInstance ().GetEnvForCurrentThread ();
841
840
842
841
jthrowable exception ;
843
- err = AndroidControllerExceptions::GetInstance ().CreateAndroidControllerException (env, message, errorCode, exception );
844
- VerifyOrReturn (err == CHIP_NO_ERROR,
845
- ChipLogError (Controller, " Unable to create AndroidControllerException: %s on eportEventCallback::ReportError" ,
846
- ErrorStr (err)));
842
+ err = AndroidClusterExceptions::GetInstance ().CreateIllegalStateException (env, message, errorCode, exception );
843
+ VerifyOrReturn (err == CHIP_NO_ERROR, ChipLogError (Controller, " Unable to create IllegalStateException: %s" , ErrorStr (err)));
847
844
848
845
jmethodID onErrorMethod;
849
846
err = JniReferences::GetInstance ().FindMethod (
@@ -946,11 +943,8 @@ void WriteAttributesCallback::ReportError(jobject attributePath, const char * me
946
943
947
944
ChipLogError (Controller, " WriteAttributesCallback ReportError is called" );
948
945
jthrowable exception ;
949
- err = AndroidControllerExceptions::GetInstance ().CreateAndroidControllerException (env, message, errorCode, exception );
950
- VerifyOrReturn (err == CHIP_NO_ERROR,
951
- ChipLogError (Controller,
952
- " Unable to create AndroidControllerException on WriteAttributesCallback::ReportError: %s" ,
953
- ErrorStr (err)));
946
+ err = AndroidClusterExceptions::GetInstance ().CreateIllegalStateException (env, message, errorCode, exception );
947
+ VerifyOrReturn (err == CHIP_NO_ERROR, ChipLogError (Controller, " Unable to create IllegalStateException: %s" , ErrorStr (err)));
954
948
955
949
jmethodID onErrorMethod;
956
950
err = JniReferences::GetInstance ().FindMethod (env, mJavaCallbackRef , " onError" ,
@@ -1049,10 +1043,8 @@ void InvokeCallback::ReportError(const char * message, ChipError::StorageType er
1049
1043
1050
1044
ChipLogError (Controller, " InvokeCallback ReportError is called" );
1051
1045
jthrowable exception ;
1052
- err = AndroidControllerExceptions::GetInstance ().CreateAndroidControllerException (env, message, errorCode, exception );
1053
- VerifyOrReturn (
1054
- err == CHIP_NO_ERROR,
1055
- ChipLogError (Controller, " Unable to create AndroidControllerException: %s on InvokeCallback::ReportError" , ErrorStr (err)));
1046
+ err = AndroidClusterExceptions::GetInstance ().CreateIllegalStateException (env, message, errorCode, exception );
1047
+ VerifyOrReturn (err == CHIP_NO_ERROR, ChipLogError (Controller, " Unable to create IllegalStateException: %s" , ErrorStr (err)));
1056
1048
1057
1049
jmethodID onErrorMethod;
1058
1050
err = JniReferences::GetInstance ().FindMethod (env, mJavaCallbackRef , " onError" , " (Ljava/lang/Exception;)V" , &onErrorMethod);
0 commit comments