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

Commit d1c710d5 authored by Michal Karpinski's avatar Michal Karpinski Committed by android-build-merger
Browse files

DO NOT MERGE [DPM] Management and retrieval of network logs

am: 4c47adef

Change-Id: I39486c9d6116023f1ee9bd576b7fcd0fe20023a1
parents b2e86905 4c47adef
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -576,6 +576,9 @@ aidl_files := \
	frameworks/base/graphics/java/android/graphics/drawable/Icon.aidl \
	frameworks/base/graphics/java/android/graphics/drawable/Icon.aidl \
	frameworks/base/core/java/android/accounts/AuthenticatorDescription.aidl \
	frameworks/base/core/java/android/accounts/AuthenticatorDescription.aidl \
	frameworks/base/core/java/android/accounts/Account.aidl \
	frameworks/base/core/java/android/accounts/Account.aidl \
	frameworks/base/core/java/android/app/admin/ConnectEvent.aidl \
	frameworks/base/core/java/android/app/admin/DnsEvent.aidl \
	frameworks/base/core/java/android/app/admin/NetworkEvent.aidl \
	frameworks/base/core/java/android/app/admin/SystemUpdatePolicy.aidl \
	frameworks/base/core/java/android/app/admin/SystemUpdatePolicy.aidl \
	frameworks/base/core/java/android/print/PrintDocumentInfo.aidl \
	frameworks/base/core/java/android/print/PrintDocumentInfo.aidl \
	frameworks/base/core/java/android/print/PageRange.aidl \
	frameworks/base/core/java/android/print/PageRange.aidl \
+21 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.app.admin;

/** {@hide} */
parcelable ConnectEvent;
+87 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.app.admin;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * A class that represents a connect library call event.
 * @hide
 */
public final class ConnectEvent extends NetworkEvent implements Parcelable {

    /** The destination IP address. */
    private final String ipAddress;

    /** The destination port number. */
    private final int port;

    public ConnectEvent(String ipAddress, int port, String packageName, long timestamp) {
        super(packageName, timestamp);
        this.ipAddress = ipAddress;
        this.port = port;
    }

    private ConnectEvent(Parcel in) {
        this.ipAddress = in.readString();
        this.port = in.readInt();
        this.packageName = in.readString();
        this.timestamp = in.readLong();
    }

    public String getIpAddress() {
        return ipAddress;
    }

    public int getPort() {
        return port;
    }

    @Override
    public String toString() {
        return String.format("ConnectEvent(%s, %d, %d, %s)", ipAddress, port, timestamp,
                packageName);
    }

    public static final Parcelable.Creator<ConnectEvent> CREATOR
            = new Parcelable.Creator<ConnectEvent>() {
        @Override
        public ConnectEvent createFromParcel(Parcel in) {
            if (in.readInt() != PARCEL_TOKEN_CONNECT_EVENT) {
                return null;
            }
            return new ConnectEvent(in);
        }

        @Override
        public ConnectEvent[] newArray(int size) {
            return new ConnectEvent[size];
        }
    };

    @Override
    public void writeToParcel(Parcel out, int flags) {
        // write parcel token first
        out.writeInt(PARCEL_TOKEN_CONNECT_EVENT);
        out.writeString(ipAddress);
        out.writeInt(port);
        out.writeString(packageName);
        out.writeLong(timestamp);
    }
}
+27 −0
Original line number Original line Diff line number Diff line
@@ -275,6 +275,15 @@ public class DeviceAdminReceiver extends BroadcastReceiver {
    public static final String ACTION_SECURITY_LOGS_AVAILABLE
    public static final String ACTION_SECURITY_LOGS_AVAILABLE
            = "android.app.action.SECURITY_LOGS_AVAILABLE";
            = "android.app.action.SECURITY_LOGS_AVAILABLE";


    /**
     * Broadcast action: notify that a new batch of network logs is ready to be collected.
     * @see DeviceAdminReceiver#onNetworkLogsAvailable
     * @hide
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_NETWORK_LOGS_AVAILABLE
            = "android.app.action.NETWORK_LOGS_AVAILABLE";

    /**
    /**
     * A string containing the SHA-256 hash of the bugreport file.
     * A string containing the SHA-256 hash of the bugreport file.
     *
     *
@@ -634,6 +643,22 @@ public class DeviceAdminReceiver extends BroadcastReceiver {
    public void onSecurityLogsAvailable(Context context, Intent intent) {
    public void onSecurityLogsAvailable(Context context, Intent intent) {
    }
    }


    /**
     * Called when a new batch of network logs can be retrieved. This callback method will only ever
     * be called when network logging is enabled. The logs can only be retrieved while network
     * logging is enabled.
     *
     * <p>This callback is only applicable to device owners.
     *
     * @param context The running context as per {@link #onReceive}.
     * @param intent The received intent as per {@link #onReceive}.
     * @see DevicePolicyManager#retrieveNetworkLogs(ComponentName)
     *
     * @hide
     */
    public void onNetworkLogsAvailable(Context context, Intent intent) {
    }

    /**
    /**
     * Intercept standard device administrator broadcasts.  Implementations
     * Intercept standard device administrator broadcasts.  Implementations
     * should not override this method; it is better to implement the
     * should not override this method; it is better to implement the
@@ -688,6 +713,8 @@ public class DeviceAdminReceiver extends BroadcastReceiver {
            onBugreportFailed(context, intent, failureCode);
            onBugreportFailed(context, intent, failureCode);
        } else if (ACTION_SECURITY_LOGS_AVAILABLE.equals(action)) {
        } else if (ACTION_SECURITY_LOGS_AVAILABLE.equals(action)) {
            onSecurityLogsAvailable(context, intent);
            onSecurityLogsAvailable(context, intent);
        } else if (ACTION_NETWORK_LOGS_AVAILABLE.equals(action)) {
            onNetworkLogsAvailable(context, intent);
        }
        }
    }
    }
}
}
+29 −0
Original line number Original line Diff line number Diff line
@@ -25,6 +25,7 @@ import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SystemApi;
import android.annotation.SystemApi;
import android.annotation.UserIdInt;
import android.annotation.UserIdInt;
import android.app.Activity;
import android.app.Activity;
import android.app.admin.NetworkEvent;
import android.app.admin.SecurityLog.SecurityEvent;
import android.app.admin.SecurityLog.SecurityEvent;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.Context;
import android.content.Context;
@@ -6622,6 +6623,7 @@ public class DevicePolicyManager {
     * @throws {@link SecurityException} if {@code admin} is not a device owner.
     * @throws {@link SecurityException} if {@code admin} is not a device owner.
     * @throws {@link RemoteException} if network logging could not be enabled or disabled due to
     * @throws {@link RemoteException} if network logging could not be enabled or disabled due to
     *         the logging service not being available
     *         the logging service not being available
     * @see #retrieveNetworkLogs
     *
     *
     * @hide
     * @hide
     */
     */
@@ -6651,4 +6653,31 @@ public class DevicePolicyManager {
            throw re.rethrowFromSystemServer();
            throw re.rethrowFromSystemServer();
        }
        }
    }
    }

    /**
     * Called by device owner to retrieve a new batch of network logging events.
     *
     * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}.
     *
     * <p> The list of network events is sorted chronologically, and contains at most 1200 events.
     *
     * <p> Access to the logs is rate limited and this method will only return a new batch of logs
     * after the device device owner has been notified via
     * {@link DeviceAdminReceiver#onNetworkLogsAvailable}.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
     * @return A new batch of network logs which is a list of {@link NetworkEvent}. Returns
     * {@code null} if there's no batch currently awaiting for retrieval or if logging is disabled.
     * @throws {@link SecurityException} if {@code admin} is not a device owner.
     *
     * @hide
     */
    public List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin) {
        throwIfParentInstance("retrieveNetworkLogs");
        try {
            return mService.retrieveNetworkLogs(admin);
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }
}
}
Loading