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

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

Merge "Save list of nanoapps that a client talks with"

parents 565c6271 7f56f34e
Loading
Loading
Loading
Loading
+30 −5
Original line number Diff line number Diff line
@@ -39,6 +39,10 @@ import android.util.proto.ProtoOutputStream;

import com.android.server.location.ClientBrokerProto;

import java.util.Collections;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;

@@ -118,6 +122,13 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
     */
    private final boolean mHasAccessContextHubPermission;

    /*
     * The set of nanoapp IDs that represent the group of nanoapps this client has a messaging
     * channel with, i.e. has sent or received messages from this particular nanoapp.
     */
    private final Set<Long> mMessageChannelNanoappIdSet =
            Collections.newSetFromMap(new ConcurrentHashMap<Long, Boolean>());

    /*
     * Helper class to manage registered PendingIntent requests from the client.
     */
@@ -134,7 +145,8 @@ public class ContextHubClientBroker extends IContextHubClient.Stub

        private boolean mValid = false;

        PendingIntentRequest() {}
        PendingIntentRequest() {
        }

        PendingIntentRequest(PendingIntent pendingIntent, long nanoAppId) {
            mPendingIntent = pendingIntent;
@@ -209,6 +221,7 @@ public class ContextHubClientBroker extends IContextHubClient.Stub

        int result;
        if (isRegistered()) {
            mMessageChannelNanoappIdSet.add(message.getNanoAppId());
            ContextHubMsg messageToNanoApp =
                    ContextHubServiceUtil.createHidlContextHubMessage(mHostEndPointId, message);

@@ -269,6 +282,7 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
     * @param message the message that came from a nanoapp
     */
    /* package */ void sendMessageToClient(NanoAppMessage message) {
        mMessageChannelNanoappIdSet.add(message.getNanoAppId());
        invokeCallback(callback -> callback.onMessageFromNanoApp(message));

        Supplier<Intent> supplier =
@@ -500,6 +514,17 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
        } else {
            out += "package: " + mPackage;
        }
        if (mMessageChannelNanoappIdSet.size() > 0) {
            out += " messageChannelNanoappSet: (";
            Iterator<Long> it = mMessageChannelNanoappIdSet.iterator();
            while (it.hasNext()) {
                out += "0x" + Long.toHexString(it.next());
                if (it.hasNext()) {
                    out += ",";
                }
            }
            out += ")";
        }
        out += "]";

        return out;