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

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

Snap for 8822995 from 30049002 to tm-qpr1-release

Change-Id: Ic309a432a3b79cea6c9886a7b9b2f808a68789d7
parents e55f3b77 30049002
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3881,7 +3881,7 @@ public class AdapterService extends Service {
        if (deviceProp != null && deviceProp.isConsolidated()) {
            return deviceProp.getIdentityAddress();
        } else {
            return address;
            return null;
        }
    }

+8 −5
Original line number Diff line number Diff line
@@ -853,19 +853,22 @@ public class AdapterServiceTest {

    @Test
    public void testAddressConsolidation() {
        // Create device properties
        // Verify that we return null when the device property for this address does not exist
        Assert.assertNull(mAdapterService.getIdentityAddress(TEST_BT_ADDR_1));

        // Create device property
        RemoteDevices remoteDevices = mAdapterService.getRemoteDevices();
        remoteDevices.addDeviceProperties(Utils.getBytesFromAddress((TEST_BT_ADDR_1)));
        String identityAddress = mAdapterService.getIdentityAddress(TEST_BT_ADDR_1);
        Assert.assertEquals(identityAddress, TEST_BT_ADDR_1);

        // Verify that we return null when the identity address is not known
        Assert.assertNull(mAdapterService.getIdentityAddress(TEST_BT_ADDR_1));

        // Trigger address consolidate callback
        remoteDevices.addressConsolidateCallback(Utils.getBytesFromAddress(TEST_BT_ADDR_1),
                Utils.getBytesFromAddress(TEST_BT_ADDR_2));

        // Verify we can get correct identity address
        identityAddress = mAdapterService.getIdentityAddress(TEST_BT_ADDR_1);
        Assert.assertEquals(identityAddress, TEST_BT_ADDR_2);
        Assert.assertEquals(TEST_BT_ADDR_2, mAdapterService.getIdentityAddress(TEST_BT_ADDR_1));
    }

    private static byte[] getMetricsSalt(HashMap<String, HashMap<String, String>> adapterConfig) {
+2 −1
Original line number Diff line number Diff line
@@ -1477,7 +1477,8 @@ public final class BluetoothDevice implements Parcelable, Attributable {
     * Returns the identity address of this BluetoothDevice.
     * <p> For example, "00:11:22:AA:BB:CC".
     *
     * @return Bluetooth identity address as a string
     * @return this device's identity address as a string or {@code null} if the identity
     *         address is either not known or is unable to be retrieved
     * @hide
     */
    @SystemApi
+49 −16
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.database.ContentObserver;
@@ -2922,9 +2923,7 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
     */
    private void updateOppLauncherComponentState(UserHandle userHandle,
            boolean bluetoothSharingDisallowed) {
        final ComponentName oppLauncherComponent = new ComponentName(
                mContext.getPackageManager().getPackagesForUid(Process.BLUETOOTH_UID)[0],
                "com.android.bluetooth.opp.BluetoothOppLauncherActivity");
        try {
            int newState;
            if (bluetoothSharingDisallowed) {
                newState = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
@@ -2933,13 +2932,47 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
            } else {
                newState = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
            }

            String launcherActivity = "com.android.bluetooth.opp.BluetoothOppLauncherActivity";

            PackageManager packageManager = mContext.createContextAsUser(userHandle, 0)
                                                        .getPackageManager();
            var allPackages = packageManager.getPackagesForUid(Process.BLUETOOTH_UID);
            for (String candidatePackage : allPackages) {
                PackageInfo packageInfo;
                try {
            mContext.createContextAsUser(userHandle, 0)
                .getPackageManager()
                .setComponentEnabledSetting(oppLauncherComponent, newState,
                        PackageManager.DONT_KILL_APP);
                    // note: we need the package manager for the SYSTEM user, not our userHandle
                    packageInfo = mContext.getPackageManager().getPackageInfo(
                        candidatePackage,
                        PackageManager.PackageInfoFlags.of(PackageManager.GET_ACTIVITIES));
                } catch (PackageManager.NameNotFoundException e) {
                    // ignore, try next package
                    Log.e(TAG, "Could not find package " + candidatePackage);
                    continue;
                } catch (Exception e) {
                    Log.e(TAG, "Error while loading package" + e);
                    continue;
                }
                if (packageInfo.activities == null) {
                    continue;
                }
                for (var activity : packageInfo.activities) {
                    if (launcherActivity.equals(activity.name)) {
                        final ComponentName oppLauncherComponent = new ComponentName(
                                candidatePackage, launcherActivity
                        );
                        packageManager.setComponentEnabledSetting(
                                oppLauncherComponent, newState, PackageManager.DONT_KILL_APP
                        );
                        return;
                    }
                }
            }

            Log.e(TAG,
                    "Cannot toggle BluetoothOppLauncherActivity, could not find it in any package");
        } catch (Exception e) {
            // The component was not found, do nothing.
            Log.e(TAG, "updateOppLauncherComponentState failed: " + e);
        }
    }

+20 −3
Original line number Diff line number Diff line
@@ -1398,7 +1398,12 @@ void gatt_sr_update_prep_cnt(tGATT_TCB& tcb, tGATT_IF gatt_if, bool is_inc,
/** Cancel LE Create Connection request */
bool gatt_cancel_open(tGATT_IF gatt_if, const RawAddress& bda) {
  tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bda, BT_TRANSPORT_LE);
  if (!p_tcb) return true;
  if (!p_tcb) {
    LOG_WARN(
        "Unable to cancel open for unknown connection gatt_if:%hhu peer:%s",
        gatt_if, PRIVATE_ADDRESS(bda));
    return true;
  }

  if (gatt_get_ch_state(p_tcb) == GATT_CH_OPEN) {
    LOG(ERROR) << __func__ << ": link connected Too late to cancel";
@@ -1407,9 +1412,21 @@ bool gatt_cancel_open(tGATT_IF gatt_if, const RawAddress& bda) {

  gatt_update_app_use_link_flag(gatt_if, p_tcb, false, false);

  if (p_tcb->app_hold_link.empty()) gatt_disconnect(p_tcb);
  if (p_tcb->app_hold_link.empty()) {
    LOG_DEBUG(
        "Client reference count is zero disconnecting device gatt_if:%hhu "
        "peer:%s",
        gatt_if, PRIVATE_ADDRESS(bda));
    gatt_disconnect(p_tcb);
  }

  connection_manager::direct_connect_remove(gatt_if, bda);
  if (!connection_manager::direct_connect_remove(gatt_if, bda)) {
    BTM_AcceptlistRemove(bda);
    LOG_INFO(
        "GATT connection manager has no record but removed filter acceptlist "
        "gatt_if:%hhu peer:%s",
        gatt_if, PRIVATE_ADDRESS(bda));
  }
  return true;
}