use of com.android.settingslib.bluetooth.LocalBluetoothManager in project android_packages_apps_Settings by crdroidandroid.
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;
}
use of com.android.settingslib.bluetooth.LocalBluetoothManager in project android_packages_apps_Settings by crdroidandroid.
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;
}
use of com.android.settingslib.bluetooth.LocalBluetoothManager in project platform_packages_apps_Settings by BlissRoms.
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);
}
use of com.android.settingslib.bluetooth.LocalBluetoothManager in project platform_packages_apps_Settings by BlissRoms.
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);
}
use of com.android.settingslib.bluetooth.LocalBluetoothManager in project platform_packages_apps_Settings by BlissRoms.
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;
}
Aggregations