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

Commit 8f9cf240 authored by hieudz's avatar hieudz Committed by Hieu Dang
Browse files

Change BluetoothPbapMethodProxy to BluetoothMethodProxy

BluetoothMethodProxy can be reused in different packages. So moving it to Bluetooth folder.

Bug: 237467631
Test: atest BluetoothPbapCallLogComposerTest
Tag: #refactor
Change-Id: Ib331e75661e294f2b3c66e3de220a2fb5d49fcf9
(cherry picked from commit f5c4ca54)
Merged-In: Ib331e75661e294f2b3c66e3de220a2fb5d49fcf9
parent c06ca0fc
Loading
Loading
Loading
Loading
+8 −9
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package com.android.bluetooth.pbap;
package com.android.bluetooth;

import android.content.ContentResolver;
import android.content.Context;
@@ -22,7 +22,6 @@ import android.database.Cursor;
import android.net.Uri;
import android.util.Log;

import com.android.bluetooth.Utils;
import com.android.internal.annotations.VisibleForTesting;
import com.android.obex.HeaderSet;

@@ -31,22 +30,22 @@ import java.io.IOException;
/**
 * Proxy class for method calls to help with unit testing
 */
public class BluetoothPbapMethodProxy {
    private static final String TAG = BluetoothPbapMethodProxy.class.getSimpleName();
    private static BluetoothPbapMethodProxy sInstance;
public class BluetoothMethodProxy {
    private static final String TAG = BluetoothMethodProxy.class.getSimpleName();
    private static BluetoothMethodProxy sInstance;
    private static final Object INSTANCE_LOCK = new Object();

    private BluetoothPbapMethodProxy() {}
    private BluetoothMethodProxy() {}

    /**
     * Get the singleton instance of proxy
     *
     * @return the singleton instance, guaranteed not null
     */
    public static BluetoothPbapMethodProxy getInstance() {
    public static BluetoothMethodProxy getInstance() {
        synchronized (INSTANCE_LOCK) {
            if (sInstance == null) {
                sInstance = new BluetoothPbapMethodProxy();
                sInstance = new BluetoothMethodProxy();
            }
        }
        return sInstance;
@@ -58,7 +57,7 @@ public class BluetoothPbapMethodProxy {
     * @param proxy a test instance of the BluetoothPbapMethodCallProxy
     */
    @VisibleForTesting
    public static void setInstanceForTesting(BluetoothPbapMethodProxy proxy) {
    public static void setInstanceForTesting(BluetoothMethodProxy proxy) {
        Utils.enforceInstrumentationTestMode();
        synchronized (INSTANCE_LOCK) {
            Log.d(TAG, "setInstanceForTesting(), set to " + proxy);
+2 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.provider.CallLog.Calls;
import android.text.TextUtils;
import android.util.Log;

import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.vcard.VCardBuilder;
@@ -107,7 +108,7 @@ public class BluetoothPbapCallLogComposer {
            return false;
        }

        mCursor = BluetoothPbapMethodProxy.getInstance().contentResolverQuery(
        mCursor = BluetoothMethodProxy.getInstance().contentResolverQuery(
                mContext.getContentResolver(), contentUri, projection, selection, selectionArgs,
                sortOrder);

+3 −2
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.provider.CallLog.Calls;
import android.text.TextUtils;
import android.util.Log;

import com.android.bluetooth.BluetoothMethodProxy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.obex.ApplicationParameter;
import com.android.obex.HeaderSet;
@@ -242,7 +243,7 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {

    private PbapStateMachine mStateMachine;

    private BluetoothPbapMethodProxy mPbapMethodProxy;
    private BluetoothMethodProxy mPbapMethodProxy;

    private enum ContactsType {
        TYPE_PHONEBOOK , TYPE_SIM ;
@@ -272,7 +273,7 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {
        mVcardManager = new BluetoothPbapVcardManager(mContext);
        mVcardSimManager = new BluetoothPbapSimVcardManager(mContext);
        mStateMachine = stateMachine;
        mPbapMethodProxy = BluetoothPbapMethodProxy.getInstance();
        mPbapMethodProxy = BluetoothMethodProxy.getInstance();
    }

    @Override
+17 −23
Original line number Diff line number Diff line
@@ -15,41 +15,35 @@
*/
package com.android.bluetooth.pbap;

import com.android.bluetooth.R;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.provider.ContactsContract.CommonDataKinds;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
import android.provider.ContactsContract.Contacts;
import android.text.TextUtils;
import android.util.Log;

import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.obex.Operation;
import com.android.obex.ResponseCodes;
import com.android.obex.ServerOperation;
import com.android.vcard.VCardBuilder;
import com.android.vcard.VCardConfig;
import com.android.vcard.VCardConstants;
import com.android.vcard.VCardUtils;

import android.content.ContentValues;
import android.provider.CallLog;
import android.provider.CallLog.Calls;
import android.text.TextUtils;
import android.util.Log;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.CommonDataKinds;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.CommonDataKinds.StructuredName;

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Collections;
import java.util.Comparator;

import com.android.obex.Operation;
import com.android.obex.ResponseCodes;
import com.android.obex.ServerOperation;
import java.util.List;

/**
 * VCard composer especially for Call Log used in Bluetooth.
@@ -119,7 +113,7 @@ public class BluetoothPbapSimVcardManager {
        }

        //checkpoint Figure out if we can apply selection, projection and sort order.
        mCursor = BluetoothPbapMethodProxy.getInstance().contentResolverQuery(mContentResolver,
        mCursor = BluetoothMethodProxy.getInstance().contentResolverQuery(mContentResolver,
                contentUri, SIM_PROJECTION, null, null, sortOrder);

        if (mCursor == null) {
@@ -273,7 +267,7 @@ public class BluetoothPbapSimVcardManager {
        int size = 0;
        Cursor contactCursor = null;
        try {
            contactCursor = BluetoothPbapMethodProxy.getInstance().contentResolverQuery(
            contactCursor = BluetoothMethodProxy.getInstance().contentResolverQuery(
                    mContentResolver, SIM_URI, SIM_PROJECTION, null,null, null);
            if (contactCursor != null) {
                size = contactCursor.getCount();
@@ -293,7 +287,7 @@ public class BluetoothPbapSimVcardManager {
        ArrayList<String> allnames = new ArrayList<String>();
        Cursor contactCursor = null;
        try {
            contactCursor = BluetoothPbapMethodProxy.getInstance().contentResolverQuery(
            contactCursor = BluetoothMethodProxy.getInstance().contentResolverQuery(
                    mContentResolver, SIM_URI, SIM_PROJECTION, null,null,null);
            if (contactCursor != null) {
                for (contactCursor.moveToFirst(); !contactCursor.isAfterLast(); contactCursor
@@ -334,7 +328,7 @@ public class BluetoothPbapSimVcardManager {
        Cursor contactCursor = null;

        try {
            contactCursor = BluetoothPbapMethodProxy.getInstance().contentResolverQuery(
            contactCursor = BluetoothMethodProxy.getInstance().contentResolverQuery(
                    mContentResolver, SIM_URI, SIM_PROJECTION, null, null, null);

            if (contactCursor != null) {
+11 −10
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
import android.util.Log;

import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.R;
import com.android.bluetooth.util.DevicePolicyUtils;
import com.android.internal.annotations.VisibleForTesting;
@@ -182,7 +183,7 @@ public class BluetoothPbapVcardManager {
            selectionClause = Phone.STARRED + " = 1";
        }
        try {
            contactCursor = BluetoothPbapMethodProxy.getInstance().contentResolverQuery(mResolver,
            contactCursor = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver,
                    myUri, new String[]{Phone.CONTACT_ID}, selectionClause,
                    null, Phone.CONTACT_ID);
            if (contactCursor == null) {
@@ -209,7 +210,7 @@ public class BluetoothPbapVcardManager {
        int size = 0;
        Cursor callCursor = null;
        try {
            callCursor = BluetoothPbapMethodProxy.getInstance().contentResolverQuery(mResolver,
            callCursor = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver,
                    myUri, null, selection, null, CallLog.Calls.DEFAULT_SORT_ORDER);
            if (callCursor != null) {
                size = callCursor.getCount();
@@ -243,7 +244,7 @@ public class BluetoothPbapVcardManager {
        Cursor callCursor = null;
        ArrayList<String> list = new ArrayList<String>();
        try {
            callCursor = BluetoothPbapMethodProxy.getInstance().contentResolverQuery(mResolver,
            callCursor = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver,
                    myUri, projection, selection, null, CALLLOG_SORT_ORDER);
            if (callCursor != null) {
                for (callCursor.moveToFirst(); !callCursor.isAfterLast(); callCursor.moveToNext()) {
@@ -295,7 +296,7 @@ public class BluetoothPbapVcardManager {
            if (orderByWhat == BluetoothPbapObexServer.ORDER_BY_ALPHABETICAL) {
                orderBy = Phone.DISPLAY_NAME;
            }
            contactCursor = BluetoothPbapMethodProxy.getInstance().contentResolverQuery(mResolver,
            contactCursor = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver,
                    myUri, PHONES_CONTACTS_PROJECTION, null, null, orderBy);
            if (contactCursor != null) {
                appendDistinctNameIdList(nameList, mContext.getString(android.R.string.unknownName),
@@ -354,7 +355,7 @@ public class BluetoothPbapVcardManager {
        final Uri myUri = DevicePolicyUtils.getEnterprisePhoneUri(mContext);
        Cursor contactCursor = null;
        try {
            contactCursor = BluetoothPbapMethodProxy.getInstance().contentResolverQuery(mResolver,
            contactCursor = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver,
                    myUri, PHONES_CONTACTS_PROJECTION, null, null,
                    Phone.CONTACT_ID);

@@ -443,7 +444,7 @@ public class BluetoothPbapVcardManager {
        }

        try {
            contactCursor = BluetoothPbapMethodProxy.getInstance().contentResolverQuery(mResolver,
            contactCursor = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver,
                    uri, projection, null, null, Phone.CONTACT_ID);

            if (contactCursor != null) {
@@ -478,7 +479,7 @@ public class BluetoothPbapVcardManager {
        long primaryVcMsb = 0;
        ArrayList<String> list = new ArrayList<String>();
        try {
            callCursor = BluetoothPbapMethodProxy.getInstance().contentResolverQuery(mResolver,
            callCursor = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver,
                    myUri, null, selection, null, null);
            while (callCursor != null && callCursor.moveToNext()) {
                count = count + 1;
@@ -522,7 +523,7 @@ public class BluetoothPbapVcardManager {
        long endPointId = 0;
        try {
            // Need test to see if order by _ID is ok here, or by date?
            callsCursor = BluetoothPbapMethodProxy.getInstance().contentResolverQuery(mResolver,
            callsCursor = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver,
                    myUri, CALLLOG_PROJECTION, typeSelection, null,
                    CALLLOG_SORT_ORDER);
            if (callsCursor != null) {
@@ -596,7 +597,7 @@ public class BluetoothPbapVcardManager {
        }

        try {
            contactCursor = BluetoothPbapMethodProxy.getInstance().contentResolverQuery(mResolver,
            contactCursor = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver,
                    myUri, PHONES_CONTACTS_PROJECTION, selectionClause,
                    null, Phone.CONTACT_ID);
            if (contactCursor != null) {
@@ -640,7 +641,7 @@ public class BluetoothPbapVcardManager {
            if (orderByWhat == BluetoothPbapObexServer.ORDER_BY_ALPHABETICAL) {
                orderBy = Phone.DISPLAY_NAME;
            }
            contactCursor = BluetoothPbapMethodProxy.getInstance().contentResolverQuery(mResolver,
            contactCursor = BluetoothMethodProxy.getInstance().contentResolverQuery(mResolver,
                    myUri, PHONES_CONTACTS_PROJECTION, null, null, orderBy);
        } catch (CursorWindowAllocationException e) {
            Log.e(TAG, "CursorWindowAllocationException while composing phonebook one vcard");
Loading