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

Commit 191f5244 authored by Joseph Pirozzo's avatar Joseph Pirozzo Committed by Android (Google) Code Review
Browse files

Merge changes I305b3231,I2fcd959a,I31dec95f into qt-qpr1-dev

* changes:
  Delete call logs when calls are made without PBAP
  Set Browsing bit to 0 in PbapSupportedFeatures
  Prevent phone's bd_addr from appearing in Accounts
parents 26002a9c 21fbd606
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -17,5 +17,4 @@
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:icon="@mipmap/bt_share"
        android:smallIcon="@mipmap/bt_share"
        android:accountType="@string/pbap_account_type"
        android:label="@string/pbap_account_type" />
        android:accountType="@string/pbap_account_type" />
+1 −1
Original line number Diff line number Diff line
@@ -99,7 +99,7 @@ class PbapClientConnectionHandler extends Handler {
    private static final long PBAP_FILTER_NICKNAME = 1 << 23;

    private static final int PBAP_SUPPORTED_FEATURE =
            PBAP_FEATURE_DEFAULT_IMAGE_FORMAT | PBAP_FEATURE_BROWSING | PBAP_FEATURE_DOWNLOADING;
            PBAP_FEATURE_DEFAULT_IMAGE_FORMAT | PBAP_FEATURE_DOWNLOADING;
    private static final long PBAP_REQUESTED_FIELDS =
            PBAP_FILTER_VERSION | PBAP_FILTER_FN | PBAP_FILTER_N | PBAP_FILTER_PHOTO
                    | PBAP_FILTER_ADR | PBAP_FILTER_EMAIL | PBAP_FILTER_TEL | PBAP_FILTER_NICKNAME;
+36 −0
Original line number Diff line number Diff line
@@ -19,9 +19,11 @@ package com.android.bluetooth.pbapclient;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadsetClient;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.IBluetoothPbapClient;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -31,6 +33,7 @@ import android.util.Log;
import com.android.bluetooth.R;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.hfpclient.connserv.HfpClientConnectionService;
import com.android.bluetooth.sdp.SdpManager;

import java.util.ArrayList;
@@ -71,6 +74,9 @@ public class PbapClientService extends ProfileService {
        filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
        // delay initial download until after the user is unlocked to add an account.
        filter.addAction(Intent.ACTION_USER_UNLOCKED);
        // To remove call logs when PBAP was never connected while calls were made,
        // we also listen for HFP to become disconnected.
        filter.addAction(BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED);
        try {
            registerReceiver(mPbapBroadcastReceiver, filter);
        } catch (Exception e) {
@@ -128,6 +134,21 @@ public class PbapClientService extends ProfileService {
        }
    }

    private void removeHfpCallLog(String accountName, Context context) {
        if (DBG) Log.d(TAG, "Removing call logs from " + accountName);
        // Delete call logs belonging to accountName==BD_ADDR that also match
        // component name "hfpclient".
        ComponentName componentName = new ComponentName(context, HfpClientConnectionService.class);
        String selectionFilter = CallLog.Calls.PHONE_ACCOUNT_ID + "=? AND "
                + CallLog.Calls.PHONE_ACCOUNT_COMPONENT_NAME + "=?";
        String[] selectionArgs = new String[]{accountName, componentName.flattenToString()};
        try {
            getContentResolver().delete(CallLog.Calls.CONTENT_URI, selectionFilter, selectionArgs);
        } catch (IllegalArgumentException e) {
            Log.w(TAG, "Call Logs could not be deleted, they may not exist yet.");
        }
    }

    private void registerSdpRecord() {
        SdpManager sdpManager = SdpManager.getDefaultManager();
        if (sdpManager == null) {
@@ -171,6 +192,21 @@ public class PbapClientService extends ProfileService {
                for (PbapClientStateMachine stateMachine : mPbapClientStateMachineMap.values()) {
                    stateMachine.resumeDownload();
                }
            } else if (action.equals(BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED)) {
                // PbapClientConnectionHandler has code to remove calllogs when PBAP disconnects.
                // However, if PBAP was never connected/enabled in the first place, and calls are
                // made over HFP, these calllogs will not be removed when the device disconnects.
                // This code ensures callogs are still removed in this case.
                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                int newState = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, -1);

                if (newState == BluetoothProfile.STATE_DISCONNECTED) {
                    if (DBG) {
                        Log.d(TAG, "Received intent to disconnect HFP with " + device);
                    }
                    // HFP client stores entries in calllog.db by BD_ADDR and component name
                    removeHfpCallLog(device.getAddress(), context);
                }
            }
        }
    }