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

Commit 890b1ffd authored by Mark Teffeteller's avatar Mark Teffeteller
Browse files

Change to use static constructor to avoid potential resource leaking in...

Change to use static constructor to avoid potential resource leaking in IntrusionDetectionEvent constructor.

Bug: 384055545
Test: atest frameworks/base/services/tests/security/intrusiondetection/src/com/android
/server/security/intrusiondetection/IntrusionDetectionServiceTest.java
Flag: android.security.afl_api
Ignore-AOSP-First: security feature

Change-Id: I57f367cf045527dd1f9800865402991807c4bd79
parent 7177560e
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -12734,9 +12734,9 @@ package android.security.authenticationpolicy {
package android.security.intrusiondetection {
  @FlaggedApi("android.security.afl_api") public final class IntrusionDetectionEvent implements android.os.Parcelable {
    ctor public IntrusionDetectionEvent(@NonNull android.app.admin.SecurityLog.SecurityEvent);
    ctor public IntrusionDetectionEvent(@NonNull android.app.admin.DnsEvent);
    ctor public IntrusionDetectionEvent(@NonNull android.app.admin.ConnectEvent);
    method @NonNull public static android.security.intrusiondetection.IntrusionDetectionEvent createForConnectEvent(@NonNull android.app.admin.ConnectEvent);
    method @NonNull public static android.security.intrusiondetection.IntrusionDetectionEvent createForDnsEvent(@NonNull android.app.admin.DnsEvent);
    method @NonNull public static android.security.intrusiondetection.IntrusionDetectionEvent createForSecurityEvent(@NonNull android.app.admin.SecurityLog.SecurityEvent);
    method @FlaggedApi("android.security.afl_api") public int describeContents();
    method @NonNull public android.app.admin.ConnectEvent getConnectEvent();
    method @NonNull public android.app.admin.DnsEvent getDnsEvent();
+42 −9
Original line number Diff line number Diff line
@@ -91,12 +91,12 @@ public final class IntrusionDetectionEvent implements Parcelable {
            };

    /**
     * Creates an IntrusionDetectionEvent object with a
     * {@link SecurityEvent} object as the event source.
     * Creates an IntrusionDetectionEvent object with a {@link SecurityEvent} object as the event
     * source.
     *
     * @param securityEvent The SecurityEvent object.
     */
    public IntrusionDetectionEvent(@NonNull SecurityEvent securityEvent) {
    private IntrusionDetectionEvent(@NonNull SecurityEvent securityEvent) {
        mType = SECURITY_EVENT;
        mSecurityEvent = securityEvent;
        mNetworkEventDns = null;
@@ -104,12 +104,11 @@ public final class IntrusionDetectionEvent implements Parcelable {
    }

    /**
     * Creates an IntrusionDetectionEvent object with a
     * {@link DnsEvent} object as the event source.
     * Creates an IntrusionDetectionEvent object with a {@link DnsEvent} object as the event source.
     *
     * @param dnsEvent The DnsEvent object.
     */
    public IntrusionDetectionEvent(@NonNull DnsEvent dnsEvent) {
    private IntrusionDetectionEvent(@NonNull DnsEvent dnsEvent) {
        mType = NETWORK_EVENT_DNS;
        mNetworkEventDns = dnsEvent;
        mSecurityEvent = null;
@@ -117,18 +116,52 @@ public final class IntrusionDetectionEvent implements Parcelable {
    }

    /**
     * Creates an IntrusionDetectionEvent object with a
     * {@link ConnectEvent} object as the event source.
     * Creates an IntrusionDetectionEvent object with a {@link ConnectEvent} object as the event
     * source.
     *
     * @param connectEvent The ConnectEvent object.
     */
    public IntrusionDetectionEvent(@NonNull ConnectEvent connectEvent) {
    private IntrusionDetectionEvent(@NonNull ConnectEvent connectEvent) {
        mType = NETWORK_EVENT_CONNECT;
        mNetworkEventConnect = connectEvent;
        mSecurityEvent = null;
        mNetworkEventDns = null;
    }

    /**
     * Creates an IntrusionDetectionEvent object with a {@link SecurityEvent} object as the event
     * source.
     *
     * @param securityEvent The SecurityEvent object.
     */
    @NonNull
    public static IntrusionDetectionEvent createForSecurityEvent(
            @NonNull SecurityEvent securityEvent) {
        return new IntrusionDetectionEvent(securityEvent);
    }

    /**
     * Creates an IntrusionDetectionEvent object with a {@link DnsEvent} object as the event source.
     *
     * @param dnsEvent The DnsEvent object.
     */
    @NonNull
    public static IntrusionDetectionEvent createForDnsEvent(@NonNull DnsEvent dnsEvent) {
        return new IntrusionDetectionEvent(dnsEvent);
    }

    /**
     * Creates an IntrusionDetectionEvent object with a {@link ConnectEvent} object as the event
     * source.
     *
     * @param connectEvent The ConnectEvent object.
     */
    @NonNull
    public static IntrusionDetectionEvent createForConnectEvent(
            @NonNull ConnectEvent connectEvent) {
        return new IntrusionDetectionEvent(connectEvent);
    }

    private IntrusionDetectionEvent(@NonNull Parcel in) {
        mType = in.readInt();
        switch (mType) {
+2 −1
Original line number Diff line number Diff line
@@ -44,7 +44,8 @@ import java.util.List;
 * which will then be delivered to the specified location.
 *
 * Usage:
 * 1. Obtain an instance of {@link IntrusionDetectionEventTransport} using the constructor.
 * 1. Obtain an instance of {@link IntrusionDetectionEventTransport} using the appropriate
 *    creation method.
 * 2. Initialize the transport by calling {@link #initialize()}.
 * 3. Add events to the transport queue using {@link #addData(List)}.
 * 4. Release the transport when finished by calling {@link #release()}.
+1 −1
Original line number Diff line number Diff line
@@ -230,7 +230,7 @@ public class IntrusionDetectionManager {
    /**
     * Disable intrusion detection.
     * If successful, IntrusionDetectionService will transition to {@link #STATE_DISABLED}.
     * <p>
     *
     * When intrusion detection is disabled, device events will no longer be collected.
     * Any events that have been collected but not yet sent to IntrusionDetectionEventTransport
     * will be transferred as a final batch.
+4 −2
Original line number Diff line number Diff line
@@ -129,7 +129,8 @@ public class NetworkLogSource implements DataSource {
                                    timestamp);
                    dnsEvent.setId(mId);
                    incrementEventID();
                    mDataAggregator.addSingleData(new IntrusionDetectionEvent(dnsEvent));
                    mDataAggregator.addSingleData(
                            IntrusionDetectionEvent.createForDnsEvent(dnsEvent));
                }

                @Override
@@ -141,7 +142,8 @@ public class NetworkLogSource implements DataSource {
                            new ConnectEvent(ipAddr, port, mPm.getNameForUid(uid), timestamp);
                    connectEvent.setId(mId);
                    incrementEventID();
                    mDataAggregator.addSingleData(new IntrusionDetectionEvent(connectEvent));
                    mDataAggregator.addSingleData(
                            IntrusionDetectionEvent.createForConnectEvent(connectEvent));
                }
            };
}
Loading