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

Commit adb94753 authored by Wenhao Wang's avatar Wenhao Wang Committed by Android (Google) Code Review
Browse files

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

Merge "Change to use static constructor to avoid potential resource leaking in IntrusionDetectionEvent constructor." into main
parents 4240e696 890b1ffd
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -12728,9 +12728,9 @@ package android.security.authenticationpolicy {
package android.security.intrusiondetection {
package android.security.intrusiondetection {
  @FlaggedApi("android.security.afl_api") public final class IntrusionDetectionEvent implements android.os.Parcelable {
  @FlaggedApi("android.security.afl_api") public final class IntrusionDetectionEvent implements android.os.Parcelable {
    ctor public IntrusionDetectionEvent(@NonNull android.app.admin.SecurityLog.SecurityEvent);
    method @NonNull public static android.security.intrusiondetection.IntrusionDetectionEvent createForConnectEvent(@NonNull android.app.admin.ConnectEvent);
    ctor public IntrusionDetectionEvent(@NonNull android.app.admin.DnsEvent);
    method @NonNull public static android.security.intrusiondetection.IntrusionDetectionEvent createForDnsEvent(@NonNull android.app.admin.DnsEvent);
    ctor public IntrusionDetectionEvent(@NonNull android.app.admin.ConnectEvent);
    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 @FlaggedApi("android.security.afl_api") public int describeContents();
    method @NonNull public android.app.admin.ConnectEvent getConnectEvent();
    method @NonNull public android.app.admin.ConnectEvent getConnectEvent();
    method @NonNull public android.app.admin.DnsEvent getDnsEvent();
    method @NonNull public android.app.admin.DnsEvent getDnsEvent();
+42 −9
Original line number Original line Diff line number Diff line
@@ -91,12 +91,12 @@ public final class IntrusionDetectionEvent implements Parcelable {
            };
            };


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


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


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


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