diff --git a/Tethering/src/com/android/networkstack/tethering/TetheringDependencies.java b/Tethering/src/com/android/networkstack/tethering/TetheringDependencies.java index 9dfd225deb..3f860566d3 100644 --- a/Tethering/src/com/android/networkstack/tethering/TetheringDependencies.java +++ b/Tethering/src/com/android/networkstack/tethering/TetheringDependencies.java @@ -156,6 +156,7 @@ public abstract class TetheringDependencies { /** * Get a reference to BluetoothAdapter to be used by tethering. */ + @Nullable public abstract BluetoothAdapter getBluetoothAdapter(); /** diff --git a/Tethering/src/com/android/networkstack/tethering/TetheringService.java b/Tethering/src/com/android/networkstack/tethering/TetheringService.java index aa73819cc3..623f5023d1 100644 --- a/Tethering/src/com/android/networkstack/tethering/TetheringService.java +++ b/Tethering/src/com/android/networkstack/tethering/TetheringService.java @@ -30,6 +30,7 @@ import static android.net.dhcp.IDhcpServer.STATUS_UNKNOWN_ERROR; import android.app.Service; import android.bluetooth.BluetoothAdapter; +import android.bluetooth.BluetoothManager; import android.content.Context; import android.content.Intent; import android.net.IIntResultListener; @@ -377,7 +378,11 @@ public class TetheringService extends Service { @Override public BluetoothAdapter getBluetoothAdapter() { - return BluetoothAdapter.getDefaultAdapter(); + final BluetoothManager btManager = getSystemService(BluetoothManager.class); + if (btManager == null) { + return null; + } + return btManager.getAdapter(); } }; }