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

Commit 66a8035e authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Adds EnforcePermission to IContextHubEndpoint interface" into main

parents 950a47ab 37cc1cf1
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ interface IContextHubEndpoint {
     * @throws IllegalArgumentException If the HubEndpointInfo is not valid.
     * @throws IllegalStateException If there are too many opened sessions.
     */
    @EnforcePermission("ACCESS_CONTEXT_HUB")
    int openSession(in HubEndpointInfo destination, in @nullable String serviceDescriptor);

    /**
@@ -49,6 +50,7 @@ interface IContextHubEndpoint {
     *
     * @throws IllegalStateException If the session wasn't opened.
     */
    @EnforcePermission("ACCESS_CONTEXT_HUB")
    void closeSession(int sessionId, int reason);

    /**
@@ -60,11 +62,13 @@ interface IContextHubEndpoint {
     *
     * @throws IllegalStateException If the session wasn't opened.
     */
    @EnforcePermission("ACCESS_CONTEXT_HUB")
    void openSessionRequestComplete(int sessionId);

    /**
     * Unregister this endpoint from the HAL, invalidate the EndpointInfo previously assigned.
     */
    @EnforcePermission("ACCESS_CONTEXT_HUB")
    void unregister();

    /**
@@ -76,6 +80,7 @@ interface IContextHubEndpoint {
     * @param transactionCallback Nullable. If the hub message requires a reply, the transactionCallback
     *                            will be set to non-null.
     */
    @EnforcePermission("ACCESS_CONTEXT_HUB")
    void sendMessage(int sessionId, in HubMessage message,
                     in @nullable IContextHubTransactionCallback transactionCallback);

@@ -87,5 +92,6 @@ interface IContextHubEndpoint {
     * @param messageSeqNumber The message sequence number, this should match a previously received HubMessage.
     * @param errorCode The message delivery status detail.
     */
    @EnforcePermission("ACCESS_CONTEXT_HUB")
    void sendMessageDeliveryStatus(int sessionId, int messageSeqNumber, byte errorCode);
}
+12 −6
Original line number Diff line number Diff line
@@ -112,9 +112,10 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub
    }

    @Override
    @android.annotation.EnforcePermission(android.Manifest.permission.ACCESS_CONTEXT_HUB)
    public int openSession(HubEndpointInfo destination, String serviceDescriptor)
            throws RemoteException {
        ContextHubServiceUtil.checkPermissions(mContext);
        super.openSession_enforcePermission();
        if (!mIsRegistered.get()) throw new IllegalStateException("Endpoint is not registered");
        int sessionId = mEndpointManager.reserveSessionId();
        EndpointInfo halEndpointInfo = ContextHubServiceUtil.convertHalEndpointInfo(destination);
@@ -139,8 +140,9 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub
    }

    @Override
    @android.annotation.EnforcePermission(android.Manifest.permission.ACCESS_CONTEXT_HUB)
    public void closeSession(int sessionId, int reason) throws RemoteException {
        ContextHubServiceUtil.checkPermissions(mContext);
        super.closeSession_enforcePermission();
        if (!mIsRegistered.get()) throw new IllegalStateException("Endpoint is not registered");
        try {
            mContextHubProxy.closeEndpointSession(sessionId, (byte) reason);
@@ -151,8 +153,9 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub
    }

    @Override
    @android.annotation.EnforcePermission(android.Manifest.permission.ACCESS_CONTEXT_HUB)
    public void unregister() {
        ContextHubServiceUtil.checkPermissions(mContext);
        super.unregister_enforcePermission();
        mIsRegistered.set(false);
        try {
            mContextHubProxy.unregisterEndpoint(mHalEndpointInfo);
@@ -174,8 +177,9 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub
    }

    @Override
    @android.annotation.EnforcePermission(android.Manifest.permission.ACCESS_CONTEXT_HUB)
    public void openSessionRequestComplete(int sessionId) {
        ContextHubServiceUtil.checkPermissions(mContext);
        super.openSessionRequestComplete_enforcePermission();
        synchronized (mOpenSessionLock) {
            try {
                mContextHubProxy.endpointSessionOpenComplete(sessionId);
@@ -187,9 +191,10 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub
    }

    @Override
    @android.annotation.EnforcePermission(android.Manifest.permission.ACCESS_CONTEXT_HUB)
    public void sendMessage(
            int sessionId, HubMessage message, IContextHubTransactionCallback callback) {
        ContextHubServiceUtil.checkPermissions(mContext);
        super.sendMessage_enforcePermission();
        Message halMessage = ContextHubServiceUtil.createHalMessage(message);
        synchronized (mOpenSessionLock) {
            if (!mActiveSessionIds.contains(sessionId)
@@ -227,8 +232,9 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub
    }

    @Override
    @android.annotation.EnforcePermission(android.Manifest.permission.ACCESS_CONTEXT_HUB)
    public void sendMessageDeliveryStatus(int sessionId, int messageSeqNumber, byte errorCode) {
        ContextHubServiceUtil.checkPermissions(mContext);
        super.sendMessageDeliveryStatus_enforcePermission();
        MessageDeliveryStatus status = new MessageDeliveryStatus();
        status.messageSequenceNumber = messageSeqNumber;
        status.errorCode = errorCode;