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

Commit ce314dfa authored by Sungsoo Lim's avatar Sungsoo Lim Committed by Automerger Merge Worker
Browse files

Merge "Prevent callbacks being called before the constructor" into rvc-dev am:...

Merge "Prevent callbacks being called before the constructor" into rvc-dev am: 8c6907d5 am: 72d06b50

Change-Id: I983263398ce89de1c163647960a121935982d737
parents abc5f373 72d06b50
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -85,7 +85,9 @@ class BluetoothRouteProvider {
        mListener = listener;
        mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
        buildBluetoothRoutes();
    }

    public void start() {
        mBluetoothAdapter.getProfileProxy(mContext, mProfileListener, BluetoothProfile.A2DP);
        mBluetoothAdapter.getProfileProxy(mContext, mProfileListener, BluetoothProfile.HEARING_AID);

+37 −39
Original line number Diff line number Diff line
@@ -103,25 +103,20 @@ class SystemMediaRoute2Provider extends MediaRoute2Provider {
            publishProviderState();

            boolean sessionInfoChanged;
            synchronized (mLock) {
                sessionInfoChanged = updateSessionInfosIfNeededLocked();
            }
            sessionInfoChanged = updateSessionInfosIfNeeded();
            if (sessionInfoChanged) {
                notifySessionInfoUpdated();
            }
        });

        mHandler.post(() -> notifyProviderState());

        //TODO: clean up this
        // This is required because it is not instantiated in the main thread and
        // BluetoothRoutesUpdatedListener can be called before here
        synchronized (mLock) {
            updateSessionInfosIfNeededLocked();
        }
        updateSessionInfosIfNeeded();

        mContext.registerReceiver(new VolumeChangeReceiver(),
                new IntentFilter(AudioManager.VOLUME_CHANGED_ACTION));

        mHandler.post(() -> {
            mBtRouteProvider.start();
            notifyProviderState();
        });
    }

    @Override
@@ -220,10 +215,12 @@ class SystemMediaRoute2Provider extends MediaRoute2Provider {
    /**
     * Updates the mSessionInfo. Returns true if the session info is changed.
     */
    boolean updateSessionInfosIfNeededLocked() {
    boolean updateSessionInfosIfNeeded() {
        synchronized (mLock) {
            // Prevent to execute this method before mBtRouteProvider is created.
            if (mBtRouteProvider == null) return false;
        RoutingSessionInfo oldSessionInfo = mSessionInfos.isEmpty() ? null : mSessionInfos.get(0);
            RoutingSessionInfo oldSessionInfo = mSessionInfos.isEmpty() ? null : mSessionInfos.get(
                    0);

            RoutingSessionInfo.Builder builder = new RoutingSessionInfo.Builder(
                    SYSTEM_SESSION_ID, "" /* clientPackageName */)
@@ -251,6 +248,7 @@ class SystemMediaRoute2Provider extends MediaRoute2Provider {
                return true;
            }
        }
    }

    void publishProviderState() {
        updateProviderState();