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

Commit 6142ace6 authored by Zoey Chen's avatar Zoey Chen Committed by Automerger Merge Worker
Browse files

Merge "[LeAudio] Create QR code scanner activity and fragment" into tm-dev am: d165ae1e

parents 57463768 d165ae1e
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -22,6 +22,16 @@
        <activity
            android:name="com.android.settingslib.users.AvatarPickerActivity"
            android:theme="@style/SudThemeGlifV2.DayNight"/>

        <activity
            android:name="com.android.settingslib.qrcode.QrCodeScanModeActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.settings.BLUETOOTH_LE_AUDIO_QR_CODE_SCANNER"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>

    </application>

</manifest>
+1 −1
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ public class CachedBluetoothDeviceManager {
    CsipDeviceManager mCsipDeviceManager;
    BluetoothDevice mOngoingSetMemberPair;

    CachedBluetoothDeviceManager(Context context, LocalBluetoothManager localBtManager) {
    public CachedBluetoothDeviceManager(Context context, LocalBluetoothManager localBtManager) {
        mContext = context;
        mBtManager = localBtManager;
        mHearingAidDeviceManager = new HearingAidDeviceManager(localBtManager, mCachedDevices);
+0 −4
Original line number Diff line number Diff line
@@ -66,10 +66,6 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
    private final ServiceListener mServiceListener = new ServiceListener() {
        @Override
        public void onServiceConnected(int profile, BluetoothProfile proxy) {
            if (profile != BluetoothProfile.LE_AUDIO_BROADCAST) {
                Log.d(TAG, "The profile is not LE_AUDIO_BROADCAST");
                return;
            }
            if (DEBUG) {
                Log.d(TAG, "Bluetooth service connected");
            }
+0 −4
Original line number Diff line number Diff line
@@ -65,10 +65,6 @@ public class LocalBluetoothLeBroadcastAssistant implements LocalBluetoothProfile
    private final ServiceListener mServiceListener = new ServiceListener() {
        @Override
        public void onServiceConnected(int profile, BluetoothProfile proxy) {
            if (profile != BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT) {
                Log.d(TAG, "The profile is not LE_AUDIO_BROADCAST_ASSISTANT");
                return;
            }
            if (DEBUG) {
                Log.d(TAG, "Bluetooth service connected");
            }
+109 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settingslib.qrcode;

import static com.android.settingslib.bluetooth.BluetoothBroadcastUtils.EXTRA_BLUETOOTH_DEVICE_SINK;
import static com.android.settingslib.bluetooth.BluetoothBroadcastUtils.EXTRA_BLUETOOTH_SINK_IS_GROUP;

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

import androidx.fragment.app.FragmentTransaction;

import com.android.settingslib.bluetooth.BluetoothBroadcastUtils;
import com.android.settingslib.R;
import com.android.settingslib.bluetooth.BluetoothUtils;

public class QrCodeScanModeActivity extends QrCodeScanModeBaseActivity {
    private static final boolean DEBUG = BluetoothUtils.D;
    private static final String TAG = "QrCodeScanModeActivity";

    private boolean mIsGroupOp;
    private BluetoothDevice mSink;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void handleIntent(Intent intent) {
        String action = intent != null ? intent.getAction() : null;
        if (DEBUG) {
            Log.d(TAG, "handleIntent(), action = " + action);
        }

        if (action == null) {
            finish();
            return;
        }

        switch (action) {
            case BluetoothBroadcastUtils.ACTION_BLUETOOTH_LE_AUDIO_QR_CODE_SCANNER:
                showQrCodeScannerFragment(intent);
                break;
            default:
                if (DEBUG) {
                    Log.e(TAG, "Launch with an invalid action");
                }
                finish();
        }
    }

    protected void showQrCodeScannerFragment(Intent intent) {
        if (DEBUG) {
            Log.d(TAG, "showQrCodeScannerFragment");
        }

        if (intent != null) {
            mSink = intent.getParcelableExtra(EXTRA_BLUETOOTH_DEVICE_SINK);
            mIsGroupOp = intent.getBooleanExtra(EXTRA_BLUETOOTH_SINK_IS_GROUP, false);
            if (DEBUG) {
                Log.d(TAG, "get extra from intent");
            }
        } else {
            if (DEBUG) {
                Log.d(TAG, "intent is null, can not get bluetooth information from intent.");
            }
        }

        QrCodeScanModeFragment fragment =
                (QrCodeScanModeFragment) mFragmentManager.findFragmentByTag(
                        BluetoothBroadcastUtils.TAG_FRAGMENT_QR_CODE_SCANNER);

        if (fragment == null) {
            fragment = new QrCodeScanModeFragment(mIsGroupOp, mSink);
        } else {
            if (fragment.isVisible()) {
                return;
            }

            // When the fragment in back stack but not on top of the stack, we can simply pop
            // stack because current fragment transactions are arranged in an order
            mFragmentManager.popBackStackImmediate();
            return;
        }
        final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();

        fragmentTransaction.replace(R.id.fragment_container, fragment,
                BluetoothBroadcastUtils.TAG_FRAGMENT_QR_CODE_SCANNER);
        fragmentTransaction.commit();
    }
}
Loading