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

Commit c3abd34c authored by Michal Karpinski's avatar Michal Karpinski
Browse files

DO NOT MERGE [DPM] DO can start network logging and listen for events

This CL adds:
1) Setter and getter in DPM to manipulate logging switch (retrieval
method to come in a subsequent CL(s)).
2) A way for DPM to register to listen for events.
3) Skeleton of NetworkLogger class (more to come in subsequent CL(s)).

Bug: 29748723
Change-Id: I5c04662ccc6febd2ba294b0eaca1ed1da9c16e47
parent c5700918
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -202,6 +202,7 @@ LOCAL_SRC_FILES += \
	core/java/android/net/IIpConnectivityMetrics.aidl \
	core/java/android/net/IIpConnectivityMetrics.aidl \
	core/java/android/net/IEthernetManager.aidl \
	core/java/android/net/IEthernetManager.aidl \
	core/java/android/net/IEthernetServiceListener.aidl \
	core/java/android/net/IEthernetServiceListener.aidl \
	core/java/android/net/INetdEventCallback.aidl \
	core/java/android/net/INetworkManagementEventObserver.aidl \
	core/java/android/net/INetworkManagementEventObserver.aidl \
	core/java/android/net/INetworkPolicyListener.aidl \
	core/java/android/net/INetworkPolicyListener.aidl \
	core/java/android/net/INetworkPolicyManager.aidl \
	core/java/android/net/INetworkPolicyManager.aidl \
+42 −0
Original line number Original line Diff line number Diff line
@@ -6609,4 +6609,46 @@ public class DevicePolicyManager {
            throw re.rethrowFromSystemServer();
            throw re.rethrowFromSystemServer();
        }
        }
    }
    }

    /**
     * Called by a device owner to control the network logging feature. Logging can only be
     * enabled on single user devices where the sole user is managed by the device owner. If a new
     * user is added on the device, logging is disabled.
     *
     * <p> Network logs contain DNS lookup and connect() library call events.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
     * @param enabled whether network logging should be enabled or not.
     * @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
     *         the logging service not being available
     *
     * @hide
     */
    public void setNetworkLoggingEnabled(@NonNull ComponentName admin, boolean enabled) {
        throwIfParentInstance("setNetworkLoggingEnabled");
        try {
            mService.setNetworkLoggingEnabled(admin, enabled);
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }

    /**
     * Return whether network logging is enabled by a device owner.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
     * @return {@code true} if network logging is enabled by device owner, {@code false} otherwise.
     * @throws {@link SecurityException} if {@code admin} is not a device owner.
     *
     * @hide
     */
    public boolean isNetworkLoggingEnabled(@NonNull ComponentName admin) {
        throwIfParentInstance("isNetworkLoggingEnabled");
        try {
            return mService.isNetworkLoggingEnabled(admin);
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }
}
}
+3 −0
Original line number Original line Diff line number Diff line
@@ -311,4 +311,7 @@ interface IDevicePolicyManager {


    void setBackupServiceEnabled(in ComponentName admin, boolean enabled);
    void setBackupServiceEnabled(in ComponentName admin, boolean enabled);
    boolean isBackupServiceEnabled(in ComponentName admin);
    boolean isBackupServiceEnabled(in ComponentName admin);

    void setNetworkLoggingEnabled(in ComponentName admin, boolean enabled);
    boolean isNetworkLoggingEnabled(in ComponentName admin);
}
}
+10 −0
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ package android.net;


import android.os.Parcelable;
import android.os.Parcelable;
import android.net.ConnectivityMetricsEvent;
import android.net.ConnectivityMetricsEvent;
import android.net.INetdEventCallback;


/** {@hide} */
/** {@hide} */
interface IIpConnectivityMetrics {
interface IIpConnectivityMetrics {
@@ -27,4 +28,13 @@ interface IIpConnectivityMetrics {
     * or -1 if the event was dropped due to rate limiting.
     * or -1 if the event was dropped due to rate limiting.
     */
     */
    int logEvent(in ConnectivityMetricsEvent event);
    int logEvent(in ConnectivityMetricsEvent event);

    /**
     * At most one callback can be registered (by DevicePolicyManager).
     * @return status {@code true} if registering/unregistering of the callback was successful,
     *         {@code false} otherwise (might happen if IIpConnectivityMetrics is not available,
     *         if it happens make sure you call it when the service is up in the caller)
     */
    boolean registerNetdEventCallback(in INetdEventCallback callback);
    boolean unregisterNetdEventCallback();
}
}
+47 −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.net;

/** {@hide} */
oneway interface INetdEventCallback {

    /**
     * Reports a single DNS lookup function call.
     * This method must not block or perform long-running operations.
     *
     * @param hostname the name that was looked up.
     * @param ipAddresses (possibly a subset of) the IP addresses returned.
     *        At most {@link #DNS_REPORTED_IP_ADDRESSES_LIMIT} addresses are logged.
     * @param ipAddressesCount the number of IP addresses returned. May be different from the length
     *        of ipAddresses if there were too many addresses to log.
     * @param timestamp the timestamp at which the query was reported by netd.
     * @param uid the UID of the application that performed the query.
     */
    void onDnsEvent(String hostname, in String[] ipAddresses, int ipAddressesCount, long timestamp,
            int uid);

    /**
     * Reports a single connect library call.
     * This method must not block or perform long-running operations.
     *
     * @param ipAddr destination IP address.
     * @param port destination port number.
     * @param timestamp the timestamp at which the call was reported by netd.
     * @param uid the UID of the application that performed the connection.
     */
    void onConnectEvent(String ipAddr, int port, long timestamp, int uid);
}
Loading