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

Commit 3bc2adff authored by Chelsea Hao's avatar Chelsea Hao Committed by Android (Google) Code Review
Browse files

Merge "[Audiosharing] Start creating view after service is connected in...

Merge "[Audiosharing] Start creating view after service is connected in confirm dialog activity." into main
parents 7f2090d3 6e5249e5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -283,7 +283,7 @@ public class SettingsActivity extends SettingsBaseActivity
        createUiFromIntent(savedState, intent);
    }

    protected void createUiFromIntent(Bundle savedState, Intent intent) {
    protected void createUiFromIntent(@Nullable Bundle savedState, Intent intent) {
        long startTime = System.currentTimeMillis();

        final FeatureFactory factory = FeatureFactory.getFeatureFactory();
+75 −1
Original line number Diff line number Diff line
@@ -16,17 +16,91 @@

package com.android.settings.connecteddevice.audiosharing.audiostreams;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import androidx.annotation.Nullable;

import com.android.settings.SettingsActivity;
import com.android.settings.bluetooth.Utils;
import com.android.settings.connecteddevice.audiosharing.AudioSharingUtils;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;

public class AudioStreamConfirmDialogActivity extends SettingsActivity
        implements LocalBluetoothProfileManager.ServiceListener {
    private static final String TAG = "AudioStreamConfirmDialogActivity";
    @Nullable private LocalBluetoothProfileManager mProfileManager;
    @Nullable private Bundle mSavedState;
    @Nullable private Intent mIntent;

public class AudioStreamConfirmDialogActivity extends SettingsActivity {
    @Override
    protected boolean isToolbarEnabled() {
        return false;
    }

    @Override
    protected void onCreate(Bundle savedState) {
        var localBluetoothManager = Utils.getLocalBluetoothManager(this);
        mProfileManager =
                localBluetoothManager == null ? null : localBluetoothManager.getProfileManager();
        super.onCreate(savedState);
    }

    @Override
    protected void createUiFromIntent(@Nullable Bundle savedState, Intent intent) {
        if (AudioSharingUtils.isFeatureEnabled()
                && !AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) {
            Log.d(TAG, "createUiFromIntent() : supported but not ready, skip createUiFromIntent");
            mSavedState = savedState;
            mIntent = intent;
            return;
        }

        Log.d(
                TAG,
                "createUiFromIntent() : not supported or already connected, starting"
                        + " createUiFromIntent");
        super.createUiFromIntent(savedState, intent);
    }

    @Override
    public void onStart() {
        if (AudioSharingUtils.isFeatureEnabled()
                && !AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) {
            Log.d(TAG, "onStart() : supported but not ready, listen to service ready");
            if (mProfileManager != null) {
                mProfileManager.addServiceListener(this);
            }
        }
        super.onStart();
    }

    @Override
    public void onStop() {
        if (mProfileManager != null) {
            mProfileManager.removeServiceListener(this);
        }
        super.onStop();
    }

    @Override
    public void onServiceConnected() {
        if (AudioSharingUtils.isFeatureEnabled()
                && AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) {
            if (mProfileManager != null) {
                mProfileManager.removeServiceListener(this);
            }
            if (mIntent != null) {
                Log.d(TAG, "onServiceConnected() : service ready, starting createUiFromIntent");
                super.createUiFromIntent(mSavedState, mIntent);
            }
        }
    }

    @Override
    public void onServiceDisconnected() {}

    @Override
    protected boolean isValidFragment(String fragmentName) {
        return AudioStreamConfirmDialog.class.getName().equals(fragmentName);