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

Commit 6aabbff6 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 8479861 from 566dbb49 to tm-qpr1-release

Change-Id: I905e941916e2c5719de90cf321e019e5e4d1c326
parents 40e0d528 566dbb49
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static android.Manifest.permission.BLUETOOTH_SCAN;
import static android.Manifest.permission.RENOUNCE_PERMISSIONS;
import static android.bluetooth.BluetoothUtils.USER_HANDLE_NULL;
import static android.content.pm.PackageManager.GET_PERMISSIONS;
import static android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.os.PowerExemptionManager.TEMPORARY_ALLOW_LIST_TYPE_FOREGROUND_SERVICE_ALLOWED;
import static android.permission.PermissionManager.PERMISSION_HARD_DENIED;
@@ -321,6 +322,11 @@ public final class Utils {
    }

    static int sForegroundUserId = USER_HANDLE_NULL.getIdentifier();

    public static int getForegroundUserId() {
        return Utils.sForegroundUserId;
    }

    public static void setForegroundUserId(int userId) {
        Utils.sForegroundUserId = userId;
    }
@@ -597,7 +603,8 @@ public final class Utils {
        PackageManager pm = context.getPackageManager();
        try {
            // TODO(b/183478032): Cache PackageInfo for use here.
            PackageInfo pkgInfo = pm.getPackageInfo(packageName, GET_PERMISSIONS);
            PackageInfo pkgInfo =
                    pm.getPackageInfo(packageName, GET_PERMISSIONS | MATCH_UNINSTALLED_PACKAGES);
            for (int i = 0; i < pkgInfo.requestedPermissions.length; i++) {
                if (pkgInfo.requestedPermissions[i].equals(BLUETOOTH_SCAN)) {
                    return (pkgInfo.requestedPermissionsFlags[i]
+1 −3
Original line number Diff line number Diff line
@@ -66,7 +66,6 @@ import android.bluetooth.UidTraffic;
import android.companion.CompanionDeviceManager;
import android.content.AttributionSource;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -3715,8 +3714,7 @@ public class AdapterService extends Service {
        @Override
        public void setForegroundUserId(int userId, AttributionSource attributionSource) {
            AdapterService service = getService();
            if (service == null || !callerIsSystemOrActiveUser(TAG, "setForegroundUserId")
                    || !Utils.checkConnectPermissionForDataDelivery(
            if (service == null || !Utils.checkConnectPermissionForDataDelivery(
                    service, Utils.getCallingAttributionSource(mService),
                    "AdapterService setForegroundUserId")) {
                return;
+6 −16
Original line number Diff line number Diff line
@@ -136,7 +136,7 @@ public class HeadsetService extends ProfileService {
    private VoiceRecognitionTimeoutEvent mVoiceRecognitionTimeoutEvent;
    // Timeout when voice recognition is started by remote device
    @VisibleForTesting static int sStartVrTimeoutMs = 5000;
    private ArrayList<StateMachineTask> mPendingClccResponses = new ArrayList<>();
    private ArrayList<HeadsetClccResponse> mHeadsetClccResponses = new ArrayList<>();
    private boolean mStarted;
    private boolean mCreated;
    private static HeadsetService sHeadsetService;
@@ -328,14 +328,6 @@ public class HeadsetService extends ProfileService {
        }
    }

    private void doForEachConnectedStateMachine(List<StateMachineTask> tasks) {
        synchronized (mStateMachines) {
            for (StateMachineTask task : tasks) {
                doForEachConnectedStateMachine(task);
            }
        }
    }

    void onDeviceStateChanged(HeadsetDeviceState deviceState) {
        doForEachConnectedStateMachine(
                stateMachine -> stateMachine.sendMessage(HeadsetStateMachine.DEVICE_STATE_CHANGED,
@@ -1862,20 +1854,18 @@ public class HeadsetService extends ProfileService {
                mSystemInterface.getAudioManager().setA2dpSuspended(false);
            }
        });

    }

    @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
    private void clccResponse(int index, int direction, int status, int mode, boolean mpty,
            String number, int type) {
        enforceCallingOrSelfPermission(MODIFY_PHONE_STATE, "Need MODIFY_PHONE_STATE permission");
        mPendingClccResponses.add(
                stateMachine -> stateMachine.sendMessage(HeadsetStateMachine.SEND_CLCC_RESPONSE,
                        new HeadsetClccResponse(index, direction, status, mode, mpty, number,
                                type)));
        mHeadsetClccResponses.add(
                new HeadsetClccResponse(index, direction, status, mode, mpty, number, type));
        if (index == CLCC_END_MARK_INDEX) {
            doForEachConnectedStateMachine(mPendingClccResponses);
            mPendingClccResponses.clear();
            doForEachConnectedStateMachine(stateMachine -> stateMachine.sendMessage(
                    HeadsetStateMachine.SEND_CLCC_RESPONSE, mHeadsetClccResponses));
            mHeadsetClccResponses.clear();
        }
    }

+7 −6
Original line number Diff line number Diff line
@@ -869,7 +869,7 @@ public class HeadsetStateMachine extends StateMachine {
                    mNativeInterface.notifyDeviceStatus(mDevice, (HeadsetDeviceState) message.obj);
                    break;
                case SEND_CLCC_RESPONSE:
                    processSendClccResponse((HeadsetClccResponse) message.obj);
                    processSendClccResponse((ArrayList<HeadsetClccResponse>) message.obj);
                    break;
                case CLCC_RSP_TIMEOUT: {
                    BluetoothDevice device = (BluetoothDevice) message.obj;
@@ -2029,16 +2029,17 @@ public class HeadsetStateMachine extends StateMachine {
        sendIndicatorIntent(device, indId, indValue);
    }

    private void processSendClccResponse(HeadsetClccResponse clcc) {
    private void processSendClccResponse(ArrayList<HeadsetClccResponse> clccList) {
        if (!hasMessages(CLCC_RSP_TIMEOUT)) {
            return;
        }
        if (clcc.mIndex == 0) {
        removeMessages(CLCC_RSP_TIMEOUT);
        }

        for (HeadsetClccResponse clcc : clccList) {
            mNativeInterface.clccResponse(mDevice, clcc.mIndex, clcc.mDirection, clcc.mStatus,
                    clcc.mMode, clcc.mMpty, clcc.mNumber, clcc.mType);
        }
    }

    private void processSendVendorSpecificResultCode(HeadsetVendorSpecificResultCode resultCode) {
        String stringToSend = resultCode.mCommand + ": ";
+21 −0
Original line number Diff line number Diff line
@@ -15,15 +15,21 @@
 */
package com.android.bluetooth;

import static com.google.common.truth.Truth.assertWithMessage;

import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.os.Handler;
import android.os.Looper;
import android.os.MessageQueue;
import android.os.Process;

import androidx.test.InstrumentationRegistry;
import androidx.test.rule.ServiceTestRule;
@@ -198,6 +204,21 @@ public class TestUtils {
        return testDevice;
    }

    public static Resources getTestApplicationResources(Context context) {
        for (String name: context.getPackageManager().getPackagesForUid(Process.BLUETOOTH_UID)) {
            if (name.contains(".android.bluetooth.tests")) {
                try {
                    return context.getPackageManager().getResourcesForApplication(name);
                } catch (PackageManager.NameNotFoundException e) {
                    assertWithMessage("Setup Failure: Unable to get test application resources"
                            + e.toString()).fail();
                }
            }
        }
        assertWithMessage("Could not find tests package").fail();
        return null;
    }

    /**
     * Wait and verify that an intent has been received.
     *
Loading