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

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

Merge "[CDM][Refactor] Use Builder to instantiate AssociationInfo." into main

parents 8d4dc014 f9b1e6e2
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -99,7 +99,7 @@ public final class AssociationInfo implements Parcelable {
     *
     * @hide
     */
    public AssociationInfo(int id, @UserIdInt int userId, @NonNull String packageName,
    private AssociationInfo(int id, @UserIdInt int userId, @NonNull String packageName,
            @Nullable MacAddress macAddress, @Nullable CharSequence displayName,
            @Nullable String deviceProfile, @Nullable AssociatedDevice associatedDevice,
            boolean selfManaged, boolean notifyOnDeviceNearby, boolean revoked, boolean pending,
@@ -528,9 +528,9 @@ public final class AssociationInfo implements Parcelable {
        private boolean mNotifyOnDeviceNearby;
        private boolean mRevoked;
        private boolean mPending;
        private long mTimeApprovedMs;
        private long mLastTimeConnectedMs;
        private int mSystemDataSyncFlags;
        private long mTimeApprovedMs = System.currentTimeMillis();
        private long mLastTimeConnectedMs = Long.MAX_VALUE; // Never connected.
        private int mSystemDataSyncFlags = -1; // By default, all system data sync is enabled.
        private Icon mDeviceIcon;
        private DeviceId mDeviceId;
        private List<String> mPackagesToNotify;
+22 −8
Original line number Diff line number Diff line
@@ -477,11 +477,13 @@ public final class AssociationDiskStore {
        final boolean notify = readBooleanAttribute(parser, XML_ATTR_NOTIFY_DEVICE_NEARBY);
        final long timeApproved = readLongAttribute(parser, XML_ATTR_TIME_APPROVED, 0L);

        return new AssociationInfo(associationId, userId, appPackage,
                MacAddress.fromString(deviceAddress), null, profile, null,
                /* managedByCompanionApp */ false, notify, /* revoked */ false, /* pending */ false,
                timeApproved, Long.MAX_VALUE, /* systemDataSyncFlags */ 0, /* deviceIcon */ null,
                /* deviceId */ null, /* packagesToNotify */ null);
        return new AssociationInfo.Builder(associationId, userId, appPackage)
                .setDeviceMacAddress(MacAddress.fromString(deviceAddress))
                .setDeviceProfile(profile)
                .setNotifyOnDeviceNearby(notify)
                .setTimeApproved(timeApproved)
                .setSystemDataSyncFlags(0)
                .build();
    }

    private static Associations readAssociationsV1(@NonNull TypedXmlPullParser parser,
@@ -558,9 +560,21 @@ public final class AssociationDiskStore {
            }
        }

        return new AssociationInfo(associationId, userId, appPackage, macAddress, displayName,
                profile, null, selfManaged, notify, revoked, pending, timeApproved,
                lastTimeConnected, systemDataSyncFlags, deviceIcon, deviceId, packagesToNotify);
        return new AssociationInfo.Builder(associationId, userId, appPackage)
                .setDeviceMacAddress(macAddress)
                .setDisplayName(displayName)
                .setDeviceProfile(profile)
                .setSelfManaged(selfManaged)
                .setNotifyOnDeviceNearby(notify)
                .setRevoked(revoked)
                .setPending(pending)
                .setTimeApproved(timeApproved)
                .setLastTimeConnected(lastTimeConnected)
                .setSystemDataSyncFlags(systemDataSyncFlags)
                .setDeviceIcon(deviceIcon)
                .setDeviceId(deviceId)
                .setPackagesToNotify(packagesToNotify)
                .build();
    }

    private static List<String> readPackagesToNotify(@NonNull TypedXmlPullParser parser)
+17 −5
Original line number Diff line number Diff line
@@ -314,11 +314,23 @@ public class AssociationRequestsProcessor {
        final int id = mAssociationStore.getNextId();
        final long timestamp = System.currentTimeMillis();

        final AssociationInfo association = new AssociationInfo(id, userId, packageName,
                 macAddress, displayName, deviceProfile, associatedDevice,
                selfManaged, /* notifyOnDeviceNearby */ false, /* revoked */ false,
                /* pending */ false, timestamp, Long.MAX_VALUE, /* systemDataSyncFlags */ 0,
                deviceIcon, /* deviceId */ null, /* packagesToNotify */ null);
        final AssociationInfo association =
                new AssociationInfo.Builder(id, userId, packageName)
                        .setDeviceMacAddress(macAddress)
                        .setDisplayName(displayName)
                        .setDeviceProfile(deviceProfile)
                        .setAssociatedDevice(associatedDevice)
                        .setSelfManaged(selfManaged)
                        .setNotifyOnDeviceNearby(false)
                        .setRevoked(false)
                        .setPending(false)
                        .setTimeApproved(timestamp)
                        .setLastTimeConnected(Long.MAX_VALUE)
                        .setSystemDataSyncFlags(0)
                        .setDeviceIcon(deviceIcon)
                        .setDeviceId(null)
                        .setPackagesToNotify(null)
                        .build();

        if (skipRoleGrant) {
            Slog.i(TAG, "Created association for " + association.getDeviceProfile() + " and userId="
+10 −9
Original line number Diff line number Diff line
@@ -1561,14 +1561,15 @@ public class VirtualDeviceManagerServiceTest {
                associationId, deviceProfile, /* displayName= */ deviceProfile);
    }

    private AssociationInfo createAssociationInfo(int associationId, String deviceProfile,
            CharSequence displayName) {
        return new AssociationInfo(associationId, /* userId= */ 0, /* packageName= */ null,
                MacAddress.BROADCAST_ADDRESS, displayName, deviceProfile,
                /* associatedDevice= */ null, /* selfManaged= */ true,
                /* notifyOnDeviceNearby= */ false, /* revoked= */ false, /* pending= */ false,
                /* timeApprovedMs= */0, /* lastTimeConnectedMs= */0,
                /* systemDataSyncFlags= */ -1, /* deviceIcon= */ null, /* deviceId= */ null,
                /* packageToNotify= */ null);
    private AssociationInfo createAssociationInfo(
            int associationId, String deviceProfile, CharSequence displayName) {
        return new AssociationInfo.Builder(associationId, /* userId= */ 0, /* packageName= */ null)
                .setDeviceMacAddress(MacAddress.BROADCAST_ADDRESS)
                .setDisplayName(displayName)
                .setDeviceProfile(deviceProfile)
                .setSelfManaged(true)
                .setTimeApproved(0)
                .setLastTimeConnected(0)
                .build();
    }
}