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

Commit 79aa9e1f authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 8832598 from 31a330e9 to tm-qpr1-release

Change-Id: I10b14a98b0a3839d7512de267070e54fe6eab073
parents ae294ff5 31a330e9
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -293,6 +293,7 @@ public class LeAudioService extends ProfileService {
        LeAudioNativeInterface nativeInterface = mLeAudioNativeInterface;
        if (nativeInterface == null) {
            Log.w(TAG, "the service is stopped. ignore init()");
            return;
        }
        nativeInterface.init(mLeAudioCodecConfig.getCodecConfigOffloading());
    }
@@ -305,6 +306,7 @@ public class LeAudioService extends ProfileService {
            return true;
        }

        mHandler.removeCallbacks(this::init);
        setActiveDevice(null);

        if (mTmapGattServer == null) {
+16 −12
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@
 */
package com.android.bluetooth.pbap;

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
@@ -26,6 +25,7 @@ import android.text.TextUtils;
import android.util.Log;

import com.android.bluetooth.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.vcard.VCardBuilder;
import com.android.vcard.VCardConfig;
import com.android.vcard.VCardConstants;
@@ -41,19 +41,24 @@ import java.util.Calendar;
public class BluetoothPbapCallLogComposer {
    private static final String TAG = "PbapCallLogComposer";

    private static final String FAILURE_REASON_FAILED_TO_GET_DATABASE_INFO =
    @VisibleForTesting
    static final String FAILURE_REASON_FAILED_TO_GET_DATABASE_INFO =
            "Failed to get database information";

    private static final String FAILURE_REASON_NO_ENTRY = "There's no exportable in the database";
    @VisibleForTesting
    static final String FAILURE_REASON_NO_ENTRY = "There's no exportable in the database";

    private static final String FAILURE_REASON_NOT_INITIALIZED =
    @VisibleForTesting
    static final String FAILURE_REASON_NOT_INITIALIZED =
            "The vCard composer object is not correctly initialized";

    /** Should be visible only from developers... (no need to translate, hopefully) */
    private static final String FAILURE_REASON_UNSUPPORTED_URI =
    @VisibleForTesting
    static final String FAILURE_REASON_UNSUPPORTED_URI =
            "The Uri vCard composer received is not supported by the composer.";

    private static final String NO_ERROR = "No error";
    @VisibleForTesting
    static final String NO_ERROR = "No error";

    /** The projection to use when querying the call log table */
    private static final String[] sCallLogProjection = new String[]{
@@ -80,7 +85,6 @@ public class BluetoothPbapCallLogComposer {
    private static final String VCARD_PROPERTY_CALLTYPE_MISSED = "MISSED";

    private final Context mContext;
    private ContentResolver mContentResolver;
    private Cursor mCursor;

    private boolean mTerminateIsCalled;
@@ -91,7 +95,6 @@ public class BluetoothPbapCallLogComposer {

    public BluetoothPbapCallLogComposer(final Context context) {
        mContext = context;
        mContentResolver = context.getContentResolver();
    }

    public boolean init(final Uri contentUri, final String selection, final String[] selectionArgs,
@@ -104,8 +107,9 @@ public class BluetoothPbapCallLogComposer {
            return false;
        }

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

        if (mCursor == null) {
            mErrorReason = FAILURE_REASON_FAILED_TO_GET_DATABASE_INFO;
@@ -175,8 +179,8 @@ public class BluetoothPbapCallLogComposer {
    /**
     * This static function is to compose vCard for phone own number
     */
    public String composeVCardForPhoneOwnNumber(int phonetype, String phoneName, String phoneNumber,
            boolean vcardVer21) {
    public static String composeVCardForPhoneOwnNumber(int phonetype, String phoneName,
            String phoneNumber, boolean vcardVer21) {
        final int vcardType = (vcardVer21 ? VCardConfig.VCARD_TYPE_V21_GENERIC
                : VCardConfig.VCARD_TYPE_V30_GENERIC)
                | VCardConfig.FLAG_REFRAIN_PHONE_NUMBER_FORMATTING;
+73 −0
Original line number Diff line number Diff line
/*
 * Copyright 2022 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.pbap;

import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.util.Log;

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

/**
 * 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;
    private static final Object INSTANCE_LOCK = new Object();

    private BluetoothPbapMethodProxy() {}

    /**
     * Get the singleton instance of proxy
     *
     * @return the singleton instance, guaranteed not null
     */
    public static BluetoothPbapMethodProxy getInstance() {
        synchronized (INSTANCE_LOCK) {
            if (sInstance == null) {
                sInstance = new BluetoothPbapMethodProxy();
            }
        }
        return sInstance;
    }

    /**
     * Allow unit tests to substitute BluetoothPbapMethodCallProxy with a test instance
     *
     * @param proxy a test instance of the BluetoothPbapMethodCallProxy
     */
    @VisibleForTesting
    public static void setInstanceForTesting(BluetoothPbapMethodProxy proxy) {
        Utils.enforceInstrumentationTestMode();
        synchronized (INSTANCE_LOCK) {
            Log.d(TAG, "setInstanceForTesting(), set to " + proxy);
            sInstance = proxy;
        }
    }

    /**
     * Return the result of {@link ContentResolver#query(Uri, String[], String, String[], String)}.
     */
    public Cursor contentResolverQuery(ContentResolver contentResolver, final Uri contentUri,
            final String[] projection, final String selection, final String[] selectionArgs,
            final String sortOrder) {
        return contentResolver.query(contentUri, projection, selection, selectionArgs, sortOrder);
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -143,8 +143,8 @@ public class BluetoothPbapVcardManager {
        BluetoothPbapCallLogComposer composer = new BluetoothPbapCallLogComposer(mContext);
        String name = BluetoothPbapService.getLocalPhoneName();
        String number = BluetoothPbapService.getLocalPhoneNum();
        String vcard = composer.composeVCardForPhoneOwnNumber(Phone.TYPE_MOBILE, name, number,
                vcardType21);
        String vcard = BluetoothPbapCallLogComposer.composeVCardForPhoneOwnNumber(
                Phone.TYPE_MOBILE, name, number, vcardType21);
        return vcard;
    }

+15 −0
Original line number Diff line number Diff line
@@ -310,6 +310,21 @@ public class LeAudioServiceTest {
        });
    }

    /**
     * Test if stop during init is ok.
     */
    @Test
    public void testStopStartStopService() throws Exception {
        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
            public void run() {
                assertThat(mService.stop()).isTrue();
                assertThat(mService.start()).isTrue();
                assertThat(mService.stop()).isTrue();
                assertThat(mService.start()).isTrue();
            }
        });
    }

    /**
     * Test get/set priority for BluetoothDevice
     */
Loading