Java Code Examples for androidx.annotation.VisibleForTesting#PROTECTED

The following examples show how to use androidx.annotation.VisibleForTesting#PROTECTED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccessLayer.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Creates an access message
 *
 * @param accessMessage Access message containing the required opcodes and parameters to create access message pdu.
 */
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
final void createAccessMessage(@NonNull final AccessMessage accessMessage) {
    final byte[] opCodes = MeshParserUtils.getOpCode(accessMessage.getOpCode());
    final byte[] parameters = accessMessage.getParameters();
    final ByteBuffer accessMessageBuffer;
    if (parameters != null) {
        accessMessageBuffer = ByteBuffer.allocate(opCodes.length + parameters.length);
        accessMessageBuffer.put(opCodes).put(parameters);
    } else {
        accessMessageBuffer = ByteBuffer.allocate(opCodes.length);
        accessMessageBuffer.put(opCodes);
    }
    final byte[] accessPdu = accessMessageBuffer.array();

    Log.v(TAG, "Created Access PDU " + MeshParserUtils.bytesToHex(accessPdu, false));
    accessMessage.setAccessPdu(accessMessageBuffer.array());
}
 
Example 2
Source File: AccessLayer.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Creates an access message
 *
 * @param accessMessage Access message containing the required opcodes and parameters to create access message pdu.
 */
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
final void createCustomAccessMessage(@NonNull final AccessMessage accessMessage) {
    final byte[] parameters = accessMessage.getParameters();
    final byte[] vendorOpcode = MeshParserUtils.createVendorOpCode(accessMessage.getOpCode(),
            accessMessage.getCompanyIdentifier());
    final ByteBuffer accessMessageBuffer;
    if (parameters != null) {
        accessMessageBuffer = ByteBuffer.allocate(vendorOpcode.length + parameters.length);
        accessMessageBuffer.put(vendorOpcode);
        accessMessageBuffer.put(parameters);
    } else {
        accessMessageBuffer = ByteBuffer.allocate(vendorOpcode.length);
        accessMessageBuffer.put(vendorOpcode);
    }
    final byte[] accessPdu = accessMessageBuffer.array();
    Log.v(TAG, "Created Access PDU " + MeshParserUtils.bytesToHex(accessPdu, false));
    accessMessage.setAccessPdu(accessPdu);
}
 
Example 3
Source File: LowerTransportLayer.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
public final void createLowerTransportAccessPDU(@NonNull final AccessMessage message) {
    final byte[] upperTransportPDU = message.getUpperTransportPdu();
    final SparseArray<byte[]> lowerTransportAccessPduMap;
    if (upperTransportPDU.length <= MAX_SEGMENTED_ACCESS_PAYLOAD_LENGTH) {
        message.setSegmented(false);
        final byte[] lowerTransportPDU = createUnsegmentedAccessMessage(message);
        lowerTransportAccessPduMap = new SparseArray<>();
        lowerTransportAccessPduMap.put(0, lowerTransportPDU);
    } else {
        message.setSegmented(true);
        lowerTransportAccessPduMap = createSegmentedAccessMessage(message);
    }

    message.setLowerTransportAccessPdu(lowerTransportAccessPduMap);
}
 
Example 4
Source File: LowerTransportLayer.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
public final void createLowerTransportControlPDU(@NonNull final ControlMessage message) {
    switch (message.getPduType()) {
        case MeshManagerApi.PDU_TYPE_PROXY_CONFIGURATION:
            final SparseArray<byte[]> lowerTransportControlPduArray = new SparseArray<>();
            lowerTransportControlPduArray.put(0, message.getTransportControlPdu());
            message.setLowerTransportControlPdu(lowerTransportControlPduArray);
            break;
        case MeshManagerApi.PDU_TYPE_NETWORK:
            final byte[] transportControlPdu = message.getTransportControlPdu();
            if (transportControlPdu.length <= MAX_UNSEGMENTED_CONTROL_PAYLOAD_LENGTH) {
                Log.v(TAG, "Creating unsegmented transport control");
                createUnsegmentedControlMessage(message);
            } else {
                Log.v(TAG, "Creating segmented transport control");
                createSegmentedControlMessage(message);
            }
    }
}
 
Example 5
Source File: GattConnection.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
synchronized void finish() {
    BluetoothGatt localGatt = this.gatt;
    if (localGatt != null) {
        closeClientIf(localGatt);
        gatt = null;
    }
    clientQueue.stop();
    asynchronousEventListeners.clear();
}
 
Example 6
Source File: LowerTransportLayer.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates an unsegmented control.
 *
 * @param message control message.
 */
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
private void createUnsegmentedControlMessage(@NonNull final ControlMessage message) {
    int pduLength;
    final ByteBuffer lowerTransportBuffer;
    message.setSegmented(false);
    final int opCode = message.getOpCode();
    final byte[] parameters = message.getParameters();
    final byte[] upperTransportControlPDU = message.getTransportControlPdu();
    final int header = (byte) ((UNSEGMENTED_HEADER << 7) | opCode);
    if (parameters != null) {
        pduLength = UNSEGMENTED_MESSAGE_HEADER_LENGTH + parameters.length + upperTransportControlPDU.length;
        lowerTransportBuffer = ByteBuffer.allocate(pduLength).order(ByteOrder.BIG_ENDIAN);
        lowerTransportBuffer.put((byte) header);
        lowerTransportBuffer.put(parameters);
    } else {
        pduLength = UNSEGMENTED_MESSAGE_HEADER_LENGTH + upperTransportControlPDU.length;
        lowerTransportBuffer = ByteBuffer.allocate(pduLength).order(ByteOrder.BIG_ENDIAN);
        lowerTransportBuffer.put((byte) header);
    }

    lowerTransportBuffer.put(upperTransportControlPDU);
    final byte[] lowerTransportPDU = lowerTransportBuffer.array();
    Log.v(TAG, "Unsegmented Lower transport control PDU " + MeshParserUtils.bytesToHex(lowerTransportPDU, false));
    final SparseArray<byte[]> lowerTransportControlPduMap = new SparseArray<>();
    lowerTransportControlPduMap.put(0, lowerTransportPDU);
    message.setLowerTransportControlPdu(lowerTransportControlPduMap);
}
 
Example 7
Source File: UpperTransportLayer.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates the upper transport access pdu
 *
 * @param message The message required to create the encrypted upper transport pdu
 */
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
void createUpperTransportPDU(@NonNull final Message message) {
    if (message instanceof AccessMessage) {
        //Access message
        final AccessMessage accessMessage = (AccessMessage) message;
        final byte[] encryptedTransportPDU = encryptUpperTransportPDU(accessMessage);
        Log.v(TAG, "Encrypted upper transport pdu: " + MeshParserUtils.bytesToHex(encryptedTransportPDU, false));
        accessMessage.setUpperTransportPdu(encryptedTransportPDU);
    } else {
        final ControlMessage controlMessage = (ControlMessage) message;
        final int opCode = controlMessage.getOpCode();
        final byte[] parameters = controlMessage.getParameters();
        final ByteBuffer accessMessageBuffer;
        if (parameters != null) {
            accessMessageBuffer = ByteBuffer.allocate(PROXY_CONFIG_OPCODE_LENGTH + parameters.length)
                    .order(ByteOrder.BIG_ENDIAN)
                    .put((byte) opCode)
                    .put(parameters);
        } else {
            accessMessageBuffer = ByteBuffer.allocate(PROXY_CONFIG_OPCODE_LENGTH);
            accessMessageBuffer.put((byte) opCode);
        }
        final byte[] accessPdu = accessMessageBuffer.array();

        Log.v(TAG, "Created Transport Control PDU " + MeshParserUtils.bytesToHex(accessPdu, false));
        controlMessage.setTransportControlPdu(accessPdu);
    }
}
 
Example 8
Source File: MeshTransport.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Constructs MeshTransport
 *
 * @param context Context
 * @param node    Mesh node
 */
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
MeshTransport(@NonNull final Context context, @NonNull final ProvisionedMeshNode node) {
    super();
    this.mContext = context;
    this.mMeshNode = node;
    initHandler();
}
 
Example 9
Source File: GattServerConnection.java    From bitgatt with Mozilla Public License 2.0 4 votes vote down vote up
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
synchronized void finish() {
    if(serverQueue != null) {
        serverQueue.stop();
    }
}
 
Example 10
Source File: ProvisionedMeshNode.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
@RestrictTo(RestrictTo.Scope.LIBRARY)
public ProvisionedMeshNode() { }
 
Example 11
Source File: NetworkLayer.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@SuppressWarnings("ConstantConditions")
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
final Message createRetransmitNetworkLayerPDU(@NonNull final Message message, final int segment) {
    final SecureUtils.K2Output k2Output = getK2Output(message);
    final int nid = k2Output.getNid();
    final byte[] encryptionKey = k2Output.getEncryptionKey();
    Log.v(TAG, "Encryption key: " + MeshParserUtils.bytesToHex(encryptionKey, false));

    final byte[] privacyKey = k2Output.getPrivacyKey();
    Log.v(TAG, "Privacy key: " + MeshParserUtils.bytesToHex(privacyKey, false));
    final int ctl = message.getCtl();
    final int ttl = message.getTtl();
    final int ivi = message.getIvIndex()[3] & 0x01; // least significant bit of IV Index
    final byte iviNID = (byte) ((ivi << 7) | nid);
    final byte ctlTTL = (byte) ((ctl << 7) | ttl);

    final int src = message.getSrc();
    final SparseArray<byte[]> lowerTransportPduMap;
    if (message instanceof AccessMessage) {
        lowerTransportPduMap = ((AccessMessage) message).getLowerTransportAccessPdu();
    } else {
        lowerTransportPduMap = ((ControlMessage) message).getLowerTransportControlPdu();
    }

    byte[] encryptedNetworkPayload = null;
    final int pduType = message.getPduType();
    if (message.getPduType() == MeshManagerApi.PDU_TYPE_NETWORK) {
        final ProvisionedMeshNode node = mUpperTransportLayerCallbacks.getNode(message.getSrc());
        final byte[] lowerTransportPdu = lowerTransportPduMap.get(segment);
        node.setSequenceNumber(MeshParserUtils.getSequenceNumber(message.getSequenceNumber()));
        //final int sequenceNumber = node.incrementSequenceNumber();//incrementSequenceNumber(mNetworkLayerCallbacks.getProvisioner(), message.getSequenceNumber());
        final byte[] sequenceNum = MeshParserUtils.getSequenceNumberBytes(node.incrementSequenceNumber());
        message.setSequenceNumber(sequenceNum);

        Log.v(TAG, "Sequence Number: " + MeshParserUtils.bytesToHex(sequenceNum, false));

        final byte[] nonce = createNetworkNonce(ctlTTL, sequenceNum, src, message.getIvIndex());
        encryptedNetworkPayload = encryptPdu(lowerTransportPdu, encryptionKey, nonce, message.getDst(), SecureUtils.getNetMicLength(message.getCtl()));
        if (encryptedNetworkPayload == null)
            return null;
        Log.v(TAG, "Encrypted Network payload: " + MeshParserUtils.bytesToHex(encryptedNetworkPayload, false));
    }

    final SparseArray<byte[]> pduArray = new SparseArray<>();
    if (encryptedNetworkPayload == null)
        return null;

    final byte[] privacyRandom = createPrivacyRandom(encryptedNetworkPayload);
    //Next we create the PECB
    final byte[] pecb = createPECB(message.getIvIndex(), privacyRandom, privacyKey);

    final byte[] header = obfuscateNetworkHeader(ctlTTL, message.getSequenceNumber(), src, pecb);
    final byte[] pdu = ByteBuffer.allocate(1 + 1 + header.length + encryptedNetworkPayload.length).order(ByteOrder.BIG_ENDIAN)
            .put((byte) pduType)
            .put(iviNID)
            .put(header)
            .put(encryptedNetworkPayload)
            .array();
    pduArray.put(segment, pdu);
    message.setNetworkLayerPdu(pduArray);
    return message;
}
 
Example 12
Source File: ViewController.java    From react-native-navigation with MIT License 4 votes vote down vote up
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
public ParentController getParentController() {
    return parentController;
}
 
Example 13
Source File: AttachMode.java    From react-native-navigation with MIT License 4 votes vote down vote up
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
public void attach(ViewController tab) {
    ViewGroup view = tab.getView();
    view.setVisibility(tab == initialTab ? View.VISIBLE : View.INVISIBLE);
    parent.addView(view, matchParentWithBehaviour(new BottomTabsBehaviour(tab.getParentController())));
}