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

Commit 597b4243 authored by Raphael Kim's avatar Raphael Kim Committed by Android (Google) Code Review
Browse files

Merge "[CDM] Implement capabilities exchange mechanism for CDM." into main

parents 15039cee cf4046d4
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -47,10 +47,12 @@ public final class AssociationInfo implements Parcelable {
     * A String indicates the selfManaged device is not connected.
     */
    private static final String LAST_TIME_CONNECTED_NONE = "None";

    /**
     * Key for the reception timestamp of the metadata.
     * @hide
     */
    static final String METADATA_TIMESTAMP = "_timestamp_";
    public static final String METADATA_TIMESTAMP = "_timestamp_";

    /**
     * A unique ID of this Association record.
+28 −0
Original line number Diff line number Diff line
@@ -312,6 +312,14 @@ public final class CompanionDeviceManager {
     * @hide
     */
    public static final int MESSAGE_REQUEST_PERMISSION_RESTORE = 0x63826983; // ?RES
    /**
     * Message header assigned to local metadata update broadcast message.
     * CDM will automatically broadcast the metadata update to paired devices. This symbol serves
     * as a reference to prevent message type conflicts and should not be used by external services.
     *
     * @hide
     */
    public static final int MESSAGE_REQUEST_METADATA_UPDATE = 0x63776885; // ?MDU
    /**
     * Message header assigned to the one-way message sent from the wearable device.
     *
@@ -1140,6 +1148,26 @@ public final class CompanionDeviceManager {
        }
    }

    /**
     * Returns the list of all associations with transports that are currently attached.
     *
     * @return the list of associations
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.USE_COMPANION_TRANSPORTS)
    public List<AssociationInfo> getAllAssociationsWithTransports() {
        if (mService == null) {
            Log.w(TAG, "CompanionDeviceManager service is not available.");
            return Collections.emptyList();
        }

        try {
            return mService.getAllAssociationsWithTransports();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Sends a message to associated remote devices. The target associations must already have a
     * connected transport.
+3 −0
Original line number Diff line number Diff line
@@ -91,6 +91,9 @@ interface ICompanionDeviceManager {
    @EnforcePermission("USE_COMPANION_TRANSPORTS")
    void removeOnTransportsChangedListener(IOnTransportsChangedListener listener);

    @EnforcePermission("USE_COMPANION_TRANSPORTS")
    List<AssociationInfo> getAllAssociationsWithTransports();

    @EnforcePermission("USE_COMPANION_TRANSPORTS")
    void sendMessage(int messageType, in byte[] data, in int[] associationIds);

+11 −2
Original line number Diff line number Diff line
@@ -198,7 +198,8 @@ public class CompanionDeviceManagerService extends SystemService {
                packageManagerInternal, mAssociationStore,
                mSystemDataTransferRequestStore, mTransportManager);

        mDataSyncProcessor = new DataSyncProcessor(mAssociationStore, mLocalMetadataStore);
        mDataSyncProcessor = new DataSyncProcessor(mAssociationStore, mLocalMetadataStore,
                mTransportManager);

        // TODO(b/279663946): move context sync to a dedicated system service
        mCrossDeviceSyncController = new CrossDeviceSyncController(getContext(), mTransportManager);
@@ -401,6 +402,14 @@ public class CompanionDeviceManagerService extends SystemService {
            mTransportManager.removeListener(listener);
        }

        @Override
        @EnforcePermission(USE_COMPANION_TRANSPORTS)
        public List<AssociationInfo> getAllAssociationsWithTransports() {
            getAllAssociationsWithTransports_enforcePermission();

            return mTransportManager.getAssociationsWithTransport();
        }

        @Override
        @EnforcePermission(USE_COMPANION_TRANSPORTS)
        public void sendMessage(int messageType, byte[] data, int[] associationIds) {
@@ -798,7 +807,7 @@ public class CompanionDeviceManagerService extends SystemService {
            return new CompanionDeviceShellCommand(CompanionDeviceManagerService.this,
                    mAssociationStore, mDevicePresenceProcessor, mTransportManager,
                    mSystemDataTransferProcessor, mAssociationRequestsProcessor,
                    mBackupRestoreProcessor, mDisassociationProcessor)
                    mBackupRestoreProcessor, mDisassociationProcessor, mDataSyncProcessor)
                    .exec(this, in.getFileDescriptor(), out.getFileDescriptor(),
                            err.getFileDescriptor(), args);
        }
+35 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.companion.datatransfer.PermissionSyncRequest;
import android.net.MacAddress;
import android.os.Binder;
import android.os.ParcelUuid;
import android.os.PersistableBundle;
import android.os.ShellCommand;
import android.util.Base64;
import android.util.proto.ProtoOutputStream;
@@ -36,6 +37,7 @@ import android.util.proto.ProtoOutputStream;
import com.android.server.companion.association.AssociationRequestsProcessor;
import com.android.server.companion.association.AssociationStore;
import com.android.server.companion.association.DisassociationProcessor;
import com.android.server.companion.datasync.DataSyncProcessor;
import com.android.server.companion.datatransfer.SystemDataTransferProcessor;
import com.android.server.companion.datatransfer.contextsync.BitmapUtils;
import com.android.server.companion.datatransfer.contextsync.CrossDeviceSyncController;
@@ -58,6 +60,7 @@ class CompanionDeviceShellCommand extends ShellCommand {
    private final SystemDataTransferProcessor mSystemDataTransferProcessor;
    private final AssociationRequestsProcessor mAssociationRequestsProcessor;
    private final BackupRestoreProcessor mBackupRestoreProcessor;
    private final DataSyncProcessor mDataSyncProcessor;

    CompanionDeviceShellCommand(CompanionDeviceManagerService service,
            AssociationStore associationStore,
@@ -66,7 +69,8 @@ class CompanionDeviceShellCommand extends ShellCommand {
            SystemDataTransferProcessor systemDataTransferProcessor,
            AssociationRequestsProcessor associationRequestsProcessor,
            BackupRestoreProcessor backupRestoreProcessor,
            DisassociationProcessor disassociationProcessor) {
            DisassociationProcessor disassociationProcessor,
            DataSyncProcessor dataSyncProcessor) {
        mService = service;
        mAssociationStore = associationStore;
        mDevicePresenceProcessor = devicePresenceProcessor;
@@ -75,6 +79,7 @@ class CompanionDeviceShellCommand extends ShellCommand {
        mAssociationRequestsProcessor = associationRequestsProcessor;
        mBackupRestoreProcessor = backupRestoreProcessor;
        mDisassociationProcessor = disassociationProcessor;
        mDataSyncProcessor = dataSyncProcessor;
    }

    @Override
@@ -462,6 +467,31 @@ class CompanionDeviceShellCommand extends ShellCommand {
                    break;
                }

                case "set-local-metadata": {
                    int userId = getNextIntArgRequired();
                    String feature = getNextArgRequired();
                    String key = getNextArgRequired();
                    String value = getNextArgRequired();
                    PersistableBundle bundle = mDataSyncProcessor.getLocalMetadata(userId)
                            .getPersistableBundle(feature);
                    if (bundle == null) {
                        bundle = new PersistableBundle();
                    }
                    if (value == null) {
                        bundle.remove(key);
                    } else {
                        try {
                            bundle.putInt(key, Integer.parseInt(value));
                        } catch (Exception e) {
                            bundle.putString(key, value);
                        }
                    }
                    mDataSyncProcessor.setLocalMetadata(userId, feature, bundle);
                    out.println("Set local metadata for user " + userId + " key " + key
                            + " value " + value);
                    break;
                }

                default:
                    return handleDefaultCommands(cmd);
            }
@@ -617,5 +647,9 @@ class CompanionDeviceShellCommand extends ShellCommand {
        pw.println("      Get perm sync state for the association.");
        pw.println("  remove-perm-sync-state <ASSOCIATION_ID>");
        pw.println("      Remove perm sync state for the association.");

        pw.println("  set-local-metadata <USER_ID> <FEATURE_KEY> <KEY> <VALUE>");
        pw.println("      Set local metadata for the user.");
        pw.println("      USE FOR DEBUGGING AND/OR TESTING PURPOSES ONLY.");
    }
}
Loading