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

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

Merge "Implement uid logging in the messageReported atom"

parents db99997d a8cd2c1f
Loading
Loading
Loading
Loading
+13 −8
Original line number Diff line number Diff line
@@ -38,10 +38,12 @@ public class HdmiCecAtomWriter {
     * @param message      The HDMI CEC message
     * @param direction    Whether the message is incoming, outgoing, or neither
     * @param errorCode    The error code from the final attempt to send the message
     * @param callingUid   The calling uid of the app that triggered this message
     */
    public void messageReported(HdmiCecMessage message, int direction, int errorCode) {
    public void messageReported(
            HdmiCecMessage message, int direction, int callingUid, int errorCode) {
        MessageReportedGenericArgs genericArgs = createMessageReportedGenericArgs(
                message, direction, errorCode);
                message, direction, errorCode, callingUid);
        MessageReportedSpecialArgs specialArgs = createMessageReportedSpecialArgs(message);
        messageReportedBase(genericArgs, specialArgs);
    }
@@ -51,9 +53,10 @@ public class HdmiCecAtomWriter {
     *
     * @param message      The HDMI CEC message
     * @param direction    Whether the message is incoming, outgoing, or neither
     * @param callingUid   The calling uid of the app that triggered this message
     */
    public void messageReported(HdmiCecMessage message, int direction) {
        messageReported(message, direction, ERROR_CODE_UNKNOWN);
    public void messageReported(HdmiCecMessage message, int direction, int callingUid) {
        messageReported(message, direction, callingUid, ERROR_CODE_UNKNOWN);
    }

    /**
@@ -65,11 +68,11 @@ public class HdmiCecAtomWriter {
     *                     otherwise, ERROR_CODE_UNKNOWN
     */
    private MessageReportedGenericArgs createMessageReportedGenericArgs(
            HdmiCecMessage message, int direction, int errorCode) {
            HdmiCecMessage message, int direction, int errorCode, int callingUid) {
        int sendMessageResult = errorCode == ERROR_CODE_UNKNOWN
                ? HdmiStatsEnums.SEND_MESSAGE_RESULT_UNKNOWN
                : errorCode + 10;
        return new MessageReportedGenericArgs(direction, message.getSource(),
        return new MessageReportedGenericArgs(callingUid, direction, message.getSource(),
                message.getDestination(), message.getOpcode(), sendMessageResult);
    }

@@ -134,7 +137,7 @@ public class HdmiCecAtomWriter {
            MessageReportedSpecialArgs specialArgs) {
        FrameworkStatsLog.write(
                FrameworkStatsLog.HDMI_CEC_MESSAGE_REPORTED,
                0, // Placeholder field
                genericArgs.mUid,
                genericArgs.mDirection,
                genericArgs.mInitiatorLogicalAddress,
                genericArgs.mDestinationLogicalAddress,
@@ -167,14 +170,16 @@ public class HdmiCecAtomWriter {
     * Contains the required arguments for creating any HdmiCecMessageReported atom
     */
    private class MessageReportedGenericArgs {
        final int mUid;
        final int mDirection;
        final int mInitiatorLogicalAddress;
        final int mDestinationLogicalAddress;
        final int mOpcode;
        final int mSendMessageResult;

        MessageReportedGenericArgs(int direction, int initiatorLogicalAddress,
        MessageReportedGenericArgs(int uid, int direction, int initiatorLogicalAddress,
                int destinationLogicalAddress, int opcode, int sendMessageResult) {
            this.mUid = uid;
            this.mDirection = direction;
            this.mInitiatorLogicalAddress = initiatorLogicalAddress;
            this.mDestinationLogicalAddress = destinationLogicalAddress;
+21 −5
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.hardware.tv.cec.V1_0.Result;
import android.hardware.tv.cec.V1_0.SendMessageResult;
import android.icu.util.IllformedLocaleException;
import android.icu.util.ULocale;
import android.os.Binder;
import android.os.Handler;
import android.os.IHwBinder;
import android.os.Looper;
@@ -525,12 +526,14 @@ final class HdmiCecController {
    // Run a Runnable on IO thread.
    // It should be careful to access member variables on IO thread because
    // it can be accessed from system thread as well.
    private void runOnIoThread(Runnable runnable) {
        mIoHandler.post(runnable);
    @VisibleForTesting
    void runOnIoThread(Runnable runnable) {
        mIoHandler.post(new WorkSourceUidPreservingRunnable(runnable));
    }

    private void runOnServiceThread(Runnable runnable) {
        mControlHandler.post(runnable);
    @VisibleForTesting
    void runOnServiceThread(Runnable runnable) {
        mControlHandler.post(new WorkSourceUidPreservingRunnable(runnable));
    }

    @ServiceThreadOnly
@@ -591,6 +594,18 @@ final class HdmiCecController {
        sendCommand(cecMessage, null);
    }

    /**
     * Returns the calling UID of the original Binder call that triggered this code.
     * If this code was not triggered by a Binder call, returns the UID of this process.
     */
    private int getCallingUid() {
        int workSourceUid = Binder.getCallingWorkSourceUid();
        if (workSourceUid == -1) {
            return Binder.getCallingUid();
        }
        return workSourceUid;
    }

    @ServiceThreadOnly
    void sendCommand(final HdmiCecMessage cecMessage,
            final HdmiControlService.SendMessageCallback callback) {
@@ -621,6 +636,7 @@ final class HdmiCecController {
                        mHdmiCecAtomWriter.messageReported(
                                cecMessage,
                                FrameworkStatsLog.HDMI_CEC_MESSAGE_REPORTED__DIRECTION__OUTGOING,
                                getCallingUid(),
                                finalError
                        );
                        if (callback != null) {
@@ -643,7 +659,7 @@ final class HdmiCecController {
        addCecMessageToHistory(true /* isReceived */, command);

        mHdmiCecAtomWriter.messageReported(command,
                incomingMessageDirection(srcAddress, dstAddress));
                incomingMessageDirection(srcAddress, dstAddress), getCallingUid());

        onReceiveCommand(command);
    }
+80 −62

File changed.

Preview size limit exceeded, changes collapsed.

+45 −0

File added.

Preview size limit exceeded, changes collapsed.

+39 −6

File changed.

Preview size limit exceeded, changes collapsed.

Loading