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

Commit 23569829 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 12348750 from 1c756ec8 to 24Q4-release

Change-Id: I8dec62d80cea41f1b27722e8b5523456cacfb93b
parents e004275f 1c756ec8
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -111,7 +111,10 @@ android_library {
        "keyboard_flags_lib",
    ],

    plugins: ["androidx.room_room-compiler-plugin"],
    plugins: [
        "SettingsLibMetadata-processor",
        "androidx.room_room-compiler-plugin",
    ],

    errorprone: {
        extra_check_modules: ["//external/nullaway:nullaway_plugin"],
+21 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.settings;

import static com.android.settingslib.flags.Flags.settingsCatalyst;

import android.app.Application;
import android.content.Context;
import android.content.pm.PackageManager;
@@ -42,13 +44,20 @@ import com.android.settings.overlay.FeatureFactoryImpl;
import com.android.settings.spa.SettingsSpaEnvironment;
import com.android.settingslib.applications.AppIconCacheManager;
import com.android.settingslib.datastore.BackupRestoreStorageManager;
import com.android.settingslib.metadata.PreferenceScreenMetadata;
import com.android.settingslib.metadata.PreferenceScreenRegistry;
import com.android.settingslib.metadata.ProvidePreferenceScreenOptions;
import com.android.settingslib.spa.framework.common.SpaEnvironmentFactory;

import com.google.android.setupcompat.util.WizardManagerHelper;

import java.lang.ref.WeakReference;
import java.util.List;

/** Settings application which sets up activity embedding rules for the large screen device. */
@ProvidePreferenceScreenOptions(
        codegenCollector = "com.android.settings/PreferenceScreenCollector/get"
)
public class SettingsApplication extends Application {

    private WeakReference<SettingsHomepageActivity> mHomeActivity = new WeakReference<>(null);
@@ -64,6 +73,11 @@ public class SettingsApplication extends Application {
    public void onCreate() {
        super.onCreate();

        if (settingsCatalyst()) {
            PreferenceScreenRegistry.INSTANCE.setPreferenceScreensSupplier(
                    this::getPreferenceScreens);
        }

        BackupRestoreStorageManager.getInstance(this)
                .add(
                        new BatterySettingsStorage(this),
@@ -90,6 +104,13 @@ public class SettingsApplication extends Application {
        registerActivityLifecycleCallbacks(new DeveloperOptionsActivityLifecycle());
    }

    /** Returns the screens using metadata. */
    protected List<PreferenceScreenMetadata> getPreferenceScreens() {
        // PreferenceScreenCollector is generated by annotation processor from classes annotated
        // with @ProvidePreferenceScreen
        return PreferenceScreenCollector.get(this);
    }

    @Override
    public void onTerminate() {
        BackupRestoreStorageManager.getInstance(this).removeAll();
+81 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.settings.connecteddevice.audiosharing;

import android.app.Dialog;
import android.os.Bundle;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;

import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
import com.android.settingslib.bluetooth.BluetoothUtils;

public class AudioSharingRetryDialogFragment extends InstrumentedDialogFragment {
    private static final String TAG = "AudioSharingRetryDialog";

    @Override
    public int getMetricsCategory() {
        // TODO: add metrics
        return 0;
    }

    /**
     * Display the {@link AudioSharingRetryDialogFragment} dialog.
     *
     * @param host The Fragment this dialog will be hosted.
     */
    public static void show(@Nullable Fragment host) {
        if (host == null || !BluetoothUtils.isAudioSharingEnabled()) return;
        final FragmentManager manager;
        try {
            manager = host.getChildFragmentManager();
        } catch (IllegalStateException e) {
            Log.d(TAG, "Fail to show dialog: " + e.getMessage());
            return;
        }
        AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
        if (dialog != null) {
            Log.d(TAG, "Dialog is showing, return.");
            return;
        }
        Log.d(TAG, "Show up the retry dialog.");
        AudioSharingRetryDialogFragment dialogFrag = new AudioSharingRetryDialogFragment();
        dialogFrag.show(manager, TAG);
    }

    @Override
    @NonNull
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        // TODO: put strings to res till they are finalized
        AlertDialog dialog =
                AudioSharingDialogFactory.newBuilder(getActivity())
                        .setTitle("Couldn't share audio")
                        .setTitleIcon(com.android.settings.R.drawable.ic_warning_24dp)
                        .setIsCustomBodyEnabled(true)
                        .setCustomMessage("Something went wrong. Please try again.")
                        .setPositiveButton(com.android.settings.R.string.okay, (d, w) -> {
                        })
                        .build();
        dialog.setCanceledOnTouchOutside(true);
        return dialog;
    }
}
+21 −8
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import android.bluetooth.BluetoothLeBroadcast;
import android.bluetooth.BluetoothLeBroadcastAssistant;
import android.bluetooth.BluetoothLeBroadcastMetadata;
import android.bluetooth.BluetoothLeBroadcastReceiveState;
import android.bluetooth.BluetoothProfile;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -379,7 +378,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
            if (FeatureFlagUtils.isEnabled(
                    mContext,
                    FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST)
                    && mAssistant.getAllConnectedDevices().isEmpty()) {
                    && hasEmptyConnectedSink()) {
                // Pop up dialog to ask users to connect at least one lea buds before audio sharing.
                AudioSharingUtils.postOnMainThread(
                        mContext,
@@ -435,8 +434,12 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
    }

    @Override
    public void onActiveDeviceChanged(CachedBluetoothDevice activeDevice, int bluetoothProfile) {
        if (activeDevice != null && bluetoothProfile == BluetoothProfile.LE_AUDIO) {
    public void onActiveDeviceChanged(@Nullable CachedBluetoothDevice activeDevice,
            int bluetoothProfile) {
        if (activeDevice != null) {
            Log.d(TAG, "onActiveDeviceChanged: device = "
                    + activeDevice.getDevice().getAnonymizedAddress()
                    + ", profile = " + bluetoothProfile);
            updateSwitch();
        }
    }
@@ -536,13 +539,19 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
                            boolean isBroadcasting = BluetoothUtils.isBroadcasting(mBtManager);
                            boolean hasActiveDevice =
                                    AudioSharingUtils.hasActiveConnectedLeadDevice(mBtManager);
                            boolean hasEmptyConnectedDevice = hasEmptyConnectedSink();
                            boolean isStateReady =
                                    isBluetoothOn()
                                            && AudioSharingUtils.isAudioSharingProfileReady(
                                            mProfileManager)
                                            && (isBroadcasting
                                            // Always enable toggle when no connected sink. We have
                                            // dialog to guide users to connect compatible devices
                                            // for audio sharing.
                                            || hasEmptyConnectedDevice
                                            // Disable toggle till device gets active after
                                            // broadcast ends.
                                            && (isBroadcasting || hasActiveDevice);
                                            || hasActiveDevice);
                            AudioSharingUtils.postOnMainThread(
                                    mContext,
                                    () -> {
@@ -566,6 +575,10 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
        return mBluetoothAdapter != null && mBluetoothAdapter.isEnabled();
    }

    private boolean hasEmptyConnectedSink() {
        return mAssistant != null && mAssistant.getAllConnectedDevices().isEmpty();
    }

    private void handleOnBroadcastReady() {
        Pair<Integer, Object>[] eventData =
                AudioSharingUtils.buildAudioSharingDialogEventData(
+5 −8
Original line number Diff line number Diff line
@@ -215,16 +215,13 @@ public class AudioSharingUtils {
            @Nullable LocalBluetoothManager localBtManager) {
        CachedBluetoothDeviceManager deviceManager =
                localBtManager == null ? null : localBtManager.getCachedDeviceManager();
        Map<Integer, List<BluetoothDevice>> groupedConnectedDevices =
                fetchConnectedDevicesByGroupId(localBtManager);
        for (List<BluetoothDevice> devices : groupedConnectedDevices.values()) {
            CachedBluetoothDevice leadDevice = getLeadDevice(deviceManager, devices);
            if (isActiveLeAudioDevice(leadDevice)) {
                return true;
            }
        }
        if (deviceManager == null) {
            Log.d(TAG, "hasActiveConnectedLeadDevice return false due to null device manager.");
            return false;
        }
        return deviceManager.getCachedDevicesCopy().stream().anyMatch(
                BluetoothUtils::isActiveMediaDevice);
    }

    /** Build {@link AudioSharingDeviceItem} from {@link CachedBluetoothDevice}. */
    public static AudioSharingDeviceItem buildAudioSharingDeviceItem(
Loading