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

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

Merge "PBAP Delete CallLog" into pi-dev

parents 50c643b9 1ac795e8
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package com.android.bluetooth.pbapclient;

import android.accounts.Account;
import android.content.ContentProviderOperation;
import android.content.ContentValues;
import android.content.Context;
@@ -23,6 +24,7 @@ import android.database.Cursor;
import android.net.Uri;
import android.os.RemoteException;
import android.provider.CallLog;
import android.provider.CallLog.Calls;
import android.provider.ContactsContract;
import android.util.Log;
import android.util.Pair;
@@ -43,14 +45,16 @@ public class CallLogPullRequest extends PullRequest {
    private static final String TIMESTAMP_PROPERTY = "X-IRMC-CALL-DATETIME";
    private static final String TIMESTAMP_FORMAT = "yyyyMMdd'T'HHmmss";


    private final Account mAccount;
    private Context mContext;
    private HashMap<String, Integer> mCallCounter;

    public CallLogPullRequest(Context context, String path, HashMap<String, Integer> map) {
    public CallLogPullRequest(Context context, String path, HashMap<String, Integer> map,
            Account account) {
        mContext = context;
        this.path = path;
        mCallCounter = map;
        mAccount = account;
    }

    @Override
@@ -84,7 +88,7 @@ public class CallLogPullRequest extends PullRequest {
                ContentValues values = new ContentValues();

                values.put(CallLog.Calls.TYPE, type);

                values.put(Calls.PHONE_ACCOUNT_ID, mAccount.hashCode());
                List<PhoneData> phones = vcard.getPhoneList();
                if (phones == null || phones.get(0).getNumber().equals(";")) {
                    values.put(CallLog.Calls.NUMBER, "");
+25 −6
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.provider.CallLog;
import android.provider.CallLog.Calls;
import android.util.Log;

import com.android.bluetooth.BluetoothObexTransport;
@@ -231,7 +232,8 @@ class PbapClientConnectionHandler extends Handler {
                    Log.d(TAG, "Completing Disconnect");
                }
                removeAccount(mAccount);
                mContext.getContentResolver().delete(CallLog.Calls.CONTENT_URI, null, null);
                removeCallLog(mAccount);

                mPbapClientStateMachine.obtainMessage(PbapClientStateMachine.MSG_CONNECTION_CLOSED)
                    .sendToTarget();
                break;
@@ -370,7 +372,8 @@ class PbapClientConnectionHandler extends Handler {
                    new BluetoothPbapRequestPullPhoneBook(path, mAccount, 0, VCARD_TYPE_30, 0, 0);
            request.execute(mObexSession);
            CallLogPullRequest processor =
                    new CallLogPullRequest(mPbapClientStateMachine.getContext(), path, callCounter);
                    new CallLogPullRequest(mPbapClientStateMachine.getContext(), path,
                        callCounter, mAccount);
            processor.setResults(request.getList());
            processor.onPullComplete();
        } catch (IOException e) {
@@ -388,13 +391,29 @@ class PbapClientConnectionHandler extends Handler {
        return false;
    }

    private void removeAccount(Account acc) {
        if (mAccountManager.removeAccountExplicitly(acc)) {
    private void removeAccount(Account account) {
        if (mAccountManager.removeAccountExplicitly(account)) {
            if (DBG) {
                Log.d(TAG, "Removed account " + acc);
                Log.d(TAG, "Removed account " + account);
            }
        } else {
            Log.e(TAG, "Failed to remove account " + mAccount);
        }
    }

    private void removeCallLog(Account account) {
        try {
            // need to check call table is exist ?
            if (mContext.getContentResolver() == null) {
                if (DBG) {
                    Log.d(TAG, "CallLog ContentResolver is not found");
                }
                return;
            }
            String where = Calls.PHONE_ACCOUNT_ID + "=" + account.hashCode();
            mContext.getContentResolver().delete(CallLog.Calls.CONTENT_URI, where, null);
        } catch (IllegalArgumentException e) {
            Log.d(TAG, "Call Logs could not be deleted, they may not exist yet.");
        }
    }
}