Show Bluetooth dialog in a specific case
If the application that initiate the bonding with BluetoothDevice#createBond is in foreground, then should dialog only instead of showing the notification & dialog Bug: 175931562 Tag: #refactor Test: manual Change-Id: I3673a0b58cbf9caabf62c951b84b49e17cfb13b8
This commit is contained in:
@@ -16,7 +16,10 @@
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.app.ActivityManager;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
@@ -57,8 +60,9 @@ final class LocalBluetoothPreferences {
|
||||
KEY_DISCOVERABLE_END_TIMESTAMP, 0);
|
||||
}
|
||||
|
||||
static boolean shouldShowDialogInForeground(Context context,
|
||||
String deviceAddress, String deviceName) {
|
||||
static boolean shouldShowDialogInForeground(Context context, @Nullable BluetoothDevice device) {
|
||||
String deviceAddress = device != null ? device.getAddress() : null;
|
||||
String deviceName = device != null ? device.getName() : null;
|
||||
LocalBluetoothManager manager = Utils.getLocalBtManager(context);
|
||||
if (manager == null) {
|
||||
if (DEBUG) Log.v(TAG, "manager == null - do not show dialog.");
|
||||
@@ -126,6 +130,20 @@ final class LocalBluetoothPreferences {
|
||||
}
|
||||
}
|
||||
|
||||
if (device != null) {
|
||||
ActivityManager activityManager = context.getSystemService(ActivityManager.class);
|
||||
String packageName = device.getCreateBondCaller();
|
||||
|
||||
if (packageName != null && activityManager.getPackageImportance(packageName)
|
||||
== ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
|
||||
if (DEBUG) {
|
||||
Log.v(TAG, "showing dialog because the initiating application "
|
||||
+ "is in foreground");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (DEBUG) Log.v(TAG, "Found no reason to show the dialog - do not show dialog.");
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user