Search in sources :

Example 56 with LocalBluetoothManager

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

the class LocalBluetoothPreferences method shouldShowDialogInForeground.

static boolean shouldShowDialogInForeground(Context context, String deviceAddress, String deviceName) {
    LocalBluetoothManager manager = Utils.getLocalBtManager(context);
    if (manager == null) {
        if (DEBUG)
            Log.v(TAG, "manager == null - do not show dialog.");
        return false;
    }
    // If Bluetooth Settings is visible
    if (manager.isForegroundActivity()) {
        return true;
    }
    // If in appliance mode, do not show dialog in foreground.
    if ((context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_TYPE_APPLIANCE) == Configuration.UI_MODE_TYPE_APPLIANCE) {
        if (DEBUG)
            Log.v(TAG, "in appliance mode - do not show dialog.");
        return false;
    }
    long currentTimeMillis = System.currentTimeMillis();
    SharedPreferences sharedPreferences = getSharedPreferences(context);
    // If the device was in discoverABLE mode recently
    long lastDiscoverableEndTime = sharedPreferences.getLong(KEY_DISCOVERABLE_END_TIMESTAMP, 0);
    if ((lastDiscoverableEndTime + GRACE_PERIOD_TO_SHOW_DIALOGS_IN_FOREGROUND) > currentTimeMillis) {
        return true;
    }
    // If the device was discoverING recently
    LocalBluetoothAdapter adapter = manager.getBluetoothAdapter();
    if (adapter != null) {
        if (adapter.isDiscovering()) {
            return true;
        }
        if ((adapter.getDiscoveryEndMillis() + GRACE_PERIOD_TO_SHOW_DIALOGS_IN_FOREGROUND) > currentTimeMillis) {
            return true;
        }
    }
    // If the device was picked in the device picker recently
    if (deviceAddress != null) {
        String lastSelectedDevice = sharedPreferences.getString(KEY_LAST_SELECTED_DEVICE, null);
        if (deviceAddress.equals(lastSelectedDevice)) {
            long lastDeviceSelectedTime = sharedPreferences.getLong(KEY_LAST_SELECTED_DEVICE_TIME, 0);
            if ((lastDeviceSelectedTime + GRACE_PERIOD_TO_SHOW_DIALOGS_IN_FOREGROUND) > currentTimeMillis) {
                return true;
            }
        }
    }
    if (!TextUtils.isEmpty(deviceName)) {
        // If the device is a custom BT keyboard specifically for this device
        String packagedKeyboardName = context.getString(com.android.internal.R.string.config_packagedKeyboardName);
        if (deviceName.equals(packagedKeyboardName)) {
            if (DEBUG)
                Log.v(TAG, "showing dialog for packaged keyboard");
            return true;
        }
    }
    if (DEBUG)
        Log.v(TAG, "Found no reason to show the dialog - do not show dialog.");
    return false;
}
Also used : SharedPreferences(android.content.SharedPreferences) LocalBluetoothManager(com.android.settingslib.bluetooth.LocalBluetoothManager) LocalBluetoothAdapter(com.android.settingslib.bluetooth.LocalBluetoothAdapter)

Example 57 with LocalBluetoothManager

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

the class LocalDeviceNameDialogFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    LocalBluetoothManager localManager = Utils.getLocalBtManager(getActivity());
    mLocalAdapter = localManager.getBluetoothAdapter();
}
Also used : LocalBluetoothManager(com.android.settingslib.bluetooth.LocalBluetoothManager)

Example 58 with LocalBluetoothManager

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

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(mDevice);
    }
    String intentName = BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY;
    if (mRequestType == BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS) {
        int phonebookPermission = mDevice.getPhonebookAccessPermission();
        if (phonebookPermission == BluetoothDevice.ACCESS_UNKNOWN) {
        // Leave 'processed' as false.
        } else if (phonebookPermission == BluetoothDevice.ACCESS_ALLOWED) {
            sendReplyIntentToReceiver(true);
            processed = true;
        } else if (phonebookPermission == BluetoothDevice.ACCESS_REJECTED) {
            sendReplyIntentToReceiver(false);
            processed = true;
        } else {
            Log.e(TAG, "Bad phonebookPermission: " + phonebookPermission);
        }
    } else if (mRequestType == BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS) {
        int messagePermission = mDevice.getMessageAccessPermission();
        if (messagePermission == BluetoothDevice.ACCESS_UNKNOWN) {
        // Leave 'processed' as false.
        } else if (messagePermission == BluetoothDevice.ACCESS_ALLOWED) {
            sendReplyIntentToReceiver(true);
            processed = true;
        } else if (messagePermission == BluetoothDevice.ACCESS_REJECTED) {
            sendReplyIntentToReceiver(false);
            processed = true;
        } else {
            Log.e(TAG, "Bad messagePermission: " + messagePermission);
        }
    } else if (mRequestType == BluetoothDevice.REQUEST_TYPE_SIM_ACCESS) {
        int simPermission = mDevice.getSimAccessPermission();
        if (simPermission == BluetoothDevice.ACCESS_UNKNOWN) {
        // Leave 'processed' as false.
        } else if (simPermission == BluetoothDevice.ACCESS_ALLOWED) {
            sendReplyIntentToReceiver(true);
            processed = true;
        } else if (simPermission == BluetoothDevice.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 59 with LocalBluetoothManager

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

the class LocalBluetoothPreferences method shouldShowDialogInForeground.

static boolean shouldShowDialogInForeground(Context context, String deviceAddress, String deviceName) {
    LocalBluetoothManager manager = Utils.getLocalBtManager(context);
    if (manager == null) {
        if (DEBUG)
            Log.v(TAG, "manager == null - do not show dialog.");
        return false;
    }
    // If Bluetooth Settings is visible
    if (manager.isForegroundActivity()) {
        return true;
    }
    // If in appliance mode, do not show dialog in foreground.
    if ((context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_TYPE_APPLIANCE) == Configuration.UI_MODE_TYPE_APPLIANCE) {
        if (DEBUG)
            Log.v(TAG, "in appliance mode - do not show dialog.");
        return false;
    }
    long currentTimeMillis = System.currentTimeMillis();
    SharedPreferences sharedPreferences = getSharedPreferences(context);
    // If the device was in discoverABLE mode recently
    long lastDiscoverableEndTime = sharedPreferences.getLong(KEY_DISCOVERABLE_END_TIMESTAMP, 0);
    if ((lastDiscoverableEndTime + GRACE_PERIOD_TO_SHOW_DIALOGS_IN_FOREGROUND) > currentTimeMillis) {
        return true;
    }
    // If the device was discoverING recently
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter != null) {
        if (adapter.isDiscovering()) {
            return true;
        }
        if ((adapter.getDiscoveryEndMillis() + GRACE_PERIOD_TO_SHOW_DIALOGS_IN_FOREGROUND) > currentTimeMillis) {
            return true;
        }
    }
    // If the device was picked in the device picker recently
    if (deviceAddress != null) {
        String lastSelectedDevice = sharedPreferences.getString(KEY_LAST_SELECTED_DEVICE, null);
        if (deviceAddress.equals(lastSelectedDevice)) {
            long lastDeviceSelectedTime = sharedPreferences.getLong(KEY_LAST_SELECTED_DEVICE_TIME, 0);
            if ((lastDeviceSelectedTime + GRACE_PERIOD_TO_SHOW_DIALOGS_IN_FOREGROUND) > currentTimeMillis) {
                return true;
            }
        }
    }
    if (!TextUtils.isEmpty(deviceName)) {
        // If the device is a custom BT keyboard specifically for this device
        String packagedKeyboardName = context.getString(com.android.internal.R.string.config_packagedKeyboardName);
        if (deviceName.equals(packagedKeyboardName)) {
            if (DEBUG)
                Log.v(TAG, "showing dialog for packaged keyboard");
            return true;
        }
    }
    if (DEBUG)
        Log.v(TAG, "Found no reason to show the dialog - do not show dialog.");
    return false;
}
Also used : SharedPreferences(android.content.SharedPreferences) LocalBluetoothManager(com.android.settingslib.bluetooth.LocalBluetoothManager) BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 60 with LocalBluetoothManager

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

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(androidx.annotation.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