Search in sources :

Example 26 with LocalBluetoothManager

use of com.android.settingslib.bluetooth.LocalBluetoothManager in project platform_packages_apps_Settings by BlissRoms.

the class RequestPermissionHelperActivity method parseIntent.

/**
 * Parse the received Intent and initialize mLocalBluetoothAdapter.
 * @return true if an error occurred; false otherwise
 */
private boolean parseIntent() {
    Intent intent = getIntent();
    if (intent == null) {
        return false;
    }
    String action = intent.getAction();
    if (ACTION_INTERNAL_REQUEST_BT_ON.equals(action)) {
        mRequest = RequestPermissionActivity.REQUEST_ENABLE;
        if (intent.hasExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION)) {
            // Value used for display purposes. Not range checking.
            mTimeout = intent.getIntExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, BluetoothDiscoverableEnabler.DEFAULT_DISCOVERABLE_TIMEOUT);
        }
    } else if (ACTION_INTERNAL_REQUEST_BT_OFF.equals(action)) {
        mRequest = RequestPermissionActivity.REQUEST_DISABLE;
    } else {
        return false;
    }
    LocalBluetoothManager manager = Utils.getLocalBtManager(this);
    if (manager == null) {
        Log.e(TAG, "Error: there's a problem starting Bluetooth");
        return false;
    }
    mAppLabel = getIntent().getCharSequenceExtra(EXTRA_APP_LABEL);
    mLocalAdapter = manager.getBluetoothAdapter();
    return true;
}
Also used : LocalBluetoothManager(com.android.settingslib.bluetooth.LocalBluetoothManager) Intent(android.content.Intent)

Example 27 with LocalBluetoothManager

use of com.android.settingslib.bluetooth.LocalBluetoothManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BluetoothDevicesSlice method getConnectedBluetoothDevices.

@VisibleForTesting
List<CachedBluetoothDevice> getConnectedBluetoothDevices() {
    final List<CachedBluetoothDevice> bluetoothDeviceList = new ArrayList<>();
    // If Bluetooth is disable, skip to get the Bluetooth devices.
    if (!BluetoothAdapter.getDefaultAdapter().isEnabled()) {
        Log.i(TAG, "Cannot get Bluetooth devices, Bluetooth is disabled.");
        return bluetoothDeviceList;
    }
    // Get the Bluetooth devices from LocalBluetoothManager.
    final LocalBluetoothManager bluetoothManager = com.android.settings.bluetooth.Utils.getLocalBtManager(mContext);
    if (bluetoothManager == null) {
        Log.i(TAG, "Cannot get Bluetooth devices, Bluetooth is unsupported.");
        return bluetoothDeviceList;
    }
    final Collection<CachedBluetoothDevice> cachedDevices = bluetoothManager.getCachedDeviceManager().getCachedDevicesCopy();
    // Get all connected devices and sort them.
    return cachedDevices.stream().filter(device -> device.getDevice().isConnected()).sorted(COMPARATOR).collect(Collectors.toList());
}
Also used : CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) ArrayList(java.util.ArrayList) LocalBluetoothManager(com.android.settingslib.bluetooth.LocalBluetoothManager) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 28 with LocalBluetoothManager

use of com.android.settingslib.bluetooth.LocalBluetoothManager in project platform_frameworks_base by android.

the class KeyboardUI method init.

// Shoud only be called on the handler thread
private void init() {
    Context context = mContext;
    mKeyboardName = context.getString(com.android.internal.R.string.config_packagedKeyboardName);
    if (TextUtils.isEmpty(mKeyboardName)) {
        if (DEBUG) {
            Slog.d(TAG, "No packaged keyboard name given.");
        }
        return;
    }
    LocalBluetoothManager bluetoothManager = LocalBluetoothManager.getInstance(context, null);
    if (bluetoothManager == null) {
        if (DEBUG) {
            Slog.e(TAG, "Failed to retrieve LocalBluetoothManager instance");
        }
        return;
    }
    mEnabled = true;
    mCachedDeviceManager = bluetoothManager.getCachedDeviceManager();
    mLocalBluetoothAdapter = bluetoothManager.getBluetoothAdapter();
    mProfileManager = bluetoothManager.getProfileManager();
    bluetoothManager.getEventManager().registerCallback(new BluetoothCallbackHandler());
    Utils.setErrorListener(new BluetoothErrorListener());
    InputManager im = context.getSystemService(InputManager.class);
    im.registerOnTabletModeChangedListener(this, mHandler);
    mInTabletMode = im.isInTabletMode();
    processKeyboardState();
    mUIHandler = new KeyboardUIHandler();
}
Also used : Context(android.content.Context) LocalBluetoothManager(com.android.settingslib.bluetooth.LocalBluetoothManager) InputManager(android.hardware.input.InputManager)

Example 29 with LocalBluetoothManager

use of com.android.settingslib.bluetooth.LocalBluetoothManager in project android_frameworks_base by ResurrectionRemix.

the class KeyboardUI method init.

// Shoud only be called on the handler thread
private void init() {
    Context context = mContext;
    mKeyboardName = context.getString(com.android.internal.R.string.config_packagedKeyboardName);
    if (TextUtils.isEmpty(mKeyboardName)) {
        if (DEBUG) {
            Slog.d(TAG, "No packaged keyboard name given.");
        }
        return;
    }
    LocalBluetoothManager bluetoothManager = LocalBluetoothManager.getInstance(context, null);
    if (bluetoothManager == null) {
        if (DEBUG) {
            Slog.e(TAG, "Failed to retrieve LocalBluetoothManager instance");
        }
        return;
    }
    mEnabled = true;
    mCachedDeviceManager = bluetoothManager.getCachedDeviceManager();
    mLocalBluetoothAdapter = bluetoothManager.getBluetoothAdapter();
    mProfileManager = bluetoothManager.getProfileManager();
    bluetoothManager.getEventManager().registerCallback(new BluetoothCallbackHandler());
    Utils.setErrorListener(new BluetoothErrorListener());
    InputManager im = context.getSystemService(InputManager.class);
    im.registerOnTabletModeChangedListener(this, mHandler);
    mInTabletMode = im.isInTabletMode();
    processKeyboardState();
    mUIHandler = new KeyboardUIHandler();
}
Also used : Context(android.content.Context) LocalBluetoothManager(com.android.settingslib.bluetooth.LocalBluetoothManager) InputManager(android.hardware.input.InputManager)

Example 30 with LocalBluetoothManager

use of com.android.settingslib.bluetooth.LocalBluetoothManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BluetoothPermissionActivity method onNegative.

private void onNegative() {
    if (DEBUG)
        Log.d(TAG, "onNegative");
    boolean always = true;
    if (mRequestType == BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS) {
        LocalBluetoothManager bluetoothManager = Utils.getLocalBtManager(this);
        CachedBluetoothDeviceManager cachedDeviceManager = bluetoothManager.getCachedDeviceManager();
        CachedBluetoothDevice cachedDevice = cachedDeviceManager.findDevice(mDevice);
        if (cachedDevice == null) {
            cachedDevice = cachedDeviceManager.addDevice(bluetoothManager.getBluetoothAdapter(), bluetoothManager.getProfileManager(), mDevice);
        }
        always = cachedDevice.checkAndIncreaseMessageRejectionCount();
    }
    sendReplyIntentToReceiver(false, always);
}
Also used : CachedBluetoothDeviceManager(com.android.settingslib.bluetooth.CachedBluetoothDeviceManager) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) LocalBluetoothManager(com.android.settingslib.bluetooth.LocalBluetoothManager)

Aggregations

LocalBluetoothManager (com.android.settingslib.bluetooth.LocalBluetoothManager)61 CachedBluetoothDevice (com.android.settingslib.bluetooth.CachedBluetoothDevice)29 BluetoothDevice (android.bluetooth.BluetoothDevice)14 CachedBluetoothDeviceManager (com.android.settingslib.bluetooth.CachedBluetoothDeviceManager)14 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)13 Intent (android.content.Intent)12 SharedPreferences (android.content.SharedPreferences)7 Context (android.content.Context)6 ApplicationInfo (android.content.pm.ApplicationInfo)6 PackageManager (android.content.pm.PackageManager)6 LocalBluetoothAdapter (com.android.settingslib.bluetooth.LocalBluetoothAdapter)6 InputManager (android.hardware.input.InputManager)5 VisibleForTesting (androidx.annotation.VisibleForTesting)2 BluetoothAdapter (android.bluetooth.BluetoothAdapter)1 HandlerThread (android.os.HandlerThread)1 ArrayList (java.util.ArrayList)1