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

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

Merge "Introduce "adb shell dpm force-security-logs""

parents 066b551e 5bb5a621
Loading
Loading
Loading
Loading
+22 −2
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_SECURITY_LOGS = "force-security-logs";

    private IDevicePolicyManager mDevicePolicyManager;
    private int mUserId = UserHandle.USER_SYSTEM;
@@ -76,11 +77,15 @@ public final class Dpm extends BaseCommand {
                "\n" +
                "dpm remove-active-admin: Disables an active admin, the admin must have declared" +
                " android:testOnly in the application in its manifest. This will also remove" +
                " device and profile owners\n" +
                " device and profile owners.\n" +
                "\n" +
                "dpm " + COMMAND_CLEAR_FREEZE_PERIOD_RECORD + ": clears framework-maintained " +
                "record of past freeze periods that the device went through. For use during " +
                "feature development to prevent triggering restriction on setting freeze periods");
                "feature development to prevent triggering restriction on setting freeze " +
                "periods.\n" +
                "\n" +
                "dpm " + COMMAND_FORCE_SECURITY_LOGS + ": makes all security logs available to " +
                "the DPC and triggers DeviceAdminReceiver.onSecurityLogsAvailable() if needed.");
    }

    @Override
@@ -109,11 +114,26 @@ public final class Dpm extends BaseCommand {
            case COMMAND_CLEAR_FREEZE_PERIOD_RECORD:
                runClearFreezePeriodRecord();
                break;
            case COMMAND_FORCE_SECURITY_LOGS:
                runForceSecurityLogs();
                break;
            default:
                throw new IllegalArgumentException ("unknown command '" + command + "'");
        }
    }

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

    private void parseArgs(boolean canHaveName) {
        String opt;
        while ((opt = nextOption()) != null) {
+17 −0
Original line number Diff line number Diff line
@@ -7682,6 +7682,7 @@ public class DevicePolicyManager {
            throw re.rethrowFromSystemServer();
        }
    }

    /**
     * Called by a device owner or profile owner of secondary users that is affiliated with the
     * device to disable the keyguard altogether.
@@ -8319,6 +8320,22 @@ public class DevicePolicyManager {
        }
    }

    /**
     * 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.
     * @hide
     */
    public long forceSecurityLogs() {
        if (mService == null) {
            return 0;
        }
        try {
            return mService.forceSecurityLogs();
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }

    /**
     * Called by the system to obtain a {@link DevicePolicyManager} whose calls act on the parent
     * profile.
+1 −0
Original line number Diff line number Diff line
@@ -349,6 +349,7 @@ interface IDevicePolicyManager {
    boolean isSecurityLoggingEnabled(in ComponentName admin);
    ParceledListSlice retrieveSecurityLogs(in ComponentName admin);
    ParceledListSlice retrievePreRebootSecurityLogs(in ComponentName admin);
    long forceSecurityLogs();

    boolean isUninstallInQueue(String packageName);
    void uninstallPackageWithActiveAdmins(String packageName);
+5 −0
Original line number Diff line number Diff line
@@ -177,4 +177,9 @@ abstract class BaseIDevicePolicyManager extends IDevicePolicyManager.Stub {
            String packageName, int userId) {
        return false;
    }

    @Override
    public long forceSecurityLogs() {
        return 0;
    }
}
+9 −0
Original line number Diff line number Diff line
@@ -11659,6 +11659,15 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        return logs != null ? new ParceledListSlice<SecurityEvent>(logs) : null;
    }
    @Override
    public long forceSecurityLogs() {
        enforceShell("forceSecurityLogs");
        if (!mInjector.securityLogGetLoggingEnabledProperty()) {
            throw new IllegalStateException("logging is not available");
        }
        return mSecurityLogMonitor.forceLogs();
    }
    private void enforceCanManageDeviceAdmin() {
        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_DEVICE_ADMINS,
                null);
Loading