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

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

Merge changes I270939ab,Ie6958d9b into tm-qpr-dev

* changes:
  Ignore failing OPP tests
  Revert "Add AdapterServiceBinderTest"
parents 0bae4db9 15d953fe
Loading
Loading
Loading
Loading
+2 −15
Original line number Diff line number Diff line
@@ -408,9 +408,6 @@ public final class Utils {

    @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
    public static void enforceBluetoothPrivilegedPermission(Context context) {
        if (isInstrumentationTestMode()) {
            return;
        }
        context.enforceCallingOrSelfPermission(
                android.Manifest.permission.BLUETOOTH_PRIVILEGED,
                "Need BLUETOOTH PRIVILEGED permission");
@@ -418,9 +415,6 @@ public final class Utils {

    @RequiresPermission(android.Manifest.permission.LOCAL_MAC_ADDRESS)
    public static void enforceLocalMacAddressPermission(Context context) {
        if (isInstrumentationTestMode()) {
            return;
        }
        context.enforceCallingOrSelfPermission(
                android.Manifest.permission.LOCAL_MAC_ADDRESS,
                "Need LOCAL_MAC_ADDRESS permission");
@@ -428,14 +422,13 @@ public final class Utils {

    @RequiresPermission(android.Manifest.permission.DUMP)
    public static void enforceDumpPermission(Context context) {
        if (isInstrumentationTestMode()) {
            return;
        }
        context.enforceCallingOrSelfPermission(
                android.Manifest.permission.DUMP,
                "Need DUMP permission");
    }

    /**
     */
    public static AttributionSource getCallingAttributionSource(Context context) {
        int callingUid = Binder.getCallingUid();
        if (callingUid == android.os.Process.ROOT_UID) {
@@ -470,9 +463,6 @@ public final class Utils {
    @SuppressLint("AndroidFrameworkRequiresPermission")
    private static boolean checkPermissionForDataDelivery(Context context, String permission,
            AttributionSource attributionSource, String message) {
        if (isInstrumentationTestMode()) {
            return true;
        }
        // STOPSHIP(b/188391719): enable this security enforcement
        // attributionSource.enforceCallingUid();
        AttributionSource currentAttribution = new AttributionSource
@@ -679,9 +669,6 @@ public final class Utils {
    }

    public static boolean checkCallerIsSystemOrActiveOrManagedUser(Context context, String tag) {
        if (isInstrumentationTestMode()) {
            return true;
        }
        final boolean res = checkCallerIsSystemOrActiveOrManagedUser(context);
        if (!res) {
            Log.w(TAG, tag + " - Not allowed for"
+6 −12
Original line number Diff line number Diff line
@@ -262,8 +262,7 @@ public class AdapterService extends Service {
    }

    private BluetoothAdapter mAdapter;
    @VisibleForTesting
    AdapterProperties mAdapterProperties;
    private AdapterProperties mAdapterProperties;
    private AdapterState mAdapterStateMachine;
    private BondStateMachine mBondStateMachine;
    private JniCallbacks mJniCallbacks;
@@ -1362,8 +1361,7 @@ public class AdapterService extends Service {
    }

    @BluetoothAdapter.RfcommListenerResult
    @VisibleForTesting
    int stopRfcommListener(ParcelUuid uuid, AttributionSource attributionSource) {
    private int stopRfcommListener(ParcelUuid uuid, AttributionSource attributionSource) {
        RfcommListenerData listenerData = mBluetoothServerSockets.get(uuid.getUuid());

        if (listenerData == null) {
@@ -1382,8 +1380,7 @@ public class AdapterService extends Service {
        return listenerData.closeServerAndPendingSockets(mHandler);
    }

    @VisibleForTesting
    IncomingRfcommSocketInfo retrievePendingSocketForServiceRecord(
    private IncomingRfcommSocketInfo retrievePendingSocketForServiceRecord(
            ParcelUuid uuid, AttributionSource attributionSource) {
        IncomingRfcommSocketInfo socketInfo = new IncomingRfcommSocketInfo();

@@ -1551,8 +1548,7 @@ public class AdapterService extends Service {
        }
    }

    @VisibleForTesting
    boolean isAvailable() {
    private boolean isAvailable() {
        return !mCleaningUp;
    }

@@ -3868,8 +3864,7 @@ public class AdapterService extends Service {
        return mAdapterProperties.getName().length();
    }

    @VisibleForTesting
    static boolean isValidIoCapability(int capability) {
    private static boolean isValidIoCapability(int capability) {
        if (capability < 0 || capability >= BluetoothAdapter.IO_CAPABILITY_MAX) {
            Log.e(TAG, "Invalid IO capability value - " + capability);
            return false;
@@ -4798,8 +4793,7 @@ public class AdapterService extends Service {
        return mAdapterProperties.isA2dpOffloadEnabled();
    }

    @VisibleForTesting
    BluetoothActivityEnergyInfo reportActivityInfo() {
    private BluetoothActivityEnergyInfo reportActivityInfo() {
        if (mAdapterProperties.getState() != BluetoothAdapter.STATE_ON
                || !mAdapterProperties.isActivityAndEnergyReportingSupported()) {
            return null;
+0 −211
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.btservice;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;
import android.bluetooth.IBluetoothOobDataCallback;
import android.content.AttributionSource;
import android.content.pm.PackageManager;
import android.os.ParcelUuid;

import com.android.bluetooth.x.com.android.modules.utils.SynchronousResultReceiver;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;

import java.io.FileDescriptor;

public class AdapterServiceBinderTest {
    @Mock private AdapterService mService;
    @Mock private AdapterProperties mAdapterProperties;
    @Mock private PackageManager mPackageManager;

    private AdapterService.AdapterServiceBinder mBinder;
    private AttributionSource mAttributionSource;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mService.mAdapterProperties = mAdapterProperties;
        doReturn(true).when(mService).isAvailable();
        doReturn(mPackageManager).when(mService).getPackageManager();
        doReturn(new String[] { "com.android.bluetooth.btservice" })
                .when(mPackageManager).getPackagesForUid(anyInt());
        mBinder = new AdapterService.AdapterServiceBinder(mService);
        mAttributionSource = new AttributionSource.Builder(0).build();
    }

    @After
    public void cleaUp() {
        mBinder.cleanup();
    }

    @Test
    public void getAddress() {
        mBinder.getAddress();
        verify(mService.mAdapterProperties).getAddress();
    }

    @Test
    public void dump() {
        FileDescriptor fd = new FileDescriptor();
        String[] args = new String[] { };
        mBinder.dump(fd, args);
        verify(mService).dump(any(), any(), any());

        Mockito.clearInvocations(mService);
        mBinder.cleanup();
        mBinder.dump(fd, args);
        verify(mService, never()).dump(any(), any(), any());
    }

    @Test
    public void generateLocalOobData() {
        int transport = 0;
        IBluetoothOobDataCallback cb = Mockito.mock(IBluetoothOobDataCallback.class);

        mBinder.generateLocalOobData(transport, cb, mAttributionSource,
                SynchronousResultReceiver.get());
        verify(mService).generateLocalOobData(transport, cb);

        Mockito.clearInvocations(mService);
        mBinder.cleanup();
        mBinder.generateLocalOobData(transport, cb, mAttributionSource,
                SynchronousResultReceiver.get());
        verify(mService, never()).generateLocalOobData(transport, cb);
    }

    @Test
    public void getBluetoothClass() {
        mBinder.getBluetoothClass(mAttributionSource, SynchronousResultReceiver.get());
        verify(mService.mAdapterProperties).getBluetoothClass();
    }

    @Test
    public void getIoCapability() {
        mBinder.getIoCapability(mAttributionSource, SynchronousResultReceiver.get());
        verify(mService.mAdapterProperties).getIoCapability();
    }

    @Test
    public void getLeIoCapability() {
        mBinder.getLeIoCapability(mAttributionSource, SynchronousResultReceiver.get());
        verify(mService.mAdapterProperties).getLeIoCapability();
    }

    @Test
    public void getLeMaximumAdvertisingDataLength() {
        mBinder.getLeMaximumAdvertisingDataLength(SynchronousResultReceiver.get());
        verify(mService).getLeMaximumAdvertisingDataLength();
    }

    @Test
    public void getScanMode() {
        mBinder.getScanMode(mAttributionSource, SynchronousResultReceiver.get());
        verify(mService.mAdapterProperties).getScanMode();
    }

    @Test
    public void isA2dpOffloadEnabled() {
        mBinder.isA2dpOffloadEnabled(mAttributionSource, SynchronousResultReceiver.get());
        verify(mService).isA2dpOffloadEnabled();
    }

    @Test
    public void isActivityAndEnergyReportingSupported() {
        mBinder.isActivityAndEnergyReportingSupported(SynchronousResultReceiver.get());
        verify(mService.mAdapterProperties).isActivityAndEnergyReportingSupported();
    }

    @Test
    public void isLe2MPhySupported() {
        mBinder.isLe2MPhySupported(SynchronousResultReceiver.get());
        verify(mService).isLe2MPhySupported();
    }

    @Test
    public void isLeCodedPhySupported() {
        mBinder.isLeCodedPhySupported(SynchronousResultReceiver.get());
        verify(mService).isLeCodedPhySupported();
    }

    @Test
    public void isLeExtendedAdvertisingSupported() {
        mBinder.isLeExtendedAdvertisingSupported(SynchronousResultReceiver.get());
        verify(mService).isLeExtendedAdvertisingSupported();
    }

    @Test
    public void removeActiveDevice() {
        int profiles = BluetoothAdapter.ACTIVE_DEVICE_ALL;
        mBinder.removeActiveDevice(profiles, mAttributionSource, SynchronousResultReceiver.get());
        verify(mService).setActiveDevice(null, profiles);
    }

    @Test
    public void reportActivityInfo() {
        mBinder.reportActivityInfo(mAttributionSource, SynchronousResultReceiver.get());
        verify(mService).reportActivityInfo();
    }

    @Test
    public void retrievePendingSocketForServiceRecord() {
        ParcelUuid uuid = ParcelUuid.fromString("0000110A-0000-1000-8000-00805F9B34FB");
        mBinder.retrievePendingSocketForServiceRecord(uuid, mAttributionSource,
                SynchronousResultReceiver.get());
        verify(mService).retrievePendingSocketForServiceRecord(uuid, mAttributionSource);
    }

    @Test
    public void setBluetoothClass() {
        BluetoothClass btClass = new BluetoothClass(0);
        mBinder.setBluetoothClass(btClass, mAttributionSource, SynchronousResultReceiver.get());
        verify(mService.mAdapterProperties).setBluetoothClass(btClass);
    }

    @Test
    public void setIoCapability() {
        int capability = BluetoothAdapter.IO_CAPABILITY_MAX - 1;
        mBinder.setIoCapability(capability, mAttributionSource, SynchronousResultReceiver.get());
        verify(mService.mAdapterProperties).setIoCapability(capability);
    }

    @Test
    public void setLeIoCapability() {
        int capability = BluetoothAdapter.IO_CAPABILITY_MAX - 1;
        mBinder.setLeIoCapability(capability, mAttributionSource, SynchronousResultReceiver.get());
        verify(mService.mAdapterProperties).setLeIoCapability(capability);
    }

    @Test
    public void stopRfcommListener() {
        ParcelUuid uuid = ParcelUuid.fromString("0000110A-0000-1000-8000-00805F9B34FB");
        mBinder.stopRfcommListener(uuid, mAttributionSource, SynchronousResultReceiver.get());
        verify(mService).stopRfcommListener(uuid, mAttributionSource);
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ import com.android.bluetooth.R;

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -65,7 +66,6 @@ import org.mockito.MockitoAnnotations;

import java.io.File;


@MediumTest
@RunWith(AndroidJUnit4.class)
public class BluetoothOppLauncherActivityTest {
@@ -151,6 +151,7 @@ public class BluetoothOppLauncherActivityTest {
        intended(hasComponent(BluetoothOppBtEnableActivity.class.getName()));
    }

    @Ignore("b/263724420")
    @Test
    public void launchDevicePicker_bluetoothEnabled_launchActivity() throws Exception {
        doReturn(true).when(mMethodProxy).bluetoothAdapterIsEnabled(any());
@@ -185,6 +186,7 @@ public class BluetoothOppLauncherActivityTest {
        assertThat(file.length()).isGreaterThan(shareContent.length());
    }

    @Ignore("b/263754734")
    @Test
    public void sendFileInfo_finishImmediately() throws Exception {
        doReturn(true).when(mMethodProxy).bluetoothAdapterIsEnabled(any());