Fixed settings crash fix when profile is connected, Bluetooth turned off/of and phone is rebooted
Change-Id: I8738569c24a3c6cc9166b38719c1e918d990242c
This commit is contained in:
@@ -24,6 +24,7 @@ import android.bluetooth.BluetoothProfile;
|
|||||||
import android.bluetooth.BluetoothUuid;
|
import android.bluetooth.BluetoothUuid;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.ParcelUuid;
|
import android.os.ParcelUuid;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
@@ -34,7 +35,11 @@ import java.util.List;
|
|||||||
* TODO: add null checks around calls to mService object.
|
* TODO: add null checks around calls to mService object.
|
||||||
*/
|
*/
|
||||||
final class A2dpProfile implements LocalBluetoothProfile {
|
final class A2dpProfile implements LocalBluetoothProfile {
|
||||||
|
private static final String TAG = "A2dpProfile";
|
||||||
|
private static boolean V = true;
|
||||||
|
|
||||||
private BluetoothA2dp mService;
|
private BluetoothA2dp mService;
|
||||||
|
private boolean mIsProfileReady;
|
||||||
|
|
||||||
static final ParcelUuid[] SINK_UUIDS = {
|
static final ParcelUuid[] SINK_UUIDS = {
|
||||||
BluetoothUuid.AudioSink,
|
BluetoothUuid.AudioSink,
|
||||||
@@ -52,16 +57,22 @@ final class A2dpProfile implements LocalBluetoothProfile {
|
|||||||
implements BluetoothProfile.ServiceListener {
|
implements BluetoothProfile.ServiceListener {
|
||||||
|
|
||||||
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
||||||
|
if (V) Log.d(TAG,"Bluetooth service disconnected");
|
||||||
mService = (BluetoothA2dp) proxy;
|
mService = (BluetoothA2dp) proxy;
|
||||||
mProfileManager.setA2dpServiceUp(true);
|
mProfileManager.setA2dpServiceUp(true);
|
||||||
|
mIsProfileReady=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onServiceDisconnected(int profile) {
|
public void onServiceDisconnected(int profile) {
|
||||||
mService = null;
|
if (V) Log.d(TAG,"Bluetooth service disconnected");
|
||||||
mProfileManager.setA2dpServiceUp(false);
|
mProfileManager.setA2dpServiceUp(false);
|
||||||
|
mIsProfileReady=false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isProfileReady() {
|
||||||
|
return mIsProfileReady;
|
||||||
|
}
|
||||||
A2dpProfile(Context context, LocalBluetoothProfileManager profileManager) {
|
A2dpProfile(Context context, LocalBluetoothProfileManager profileManager) {
|
||||||
|
|
||||||
mProfileManager = profileManager;
|
mProfileManager = profileManager;
|
||||||
@@ -144,10 +155,6 @@ final class A2dpProfile implements LocalBluetoothProfile {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isProfileReady() {
|
|
||||||
return mService != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
@@ -177,4 +184,16 @@ final class A2dpProfile implements LocalBluetoothProfile {
|
|||||||
public int getDrawableResource(BluetoothClass btClass) {
|
public int getDrawableResource(BluetoothClass btClass) {
|
||||||
return R.drawable.ic_bt_headphones_a2dp;
|
return R.drawable.ic_bt_headphones_a2dp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void finalize() {
|
||||||
|
if (V) Log.d(TAG, "finalize()");
|
||||||
|
if (mService != null) {
|
||||||
|
try {
|
||||||
|
BluetoothAdapter.getDefaultAdapter().closeProfileProxy(BluetoothProfile.A2DP, mService);
|
||||||
|
mService = null;
|
||||||
|
}catch (Throwable t) {
|
||||||
|
Log.w(TAG, "Error cleaning up A2DP proxy", t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.bluetooth;
|
package com.android.settings.bluetooth;
|
||||||
|
|
||||||
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothClass;
|
import android.bluetooth.BluetoothClass;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.bluetooth.BluetoothHeadset;
|
import android.bluetooth.BluetoothHeadset;
|
||||||
@@ -34,9 +35,10 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
final class HeadsetProfile implements LocalBluetoothProfile {
|
final class HeadsetProfile implements LocalBluetoothProfile {
|
||||||
private static final String TAG = "HeadsetProfile";
|
private static final String TAG = "HeadsetProfile";
|
||||||
|
private static boolean V = true;
|
||||||
|
|
||||||
private BluetoothHeadset mService;
|
private BluetoothHeadset mService;
|
||||||
private boolean mProfileReady;
|
private boolean mIsProfileReady;
|
||||||
|
|
||||||
private final LocalBluetoothAdapter mLocalAdapter;
|
private final LocalBluetoothAdapter mLocalAdapter;
|
||||||
private final CachedBluetoothDeviceManager mDeviceManager;
|
private final CachedBluetoothDeviceManager mDeviceManager;
|
||||||
@@ -57,8 +59,8 @@ final class HeadsetProfile implements LocalBluetoothProfile {
|
|||||||
implements BluetoothProfile.ServiceListener {
|
implements BluetoothProfile.ServiceListener {
|
||||||
|
|
||||||
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
||||||
|
if (V) Log.d(TAG,"Bluetooth service connected");
|
||||||
mService = (BluetoothHeadset) proxy;
|
mService = (BluetoothHeadset) proxy;
|
||||||
mProfileReady = true;
|
|
||||||
// We just bound to the service, so refresh the UI of the
|
// We just bound to the service, so refresh the UI of the
|
||||||
// headset device.
|
// headset device.
|
||||||
List<BluetoothDevice> deviceList = mService.getConnectedDevices();
|
List<BluetoothDevice> deviceList = mService.getConnectedDevices();
|
||||||
@@ -78,16 +80,21 @@ final class HeadsetProfile implements LocalBluetoothProfile {
|
|||||||
|
|
||||||
mProfileManager.callServiceConnectedListeners();
|
mProfileManager.callServiceConnectedListeners();
|
||||||
mProfileManager.setHfServiceUp(true);
|
mProfileManager.setHfServiceUp(true);
|
||||||
|
mIsProfileReady=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onServiceDisconnected(int profile) {
|
public void onServiceDisconnected(int profile) {
|
||||||
mProfileReady = false;
|
if (V) Log.d(TAG,"Bluetooth service disconnected");
|
||||||
mService = null;
|
|
||||||
mProfileManager.callServiceDisconnectedListeners();
|
mProfileManager.callServiceDisconnectedListeners();
|
||||||
mProfileManager.setHfServiceUp(false);
|
mProfileManager.setHfServiceUp(false);
|
||||||
|
mIsProfileReady=false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isProfileReady() {
|
||||||
|
return mIsProfileReady;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(): The calls must get queued if mService becomes null.
|
// TODO(): The calls must get queued if mService becomes null.
|
||||||
// It can happen when the phone app crashes for some reason.
|
// It can happen when the phone app crashes for some reason.
|
||||||
// All callers should have service listeners. Dock Service is the only
|
// All callers should have service listeners. Dock Service is the only
|
||||||
@@ -174,10 +181,6 @@ final class HeadsetProfile implements LocalBluetoothProfile {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean isProfileReady() {
|
|
||||||
return mProfileReady;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
@@ -207,4 +210,16 @@ final class HeadsetProfile implements LocalBluetoothProfile {
|
|||||||
public int getDrawableResource(BluetoothClass btClass) {
|
public int getDrawableResource(BluetoothClass btClass) {
|
||||||
return R.drawable.ic_bt_headset_hfp;
|
return R.drawable.ic_bt_headset_hfp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void finalize() {
|
||||||
|
if (V) Log.d(TAG, "finalize()");
|
||||||
|
if (mService != null) {
|
||||||
|
try {
|
||||||
|
BluetoothAdapter.getDefaultAdapter().closeProfileProxy(BluetoothProfile.HEADSET, mService);
|
||||||
|
mService = null;
|
||||||
|
}catch (Throwable t) {
|
||||||
|
Log.w(TAG, "Error cleaning up HID proxy", t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,11 +16,13 @@
|
|||||||
|
|
||||||
package com.android.settings.bluetooth;
|
package com.android.settings.bluetooth;
|
||||||
|
|
||||||
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothClass;
|
import android.bluetooth.BluetoothClass;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.bluetooth.BluetoothInputDevice;
|
import android.bluetooth.BluetoothInputDevice;
|
||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
@@ -30,8 +32,11 @@ import java.util.List;
|
|||||||
* HidProfile handles Bluetooth HID profile.
|
* HidProfile handles Bluetooth HID profile.
|
||||||
*/
|
*/
|
||||||
final class HidProfile implements LocalBluetoothProfile {
|
final class HidProfile implements LocalBluetoothProfile {
|
||||||
|
private static final String TAG = "HidProfile";
|
||||||
|
private static boolean V = true;
|
||||||
|
|
||||||
private BluetoothInputDevice mService;
|
private BluetoothInputDevice mService;
|
||||||
private boolean mProfileReady;
|
private boolean mIsProfileReady;
|
||||||
|
|
||||||
static final String NAME = "HID";
|
static final String NAME = "HID";
|
||||||
|
|
||||||
@@ -43,16 +48,21 @@ final class HidProfile implements LocalBluetoothProfile {
|
|||||||
implements BluetoothProfile.ServiceListener {
|
implements BluetoothProfile.ServiceListener {
|
||||||
|
|
||||||
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
||||||
|
if (V) Log.d(TAG,"Bluetooth service connected");
|
||||||
mService = (BluetoothInputDevice) proxy;
|
mService = (BluetoothInputDevice) proxy;
|
||||||
mProfileReady = true;
|
mIsProfileReady=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onServiceDisconnected(int profile) {
|
public void onServiceDisconnected(int profile) {
|
||||||
mProfileReady = false;
|
if (V) Log.d(TAG,"Bluetooth service disconnected");
|
||||||
mService = null;
|
mIsProfileReady=false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isProfileReady() {
|
||||||
|
return mIsProfileReady;
|
||||||
|
}
|
||||||
|
|
||||||
HidProfile(Context context, LocalBluetoothAdapter adapter) {
|
HidProfile(Context context, LocalBluetoothAdapter adapter) {
|
||||||
adapter.getProfileProxy(context, new InputDeviceServiceListener(),
|
adapter.getProfileProxy(context, new InputDeviceServiceListener(),
|
||||||
BluetoothProfile.INPUT_DEVICE);
|
BluetoothProfile.INPUT_DEVICE);
|
||||||
@@ -100,10 +110,6 @@ final class HidProfile implements LocalBluetoothProfile {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isProfileReady() {
|
|
||||||
return mProfileReady;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
@@ -149,4 +155,16 @@ final class HidProfile implements LocalBluetoothProfile {
|
|||||||
return R.drawable.ic_bt_misc_hid;
|
return R.drawable.ic_bt_misc_hid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void finalize() {
|
||||||
|
if (V) Log.d(TAG, "finalize()");
|
||||||
|
if (mService != null) {
|
||||||
|
try {
|
||||||
|
BluetoothAdapter.getDefaultAdapter().closeProfileProxy(BluetoothProfile.INPUT_DEVICE, mService);
|
||||||
|
mService = null;
|
||||||
|
}catch (Throwable t) {
|
||||||
|
Log.w(TAG, "Error cleaning up HID proxy", t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -22,6 +22,7 @@ import android.bluetooth.BluetoothDevice;
|
|||||||
import android.bluetooth.BluetoothPan;
|
import android.bluetooth.BluetoothPan;
|
||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
@@ -32,7 +33,12 @@ import java.util.List;
|
|||||||
* PanProfile handles Bluetooth PAN profile (NAP and PANU).
|
* PanProfile handles Bluetooth PAN profile (NAP and PANU).
|
||||||
*/
|
*/
|
||||||
final class PanProfile implements LocalBluetoothProfile {
|
final class PanProfile implements LocalBluetoothProfile {
|
||||||
|
private static final String TAG = "PanProfile";
|
||||||
|
private static boolean V = true;
|
||||||
|
|
||||||
private BluetoothPan mService;
|
private BluetoothPan mService;
|
||||||
|
private boolean mIsProfileReady;
|
||||||
|
|
||||||
// Tethering direction for each device
|
// Tethering direction for each device
|
||||||
private final HashMap<BluetoothDevice, Integer> mDeviceRoleMap =
|
private final HashMap<BluetoothDevice, Integer> mDeviceRoleMap =
|
||||||
new HashMap<BluetoothDevice, Integer>();
|
new HashMap<BluetoothDevice, Integer>();
|
||||||
@@ -47,14 +53,21 @@ final class PanProfile implements LocalBluetoothProfile {
|
|||||||
implements BluetoothProfile.ServiceListener {
|
implements BluetoothProfile.ServiceListener {
|
||||||
|
|
||||||
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
||||||
|
if (V) Log.d(TAG,"Bluetooth service connected");
|
||||||
mService = (BluetoothPan) proxy;
|
mService = (BluetoothPan) proxy;
|
||||||
|
mIsProfileReady=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onServiceDisconnected(int profile) {
|
public void onServiceDisconnected(int profile) {
|
||||||
|
if (V) Log.d(TAG,"Bluetooth service disconnected");
|
||||||
|
mIsProfileReady=false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isProfileReady() {
|
||||||
|
return mIsProfileReady;
|
||||||
|
}
|
||||||
|
|
||||||
PanProfile(Context context) {
|
PanProfile(Context context) {
|
||||||
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
adapter.getProfileProxy(context, new PanServiceListener(),
|
adapter.getProfileProxy(context, new PanServiceListener(),
|
||||||
@@ -99,10 +112,6 @@ final class PanProfile implements LocalBluetoothProfile {
|
|||||||
// ignore: isPreferred is always true for PAN
|
// ignore: isPreferred is always true for PAN
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isProfileReady() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
@@ -153,4 +162,16 @@ final class PanProfile implements LocalBluetoothProfile {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void finalize() {
|
||||||
|
if (V) Log.d(TAG, "finalize()");
|
||||||
|
if (mService != null) {
|
||||||
|
try {
|
||||||
|
BluetoothAdapter.getDefaultAdapter().closeProfileProxy(BluetoothProfile.PAN, mService);
|
||||||
|
mService = null;
|
||||||
|
}catch (Throwable t) {
|
||||||
|
Log.w(TAG, "Error cleaning up PAN proxy", t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user