diff --git a/src/setup_payload/java/BUILD.gn b/src/setup_payload/java/BUILD.gn deleted file mode 100644 index bf4402ccdaeec6..00000000000000 --- a/src/setup_payload/java/BUILD.gn +++ /dev/null @@ -1,64 +0,0 @@ -# Copyright (c) 2020 Project CHIP Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build_overrides/build.gni") -import("//build_overrides/chip.gni") -import("${chip_root}/build/chip/java/config.gni") -import("${chip_root}/build/chip/java/rules.gni") - -if (!matter_enable_java_compilation) { - import("${build_root}/config/android_abi.gni") -} - -shared_library("jni") { - output_name = "libSetupPayloadParser" - if (matter_enable_java_compilation) { - include_dirs = java_matter_controller_dependent_paths - output_dir = "${root_out_dir}/lib/jni" - } else { - output_dir = "${root_out_dir}/lib/jni/${android_abi}" - } - - sources = [ "SetupPayloadParser-JNI.cpp" ] - - deps = [ - "${chip_root}/src/lib", - "${chip_root}/src/setup_payload", - ] -} - -android_library("java") { - output_name = "SetupPayloadParser.jar" - - data_deps = [ ":jni" ] - - if (!matter_enable_java_compilation) { - data_deps += [ "${chip_root}/build/chip/java:shared_cpplib" ] - } - - sources = [ - "src/chip/setuppayload/DiscoveryCapability.java", - "src/chip/setuppayload/OptionalQRCodeInfo.java", - "src/chip/setuppayload/SetupPayload.java", - "src/chip/setuppayload/SetupPayloadParser.java", - ] - - javac_flags = [ - "-Xlint:deprecation", - "-parameters", # Store infomation about method parameters - ] - - # TODO: add classpath support (we likely need to add something like - # ..../platforms/android-26/android.jar to access BLE items) -} diff --git a/src/setup_payload/java/SetupPayloadParser-JNI.cpp b/src/setup_payload/java/SetupPayloadParser-JNI.cpp deleted file mode 100644 index dd197711e7d621..00000000000000 --- a/src/setup_payload/java/SetupPayloadParser-JNI.cpp +++ /dev/null @@ -1,376 +0,0 @@ -#include "lib/core/CHIPError.h" -#include "lib/support/JniTypeWrappers.h" -#include -#include -#include -#include - -#include -#include -#include -#include - -#include - -#include - -using namespace chip; - -#define SETUP_PAYLOAD_PARSER_JNI_ERROR_MIN 10 // avoiding collision with CHIPJNIError.h -#define _SETUP_PAYLOAD_PARSER_JNI_ERROR(e) CHIP_APPLICATION_ERROR(SETUP_PAYLOAD_PARSER_JNI_ERROR_MIN + (e)) - -#define SETUP_PAYLOAD_PARSER_JNI_ERROR_EXCEPTION_THROWN _SETUP_PAYLOAD_PARSER_JNI_ERROR(0) -#define SETUP_PAYLOAD_PARSER_JNI_ERROR_TYPE_NOT_FOUND _SETUP_PAYLOAD_PARSER_JNI_ERROR(1) -#define SETUP_PAYLOAD_PARSER_JNI_ERROR_METHOD_NOT_FOUND _SETUP_PAYLOAD_PARSER_JNI_ERROR(2) -#define SETUP_PAYLOAD_PARSER_JNI_ERROR_FIELD_NOT_FOUND _SETUP_PAYLOAD_PARSER_JNI_ERROR(3) - -#define JNI_METHOD(RETURN, METHOD_NAME) extern "C" JNIEXPORT RETURN JNICALL Java_chip_setuppayload_SetupPayloadParser_##METHOD_NAME - -static jobject TransformSetupPayload(JNIEnv * env, SetupPayload & payload); -static jobject CreateCapabilitiesHashSet(JNIEnv * env, RendezvousInformationFlags flags); -static void TransformSetupPayloadFromJobject(JNIEnv * env, jobject jPayload, SetupPayload & payload); -static void CreateCapabilitiesFromHashSet(JNIEnv * env, jobject discoveryCapabilitiesObj, RendezvousInformationFlags & flags); -static CHIP_ERROR ThrowUnrecognizedQRCodeException(JNIEnv * env, jstring qrCodeObj); -static CHIP_ERROR ThrowInvalidEntryCodeFormatException(JNIEnv * env, jstring entryCodeObj); - -jint JNI_OnLoad(JavaVM * jvm, void * reserved) -{ - ChipLogProgress(SetupPayload, "JNI_OnLoad() called"); - chip::Platform::MemoryInit(); - return JNI_VERSION_1_6; -} - -JNI_METHOD(jobject, fetchPayloadFromQrCode)(JNIEnv * env, jobject self, jstring qrCodeObj, jboolean allowInvalidPayload) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - const char * qrString = NULL; - SetupPayload payload; - - qrString = env->GetStringUTFChars(qrCodeObj, 0); - - err = QRCodeSetupPayloadParser(qrString).populatePayload(payload); - env->ReleaseStringUTFChars(qrCodeObj, qrString); - - if (allowInvalidPayload == JNI_FALSE && !payload.isValidQRCodePayload()) - { - jclass exceptionCls = env->FindClass("chip/setuppayload/SetupPayloadParser$SetupPayloadException"); - JniReferences::GetInstance().ThrowError(env, exceptionCls, CHIP_ERROR_INVALID_ARGUMENT); - return nullptr; - } - - if (err != CHIP_NO_ERROR) - { - err = ThrowUnrecognizedQRCodeException(env, qrCodeObj); - if (err != CHIP_NO_ERROR) - { - ChipLogError(SetupPayload, "Error throwing UnrecognizedQRCodeException: %" CHIP_ERROR_FORMAT, err.Format()); - } - return nullptr; - } - - return TransformSetupPayload(env, payload); -} - -JNI_METHOD(jobject, fetchPayloadFromManualEntryCode)(JNIEnv * env, jobject self, jstring entryCode, jboolean allowInvalidPayload) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - const char * entryCodeString = NULL; - SetupPayload payload; - - entryCodeString = env->GetStringUTFChars(entryCode, 0); - - err = ManualSetupPayloadParser(entryCodeString).populatePayload(payload); - env->ReleaseStringUTFChars(entryCode, entryCodeString); - - if (allowInvalidPayload == JNI_FALSE && !payload.isValidManualCode()) - { - jclass exceptionCls = env->FindClass("chip/setuppayload/SetupPayloadParser$SetupPayloadException"); - JniReferences::GetInstance().ThrowError(env, exceptionCls, CHIP_ERROR_INVALID_ARGUMENT); - return nullptr; - } - - if (err != CHIP_NO_ERROR) - { - err = ThrowInvalidEntryCodeFormatException(env, entryCode); - if (err != CHIP_NO_ERROR) - { - ChipLogError(SetupPayload, "Error throwing InvalidEntryCodeFormatException: %" CHIP_ERROR_FORMAT, err.Format()); - } - return nullptr; - } - - return TransformSetupPayload(env, payload); -} - -jobject TransformSetupPayload(JNIEnv * env, SetupPayload & payload) -{ - jclass setupPayloadClass = env->FindClass("chip/setuppayload/SetupPayload"); - jmethodID setupConstr = env->GetMethodID(setupPayloadClass, "", "()V"); - jobject setupPayload = env->NewObject(setupPayloadClass, setupConstr); - - jfieldID version = env->GetFieldID(setupPayloadClass, "version", "I"); - jfieldID vendorId = env->GetFieldID(setupPayloadClass, "vendorId", "I"); - jfieldID productId = env->GetFieldID(setupPayloadClass, "productId", "I"); - jfieldID commissioningFlow = env->GetFieldID(setupPayloadClass, "commissioningFlow", "I"); - jfieldID discriminator = env->GetFieldID(setupPayloadClass, "discriminator", "I"); - jfieldID hasShortDiscriminator = env->GetFieldID(setupPayloadClass, "hasShortDiscriminator", "Z"); - jfieldID setUpPinCode = env->GetFieldID(setupPayloadClass, "setupPinCode", "J"); - jfieldID discoveryCapabilities = env->GetFieldID(setupPayloadClass, "discoveryCapabilities", "Ljava/util/Set;"); - - env->SetIntField(setupPayload, version, payload.version); - env->SetIntField(setupPayload, vendorId, payload.vendorID); - env->SetIntField(setupPayload, productId, payload.productID); - env->SetIntField(setupPayload, commissioningFlow, static_cast(payload.commissioningFlow)); - uint16_t discriminatorValue; - bool isShortDiscriminator = payload.discriminator.IsShortDiscriminator(); - if (isShortDiscriminator) - { - discriminatorValue = static_cast(payload.discriminator.GetShortValue()) - << (SetupDiscriminator::kLongBits - SetupDiscriminator::kShortBits); - } - else - { - discriminatorValue = payload.discriminator.GetLongValue(); - } - env->SetIntField(setupPayload, discriminator, discriminatorValue); - env->SetBooleanField(setupPayload, hasShortDiscriminator, isShortDiscriminator); - env->SetLongField(setupPayload, setUpPinCode, payload.setUpPINCode); - - env->SetObjectField(setupPayload, discoveryCapabilities, - CreateCapabilitiesHashSet(env, payload.rendezvousInformation.ValueOr(RendezvousInformationFlag::kNone))); - - jmethodID addOptionalInfoMid = - env->GetMethodID(setupPayloadClass, "addOptionalQRCodeInfo", "(Lchip/setuppayload/OptionalQRCodeInfo;)V"); - - std::vector optional_info = payload.getAllOptionalVendorData(); - for (OptionalQRCodeInfo & info : optional_info) - { - - jclass optionalInfoClass = env->FindClass("chip/setuppayload/OptionalQRCodeInfo"); - jobject optionalInfo = env->AllocObject(optionalInfoClass); - jfieldID tag = env->GetFieldID(optionalInfoClass, "tag", "I"); - jfieldID type = env->GetFieldID(optionalInfoClass, "type", "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); - jfieldID data = env->GetFieldID(optionalInfoClass, "data", "Ljava/lang/String;"); - jfieldID int32 = env->GetFieldID(optionalInfoClass, "int32", "I"); - - env->SetIntField(optionalInfo, tag, info.tag); - - jclass enumClass = env->FindClass("chip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType"); - jfieldID enumType = nullptr; - - switch (info.type) - { - case optionalQRCodeInfoTypeString: - enumType = - env->GetStaticFieldID(enumClass, "TYPE_STRING", "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); - break; - case optionalQRCodeInfoTypeInt32: - enumType = - env->GetStaticFieldID(enumClass, "TYPE_INT32", "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); - break; - case optionalQRCodeInfoTypeInt64: - enumType = - env->GetStaticFieldID(enumClass, "TYPE_INT64", "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); - break; - case optionalQRCodeInfoTypeUInt32: - enumType = - env->GetStaticFieldID(enumClass, "TYPE_UINT32", "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); - break; - case optionalQRCodeInfoTypeUInt64: - enumType = - env->GetStaticFieldID(enumClass, "TYPE_UINT64", "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); - break; - case optionalQRCodeInfoTypeUnknown: - default: // Optional Type variable has to set any value. - enumType = - env->GetStaticFieldID(enumClass, "TYPE_UNKNOWN", "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); - break; - } - - if (enumType != nullptr) - { - jobject enumObj = env->GetStaticObjectField(enumClass, enumType); - env->SetObjectField(optionalInfo, type, enumObj); - } - - env->SetObjectField(optionalInfo, data, env->NewStringUTF(info.data.c_str())); - env->SetIntField(optionalInfo, int32, info.int32); - - env->CallVoidMethod(setupPayload, addOptionalInfoMid, optionalInfo); - } - - return setupPayload; -} - -jobject CreateCapabilitiesHashSet(JNIEnv * env, RendezvousInformationFlags flags) -{ - jclass hashSetClass = env->FindClass("java/util/HashSet"); - jmethodID hashSetConstructor = env->GetMethodID(hashSetClass, "", "()V"); - jobject capabilitiesHashSet = env->NewObject(hashSetClass, hashSetConstructor); - - jmethodID hashSetAddMethod = env->GetMethodID(hashSetClass, "add", "(Ljava/lang/Object;)Z"); - jclass capabilityEnum = env->FindClass("chip/setuppayload/DiscoveryCapability"); - - if (flags.Has(chip::RendezvousInformationFlag::kBLE)) - { - jfieldID bleCapability = env->GetStaticFieldID(capabilityEnum, "BLE", "Lchip/setuppayload/DiscoveryCapability;"); - jobject enumObj = env->GetStaticObjectField(capabilityEnum, bleCapability); - env->CallBooleanMethod(capabilitiesHashSet, hashSetAddMethod, enumObj); - } - if (flags.Has(chip::RendezvousInformationFlag::kSoftAP)) - { - jfieldID softApCapability = env->GetStaticFieldID(capabilityEnum, "SOFT_AP", "Lchip/setuppayload/DiscoveryCapability;"); - jobject enumObj = env->GetStaticObjectField(capabilityEnum, softApCapability); - env->CallBooleanMethod(capabilitiesHashSet, hashSetAddMethod, enumObj); - } - if (flags.Has(chip::RendezvousInformationFlag::kOnNetwork)) - { - jfieldID onNetworkCapability = - env->GetStaticFieldID(capabilityEnum, "ON_NETWORK", "Lchip/setuppayload/DiscoveryCapability;"); - jobject enumObj = env->GetStaticObjectField(capabilityEnum, onNetworkCapability); - env->CallBooleanMethod(capabilitiesHashSet, hashSetAddMethod, enumObj); - } - return capabilitiesHashSet; -} - -JNI_METHOD(jstring, getQrCodeFromPayload)(JNIEnv * env, jobject self, jobject setupPayload) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - SetupPayload payload; - std::string qrString; - - TransformSetupPayloadFromJobject(env, setupPayload, payload); - - err = QRCodeSetupPayloadGenerator(payload).payloadBase38Representation(qrString); - if (err != CHIP_NO_ERROR) - { - jclass exceptionCls = env->FindClass("chip/setuppayload/SetupPayloadParser$SetupPayloadException"); - JniReferences::GetInstance().ThrowError(env, exceptionCls, err); - return nullptr; - } - - return env->NewStringUTF(qrString.c_str()); -} - -JNI_METHOD(jstring, getManualEntryCodeFromPayload)(JNIEnv * env, jobject self, jobject setupPayload) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - SetupPayload payload; - std::string outDecimalString; - - TransformSetupPayloadFromJobject(env, setupPayload, payload); - - err = ManualSetupPayloadGenerator(payload).payloadDecimalStringRepresentation(outDecimalString); - if (err != CHIP_NO_ERROR) - { - jclass exceptionCls = env->FindClass("chip/setuppayload/SetupPayloadParser$SetupPayloadException"); - JniReferences::GetInstance().ThrowError(env, exceptionCls, err); - return nullptr; - } - - return env->NewStringUTF(outDecimalString.c_str()); -} - -void TransformSetupPayloadFromJobject(JNIEnv * env, jobject jPayload, SetupPayload & payload) -{ - jclass setupPayloadClass = env->FindClass("chip/setuppayload/SetupPayload"); - - jfieldID version = env->GetFieldID(setupPayloadClass, "version", "I"); - jfieldID vendorId = env->GetFieldID(setupPayloadClass, "vendorId", "I"); - jfieldID productId = env->GetFieldID(setupPayloadClass, "productId", "I"); - jfieldID commissioningFlow = env->GetFieldID(setupPayloadClass, "commissioningFlow", "I"); - jfieldID discriminator = env->GetFieldID(setupPayloadClass, "discriminator", "I"); - jfieldID hasShortDiscriminatorFieldId = env->GetFieldID(setupPayloadClass, "hasShortDiscriminator", "Z"); - jfieldID setUpPinCode = env->GetFieldID(setupPayloadClass, "setupPinCode", "J"); - jfieldID discoveryCapabilities = env->GetFieldID(setupPayloadClass, "discoveryCapabilities", "Ljava/util/Set;"); - - payload.version = env->GetIntField(jPayload, version); - payload.vendorID = env->GetIntField(jPayload, vendorId); - payload.productID = env->GetIntField(jPayload, productId); - payload.commissioningFlow = static_cast(env->GetIntField(jPayload, commissioningFlow)); - jboolean hasShortDiscriminator = env->GetBooleanField(jPayload, hasShortDiscriminatorFieldId); - if (hasShortDiscriminator) - { - payload.discriminator.SetShortValue(env->GetShortField(jPayload, discriminator)); - } - else - { - payload.discriminator.SetLongValue(env->GetIntField(jPayload, discriminator)); - } - payload.setUpPINCode = static_cast(env->GetLongField(jPayload, setUpPinCode)); - - jobject discoveryCapabilitiesObj = env->GetObjectField(jPayload, discoveryCapabilities); - CreateCapabilitiesFromHashSet(env, discoveryCapabilitiesObj, - payload.rendezvousInformation.Emplace(RendezvousInformationFlag::kNone)); -} - -void CreateCapabilitiesFromHashSet(JNIEnv * env, jobject discoveryCapabilitiesObj, RendezvousInformationFlags & flags) -{ - jclass hashSetClass = env->FindClass("java/util/HashSet"); - jmethodID hashSetContainsMethod = env->GetMethodID(hashSetClass, "contains", "(Ljava/lang/Object;)Z"); - - jboolean contains; - jclass capabilityEnum = env->FindClass("chip/setuppayload/DiscoveryCapability"); - - jfieldID bleCapability = env->GetStaticFieldID(capabilityEnum, "BLE", "Lchip/setuppayload/DiscoveryCapability;"); - jobject bleObj = env->GetStaticObjectField(capabilityEnum, bleCapability); - contains = env->CallBooleanMethod(discoveryCapabilitiesObj, hashSetContainsMethod, bleObj); - if (contains) - { - flags.Set(chip::RendezvousInformationFlag::kBLE); - } - - jfieldID softApCapability = env->GetStaticFieldID(capabilityEnum, "SOFT_AP", "Lchip/setuppayload/DiscoveryCapability;"); - jobject softApObj = env->GetStaticObjectField(capabilityEnum, softApCapability); - contains = env->CallBooleanMethod(discoveryCapabilitiesObj, hashSetContainsMethod, softApObj); - if (contains) - { - flags.Set(chip::RendezvousInformationFlag::kSoftAP); - } - - jfieldID onNetworkCapability = env->GetStaticFieldID(capabilityEnum, "ON_NETWORK", "Lchip/setuppayload/DiscoveryCapability;"); - jobject onNetworkObj = env->GetStaticObjectField(capabilityEnum, onNetworkCapability); - contains = env->CallBooleanMethod(discoveryCapabilitiesObj, hashSetContainsMethod, onNetworkObj); - if (contains) - { - flags.Set(chip::RendezvousInformationFlag::kOnNetwork); - } -} - -CHIP_ERROR ThrowUnrecognizedQRCodeException(JNIEnv * env, jstring qrCodeObj) -{ - jclass exceptionCls = nullptr; - jmethodID exceptionConstructor = nullptr; - jthrowable exception = nullptr; - - env->ExceptionClear(); - - exceptionCls = env->FindClass("chip/setuppayload/SetupPayloadParser$UnrecognizedQrCodeException"); - VerifyOrReturnError(exceptionCls != NULL, SETUP_PAYLOAD_PARSER_JNI_ERROR_TYPE_NOT_FOUND); - exceptionConstructor = env->GetMethodID(exceptionCls, "", "(Ljava/lang/String;)V"); - VerifyOrReturnError(exceptionConstructor != NULL, SETUP_PAYLOAD_PARSER_JNI_ERROR_METHOD_NOT_FOUND); - exception = (jthrowable) env->NewObject(exceptionCls, exceptionConstructor, qrCodeObj); - VerifyOrReturnError(exception != NULL, SETUP_PAYLOAD_PARSER_JNI_ERROR_EXCEPTION_THROWN); - - env->Throw(exception); - return CHIP_NO_ERROR; -} - -CHIP_ERROR ThrowInvalidEntryCodeFormatException(JNIEnv * env, jstring entryCodeObj) -{ - jclass exceptionCls = nullptr; - jmethodID exceptionConstructor = nullptr; - jthrowable exception = nullptr; - - env->ExceptionClear(); - - exceptionCls = env->FindClass("chip/setuppayload/SetupPayloadParser$InvalidEntryCodeFormatException"); - VerifyOrReturnError(exceptionCls != NULL, SETUP_PAYLOAD_PARSER_JNI_ERROR_TYPE_NOT_FOUND); - exceptionConstructor = env->GetMethodID(exceptionCls, "", "(Ljava/lang/String;)V"); - VerifyOrReturnError(exceptionConstructor != NULL, SETUP_PAYLOAD_PARSER_JNI_ERROR_METHOD_NOT_FOUND); - exception = (jthrowable) env->NewObject(exceptionCls, exceptionConstructor, entryCodeObj); - VerifyOrReturnError(exception != NULL, SETUP_PAYLOAD_PARSER_JNI_ERROR_EXCEPTION_THROWN); - - env->Throw(exception); - return CHIP_NO_ERROR; -} diff --git a/src/setup_payload/java/src/chip/setuppayload/DiscoveryCapability.java b/src/setup_payload/java/src/chip/setuppayload/DiscoveryCapability.java deleted file mode 100644 index 06811152172d78..00000000000000 --- a/src/setup_payload/java/src/chip/setuppayload/DiscoveryCapability.java +++ /dev/null @@ -1,8 +0,0 @@ -package chip.setuppayload; - -/** Enum values for possible bits in the onboarding paylod's discovery capabilities bitmask. */ -public enum DiscoveryCapability { - SOFT_AP, - BLE, - ON_NETWORK -} diff --git a/src/setup_payload/java/src/chip/setuppayload/OptionalQRCodeInfo.java b/src/setup_payload/java/src/chip/setuppayload/OptionalQRCodeInfo.java deleted file mode 100644 index 5290dfdf40cc01..00000000000000 --- a/src/setup_payload/java/src/chip/setuppayload/OptionalQRCodeInfo.java +++ /dev/null @@ -1,17 +0,0 @@ -package chip.setuppayload; - -public class OptionalQRCodeInfo { - public enum OptionalQRCodeInfoType { - TYPE_UNKNOWN, - TYPE_STRING, - TYPE_INT32, - TYPE_INT64, - TYPE_UINT32, - TYPE_UINT64 - }; - - public int tag; - public OptionalQRCodeInfoType type; - public String data; - public int int32; -}; diff --git a/src/setup_payload/java/src/chip/setuppayload/SetupPayload.java b/src/setup_payload/java/src/chip/setuppayload/SetupPayload.java deleted file mode 100644 index 18723ccd068335..00000000000000 --- a/src/setup_payload/java/src/chip/setuppayload/SetupPayload.java +++ /dev/null @@ -1,84 +0,0 @@ -package chip.setuppayload; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -/** Class to hold the data from the scanned QR code or manual entry code. */ -public class SetupPayload { - /** Version info of the SetupPayload: version SHALL be 0 */ - public int version; - /** The CHIP device vendor ID: Vendor ID SHALL be between 1 and 0xFFF4. */ - public int vendorId; - /** The CHIP device product ID: Product ID SHALL BE greater than 0. */ - public int productId; - /** Commissioning flow: 0 = standard, 1 = requires user action, 2 = custom */ - public int commissioningFlow; - /** - * The CHIP device supported rendezvous flags: At least one DiscoveryCapability must be included. - */ - public Set discoveryCapabilities; - /** The CHIP device discriminator: */ - public int discriminator; - /** - * If hasShortDiscriminator is true, the discriminator value contains just the high 4 bits of the - * full discriminator. For example, if hasShortDiscriminator is true and discriminator is 0xA, - * then the full discriminator can be anything in the range 0xA00 t0 0xAFF. - */ - public boolean hasShortDiscriminator; - /** - * The CHIP device setup PIN code: setupPINCode SHALL be greater than 0. Also invalid setupPINCode - * is {000000000, 11111111, 22222222, 33333333, 44444444, 55555555, 66666666, 77777777, 88888888, - * 99999999, 12345678, 87654321}. - */ - public long setupPinCode; - /** The CHIP device optional QR code info map */ - public Map optionalQRCodeInfo; - - public SetupPayload() { - this.optionalQRCodeInfo = new HashMap(); - } - - public SetupPayload( - int version, - int vendorId, - int productId, - int commissioningFlow, - Set discoveryCapabilities, - int discriminator, - long setupPinCode) { - this( - version, - vendorId, - productId, - commissioningFlow, - discoveryCapabilities, - discriminator, - false, - setupPinCode); - } - - public SetupPayload( - int version, - int vendorId, - int productId, - int commissioningFlow, - Set discoveryCapabilities, - int discriminator, - boolean hasShortDiscriminator, - long setupPinCode) { - this.version = version; - this.vendorId = vendorId; - this.productId = productId; - this.commissioningFlow = commissioningFlow; - this.discoveryCapabilities = discoveryCapabilities; - this.discriminator = discriminator; - this.hasShortDiscriminator = hasShortDiscriminator; - this.setupPinCode = setupPinCode; - this.optionalQRCodeInfo = new HashMap(); - } - - public void addOptionalQRCodeInfo(OptionalQRCodeInfo info) { - this.optionalQRCodeInfo.put(info.tag, info); - } -} diff --git a/src/setup_payload/java/src/chip/setuppayload/SetupPayloadParser.java b/src/setup_payload/java/src/chip/setuppayload/SetupPayloadParser.java deleted file mode 100644 index 1f035253c27d4a..00000000000000 --- a/src/setup_payload/java/src/chip/setuppayload/SetupPayloadParser.java +++ /dev/null @@ -1,109 +0,0 @@ -package chip.setuppayload; - -import java.util.logging.Level; -import java.util.logging.Logger; - -/** Parser for scanned QR code or manual entry code. */ -public class SetupPayloadParser { - - private static final Logger LOGGER = Logger.getLogger(SetupPayloadParser.class.getSimpleName()); - - /** - * Returns {@link SetupPayload} parsed from the QR code string. If an invalid element is included - * in the QRCode Parse result, SetupPayloadException occurs. Refer to {@link SetupPayload} for the - * description of the invalid element. - */ - public SetupPayload parseQrCode(String qrCodeString) - throws UnrecognizedQrCodeException, SetupPayloadException { - return fetchPayloadFromQrCode(qrCodeString, false); - } - - /** - * Returns {@link SetupPayload} parsed from the QR code string. - * - * @param qrCodeString the QRCode for commissioning device. - * @param allowInvalidPayload Allow invalid payload components. If this value is true, payload - * element validation is not checked. Consider saying that the payload must still parse - * correctly, but this skips validation of the content past parsing (i.e. it does not validate - * ranges for individual elements). Refer to {@link SetupPayload} for the description of the - * invalid element. - */ - public SetupPayload parseQrCode(String qrCodeString, boolean allowInvalidPayload) - throws UnrecognizedQrCodeException, SetupPayloadException { - return fetchPayloadFromQrCode(qrCodeString, allowInvalidPayload); - } - - /** - * Returns {@link SetupPayload} parsed from the manual entry code string. If an SetupPINCode has - * invalid value, SetupPayloadException occurs. Refer to {@link SetupPayload} for the description - * of the invalid element. - */ - public SetupPayload parseManualEntryCode(String entryCodeString) - throws InvalidEntryCodeFormatException, SetupPayloadException { - return fetchPayloadFromManualEntryCode(entryCodeString, false); - } - - /** - * Returns {@link SetupPayload} parsed from the manual entry code string. - * - * @param entryCodeString the manual Pairing Code for commissioning device. - * @param allowInvalidPayload Allow invalid payload components. If this value is true, payload - * element validation is not checked. Consider saying that the payload must still parse - * correctly, but this skips validation of the content past parsing (i.e. it does not validate - * ranges for individual elements). Refer to {@link SetupPayload} for the description of the - * invalid element. - */ - public SetupPayload parseManualEntryCode(String entryCodeString, boolean allowInvalidPayload) - throws InvalidEntryCodeFormatException, SetupPayloadException { - return fetchPayloadFromManualEntryCode(entryCodeString, allowInvalidPayload); - } - - /** Get QR code string from {@link SetupPayload}. */ - public native String getQrCodeFromPayload(SetupPayload payload) throws SetupPayloadException; - - /** Get manual entry code string from {@link SetupPayload}. */ - public native String getManualEntryCodeFromPayload(SetupPayload payload) - throws SetupPayloadException; - - private native SetupPayload fetchPayloadFromQrCode( - String qrCodeString, boolean isAllowInvalidPayload) - throws UnrecognizedQrCodeException, SetupPayloadException; - - private native SetupPayload fetchPayloadFromManualEntryCode( - String entryCodeString, boolean isAllowInvalidPayload) - throws InvalidEntryCodeFormatException, SetupPayloadException; - - static { - try { - System.loadLibrary("SetupPayloadParser"); - } catch (UnsatisfiedLinkError e) { - LOGGER.log(Level.SEVERE, "Cannot load library.", e); - } - } - - public static class UnrecognizedQrCodeException extends Exception { - private static final long serialVersionUID = 1L; - - public UnrecognizedQrCodeException(String qrCode) { - super(String.format("Invalid QR code string: %s", qrCode), null); - } - } - - public static class InvalidEntryCodeFormatException extends Exception { - private static final long serialVersionUID = 1L; - - public InvalidEntryCodeFormatException(String entryCode) { - super(String.format("Invalid format for entry code string: %s", entryCode), null); - } - } - - public static class SetupPayloadException extends Exception { - private static final long serialVersionUID = 1L; - public int errorCode; - - public SetupPayloadException(int errorCode, String message) { - super(message != null ? message : String.format("Error Code %d", errorCode)); - this.errorCode = errorCode; - } - } -}