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

Commit 0f56760c authored by Evan Chen's avatar Evan Chen
Browse files

Move simuilate device appeared/disappeared back

Reintroduce these two commands to revert the regression.

Test: cts
Bug: 307685323
Change-Id: I6daf0783810fcb92ebb57dd8bfc299008a9eb877
parent b94c7a94
Loading
Loading
Loading
Loading
+48 −12
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.companion.CompanionDeviceManager.MESSAGE_REQUEST_CONTEXT_S

import android.companion.AssociationInfo;
import android.companion.ContextSyncMessage;
import android.companion.Flags;
import android.companion.Telecom;
import android.companion.datatransfer.PermissionSyncRequest;
import android.net.MacAddress;
@@ -65,7 +66,14 @@ class CompanionDeviceShellCommand extends ShellCommand {
    public int onCommand(String cmd) {
        final PrintWriter out = getOutPrintWriter();
        final int associationId;

        try {
            if ("simulate-device-event".equals(cmd) && Flags.devicePresence()) {
                associationId = getNextIntArgRequired();
                int event = getNextIntArgRequired();
                mDevicePresenceMonitor.simulateDeviceEvent(associationId, event);
                return 0;
            }
            switch (cmd) {
                case "list": {
                    final int userId = getNextIntArgRequired();
@@ -107,10 +115,15 @@ class CompanionDeviceShellCommand extends ShellCommand {
                    mService.loadAssociationsFromDisk();
                    break;

                case "simulate-device-event":
                case "simulate-device-appeared":
                    associationId = getNextIntArgRequired();
                    int event = getNextIntArgRequired();
                    mDevicePresenceMonitor.simulateDeviceEvent(associationId, event);
                    mDevicePresenceMonitor.simulateDeviceEvent(associationId, /* event */ 0);
                    break;

                case "simulate-device-disappeared":
                    associationId = getNextIntArgRequired();
                    mDevicePresenceMonitor.simulateDeviceEvent(associationId, /* event */ 1);
                    break;

                case "remove-inactive-associations": {
                    // This command should trigger the same "clean-up" job as performed by the
@@ -346,9 +359,7 @@ class CompanionDeviceShellCommand extends ShellCommand {
        pw.println("      information from persistent storage. USE FOR DEBUGGING PURPOSES ONLY.");
        pw.println("      USE FOR DEBUGGING AND/OR TESTING PURPOSES ONLY.");

        pw.println("  simulate-device-event ASSOCIATION_ID EVENT");
        pw.println("  Simulate the companion device event changes:");
        pw.println("    Case(0): ");
        pw.println("  simulate-device-appeared ASSOCIATION_ID");
        pw.println("      Make CDM act as if the given companion device has appeared.");
        pw.println("      I.e. bind the associated companion application's");
        pw.println("      CompanionDeviceService(s) and trigger onDeviceAppeared() callback.");
@@ -356,18 +367,43 @@ class CompanionDeviceShellCommand extends ShellCommand {
        pw.println("      will act as if device disappeared, unless 'simulate-device-disappeared'");
        pw.println("      or 'simulate-device-appeared' is called again before 60 seconds run out"
                + ".");
        pw.println("    Case(1): ");
        pw.println("      USE FOR DEBUGGING AND/OR TESTING PURPOSES ONLY.");

        pw.println("  simulate-device-disappeared ASSOCIATION_ID");
        pw.println("      Make CDM act as if the given companion device has disappeared.");
        pw.println("      I.e. unbind the associated companion application's");
        pw.println("      CompanionDeviceService(s) and trigger onDeviceDisappeared() callback.");
        pw.println("      NOTE: This will only have effect if 'simulate-device-appeared' was");
        pw.println("      invoked for the same device (same ASSOCIATION_ID) no longer than");
        pw.println("      60 seconds ago.");

        if (Flags.devicePresence()) {
            pw.println("  simulate-device-event ASSOCIATION_ID EVENT");
            pw.println("  Simulate the companion device event changes:");
            pw.println("    Case(0): ");
            pw.println("      Make CDM act as if the given companion device has appeared.");
            pw.println("      I.e. bind the associated companion application's");
            pw.println("      CompanionDeviceService(s) and trigger onDeviceAppeared() callback.");
            pw.println("      The CDM will consider the devices as present for"
                    + "60 seconds and then");
            pw.println("      will act as if device disappeared, unless"
                    + "'simulate-device-disappeared'");
            pw.println("      or 'simulate-device-appeared' is called again before 60 seconds"
                    + "run out.");
            pw.println("    Case(1): ");
            pw.println("      Make CDM act as if the given companion device has disappeared.");
            pw.println("      I.e. unbind the associated companion application's");
            pw.println("      CompanionDeviceService(s) and trigger onDeviceDisappeared()"
                    + "callback.");
            pw.println("      NOTE: This will only have effect if 'simulate-device-appeared' was");
            pw.println("      invoked for the same device (same ASSOCIATION_ID) no longer than");
            pw.println("      60 seconds ago.");
            pw.println("    Case(2): ");
            pw.println("      Make CDM act as if the given companion device is BT connected ");
            pw.println("    Case(3): ");
            pw.println("      Make CDM act as if the given companion device is BT disconnected ");
            pw.println("      USE FOR DEBUGGING AND/OR TESTING PURPOSES ONLY.");
        }

        pw.println("  remove-inactive-associations");
        pw.println("      Remove self-managed associations that have not been active ");
+1 −1
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ public class CompanionDevicePresenceMonitor implements AssociationStore.OnChange
        void onDeviceDisappeared(int associationId);

        /**Invoked when device has corresponding event changes. */
        void onDeviceEvent(int associationId, int state);
        void onDeviceEvent(int associationId, int event);
    }

    private final @NonNull AssociationStore mAssociationStore;