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

Commit 83791836 authored by Myles Watson's avatar Myles Watson
Browse files

PBAP: Reload contacts on user switch

When the active user changes, update contacts.

The car kit will still have the old contacts, but when it
asks for new contacts it will get contacts for the new user.

Bug: 72435402
Test: Connect and disconnect to a car kit, switch users, repeat
Change-Id: Ia015aa5b3d6dece4515d76bb1804e2c1ba05e349
parent 4cb75999
Loading
Loading
Loading
Loading
+25 −5
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.os.PowerManager;
import android.os.UserManager;
import android.support.annotation.VisibleForTesting;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
@@ -175,6 +176,11 @@ public class BluetoothPbapService extends ProfileService implements IObexConnect
        @Override
        public void onChange(boolean selfChange) {
            Log.d(TAG, " onChange on contact uri ");
            sendUpdateRequest();
        }
    }

    private void sendUpdateRequest() {
        if (mContactsLoaded) {
            if (!mSessionStatusHandler.hasMessages(CHECK_SECONDARY_VERSION_COUNTER)) {
                mSessionStatusHandler.sendMessage(
@@ -182,7 +188,6 @@ public class BluetoothPbapService extends ProfileService implements IObexConnect
            }
        }
    }
    }

    private BluetoothPbapContentObserver mContactChangeObserver;

@@ -565,6 +570,21 @@ public class BluetoothPbapService extends ProfileService implements IObexConnect
        sBluetoothPbapService = instance;
    }

    @Override
    protected void setCurrentUser(int userId) {
        Log.i(TAG, "setCurrentUser(" + userId + ")");
        UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
        if (userManager.isUserUnlocked(userId)) {
            setUserUnlocked(userId);
        }
    }

    @Override
    protected void setUserUnlocked(int userId) {
        Log.i(TAG, "setUserUnlocked(" + userId + ")");
        sendUpdateRequest();
    }

    private static class PbapBinder extends IBluetoothPbap.Stub implements IProfileServiceBinder {
        private BluetoothPbapService mService;