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

Commit 7b893512 authored by Lei Ju's avatar Lei Ju Committed by Android (Google) Code Review
Browse files

Merge "Add nanoapp messasge records into dump."

parents 6757f280 acd76499
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -829,7 +829,7 @@ public final class ContextHubManager {

    /**
     * Equivalent to
     * {@link #createClient(ContextHubInfo, Executor, String, ContextHubClientCallback)}
     * {@link  #createClient(Context, ContextHubInfo, Executor, ContextHubClientCallback)}
     * with the {@link Context} being set to null.
     */
    @RequiresPermission(android.Manifest.permission.ACCESS_CONTEXT_HUB)
+26 −8
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -109,7 +110,8 @@ public class ContextHubService extends IContextHubService.Stub {
            CONTEXT_HUB_EVENT_UNKNOWN,
            CONTEXT_HUB_EVENT_RESTARTED,
    })
    public @interface Type { }
    public @interface Type {
    }

    public static final int CONTEXT_HUB_EVENT_UNKNOWN = 0;
    public static final int CONTEXT_HUB_EVENT_RESTARTED = 1;
@@ -170,6 +172,10 @@ public class ContextHubService extends IContextHubService.Stub {

    private final Map<Integer, AtomicLong> mLastRestartTimestampMap = new HashMap<>();

    private static final int MAX_NUM_OF_NANOAPP_MESSAGE_RECORDS = 10;
    private final ConcurrentLinkedEvictingDeque<NanoAppMessage> mNanoAppMessageRecords =
            new ConcurrentLinkedEvictingDeque<>(MAX_NUM_OF_NANOAPP_MESSAGE_RECORDS);

    /**
     * Class extending the callback to register with a Context Hub.
     */
@@ -687,12 +693,17 @@ public class ContextHubService extends IContextHubService.Stub {
     * @param contextHubId the ID of the hub the message came from
     * @param hostEndpointId the host endpoint ID of the client receiving this message
     * @param message the message contents
     * @param reqPermissions the permissions required to consume this message
     * @param nanoappPermissions the set of permissions the nanoapp holds
     * @param messagePermissions the set of permissions that should be used for attributing
     *     permissions when this message is consumed by a client
     */
    private void handleClientMessageCallback(
            int contextHubId, short hostEndpointId, NanoAppMessage message,
            int contextHubId,
            short hostEndpointId,
            NanoAppMessage message,
            List<String> nanoappPermissions,
            List<String> messagePermissions) {
        mNanoAppMessageRecords.add(message);
        mClientManager.onMessageFromNanoApp(
                contextHubId, hostEndpointId, message, nanoappPermissions, messagePermissions);
    }
@@ -1012,6 +1023,13 @@ public class ContextHubService extends IContextHubService.Stub {
        // Dump nanoAppHash
        mNanoAppStateManager.foreachNanoAppInstanceInfo((info) -> pw.println(info));

        pw.println("");
        pw.println("=================== NANOAPPS MESSAGES ====================");
        Iterator<NanoAppMessage> iterator = mNanoAppMessageRecords.descendingIterator();
        while (iterator.hasNext()) {
            pw.println(iterator.next());
        }

        pw.println("");
        pw.println("=================== CLIENTS ====================");
        pw.println(mClientManager);