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

Commit 82e71b72 authored by Haijie Hong's avatar Haijie Hong Committed by Android (Google) Code Review
Browse files

Merge "Exit bluetooth device details page when bluetooth is off" into main

parents 758e6959 1ab367d3
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -19,7 +19,9 @@ package com.android.settings.bluetooth;
import static android.bluetooth.BluetoothDevice.BOND_NONE;
import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;

import android.app.Activity;
import android.app.settings.SettingsEnums;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.Intent;
@@ -51,6 +53,7 @@ import com.android.settings.dashboard.RestrictedDashboardFragment;
import com.android.settings.inputmethod.KeyboardSettingsPreferenceController;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.slices.SlicePreferenceController;
import com.android.settingslib.bluetooth.BluetoothCallback;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -98,6 +101,20 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment

    private UserManager mUserManager;

    private final BluetoothCallback mBluetoothCallback =
            new BluetoothCallback() {
                @Override
                public void onBluetoothStateChanged(int bluetoothState) {
                    if (bluetoothState == BluetoothAdapter.STATE_OFF) {
                        Log.i(TAG, "Bluetooth is off, exit activity.");
                        Activity activity = getActivity();
                        if (activity != null) {
                            activity.finish();
                        }
                    }
                }
            };

    public BluetoothDeviceDetailsFragment() {
        super(DISALLOW_CONFIG_BLUETOOTH);
    }
@@ -183,6 +200,14 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
        use(BlockingPrefWithSliceController.class).setSliceUri(sliceEnabled
                ? featureProvider.getBluetoothDeviceSettingsUri(mCachedDevice.getDevice())
                : null);

        mManager.getEventManager().registerCallback(mBluetoothCallback);
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mManager.getEventManager().unregisterCallback(mBluetoothCallback);
    }

    private void updateExtraControlUri(int viewWidth) {