Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 75124194 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Reject messages larger than MTU size"

parents abc02e84 3009e50f
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.app.PendingIntent;
import android.os.RemoteException;
import android.util.Log;

import com.android.internal.util.Preconditions;

@@ -38,6 +39,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
 */
@SystemApi
public class ContextHubClient implements Closeable {
    private static final String TAG = "ContextHubClient";

    /*
     * The proxy to the client interface at the service.
     */
@@ -139,6 +142,14 @@ public class ContextHubClient implements Closeable {
    public int sendMessageToNanoApp(@NonNull NanoAppMessage message) {
        Preconditions.checkNotNull(message, "NanoAppMessage cannot be null");

        int maxPayloadBytes = mAttachedHub.getMaxPacketLengthBytes();
        byte[] payload = message.getMessageBody();
        if (payload != null && payload.length > maxPayloadBytes) {
            Log.e(TAG, "Message (" + payload.length + " bytes) exceeds max payload length ("
                    + maxPayloadBytes + " bytes)");
            return ContextHubTransaction.RESULT_FAILED_BAD_PARAMS;
        }

        try {
            return mClientProxy.sendMessageToNanoApp(message);
        } catch (RemoteException e) {