Fixed settings crash fix when profile is connected, Bluetooth turned off/of and phone is rebooted

Change-Id: I8738569c24a3c6cc9166b38719c1e918d990242c
This commit is contained in:
fredc
2012-05-08 17:56:24 -07:00
committed by Matthew Xie
parent 2ac143fff7
commit 654a3ab77d
4 changed files with 99 additions and 26 deletions

View File

@@ -22,6 +22,7 @@ import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothPan;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.util.Log;
import com.android.settings.R;
@@ -32,7 +33,12 @@ import java.util.List;
* PanProfile handles Bluetooth PAN profile (NAP and PANU).
*/
final class PanProfile implements LocalBluetoothProfile {
private static final String TAG = "PanProfile";
private static boolean V = true;
private BluetoothPan mService;
private boolean mIsProfileReady;
// Tethering direction for each device
private final HashMap<BluetoothDevice, Integer> mDeviceRoleMap =
new HashMap<BluetoothDevice, Integer>();
@@ -47,14 +53,21 @@ final class PanProfile implements LocalBluetoothProfile {
implements BluetoothProfile.ServiceListener {
public void onServiceConnected(int profile, BluetoothProfile proxy) {
if (V) Log.d(TAG,"Bluetooth service connected");
mService = (BluetoothPan) proxy;
mIsProfileReady=true;
}
public void onServiceDisconnected(int profile) {
if (V) Log.d(TAG,"Bluetooth service disconnected");
mIsProfileReady=false;
}
}
public boolean isProfileReady() {
return mIsProfileReady;
}
PanProfile(Context context) {
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
adapter.getProfileProxy(context, new PanServiceListener(),
@@ -99,10 +112,6 @@ final class PanProfile implements LocalBluetoothProfile {
// ignore: isPreferred is always true for PAN
}
public boolean isProfileReady() {
return true;
}
public String toString() {
return NAME;
}
@@ -153,4 +162,16 @@ final class PanProfile implements LocalBluetoothProfile {
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);
}
}
}
}