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

Commit 3009e50f authored by Arthur Ishiguro's avatar Arthur Ishiguro
Browse files

Reject messages larger than MTU size

Bug: 143360045
Test: Compile only
Change-Id: I2b8c226a5b8dffd3b9e9f7d533588592f6a1ec9b
parent 8142ee3e
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) {