Search in sources :

Example 51 with LocalBluetoothManager

use of com.android.settingslib.bluetooth.LocalBluetoothManager in project android_packages_apps_Settings by SudaMod.

the class RemoteDeviceNameDialogFragment method getDevice.

@VisibleForTesting
CachedBluetoothDevice getDevice(Context context) {
    String deviceAddress = getArguments().getString(KEY_CACHED_DEVICE_ADDRESS);
    LocalBluetoothManager manager = Utils.getLocalBtManager(context);
    BluetoothDevice device = manager.getBluetoothAdapter().getRemoteDevice(deviceAddress);
    return manager.getCachedDeviceManager().findDevice(device);
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) LocalBluetoothManager(com.android.settingslib.bluetooth.LocalBluetoothManager) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 52 with LocalBluetoothManager

use of com.android.settingslib.bluetooth.LocalBluetoothManager in project android_packages_apps_Settings by SudaMod.

the class RequestPermissionActivity 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 true;
    }
    if (intent.getAction().equals(BluetoothAdapter.ACTION_REQUEST_ENABLE)) {
        mRequest = REQUEST_ENABLE;
    } else if (intent.getAction().equals(BluetoothAdapter.ACTION_REQUEST_DISABLE)) {
        mRequest = REQUEST_DISABLE;
    } else if (intent.getAction().equals(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE)) {
        mRequest = REQUEST_ENABLE_DISCOVERABLE;
        mTimeout = intent.getIntExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, BluetoothDiscoverableEnabler.DEFAULT_DISCOVERABLE_TIMEOUT);
        Log.d(TAG, "Setting Bluetooth Discoverable Timeout = " + mTimeout);
        if (mTimeout < 1 || mTimeout > MAX_DISCOVERABLE_TIMEOUT) {
            mTimeout = BluetoothDiscoverableEnabler.DEFAULT_DISCOVERABLE_TIMEOUT;
        }
    } else {
        Log.e(TAG, "Error: this activity may be started only with intent " + BluetoothAdapter.ACTION_REQUEST_ENABLE + " or " + BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
        setResult(RESULT_CANCELED);
        return true;
    }
    LocalBluetoothManager manager = Utils.getLocalBtManager(this);
    if (manager == null) {
        Log.e(TAG, "Error: there's a problem starting Bluetooth");
        setResult(RESULT_CANCELED);
        return true;
    }
    String packageName = getCallingPackage();
    if (TextUtils.isEmpty(packageName)) {
        packageName = getIntent().getStringExtra(Intent.EXTRA_PACKAGE_NAME);
    }
    if (!TextUtils.isEmpty(packageName)) {
        try {
            ApplicationInfo applicationInfo = getPackageManager().getApplicationInfo(packageName, 0);
            mAppLabel = applicationInfo.loadSafeLabel(getPackageManager());
        } catch (PackageManager.NameNotFoundException e) {
            Log.e(TAG, "Couldn't find app with package name " + packageName);
            setResult(RESULT_CANCELED);
            return true;
        }
    }
    mLocalAdapter = manager.getBluetoothAdapter();
    return false;
}
Also used : PackageManager(android.content.pm.PackageManager) LocalBluetoothManager(com.android.settingslib.bluetooth.LocalBluetoothManager) ApplicationInfo(android.content.pm.ApplicationInfo) Intent(android.content.Intent)

Example 53 with LocalBluetoothManager

use of com.android.settingslib.bluetooth.LocalBluetoothManager in project android_packages_apps_Settings by SudaMod.

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 54 with LocalBluetoothManager

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

the class BluetoothPermissionRequest method checkUserChoice.

/**
 * @return true user had made a choice, this method replies to the request according
 *              to user's previous decision
 *         false user hadnot made any choice on this device
 */
private boolean checkUserChoice() {
    boolean processed = false;
    // ignore if it is something else than phonebook/message settings it wants us to remember
    if (mRequestType != BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS && mRequestType != BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS && mRequestType != BluetoothDevice.REQUEST_TYPE_SIM_ACCESS) {
        if (DEBUG)
            Log.d(TAG, "checkUserChoice(): Unknown RequestType " + mRequestType);
        return processed;
    }
    LocalBluetoothManager bluetoothManager = Utils.getLocalBtManager(mContext);
    CachedBluetoothDeviceManager cachedDeviceManager = bluetoothManager.getCachedDeviceManager();
    CachedBluetoothDevice cachedDevice = cachedDeviceManager.findDevice(mDevice);
    if (cachedDevice == null) {
        cachedDevice = cachedDeviceManager.addDevice(bluetoothManager.getBluetoothAdapter(), bluetoothManager.getProfileManager(), mDevice);
    }
    String intentName = BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY;
    if (mRequestType == BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS) {
        int phonebookPermission = cachedDevice.getPhonebookPermissionChoice();
        if (phonebookPermission == CachedBluetoothDevice.ACCESS_UNKNOWN) {
        // Leave 'processed' as false.
        } else if (phonebookPermission == CachedBluetoothDevice.ACCESS_ALLOWED) {
            sendReplyIntentToReceiver(true);
            processed = true;
        } else if (phonebookPermission == CachedBluetoothDevice.ACCESS_REJECTED) {
            sendReplyIntentToReceiver(false);
            processed = true;
        } else {
            Log.e(TAG, "Bad phonebookPermission: " + phonebookPermission);
        }
    } else if (mRequestType == BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS) {
        int messagePermission = cachedDevice.getMessagePermissionChoice();
        if (messagePermission == CachedBluetoothDevice.ACCESS_UNKNOWN) {
        // Leave 'processed' as false.
        } else if (messagePermission == CachedBluetoothDevice.ACCESS_ALLOWED) {
            sendReplyIntentToReceiver(true);
            processed = true;
        } else if (messagePermission == CachedBluetoothDevice.ACCESS_REJECTED) {
            sendReplyIntentToReceiver(false);
            processed = true;
        } else {
            Log.e(TAG, "Bad messagePermission: " + messagePermission);
        }
    } else if (mRequestType == BluetoothDevice.REQUEST_TYPE_SIM_ACCESS) {
        int simPermission = cachedDevice.getSimPermissionChoice();
        if (simPermission == CachedBluetoothDevice.ACCESS_UNKNOWN) {
        // Leave 'processed' as false.
        } else if (simPermission == CachedBluetoothDevice.ACCESS_ALLOWED) {
            sendReplyIntentToReceiver(true);
            processed = true;
        } else if (simPermission == CachedBluetoothDevice.ACCESS_REJECTED) {
            sendReplyIntentToReceiver(false);
            processed = true;
        } else {
            Log.e(TAG, "Bad simPermission: " + simPermission);
        }
    }
    if (DEBUG)
        Log.d(TAG, "checkUserChoice(): returning " + processed);
    return processed;
}
Also used : CachedBluetoothDeviceManager(com.android.settingslib.bluetooth.CachedBluetoothDeviceManager) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) LocalBluetoothManager(com.android.settingslib.bluetooth.LocalBluetoothManager)

Example 55 with LocalBluetoothManager

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

the class ForgetDeviceDialogFragment method getDevice.

@VisibleForTesting
CachedBluetoothDevice getDevice(Context context) {
    String deviceAddress = getArguments().getString(KEY_DEVICE_ADDRESS);
    LocalBluetoothManager manager = Utils.getLocalBtManager(context);
    BluetoothDevice device = manager.getBluetoothAdapter().getRemoteDevice(deviceAddress);
    return manager.getCachedDeviceManager().findDevice(device);
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) LocalBluetoothManager(com.android.settingslib.bluetooth.LocalBluetoothManager) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

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