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

Commit 5a610cb7 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add dpm force-network-logs command to force network logs retrieval."

parents 59cdf690 24ed35cd
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ public final class Dpm extends BaseCommand {
    private static final String COMMAND_SET_PROFILE_OWNER = "set-profile-owner";
    private static final String COMMAND_REMOVE_ACTIVE_ADMIN = "remove-active-admin";
    private static final String COMMAND_CLEAR_FREEZE_PERIOD_RECORD = "clear-freeze-period-record";
    private static final String COMMAND_FORCE_NETWORK_LOGS = "force-network-logs";
    private static final String COMMAND_FORCE_SECURITY_LOGS = "force-security-logs";

    private IDevicePolicyManager mDevicePolicyManager;
@@ -84,6 +85,9 @@ public final class Dpm extends BaseCommand {
                "feature development to prevent triggering restriction on setting freeze " +
                "periods.\n" +
                "\n" +
                "dpm " + COMMAND_FORCE_NETWORK_LOGS + ": makes all network logs available to " +
                "the DPC and triggers DeviceAdminReceiver.onNetworkLogsAvailable() if needed.\n" +
                "\n" +
                "dpm " + COMMAND_FORCE_SECURITY_LOGS + ": makes all security logs available to " +
                "the DPC and triggers DeviceAdminReceiver.onSecurityLogsAvailable() if needed.");
    }
@@ -114,6 +118,9 @@ public final class Dpm extends BaseCommand {
            case COMMAND_CLEAR_FREEZE_PERIOD_RECORD:
                runClearFreezePeriodRecord();
                break;
            case COMMAND_FORCE_NETWORK_LOGS:
                runForceNetworkLogs();
                break;
            case COMMAND_FORCE_SECURITY_LOGS:
                runForceSecurityLogs();
                break;
@@ -122,6 +129,18 @@ public final class Dpm extends BaseCommand {
        }
    }

    private void runForceNetworkLogs() throws RemoteException, InterruptedException {
        while (true) {
            final long toWait = mDevicePolicyManager.forceNetworkLogs();
            if (toWait == 0) {
                break;
            }
            System.out.println("We have to wait for " + toWait + " milliseconds...");
            Thread.sleep(toWait);
        }
        System.out.println("Success");
    }

    private void runForceSecurityLogs() throws RemoteException, InterruptedException {
        while (true) {
            final long toWait = mDevicePolicyManager.forceSecurityLogs();
+16 −0
Original line number Diff line number Diff line
@@ -8299,6 +8299,22 @@ public class DevicePolicyManager {
        }
    }

    /**
     * Makes all accumulated network logs available to DPC in a new batch.
     * Only callable by ADB. If throttled, returns time to wait in milliseconds, otherwise 0.
     * @hide
     */
    public long forceNetworkLogs() {
        if (mService == null) {
            return -1;
        }
        try {
            return mService.forceNetworkLogs();
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }

    /**
     * Forces a batch of security logs to be fetched from logd and makes it available for DPC.
     * Only callable by ADB. If throttled, returns time to wait in milliseconds, otherwise 0.
+1 −0
Original line number Diff line number Diff line
@@ -347,6 +347,7 @@ interface IDevicePolicyManager {
    boolean isSecurityLoggingEnabled(in ComponentName admin);
    ParceledListSlice retrieveSecurityLogs(in ComponentName admin);
    ParceledListSlice retrievePreRebootSecurityLogs(in ComponentName admin);
    long forceNetworkLogs();
    long forceSecurityLogs();

    boolean isUninstallInQueue(String packageName);
+5 −0
Original line number Diff line number Diff line
@@ -151,6 +151,11 @@ abstract class BaseIDevicePolicyManager extends IDevicePolicyManager.Stub {
        return false;
    }

    @Override
    public long forceNetworkLogs() {
        return 0;
    }

    @Override
    public long forceSecurityLogs() {
        return 0;
+14 −1
Original line number Diff line number Diff line
@@ -10694,7 +10694,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                    return false;
                }
        }
        return false;
    }
@@ -12282,6 +12281,20 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        }
    }
    @Override
    public long forceNetworkLogs() {
        enforceShell("forceNetworkLogs");
        synchronized (getLockObject()) {
            if (!isNetworkLoggingEnabledInternalLocked()) {
                throw new IllegalStateException("logging is not available");
            }
            if (mNetworkLogger != null) {
                return mNetworkLogger.forceBatchFinalization();
            }
            return 0;
        }
    }
    /** Pauses security and network logging if there are unaffiliated users on the device */
    private void maybePauseDeviceWideLoggingLocked() {
        if (!areAllUsersAffiliatedWithDeviceLocked()) {
Loading