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

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

Merge changes from topics...

Merge changes from topics "cherrypicker-L79300000959313887:N44400001350255483", "presubmit-am-8be4197d2a474227bfd9dda9ea6229b0" into tm-mainline-prod

* changes:
  Support Event 1.1 with Datetime field.
  Refactor ObexTime to use java.time.Instant to prevent introducing new usages of java.util.Date.
  Fix address consolidation in SDP lookup and BT Obex Transport.
parents 5b813416 4cd29980
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -119,7 +119,9 @@ public class BluetoothObexTransport implements ObexTransport {
        if (mSocket == null) {
            return null;
        }
        return mSocket.getRemoteDevice().getAddress();
        return mSocket.getConnectionType() == BluetoothSocket.TYPE_RFCOMM
                ? mSocket.getRemoteDevice().getIdentityAddress()
                : mSocket.getRemoteDevice().getAddress();
    }

    @Override
+13 −7
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ import com.android.vcard.VCardConstants;
import com.android.vcard.VCardEntry;
import com.android.vcard.VCardProperty;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
@@ -152,7 +153,8 @@ class MceStateMachine extends StateMachine {
     * Note: In the future it may be best to use the entries from the MessageListing in full instead
     * of this small subset.
     */
    private class MessageMetadata {
    @VisibleForTesting
    static class MessageMetadata {
        private final String mHandle;
        private final Long mTimestamp;
        private boolean mRead;
@@ -181,7 +183,8 @@ class MceStateMachine extends StateMachine {
    }

    // Map each message to its metadata via the handle
    private ConcurrentHashMap<String, MessageMetadata> mMessages =
    @VisibleForTesting
    ConcurrentHashMap<String, MessageMetadata> mMessages =
            new ConcurrentHashMap<String, MessageMetadata>();

    MceStateMachine(MapClientService service, BluetoothDevice device) {
@@ -689,12 +692,15 @@ class MceStateMachine extends StateMachine {
                    }
                    switch (ev.getType()) {
                        case NEW_MESSAGE:
                            // Infer the timestamp for this message as 'now' and read status false
                            // instead of getting the message listing data for it
                            if (!mMessages.contains(ev.getHandle())) {
                                Calendar calendar = Calendar.getInstance();
                            if (!mMessages.containsKey(ev.getHandle())) {
                                Long timestamp = ev.getTimestamp();
                                if (timestamp == null) {
                                    // Infer the timestamp for this message as 'now' and read status
                                    // false instead of getting the message listing data for it
                                    timestamp = new Long(Instant.now().toEpochMilli());
                                }
                                MessageMetadata metadata = new MessageMetadata(ev.getHandle(),
                                        calendar.getTime().getTime(), false);
                                        timestamp, false);
                                mMessages.put(ev.getHandle(), metadata);
                            }
                            mMasClient.makeRequest(new RequestGetMessage(ev.getHandle(),
+35 −1
Original line number Diff line number Diff line
@@ -16,8 +16,11 @@

package com.android.bluetooth.mapclient;

import android.annotation.Nullable;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;

import org.json.JSONException;
import org.json.JSONObject;
import org.xmlpull.v1.XmlPullParser;
@@ -38,12 +41,14 @@ import java.util.HashMap;
public class EventReport {
    private static final String TAG = "EventReport";
    private final Type mType;
    private final String mDateTime;
    private final String mHandle;
    private final String mFolder;
    private final String mOldFolder;
    private final Bmessage.Type mMsgType;

    private EventReport(HashMap<String, String> attrs) throws IllegalArgumentException {
    @VisibleForTesting
    EventReport(HashMap<String, String> attrs) throws IllegalArgumentException {
        mType = parseType(attrs.get("type"));

        if (mType != Type.MEMORY_FULL && mType != Type.MEMORY_AVAILABLE) {
@@ -64,6 +69,8 @@ public class EventReport {

        mOldFolder = attrs.get("old_folder");

        mDateTime = attrs.get("datetime");

        if (mType != Type.MEMORY_FULL && mType != Type.MEMORY_AVAILABLE) {
            String s = attrs.get("msg_type");

@@ -180,12 +187,39 @@ public class EventReport {
        return mMsgType;
    }

    /**
     * @return value corresponding to <code>datetime</code> parameter in MAP
     * specification for NEW_MESSAGE (can be null)
     */
    @Nullable
    public String getDateTime() {
        return mDateTime;
    }

    /**
     * @return timestamp from the value corresponding to <code>datetime</code> parameter in MAP
     * specification for NEW_MESSAGE (can be null)
     */
    @Nullable
    public Long getTimestamp() {
        if (mDateTime != null) {
            ObexTime obexTime = new ObexTime(mDateTime);
            if (obexTime != null) {
                return obexTime.getInstant().toEpochMilli();
            }
        }
        return null;
    }

    @Override
    public String toString() {
        JSONObject json = new JSONObject();

        try {
            json.put("type", mType);
            if (mDateTime != null) {
                json.put("datetime", mDateTime);
            }
            json.put("handle", mHandle);
            json.put("folder", mFolder);
            json.put("old_folder", mOldFolder);
+26 −7
Original line number Diff line number Diff line
@@ -16,8 +16,12 @@

package com.android.bluetooth.mapclient;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;
import java.util.regex.Matcher;
@@ -25,7 +29,7 @@ import java.util.regex.Pattern;

public final class ObexTime {

    private Date mDate;
    private Instant mInstant;

    public ObexTime(String time) {
        /*
@@ -86,26 +90,41 @@ public final class ObexTime {
                builder.setTimeZone(tz);
            }

            mDate = builder.build().getTime();
            mInstant = builder.build().toInstant();
        }
    }

    public ObexTime(Date date) {
        mDate = date;
        mInstant = date.toInstant();
    }

    public ObexTime(Instant instant) {
        mInstant = instant;
    }

    /**
     * @deprecated Use #{@link #getInstant()} instead.
     */
    @Deprecated
    public Date getTime() {
        return mDate;
        if (mInstant == null) {
            return null;
        }
        return Date.from(mInstant);
    }

    public Instant getInstant() {
        return mInstant;
    }

    @Override
    public String toString() {
        if (mDate == null) {
        if (mInstant == null) {
            return null;
        }

        Calendar cal = Calendar.getInstance();
        cal.setTime(mDate);
        Calendar cal = GregorianCalendar.from(
                ZonedDateTime.ofInstant(mInstant, ZoneId.systemDefault()));

        /* note that months are numbered stating from 0 */
        return String.format(Locale.US, "%04d%02d%02dT%02d%02d%02d", cal.get(Calendar.YEAR),
+7 −5
Original line number Diff line number Diff line
@@ -186,8 +186,9 @@ public class SdpManager {
            addressString = sAdapterService.getIdentityAddress(addressString);
            ParcelUuid uuid = Utils.byteArrayToUuid(uuidBytes)[0];
            for (SdpSearchInstance inst : mList) {
                if (inst.getDevice().getAddress().equals(addressString) && inst.getUuid()
                        .equals(uuid)) {
                String instAddressString =
                        sAdapterService.getIdentityAddress(inst.getDevice().getAddress());
                if (instAddressString.equals(addressString) && inst.getUuid().equals(uuid)) {
                    return inst;
                }
            }
@@ -195,10 +196,11 @@ public class SdpManager {
        }

        boolean isSearching(BluetoothDevice device, ParcelUuid uuid) {
            String addressString = device.getAddress();
            String addressString = sAdapterService.getIdentityAddress(device.getAddress());
            for (SdpSearchInstance inst : mList) {
                if (inst.getDevice().getAddress().equals(addressString) && inst.getUuid()
                        .equals(uuid)) {
                String instAddressString =
                        sAdapterService.getIdentityAddress(inst.getDevice().getAddress());
                if (instAddressString.equals(addressString) && inst.getUuid().equals(uuid)) {
                    return inst.isSearching();
                }
            }
Loading