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

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

DO NOT MERGE [DPM] DO uses batch token to retrieve network logs, and can...

DO NOT MERGE [DPM] DO uses batch token to retrieve network logs, and can retrieve the same batch many times
am: bbf352a2

Change-Id: I6df35873ec30044780fab02329bab327af8df161
parents d1c710d5 bbf352a2
Loading
Loading
Loading
Loading
+30 −4
Original line number Original line Diff line number Diff line
@@ -284,6 +284,27 @@ public class DeviceAdminReceiver extends BroadcastReceiver {
    public static final String ACTION_NETWORK_LOGS_AVAILABLE
    public static final String ACTION_NETWORK_LOGS_AVAILABLE
            = "android.app.action.NETWORK_LOGS_AVAILABLE";
            = "android.app.action.NETWORK_LOGS_AVAILABLE";


    /**
     * A {@code long} containing a token of the current batch of network logs, that has to be used
     * to retrieve the batch of logs by the device owner.
     *
     * @see #ACTION_NETWORK_LOGS_AVAILABLE
     * @see DevicePolicyManager#retrieveNetworkLogs
     * @hide
     */
    public static final String EXTRA_NETWORK_LOGS_TOKEN =
            "android.app.extra.EXTRA_NETWORK_LOGS_TOKEN";

    /**
     * An {@code int} count representing a total count of network logs inside the current batch of
     * network logs.
     *
     * @see #ACTION_NETWORK_LOGS_AVAILABLE
     * @hide
     */
    public static final String EXTRA_NETWORK_LOGS_COUNT =
            "android.app.extra.EXTRA_NETWORK_LOGS_COUNT";

    /**
    /**
     * A string containing the SHA-256 hash of the bugreport file.
     * A string containing the SHA-256 hash of the bugreport file.
     *
     *
@@ -644,19 +665,22 @@ public class DeviceAdminReceiver extends BroadcastReceiver {
    }
    }


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


    /**
    /**
@@ -714,7 +738,9 @@ public class DeviceAdminReceiver extends BroadcastReceiver {
        } 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)) {
        } else if (ACTION_NETWORK_LOGS_AVAILABLE.equals(action)) {
            onNetworkLogsAvailable(context, intent);
            long batchToken = intent.getLongExtra(EXTRA_NETWORK_LOGS_TOKEN, -1);
            int networkLogsCount = intent.getIntExtra(EXTRA_NETWORK_LOGS_COUNT, 0);
            onNetworkLogsAvailable(context, intent, batchToken, networkLogsCount);
        }
        }
    }
    }
}
}
+11 −6
Original line number Original line Diff line number Diff line
@@ -6621,8 +6621,6 @@ public class DevicePolicyManager {
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
     * @param enabled whether network logging should be enabled or not.
     * @param enabled whether network logging should be enabled or not.
     * @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
     *         the logging service not being available
     * @see #retrieveNetworkLogs
     * @see #retrieveNetworkLogs
     *
     *
     * @hide
     * @hide
@@ -6655,7 +6653,10 @@ public class DevicePolicyManager {
    }
    }


    /**
    /**
     * Called by device owner to retrieve a new batch of network logging events.
     * Called by device owner to retrieve the most recent batch of network logging events.
     * A device owner has to provide a batchToken provided as part of
     * {@link DeviceAdminReceiver#onNetworkLogsAvailable} callback. If the token doesn't match the
     * token of the most recent available batch of logs, {@code null} will be returned.
     *
     *
     * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}.
     * <p> {@link NetworkEvent} can be one of {@link DnsEvent} or {@link ConnectEvent}.
     *
     *
@@ -6666,16 +6667,20 @@ public class DevicePolicyManager {
     * {@link DeviceAdminReceiver#onNetworkLogsAvailable}.
     * {@link DeviceAdminReceiver#onNetworkLogsAvailable}.
     *
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
     * @param batchToken A token of the batch to retrieve
     * @return A new batch of network logs which is a list of {@link NetworkEvent}. Returns
     * @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.
     *        {@code null} if the batch represented by batchToken is no longer available or if
     *        logging is disabled.
     * @throws {@link SecurityException} if {@code admin} is not a device owner.
     * @throws {@link SecurityException} if {@code admin} is not a device owner.
     * @see DeviceAdminReceiver#onNetworkLogsAvailable
     *
     *
     * @hide
     * @hide
     */
     */
    public List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin) {
    public @Nullable List<NetworkEvent> retrieveNetworkLogs(@NonNull ComponentName admin,
            long batchToken) {
        throwIfParentInstance("retrieveNetworkLogs");
        throwIfParentInstance("retrieveNetworkLogs");
        try {
        try {
            return mService.retrieveNetworkLogs(admin);
            return mService.retrieveNetworkLogs(admin, batchToken);
        } catch (RemoteException re) {
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
            throw re.rethrowFromSystemServer();
        }
        }
+1 −1
Original line number Original line Diff line number Diff line
@@ -315,5 +315,5 @@ interface IDevicePolicyManager {


    void setNetworkLoggingEnabled(in ComponentName admin, boolean enabled);
    void setNetworkLoggingEnabled(in ComponentName admin, boolean enabled);
    boolean isNetworkLoggingEnabled(in ComponentName admin);
    boolean isNetworkLoggingEnabled(in ComponentName admin);
    List<NetworkEvent> retrieveNetworkLogs(in ComponentName admin);
    List<NetworkEvent> retrieveNetworkLogs(in ComponentName admin, long batchToken);
}
}
+14 −8
Original line number Original line Diff line number Diff line
@@ -488,10 +488,13 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
             * to listen for events.
             * to listen for events.
             */
             */
            if (Intent.ACTION_USER_STARTED.equals(action)
            if (Intent.ACTION_USER_STARTED.equals(action)
                    && userHandle == mOwners.getDeviceOwnerUserId()
                    && userHandle == mOwners.getDeviceOwnerUserId()) {
                    && isNetworkLoggingEnabledInternal()) {
                synchronized (DevicePolicyManagerService.this) {
                    if (isNetworkLoggingEnabledInternalLocked()) {
                        setNetworkLoggingActiveInternal(true);
                        setNetworkLoggingActiveInternal(true);
                    }
                    }
                }
            }
            if (Intent.ACTION_BOOT_COMPLETED.equals(action)
            if (Intent.ACTION_BOOT_COMPLETED.equals(action)
                    && userHandle == mOwners.getDeviceOwnerUserId()
                    && userHandle == mOwners.getDeviceOwnerUserId()
                    && getDeviceOwnerRemoteBugreportUri() != null) {
                    && getDeviceOwnerRemoteBugreportUri() != null) {
@@ -9433,7 +9436,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
        Preconditions.checkNotNull(admin);
        Preconditions.checkNotNull(admin);
        ensureDeviceOwnerManagingSingleUser(admin);
        ensureDeviceOwnerManagingSingleUser(admin);


        if (enabled == isNetworkLoggingEnabledInternal()) {
        if (enabled == isNetworkLoggingEnabledInternalLocked()) {
            // already in the requested state
            // already in the requested state
            return;
            return;
        }
        }
@@ -9474,11 +9477,11 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
        Preconditions.checkNotNull(admin);
        Preconditions.checkNotNull(admin);
        synchronized (this) {
        synchronized (this) {
            getActiveAdminForCallerLocked(admin, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER);
            getActiveAdminForCallerLocked(admin, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER);
            return isNetworkLoggingEnabledInternal();
            return isNetworkLoggingEnabledInternalLocked();
        }
        }
    }
    }


    private synchronized boolean isNetworkLoggingEnabledInternal() {
    private boolean isNetworkLoggingEnabledInternalLocked() {
        ActiveAdmin deviceOwner = getDeviceOwnerAdminLocked();
        ActiveAdmin deviceOwner = getDeviceOwnerAdminLocked();
        return (deviceOwner != null) && deviceOwner.isNetworkLoggingEnabled;
        return (deviceOwner != null) && deviceOwner.isNetworkLoggingEnabled;
    }
    }
@@ -9489,7 +9492,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
     * Ideally this would be done with ParceledList, however it only supports homogeneous types.
     * Ideally this would be done with ParceledList, however it only supports homogeneous types.
     */
     */
    @Override
    @Override
    public synchronized List<NetworkEvent> retrieveNetworkLogs(ComponentName admin) {
    public synchronized List<NetworkEvent> retrieveNetworkLogs(ComponentName admin,
            long batchToken) {
        if (!mHasFeature) {
        if (!mHasFeature) {
            return null;
            return null;
        }
        }
@@ -9499,6 +9503,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
        if (mNetworkLogger == null) {
        if (mNetworkLogger == null) {
            return null;
            return null;
        }
        }
        return isNetworkLoggingEnabledInternal() ? mNetworkLogger.retrieveLogs() : null;
        return isNetworkLoggingEnabledInternalLocked()
                ? mNetworkLogger.retrieveLogs(batchToken)
                : null;
    }
    }
}
}
+2 −2
Original line number Original line Diff line number Diff line
@@ -147,7 +147,7 @@ final class NetworkLogger {
        }
        }
    }
    }


    List<NetworkEvent> retrieveLogs() {
    List<NetworkEvent> retrieveLogs(long batchToken) {
        return mNetworkLoggingHandler.retrieveFullLogBatch();
        return mNetworkLoggingHandler.retrieveFullLogBatch(batchToken);
    }
    }
}
}
Loading