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

Commit 61b19b06 authored by Gaurav Asati's avatar Gaurav Asati Committed by Linux Build Service Account
Browse files

Bluetooth: Destroy BT Dialog on BT power off.

Check for Bluetooth off Broadcast to destroy disconnect
dialog when Bluetooth is turned off from power widget.

CRs-Fixed: 579028
Conflicts:
	src/com/android/settings/bluetooth/DeviceProfilesSettings.java

Change-Id: Ie556a17c7d574f77da5181c08705648ebf5733cc
parent fa02a7e4
Loading
Loading
Loading
Loading
+39 −6
Original line number Diff line number Diff line
@@ -19,11 +19,15 @@ package com.android.settings.bluetooth;
import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;

import android.app.AlertDialog;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.UserManager;
import android.preference.Preference;
import android.text.Html;
@@ -56,6 +60,10 @@ public final class BluetoothDevicePreference extends Preference implements

    private AlertDialog mDisconnectDialog;

    private Context mContext;

    private static final int OK_BUTTON = -1;

    public BluetoothDevicePreference(Context context, CachedBluetoothDevice cachedDevice) {
        super(context);

@@ -191,21 +199,28 @@ public final class BluetoothDevicePreference extends Preference implements

    // Show disconnect confirmation dialog for a device.
    private void askDisconnect() {
        Context context = getContext();
        mContext = getContext();
        String name = mCachedDevice.getName();
        if (TextUtils.isEmpty(name)) {
            name = context.getString(R.string.bluetooth_device);
            name = mContext.getString(R.string.bluetooth_device);
        }
        String message = context.getString(R.string.bluetooth_disconnect_all_profiles, name);
        String title = context.getString(R.string.bluetooth_disconnect_title);
        String message = mContext.getString(R.string.bluetooth_disconnect_all_profiles, name);
        String title = mContext.getString(R.string.bluetooth_disconnect_title);

        IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
        mContext.registerReceiver(mBluetoothReceiver, filter);

        DialogInterface.OnClickListener disconnectListener = new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // Disconnect only when user has selected OK
                if (which == OK_BUTTON) {
                    mCachedDevice.disconnect();
                }
                mContext.unregisterReceiver(mBluetoothReceiver);
            }
        };

        mDisconnectDialog = Utils.showDisconnectDialog(context,
        mDisconnectDialog = Utils.showDisconnectDialog(mContext,
                mDisconnectDialog, disconnectListener, title, Html.fromHtml(message));
    }

@@ -323,4 +338,22 @@ public final class BluetoothDevicePreference extends Preference implements
        }
        return R.drawable.ic_settings_bluetooth2;
    }

    private final BroadcastReceiver mBluetoothReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
                switch (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)) {
                    case BluetoothAdapter.STATE_TURNING_OFF:
                        Log.v(TAG, "Receiver DISABLED_ACTION ");
                        if (mDisconnectDialog != null && mDisconnectDialog.isShowing()) {
                            mDisconnectDialog.dismiss();
                        }
                        mContext.unregisterReceiver(mBluetoothReceiver);
                        break;
                }
            }
        }
    };
}
+10 −5
Original line number Diff line number Diff line
@@ -62,6 +62,8 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
    private LocalBluetoothManager mManager;
    private LocalBluetoothProfileManager mProfileManager;

    private static final int OK_BUTTON = -1;

    private PreferenceGroup mProfileContainer;
    private EditTextPreference mDeviceNamePref;

@@ -268,6 +270,8 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
        DialogInterface.OnClickListener disconnectListener =
                new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // Disconnect only when user has selected OK
                if (which == OK_BUTTON) {
                    device.disconnect(profile);
                    profile.setPreferred(device.getDevice(), false);
                    if (profile instanceof MapProfile) {
@@ -276,6 +280,7 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
                            (CheckBoxPreference)findPreference(profile.toString()), profile);
                    }
                }
            }
        };

        mDisconnectDialog = Utils.showDisconnectDialog(context,
+1 −1
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ final class Utils {
        if (dialog == null) {
            dialog = new AlertDialog.Builder(context)
                    .setPositiveButton(android.R.string.ok, disconnectListener)
                    .setNegativeButton(android.R.string.cancel, null)
                    .setNegativeButton(android.R.string.cancel, disconnectListener)
                    .create();
        } else {
            if (dialog.isShowing()) {