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

Commit 59b4e4ba authored by Hemant Gupta's avatar Hemant Gupta Committed by android-build-merger
Browse files

Merge "PBAP: Handle PBAP Disconnection when contacts are not loaded"

am: 0d8c3245

Change-Id: Ic77b79bcd7746d0bb4e1e3d8aa52bea00f418164
parents 072e7916 0d8c3245
Loading
Loading
Loading
Loading
+45 −6
Original line number Diff line number Diff line
@@ -200,6 +200,10 @@ public class BluetoothPbapService extends ProfileService implements IObexConnect
    private static final String ACCESS_AUTHORITY_CLASS =
            "com.android.settings.bluetooth.BluetoothPermissionRequest";

    private Thread mThreadLoadContacts = null;

    private Thread mThreadUpdateSecVersionCounter = null;

    private class BluetoothPbapContentObserver extends ContentObserver {
        BluetoothPbapContentObserver() {
            super(new Handler());
@@ -263,11 +267,14 @@ public class BluetoothPbapService extends ProfileService implements IObexConnect
            if (DEBUG) {
                Log.d(TAG, "ACL disconnected for " + device);
            }
            if (mIsWaitingAuthorization && mRemoteDevice.equals(device)) {
            if (mRemoteDevice.equals(device)) {
                if (mIsWaitingAuthorization) {
                    mSessionStatusHandler.removeMessages(USER_TIMEOUT);
                    mSessionStatusHandler.obtainMessage(USER_TIMEOUT).sendToTarget();
                }
            mSessionStatusHandler.obtainMessage(MSG_SERVERSESSION_CLOSE).sendToTarget();
                mSessionStatusHandler.obtainMessage(MSG_SERVERSESSION_CLOSE)
                    .sendToTarget();
            }
            return;
        }

@@ -383,6 +390,7 @@ public class BluetoothPbapService extends ProfileService implements IObexConnect
        if (mSessionStatusHandler != null) {
            mSessionStatusHandler.removeCallbacksAndMessages(null);
        }
        mRemoteDevice = null;
        if (VERBOSE) {
            Log.v(TAG, "Pbap Service closeService out");
        }
@@ -561,10 +569,10 @@ public class BluetoothPbapService extends ProfileService implements IObexConnect
                    closeService();
                    break;
                case LOAD_CONTACTS:
                    BluetoothPbapUtils.loadAllContacts(mContext, this);
                    loadAllContacts();
                    break;
                case CHECK_SECONDARY_VERSION_COUNTER:
                    BluetoothPbapUtils.updateSecondaryVersionCounter(mContext, this);
                    updateSecondaryVersion();
                    break;
                case ROLLOVER_COUNTERS:
                    BluetoothPbapUtils.rolloverCounters();
@@ -941,4 +949,35 @@ public class BluetoothPbapService extends ProfileService implements IObexConnect
            startSocketListeners();
        }
    }

    private void loadAllContacts() {
        if (mThreadLoadContacts == null) {
            Runnable r = new Runnable() {
                @Override
                public void run() {
                    BluetoothPbapUtils.loadAllContacts(mContext,
                            mSessionStatusHandler);
                    mThreadLoadContacts = null;
                }
            };
            mThreadLoadContacts = new Thread(r);
            mThreadLoadContacts.start();
        }
    }

    private void updateSecondaryVersion() {
        if (mThreadUpdateSecVersionCounter == null) {
            Runnable r = new Runnable() {
                @Override
                public void run() {
                    BluetoothPbapUtils.updateSecondaryVersionCounter(mContext,
                            mSessionStatusHandler);
                    mThreadUpdateSecVersionCounter = null;
                }
            };
            mThreadUpdateSecVersionCounter = new Thread(r);
            mThreadUpdateSecVersionCounter.start();
        }
    }

}
+5 −5
Original line number Diff line number Diff line
@@ -253,7 +253,7 @@ public class BluetoothPbapUtils {
        edit.putLong("primary", primaryCounter);
        edit.putLong("secondary", secondaryCounter);
        edit.putLong("dbIdentifier", dbIdentifier);
        edit.putLong("totalContacts", totalContacts);
        if (contactsLoaded) edit.putLong("totalContacts", totalContacts);
        edit.putLong("lastUpdatedTimestamp", lastUpdatedTimestamp);
        edit.putLong("totalFields", totalFields);
        edit.putLong("totalSvcFields", totalSvcFields);
@@ -295,12 +295,12 @@ public class BluetoothPbapUtils {

        try {
            String[] projection = {Data.CONTACT_ID, Data.DATA1, Data.MIMETYPE};
            int contactCount = 0;
            if ((contactCount =
                    fetchAndSetContacts(mContext, mHandler, projection, null, null, true)) < 0) {
            totalContacts = fetchAndSetContacts(mContext, mHandler, projection,
                null, null, true);
            if (totalContacts < 0) {
                totalContacts = 0;
                return;
            }
            totalContacts = contactCount; // to set total contacts count fetched on Connect
            contactsLoaded = true;
        } catch (Exception e) {
            Log.e(TAG, "Exception occurred in load contacts: " + e);