Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f242b7b9 authored by Nick Pelly's avatar Nick Pelly
Browse files

Introduce BluetoothAdapter.getDefaultAdapter().

This is the main entry point to the Bluetooth APIs, and returns the default
local Bluetooth adapter.

It replaces context.getSystemService(Context.BLUETOOTH_SERVICE). This was
never in a public SDK release.

DrNo: eastham
Bug: 2158765
Joke: Why can't you play cards in the jungle? Because there's too many cheetas!
Change-Id: Ieed8be009ee5aba621cb69090ee8c8a9c19c840d
parent 16fb88a6
Loading
Loading
Loading
Loading
+11 −11
Original line number Diff line number Diff line
@@ -25550,6 +25550,17 @@
 visibility="public"
>
</method>
<method name="getDefaultAdapter"
 return="android.bluetooth.BluetoothAdapter"
 abstract="false"
 native="false"
 synchronized="true"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getName"
 return="java.lang.String"
 abstract="false"
@@ -31505,17 +31516,6 @@
 visibility="public"
>
</field>
<field name="BLUETOOTH_SERVICE"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;bluetooth&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="CLIPBOARD_SERVICE"
 type="java.lang.String"
 transient="false"
+0 −18
Original line number Diff line number Diff line
@@ -22,8 +22,6 @@ import com.google.android.collect.Maps;

import org.xmlpull.v1.XmlPullParserException;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.IBluetooth;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
@@ -182,8 +180,6 @@ class ApplicationContext extends Context {
    private StatusBarManager mStatusBarManager = null;
    private TelephonyManager mTelephonyManager = null;
    private ClipboardManager mClipboardManager = null;
    private boolean mIsBluetoothAdapterCached = false;
    private BluetoothAdapter mBluetoothAdapter;
    private boolean mRestricted;
    private AccountManager mAccountManager; // protected by mSync

@@ -883,8 +879,6 @@ class ApplicationContext extends Context {
            return getSearchManager();
        } else if (SENSOR_SERVICE.equals(name)) {
            return getSensorManager();
        } else if (BLUETOOTH_SERVICE.equals(name)) {
            return getBluetoothAdapter();
        } else if (VIBRATOR_SERVICE.equals(name)) {
            return getVibrator();
        } else if (STATUS_BAR_SERVICE.equals(name)) {
@@ -1034,18 +1028,6 @@ class ApplicationContext extends Context {
        return mSearchManager;
    }

    private synchronized BluetoothAdapter getBluetoothAdapter() {
        if (!mIsBluetoothAdapterCached) {
            mIsBluetoothAdapterCached = true;
            IBinder b = ServiceManager.getService(BLUETOOTH_SERVICE);
            if (b != null) {
                IBluetooth service = IBluetooth.Stub.asInterface(b);
                mBluetoothAdapter = new BluetoothAdapter(service);
            }
        }
        return mBluetoothAdapter;
    }

    private SensorManager getSensorManager() {
        synchronized (mSync) {
            if (mSensorManager == null) {
+33 −5
Original line number Diff line number Diff line
@@ -20,9 +20,11 @@ import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.ParcelUuid;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;

import java.io.IOException;
@@ -36,10 +38,8 @@ import java.util.UUID;
/**
 * Represents the local Bluetooth adapter.
 *
 * <p>Use {@link android.content.Context#getSystemService} with {@link
 * android.content.Context#BLUETOOTH_SERVICE} to get the default local
 * Bluetooth adapter. On most Android devices there is only one local
 * Bluetotoh adapter.
 * <p>Use {@link #getDefaultAdapter} to get the default local Bluetooth
 * adapter.
 *
 * <p>Use the {@link BluetoothDevice} class for operations on remote Bluetooth
 * devices.
@@ -257,12 +257,40 @@ public final class BluetoothAdapter {
     */
    public static final String EXTRA_LOCAL_NAME = "android.bluetooth.adapter.extra.LOCAL_NAME";

    /** @hide */
    public static final String BLUETOOTH_SERVICE = "bluetooth";

    private static final int ADDRESS_LENGTH = 17;

    /**
     * Lazyily initialized singleton. Guaranteed final after first object
     * constructed.
     */
    private static BluetoothAdapter sAdapter;

    private final IBluetooth mService;

    /**
     * Do not use this constructor. Use Context.getSystemService() instead.
     * Get a handle to the default local Bluetooth adapter.
     * <p>Currently Android only supports one Bluetooth adapter, but the API
     * could be extended to support more. This will always return the default
     * adapter.
     * @return the default local adapter, or null if Bluetooth is not supported
     *         on this hardware platform
     */
    public static synchronized BluetoothAdapter getDefaultAdapter() {
        if (sAdapter == null) {
            IBinder b = ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE);
            if (b != null) {
                IBluetooth service = IBluetooth.Stub.asInterface(b);
                sAdapter = new BluetoothAdapter(service);
            }
        }
        return sAdapter;
    }

    /**
     * Use {@link #getDefaultAdapter} to get the BluetoothAdapter instance.
     * @hide
     */
    public BluetoothAdapter(IBluetooth service) {
+1 −2
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package android.bluetooth;

import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.content.Context;
import android.os.IBinder;
import android.os.Parcel;
import android.os.Parcelable;
@@ -328,7 +327,7 @@ public final class BluetoothDevice implements Parcelable {
    /*package*/ static IBluetooth getService() {
        synchronized (BluetoothDevice.class) {
            if (sService == null) {
                IBinder b = ServiceManager.getService(Context.BLUETOOTH_SERVICE);
                IBinder b = ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE);
                if (b == null) {
                    throw new RuntimeException("Bluetooth service not available");
                }
+0 −8
Original line number Diff line number Diff line
@@ -1217,14 +1217,6 @@ public abstract class Context {
     * @see android.hardware.SensorManager
     */
    public static final String SENSOR_SERVICE = "sensor";
    /**
     * Use with {@link #getSystemService} to retrieve a {@link
     * android.bluetooth.BluetoothAdapter} for using Bluetooth.
     *
     * @see #getSystemService
     * @see android.bluetooth.BluetoothAdapter
     */
    public static final String BLUETOOTH_SERVICE = "bluetooth";
    /**
     * Use with {@link #getSystemService} to retrieve a
     * com.android.server.WallpaperService for accessing wallpapers.
Loading