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

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

Merge changes from topic "cherrypicker-L44800000956518937:N36300001297725767" into tm-qpr-dev

* changes:
  Add (CallLog/Phonebook)PullRequestTest
  Add ObexAppParametersTest
  Add BluetoothPbapObexAuthenticatorTest/BluetoothPbapRequestTest
  Add tests for classes in package pbapclient
parents 30966414 05fa0df4
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.bluetooth.pbapclient;
import android.os.Handler;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
import com.android.obex.Authenticator;
import com.android.obex.PasswordAuthentication;

@@ -28,15 +29,14 @@ import java.util.Arrays;
 * with PSE devices prior to PBAP 1.2. With profiles prior to 1.2 the actual initiation of
 * authentication is implementation defined.
 */


class BluetoothPbapObexAuthenticator implements Authenticator {

    private static final String TAG = "BtPbapObexAuthenticator";
    private static final boolean DBG = Utils.DBG;

    //Default session key for legacy devices is 0000
    private String mSessionKey = "0000";
    @VisibleForTesting
    String mSessionKey = "0000";

    private final Handler mCallback;

@@ -69,5 +69,4 @@ class BluetoothPbapObexAuthenticator implements Authenticator {
        /* required only in case PCE challenges PSE which we don't do now */
        return null;
    }

}
+0 −98
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.bluetooth.pbapclient;

import android.bluetooth.BluetoothSocket;

import com.android.obex.ObexTransport;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

class BluetoothPbapObexTransport implements ObexTransport {

    private BluetoothSocket mSocket = null;

    BluetoothPbapObexTransport(BluetoothSocket rfs) {
        super();
        mSocket = rfs;
    }

    @Override
    public void close() throws IOException {
        mSocket.close();
    }

    @Override
    public DataInputStream openDataInputStream() throws IOException {
        return new DataInputStream(openInputStream());
    }

    @Override
    public DataOutputStream openDataOutputStream() throws IOException {
        return new DataOutputStream(openOutputStream());
    }

    @Override
    public InputStream openInputStream() throws IOException {
        return mSocket.getInputStream();
    }

    @Override
    public OutputStream openOutputStream() throws IOException {
        return mSocket.getOutputStream();
    }

    @Override
    public void connect() throws IOException {
    }

    @Override
    public void create() throws IOException {
    }

    @Override
    public void disconnect() throws IOException {
    }

    @Override
    public void listen() throws IOException {
    }

    public boolean isConnected() throws IOException {
        // return true;
        return mSocket.isConnected();
    }

    @Override
    public int getMaxTransmitPacketSize() {
        return -1;
    }

    @Override
    public int getMaxReceivePacketSize() {
        return -1;
    }

    @Override
    public boolean isSrmSupported() {
        return false;
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.provider.ContactsContract;
import android.util.Log;
import android.util.Pair;

import com.android.internal.annotations.VisibleForTesting;
import com.android.vcard.VCardEntry;
import com.android.vcard.VCardEntry.PhoneData;

@@ -42,7 +43,8 @@ public class CallLogPullRequest extends PullRequest {
    private static final boolean DBG = Utils.DBG;
    private static final boolean VDBG = Utils.VDBG;
    private static final String TAG = "PbapCallLogPullRequest";
    private static final String TIMESTAMP_PROPERTY = "X-IRMC-CALL-DATETIME";
    @VisibleForTesting
    static final String TIMESTAMP_PROPERTY = "X-IRMC-CALL-DATETIME";
    private static final String TIMESTAMP_FORMAT = "yyyyMMdd'T'HHmmss";

    private final Account mAccount;
+0 −172
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.bluetooth.pbapclient;

import com.android.vcard.VCardEntry;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 *  A simpler more public version of VCardEntry.
 */
public class PhonebookEntry {
    public static class Name {
        public String family;
        public String given;
        public String middle;
        public String prefix;
        public String suffix;

        public Name() { }

        @Override
        public boolean equals(Object o) {
            if (!(o instanceof Name)) {
                return false;
            }

            Name n = ((Name) o);
            return (Objects.equals(family, n.family) || family != null && family.equals(n.family))
                    && (Objects.equals(given, n.given) || given != null && given.equals(n.given))
                    && (Objects.equals(middle, n.middle) || middle != null && middle.equals(
                    n.middle)) && (Objects.equals(prefix, n.prefix)
                    || prefix != null && prefix.equals(n.prefix)) && (
                    Objects.equals(suffix, n.suffix) || suffix != null && suffix.equals(n.suffix));
        }

        @Override
        public int hashCode() {
            int result = 23 * (family == null ? 0 : family.hashCode());
            result = 23 * result + (given == null ? 0 : given.hashCode());
            result = 23 * result + (middle == null ? 0 : middle.hashCode());
            result = 23 * result + (prefix == null ? 0 : prefix.hashCode());
            result = 23 * result + (suffix == null ? 0 : suffix.hashCode());
            return result;
        }

        @Override
        public String toString() {
            StringBuilder sb = new StringBuilder();
            sb.append("Name: { family: ");
            sb.append(family);
            sb.append(" given: ");
            sb.append(given);
            sb.append(" middle: ");
            sb.append(middle);
            sb.append(" prefix: ");
            sb.append(prefix);
            sb.append(" suffix: ");
            sb.append(suffix);
            sb.append(" }");
            return sb.toString();
        }
    }

    public static class Phone {
        public int type;
        public String number;

        @Override
        public boolean equals(Object o) {
            if (!(o instanceof Phone)) {
                return false;
            }

            Phone p = (Phone) o;
            return (Objects.equals(number, p.number) || number != null && number.equals(p.number))
                    && type == p.type;
        }

        @Override
        public int hashCode() {
            return 23 * type + number.hashCode();
        }

        @Override
        public String toString() {
            StringBuilder sb = new StringBuilder();
            sb.append(" Phone: { number: ");
            sb.append(number);
            sb.append(" type: " + type);
            sb.append(" }");
            return sb.toString();
        }
    }

    @Override
    public boolean equals(Object object) {
        if (object instanceof PhonebookEntry) {
            return equals((PhonebookEntry) object);
        }
        return false;
    }

    public PhonebookEntry() {
        name = new Name();
        phones = new ArrayList<Phone>();
    }

    public PhonebookEntry(VCardEntry v) {
        name = new Name();
        phones = new ArrayList<Phone>();

        VCardEntry.NameData n = v.getNameData();
        name.family = n.getFamily();
        name.given = n.getGiven();
        name.middle = n.getMiddle();
        name.prefix = n.getPrefix();
        name.suffix = n.getSuffix();

        List<VCardEntry.PhoneData> vp = v.getPhoneList();
        if (vp == null || vp.isEmpty()) {
            return;
        }

        for (VCardEntry.PhoneData p : vp) {
            Phone phone = new Phone();
            phone.type = p.getType();
            phone.number = p.getNumber();
            phones.add(phone);
        }
    }

    private boolean equals(PhonebookEntry p) {
        return name.equals(p.name) && phones.equals(p.phones);
    }

    @Override
    public int hashCode() {
        return name.hashCode() + 23 * phones.hashCode();
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("PhonebookEntry { id: ");
        sb.append(id);
        sb.append(" ");
        sb.append(name.toString());
        sb.append(phones.toString());
        sb.append(" }");
        return sb.toString();
    }

    public Name name;
    public List<Phone> phones;
    public String id;
}
+3 −1
Original line number Diff line number Diff line
@@ -24,12 +24,14 @@ import android.os.RemoteException;
import android.provider.ContactsContract;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
import com.android.vcard.VCardEntry;

import java.util.ArrayList;

public class PhonebookPullRequest extends PullRequest {
    private static final int MAX_OPS = 250;
    @VisibleForTesting
    static final int MAX_OPS = 250;
    private static final boolean VDBG = Utils.VDBG;
    private static final String TAG = "PbapPbPullRequest";

Loading