Merge change 24202 into eclair

* changes:
  API_CHANGE
This commit is contained in:
Android (Google) Code Review
2009-09-09 14:30:15 -04:00
10 changed files with 509 additions and 140 deletions

View File

@@ -25457,6 +25457,50 @@
deprecated="not deprecated"
visibility="public"
>
<method name="disable"
return="boolean"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="enable"
return="boolean"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="getAddress"
return="java.lang.String"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="getName"
return="java.lang.String"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="getRemoteDevice"
return="android.bluetooth.BluetoothDevice"
abstract="false"
@@ -25470,6 +25514,39 @@
<parameter name="address" type="java.lang.String">
</parameter>
</method>
<method name="getScanMode"
return="int"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="getState"
return="int"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="isEnabled"
return="boolean"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="listenUsingRfcommOn"
return="android.bluetooth.BluetoothServerSocket"
abstract="false"
@@ -25485,6 +25562,175 @@
<exception name="IOException" type="java.io.IOException">
</exception>
</method>
<method name="setName"
return="boolean"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="name" type="java.lang.String">
</parameter>
</method>
<method name="setScanMode"
return="boolean"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="mode" type="int">
</parameter>
</method>
<field name="ACTION_SCAN_MODE_CHANGED"
type="java.lang.String"
transient="false"
volatile="false"
value="&quot;android.bluetooth.intent.action.SCAN_MODE_CHANGED&quot;"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="ACTION_STATE_CHANGED"
type="java.lang.String"
transient="false"
volatile="false"
value="&quot;android.bluetooth.intent.action.STATE_CHANGED&quot;"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="EXTRA_PREVIOUS_SCAN_MODE"
type="java.lang.String"
transient="false"
volatile="false"
value="&quot;android.bluetooth.intent.extra.PREVIOUS_SCAN_MODE&quot;"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="EXTRA_PREVIOUS_STATE"
type="java.lang.String"
transient="false"
volatile="false"
value="&quot;android.bluetooth.intent.extra.PREVIOUS_STATE&quot;"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="EXTRA_SCAN_MODE"
type="java.lang.String"
transient="false"
volatile="false"
value="&quot;android.bluetooth.intent.extra.SCAN_MODE&quot;"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="EXTRA_STATE"
type="java.lang.String"
transient="false"
volatile="false"
value="&quot;android.bluetooth.intent.extra.STATE&quot;"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="SCAN_MODE_CONNECTABLE"
type="int"
transient="false"
volatile="false"
value="51"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="SCAN_MODE_CONNECTABLE_DISCOVERABLE"
type="int"
transient="false"
volatile="false"
value="53"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="SCAN_MODE_NONE"
type="int"
transient="false"
volatile="false"
value="50"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="STATE_OFF"
type="int"
transient="false"
volatile="false"
value="40"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="STATE_ON"
type="int"
transient="false"
volatile="false"
value="42"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="STATE_TURNING_OFF"
type="int"
transient="false"
volatile="false"
value="43"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="STATE_TURNING_ON"
type="int"
transient="false"
volatile="false"
value="41"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
</class>
<class name="BluetoothDevice"
extends="java.lang.Object"
@@ -25533,6 +25779,17 @@
visibility="public"
>
</method>
<method name="getName"
return="java.lang.String"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="writeToParcel"
return="void"
abstract="false"

View File

@@ -16,6 +16,8 @@
package android.bluetooth;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.os.RemoteException;
import android.util.Log;
@@ -40,32 +42,109 @@ import java.util.HashSet;
public final class BluetoothAdapter {
private static final String TAG = "BluetoothAdapter";
/** @hide */
public static final int BLUETOOTH_STATE_OFF = 0;
/** @hide */
public static final int BLUETOOTH_STATE_TURNING_ON = 1;
/** @hide */
public static final int BLUETOOTH_STATE_ON = 2;
/** @hide */
public static final int BLUETOOTH_STATE_TURNING_OFF = 3;
/**
* Broadcast Action: The state of the local Bluetooth adapter has been
* changed.
* <p>For example, Bluetooth has been turned on or off.
* <p>Contains the extra fields {@link #EXTRA_STATE} and {@link
* #EXTRA_PREVIOUS_STATE} containing the new and old states
* respectively.
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} to receive.
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_STATE_CHANGED =
"android.bluetooth.intent.action.STATE_CHANGED";
/** Inquiry scan and page scan are both off.
* Device is neither discoverable nor connectable
* @hide */
public static final int SCAN_MODE_NONE = 0;
/** Page scan is on, inquiry scan is off.
* Device is connectable, but not discoverable
* @hide*/
public static final int SCAN_MODE_CONNECTABLE = 1;
/** Page scan and inquiry scan are on.
* Device is connectable and discoverable
* @hide*/
public static final int SCAN_MODE_CONNECTABLE_DISCOVERABLE = 3;
/**
* Used as an int extra field in {@link #ACTION_STATE_CHANGED}
* intents to request the current power state. Possible values are:
* {@link #STATE_OFF},
* {@link #STATE_TURNING_ON},
* {@link #STATE_ON},
* {@link #STATE_TURNING_OFF},
*/
public static final String EXTRA_STATE =
"android.bluetooth.intent.extra.STATE";
/**
* Used as an int extra field in {@link #ACTION_STATE_CHANGED}
* intents to request the previous power state. Possible values are:
* {@link #STATE_OFF},
* {@link #STATE_TURNING_ON},
* {@link #STATE_ON},
* {@link #STATE_TURNING_OFF},
*/
public static final String EXTRA_PREVIOUS_STATE =
"android.bluetooth.intent.extra.PREVIOUS_STATE";
/** @hide */
public static final int RESULT_FAILURE = -1;
/** @hide */
public static final int RESULT_SUCCESS = 0;
/**
* Indicates the local Bluetooth adapter is off.
*/
public static final int STATE_OFF = 40;
/**
* Indicates the local Bluetooth adapter is turning on. However local
* clients should wait for {@link #STATE_ON} before attempting to
* use the adapter.
*/
public static final int STATE_TURNING_ON = 41;
/**
* Indicates the local Bluetooth adapter is on, and ready for use.
*/
public static final int STATE_ON = 42;
/**
* Indicates the local Bluetooth adapter is turning off. Local clients
* should immediately attempt graceful disconnection of any remote links.
*/
public static final int STATE_TURNING_OFF = 43;
/**
* Broadcast Action: Indicates the Bluetooth scan mode of the local Adapter
* has changed.
* <p>Contains the extra fields {@link #EXTRA_SCAN_MODE} and {@link
* #EXTRA_PREVIOUS_SCAN_MODE} containing the new and old scan modes
* respectively.
* <p>Requires {@link android.Manifest.permission#BLUETOOTH}
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_SCAN_MODE_CHANGED =
"android.bluetooth.intent.action.SCAN_MODE_CHANGED";
/**
* Used as an int extra field in {@link #ACTION_SCAN_MODE_CHANGED}
* intents to request the current scan mode. Possible values are:
* {@link #SCAN_MODE_NONE},
* {@link #SCAN_MODE_CONNECTABLE},
* {@link #SCAN_MODE_CONNECTABLE_DISCOVERABLE},
*/
public static final String EXTRA_SCAN_MODE = "android.bluetooth.intent.extra.SCAN_MODE";
/**
* Used as an int extra field in {@link #ACTION_SCAN_MODE_CHANGED}
* intents to request the previous scan mode. Possible values are:
* {@link #SCAN_MODE_NONE},
* {@link #SCAN_MODE_CONNECTABLE},
* {@link #SCAN_MODE_CONNECTABLE_DISCOVERABLE},
*/
public static final String EXTRA_PREVIOUS_SCAN_MODE =
"android.bluetooth.intent.extra.PREVIOUS_SCAN_MODE";
/**
* Indicates that both inquiry scan and page scan are disabled on the local
* Bluetooth adapter. Therefore this device is neither discoverable
* nor connectable from remote Bluetooth devices.
*/
public static final int SCAN_MODE_NONE = 50;
/**
* Indicates that inquiry scan is disabled, but page scan is enabled on the
* local Bluetooth adapter. Therefore this device is not discoverable from
* remote Bluetooth devices, but is connectable from remote devices that
* have previously discovered this device.
*/
public static final int SCAN_MODE_CONNECTABLE = 51;
/**
* Indicates that both inquiry scan and page scan are enabled on the local
* Bluetooth adapter. Therefore this device is both discoverable and
* connectable from remote Bluetooth devices.
*/
public static final int SCAN_MODE_CONNECTABLE_DISCOVERABLE = 53;
/** The user will be prompted to enter a pin
* @hide */
@@ -97,6 +176,7 @@ public final class BluetoothAdapter {
* such as "00:11:22:33:AA:BB".
* <p>A {@link BluetoothDevice} will always be returned for a valid
* hardware address, even if this adapter has never seen that device.
*
* @param address valid Bluetooth MAC address
* @throws IllegalArgumentException if address is invalid
*/
@@ -105,10 +185,12 @@ public final class BluetoothAdapter {
}
/**
* Is Bluetooth currently turned on.
* Return true if Bluetooth is currently enabled and ready for use.
* <p>Equivalent to:
* <code>getBluetoothState() == STATE_ON</code>
* <p>Requires {@link android.Manifest.permission#BLUETOOTH}
*
* @return true if Bluetooth enabled, false otherwise.
* @hide
* @return true if the local adapter is turned on
*/
public boolean isEnabled() {
try {
@@ -118,28 +200,40 @@ public final class BluetoothAdapter {
}
/**
* Get the current state of Bluetooth.
* Get the current state of the local Bluetooth adapter.
* <p>Possible return values are
* {@link #STATE_OFF},
* {@link #STATE_TURNING_ON},
* {@link #STATE_ON},
* {@link #STATE_TURNING_OFF}.
* <p>Requires {@link android.Manifest.permission#BLUETOOTH}
*
* @return One of BLUETOOTH_STATE_ or BluetoothError.ERROR.
* @hide
* @return current state of Bluetooth adapter
*/
public int getBluetoothState() {
public int getState() {
try {
return mService.getBluetoothState();
} catch (RemoteException e) {Log.e(TAG, "", e);}
return BluetoothError.ERROR;
return STATE_OFF;
}
/**
* Enable the Bluetooth device.
* Turn on the underlying hardware.
* This is an asynchronous call,
* BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION can be used to check if
* and when the device is sucessfully enabled.
* @return false if we cannot enable the Bluetooth device. True does not
* imply the device was enabled, it only implies that so far there were no
* problems.
* @hide
* Turn on the local Bluetooth adapter.
* <p>This powers on the underlying Bluetooth hardware, and starts all
* Bluetooth system services.
* <p>This is an asynchronous call: it will return immediatley, and
* clients should listen for {@link #ACTION_STATE_CHANGED}
* to be notified of subsequent adapter state changes. If this call returns
* true, then the adapter state will immediately transition from {@link
* #STATE_OFF} to {@link #STATE_TURNING_ON}, and some time
* later transition to either {@link #STATE_OFF} or {@link
* #STATE_ON}. If this call returns false then there was an
* immediate problem that will prevent the adapter from being turned on -
* such as Airplane mode, or the adapter is already turned on.
* <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
*
* @return true to indicate adapter startup has begun, or false on
* immediate error
*/
public boolean enable() {
try {
@@ -149,11 +243,22 @@ public final class BluetoothAdapter {
}
/**
* Disable the Bluetooth device.
* This turns off the underlying hardware.
* Turn off the local Bluetooth adapter.
* <p>This gracefully shuts down all Bluetooth connections, stops Bluetooth
* system services, and powers down the underlying Bluetooth hardware.
* <p>This is an asynchronous call: it will return immediatley, and
* clients should listen for {@link #ACTION_STATE_CHANGED}
* to be notified of subsequent adapter state changes. If this call returns
* true, then the adapter state will immediately transition from {@link
* #STATE_ON} to {@link #STATE_TURNING_OFF}, and some time
* later transition to either {@link #STATE_OFF} or {@link
* #STATE_ON}. If this call returns false then there was an
* immediate problem that will prevent the adapter from being turned off -
* such as the adapter already being turned off.
* <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
*
* @return true if successful, false otherwise.
* @hide
* @return true to indicate adapter shutdown has begun, or false on
* immediate error
*/
public boolean disable() {
try {
@@ -162,7 +267,13 @@ public final class BluetoothAdapter {
return false;
}
/** @hide */
/**
* Returns the hardware address of the local Bluetooth adapter.
* <p>For example, "00:11:22:AA:BB:CC".
* <p>Requires {@link android.Manifest.permission#BLUETOOTH}
*
* @return Bluetooth hardware address as string
*/
public String getAddress() {
try {
return mService.getAddress();
@@ -171,13 +282,11 @@ public final class BluetoothAdapter {
}
/**
* Get the friendly Bluetooth name of this device.
* Get the friendly Bluetooth name of the local Bluetooth adapter.
* <p>This name is visible to remote Bluetooth devices.
* <p>Requires {@link android.Manifest.permission#BLUETOOTH}
*
* This name is visible to remote Bluetooth devices. Currently it is only
* possible to retrieve the Bluetooth name when Bluetooth is enabled.
*
* @return the Bluetooth name, or null if there was a problem.
* @hide
* @return the Bluetooth name, or null on error
*/
public String getName() {
try {
@@ -187,14 +296,15 @@ public final class BluetoothAdapter {
}
/**
* Set the friendly Bluetooth name of this device.
* Set the friendly Bluetooth name of the local Bluetoth adapter.
* <p>This name is visible to remote Bluetooth devices.
* <p>Valid Bluetooth names are a maximum of 248 UTF-8 characters, however
* many remote devices can only display the first 40 characters, and some
* may be limited to just 20.
* <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
*
* This name is visible to remote Bluetooth devices. The Bluetooth Service
* is responsible for persisting this name.
*
* @param name the name to set
* @return true, if the name was successfully set. False otherwise.
* @hide
* @param name a valid Bluetooth name
* @return true if the name was set, false otherwise
*/
public boolean setName(String name) {
try {
@@ -204,28 +314,46 @@ public final class BluetoothAdapter {
}
/**
* Get the current scan mode.
* Used to determine if the local device is connectable and/or discoverable
* @return Scan mode, one of SCAN_MODE_* or an error code
* @hide
* Get the current Bluetooth scan mode of the local Bluetooth adaper.
* <p>The Bluetooth scan mode determines if the local adapter is
* connectable and/or discoverable from remote Bluetooth devices.
* <p>Possible values are:
* {@link #SCAN_MODE_NONE},
* {@link #SCAN_MODE_CONNECTABLE},
* {@link #SCAN_MODE_CONNECTABLE_DISCOVERABLE}.
* <p>Requires {@link android.Manifest.permission#BLUETOOTH}
*
* @return scan mode
*/
public int getScanMode() {
try {
return mService.getScanMode();
} catch (RemoteException e) {Log.e(TAG, "", e);}
return BluetoothError.ERROR_IPC;
return SCAN_MODE_NONE;
}
/**
* Set the current scan mode.
* Used to make the local device connectable and/or discoverable
* @param scanMode One of SCAN_MODE_*
* @hide
* Set the Bluetooth scan mode of the local Bluetooth adapter.
* <p>The Bluetooth scan mode determines if the local adapter is
* connectable and/or discoverable from remote Bluetooth devices.
* <p>For privacy reasons, it is recommended to limit the duration of time
* that the local adapter remains in a discoverable scan mode. For example,
* 2 minutes is a generous time to allow a remote Bluetooth device to
* initiate and complete its discovery process.
* <p>Valid scan mode values are:
* {@link #SCAN_MODE_NONE},
* {@link #SCAN_MODE_CONNECTABLE},
* {@link #SCAN_MODE_CONNECTABLE_DISCOVERABLE}.
* <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
*
* @param mode valid scan mode
* @return true if the scan mode was set, false otherwise
*/
public void setScanMode(int scanMode) {
public boolean setScanMode(int mode) {
try {
mService.setScanMode(scanMode);
return mService.setScanMode(mode);
} catch (RemoteException e) {Log.e(TAG, "", e);}
return false;
}
/** @hide */

View File

@@ -193,9 +193,9 @@ public final class BluetoothDevice implements Parcelable {
* <p>The local adapter will automatically retrieve remote names when
* performing a device scan, and will cache them. This method just returns
* the name for this device from the cache.
* <p>Requires {@link android.Manifest.permission#BLUETOOTH}
*
* @return the Bluetooth name, or null if there was a problem.
* @hide
*/
public String getName() {
try {
@@ -358,6 +358,7 @@ public final class BluetoothDevice implements Parcelable {
* connection.
* <p>Valid RFCOMM channels are in range 1 to 30.
* <p>Requires {@link android.Manifest.permission#BLUETOOTH}
*
* @param channel RFCOMM channel to connect to
* @return a RFCOMM BluetoothServerSocket ready for an outgoing connection
* @throws IOException on error, for example Bluetooth not available, or

View File

@@ -21,6 +21,8 @@ package android.bluetooth;
*
* Errors are always negative.
*
* TODO: Deprecate this class.
*
* @hide
*/
public class BluetoothError {

View File

@@ -20,17 +20,12 @@ import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
/**
* The Android Bluetooth API is not finalized, and *will* change. Use at your
* own risk.
*
* Manages the local Bluetooth device. Scan for devices, create bondings,
* power up and down the adapter.
* Bluetooth API constants.
*
* TODO: Deprecate this class
* @hide
*/
public interface BluetoothIntent {
public static final String SCAN_MODE =
"android.bluetooth.intent.SCAN_MODE";
public static final String DEVICE =
"android.bluetooth.intent.DEVICE";
public static final String NAME =
@@ -41,10 +36,6 @@ public interface BluetoothIntent {
"android.bluetooth.intent.RSSI";
public static final String CLASS =
"android.bluetooth.intent.CLASS";
public static final String BLUETOOTH_STATE =
"android.bluetooth.intent.BLUETOOTH_STATE";
public static final String BLUETOOTH_PREVIOUS_STATE =
"android.bluetooth.intent.BLUETOOTH_PREVIOUS_STATE";
public static final String HEADSET_STATE =
"android.bluetooth.intent.HEADSET_STATE";
public static final String HEADSET_PREVIOUS_STATE =
@@ -91,25 +82,10 @@ public interface BluetoothIntent {
public static final String DEVICE_PICKER_DEVICE_PICKER =
"android.bluetooth.intent.action.DEVICE_PICKER";
/** Broadcast when the local Bluetooth device state changes, for example
* when Bluetooth is enabled. Will contain int extra's BLUETOOTH_STATE and
* BLUETOOTH_PREVIOUS_STATE. */
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String BLUETOOTH_STATE_CHANGED_ACTION =
"android.bluetooth.intent.action.BLUETOOTH_STATE_CHANGED";
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String NAME_CHANGED_ACTION =
"android.bluetooth.intent.action.NAME_CHANGED";
/**
* Broadcast when the scan mode changes. Always contains an int extra
* named SCAN_MODE that contains the new scan mode.
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String SCAN_MODE_CHANGED_ACTION =
"android.bluetooth.intent.action.SCAN_MODE_CHANGED";
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String DISCOVERY_STARTED_ACTION =
"android.bluetooth.intent.action.DISCOVERY_STARTED";

View File

@@ -81,14 +81,14 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
String action = intent.getAction();
BluetoothDevice device =
intent.getParcelableExtra(BluetoothIntent.DEVICE);
if (action.equals(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION)) {
int state = intent.getIntExtra(BluetoothIntent.BLUETOOTH_STATE,
if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
BluetoothError.ERROR);
switch (state) {
case BluetoothAdapter.BLUETOOTH_STATE_ON:
case BluetoothAdapter.STATE_ON:
onBluetoothEnable();
break;
case BluetoothAdapter.BLUETOOTH_STATE_TURNING_OFF:
case BluetoothAdapter.STATE_TURNING_OFF:
onBluetoothDisable();
break;
}
@@ -134,7 +134,7 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
mAdapter = (BluetoothAdapter) context.getSystemService(Context.BLUETOOTH_SERVICE);
mIntentFilter = new IntentFilter(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION);
mIntentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
mIntentFilter.addAction(BluetoothIntent.BOND_STATE_CHANGED_ACTION);
mIntentFilter.addAction(BluetoothIntent.REMOTE_DEVICE_CONNECTED_ACTION);
mContext.registerReceiver(mReceiver, mIntentFilter);

View File

@@ -265,8 +265,8 @@ class BluetoothEventLoop {
pairable.equals("true"),
discoverable.equals("true"));
if (mode >= 0) {
Intent intent = new Intent(BluetoothIntent.SCAN_MODE_CHANGED_ACTION);
intent.putExtra(BluetoothIntent.SCAN_MODE, mode);
Intent intent = new Intent(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
intent.putExtra(BluetoothAdapter.EXTRA_SCAN_MODE, mode);
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
mContext.sendBroadcast(intent, BLUETOOTH_PERM);
}
@@ -371,7 +371,7 @@ class BluetoothEventLoop {
address = address.toUpperCase();
mPasskeyAgentRequestData.put(address, new Integer(nativeData));
if (mBluetoothService.getBluetoothState() == BluetoothAdapter.BLUETOOTH_STATE_TURNING_OFF) {
if (mBluetoothService.getBluetoothState() == BluetoothAdapter.STATE_TURNING_OFF) {
// shutdown path
mBluetoothService.cancelPairingUserInput(address);
return null;

View File

@@ -102,7 +102,7 @@ public class BluetoothService extends IBluetooth.Stub {
disableNative();
}
mBluetoothState = BluetoothAdapter.BLUETOOTH_STATE_OFF;
mBluetoothState = BluetoothAdapter.STATE_OFF;
mIsDiscovering = false;
mAdapterProperties = new HashMap<String, String>();
mDeviceProperties = new HashMap<String, Map<String,String>>();
@@ -128,7 +128,7 @@ public class BluetoothService extends IBluetooth.Stub {
public boolean isEnabled() {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
return mBluetoothState == BluetoothAdapter.BLUETOOTH_STATE_ON;
return mBluetoothState == BluetoothAdapter.STATE_ON;
}
public int getBluetoothState() {
@@ -153,9 +153,9 @@ public class BluetoothService extends IBluetooth.Stub {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
switch (mBluetoothState) {
case BluetoothAdapter.BLUETOOTH_STATE_OFF:
case BluetoothAdapter.STATE_OFF:
return true;
case BluetoothAdapter.BLUETOOTH_STATE_ON:
case BluetoothAdapter.STATE_ON:
break;
default:
return false;
@@ -163,7 +163,7 @@ public class BluetoothService extends IBluetooth.Stub {
if (mEnableThread != null && mEnableThread.isAlive()) {
return false;
}
setBluetoothState(BluetoothAdapter.BLUETOOTH_STATE_TURNING_OFF);
setBluetoothState(BluetoothAdapter.STATE_TURNING_OFF);
// Allow 3 seconds for profiles to gracefully disconnect
// TODO: Introduce a callback mechanism so that each profile can notify
@@ -175,7 +175,7 @@ public class BluetoothService extends IBluetooth.Stub {
private synchronized void finishDisable(boolean saveSetting) {
if (mBluetoothState != BluetoothAdapter.BLUETOOTH_STATE_TURNING_OFF) {
if (mBluetoothState != BluetoothAdapter.STATE_TURNING_OFF) {
return;
}
mEventLoop.stop();
@@ -189,8 +189,8 @@ public class BluetoothService extends IBluetooth.Stub {
}
// update mode
Intent intent = new Intent(BluetoothIntent.SCAN_MODE_CHANGED_ACTION);
intent.putExtra(BluetoothIntent.SCAN_MODE, BluetoothAdapter.SCAN_MODE_NONE);
Intent intent = new Intent(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
intent.putExtra(BluetoothAdapter.EXTRA_SCAN_MODE, BluetoothAdapter.SCAN_MODE_NONE);
mContext.sendBroadcast(intent, BLUETOOTH_PERM);
mIsDiscovering = false;
@@ -200,7 +200,7 @@ public class BluetoothService extends IBluetooth.Stub {
persistBluetoothOnSetting(false);
}
setBluetoothState(BluetoothAdapter.BLUETOOTH_STATE_OFF);
setBluetoothState(BluetoothAdapter.STATE_OFF);
// Log bluetooth off to battery stats.
long ident = Binder.clearCallingIdentity();
@@ -237,13 +237,13 @@ public class BluetoothService extends IBluetooth.Stub {
if (mIsAirplaneSensitive && isAirplaneModeOn()) {
return false;
}
if (mBluetoothState != BluetoothAdapter.BLUETOOTH_STATE_OFF) {
if (mBluetoothState != BluetoothAdapter.STATE_OFF) {
return false;
}
if (mEnableThread != null && mEnableThread.isAlive()) {
return false;
}
setBluetoothState(BluetoothAdapter.BLUETOOTH_STATE_TURNING_ON);
setBluetoothState(BluetoothAdapter.STATE_TURNING_ON);
mEnableThread = new EnableThread(saveSetting);
mEnableThread.start();
return true;
@@ -251,7 +251,7 @@ public class BluetoothService extends IBluetooth.Stub {
/** Forcibly restart Bluetooth if it is on */
/* package */ synchronized void restart() {
if (mBluetoothState != BluetoothAdapter.BLUETOOTH_STATE_ON) {
if (mBluetoothState != BluetoothAdapter.STATE_ON) {
return;
}
mRestart = true;
@@ -267,9 +267,9 @@ public class BluetoothService extends IBluetooth.Stub {
if (DBG) log("Bluetooth state " + mBluetoothState + " -> " + state);
Intent intent = new Intent(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION);
intent.putExtra(BluetoothIntent.BLUETOOTH_PREVIOUS_STATE, mBluetoothState);
intent.putExtra(BluetoothIntent.BLUETOOTH_STATE, state);
Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
intent.putExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE, mBluetoothState);
intent.putExtra(BluetoothAdapter.EXTRA_STATE, state);
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
mBluetoothState = state;
@@ -357,8 +357,8 @@ public class BluetoothService extends IBluetooth.Stub {
mEnableThread = null;
setBluetoothState(res ?
BluetoothAdapter.BLUETOOTH_STATE_ON :
BluetoothAdapter.BLUETOOTH_STATE_OFF);
BluetoothAdapter.STATE_ON :
BluetoothAdapter.STATE_OFF);
if (res) {
// Update mode
@@ -411,7 +411,7 @@ public class BluetoothService extends IBluetooth.Stub {
));
public synchronized void loadBondState() {
if (mBluetoothState != BluetoothAdapter.BLUETOOTH_STATE_TURNING_ON) {
if (mBluetoothState != BluetoothAdapter.STATE_TURNING_ON) {
return;
}
String []bonds = null;
@@ -633,17 +633,22 @@ public class BluetoothService extends IBluetooth.Stub {
public synchronized boolean setScanMode(int mode) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH_ADMIN permission");
boolean pairable = false, discoverable = false;
String modeString = scanModeToBluezString(mode);
if (modeString.equals("off")) {
boolean pairable = false;
boolean discoverable = false;
switch (mode) {
case BluetoothAdapter.SCAN_MODE_NONE:
pairable = false;
discoverable = false;
} else if (modeString.equals("pariable")) {
break;
case BluetoothAdapter.SCAN_MODE_CONNECTABLE:
pairable = true;
discoverable = false;
} else if (modeString.equals("discoverable")) {
case BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE:
pairable = true;
discoverable = true;
default:
Log.w(TAG, "Requested invalid scan mode " + mode);
return false;
}
setPropertyBoolean("Pairable", pairable);
setPropertyBoolean("Discoverable", discoverable);
@@ -709,7 +714,7 @@ public class BluetoothService extends IBluetooth.Stub {
public synchronized int getScanMode() {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
if (!isEnabled())
return BluetoothError.ERROR;
return BluetoothAdapter.SCAN_MODE_NONE;
boolean pairable = getProperty("Pairable").equals("true");
boolean discoverable = getProperty("Discoverable").equals("true");
@@ -1103,16 +1108,16 @@ public class BluetoothService extends IBluetooth.Stub {
pw.println("\nmIsAirplaneSensitive = " + mIsAirplaneSensitive + "\n");
switch(mBluetoothState) {
case BluetoothAdapter.BLUETOOTH_STATE_OFF:
case BluetoothAdapter.STATE_OFF:
pw.println("\nBluetooth OFF\n");
return;
case BluetoothAdapter.BLUETOOTH_STATE_TURNING_ON:
case BluetoothAdapter.STATE_TURNING_ON:
pw.println("\nBluetooth TURNING ON\n");
return;
case BluetoothAdapter.BLUETOOTH_STATE_TURNING_OFF:
case BluetoothAdapter.STATE_TURNING_OFF:
pw.println("\nBluetooth TURNING OFF\n");
return;
case BluetoothAdapter.BLUETOOTH_STATE_ON:
case BluetoothAdapter.STATE_ON:
pw.println("\nBluetooth ON\n");
}

View File

@@ -185,7 +185,7 @@ public final class ShutdownThread extends Thread {
try {
bluetoothOff = bluetooth == null ||
bluetooth.getBluetoothState() == BluetoothAdapter.BLUETOOTH_STATE_OFF;
bluetooth.getBluetoothState() == BluetoothAdapter.STATE_OFF;
if (!bluetoothOff) {
Log.w(TAG, "Disabling Bluetooth...");
bluetooth.disable(false); // disable but don't persist new state
@@ -213,7 +213,7 @@ public final class ShutdownThread extends Thread {
if (!bluetoothOff) {
try {
bluetoothOff =
bluetooth.getBluetoothState() == BluetoothAdapter.BLUETOOTH_STATE_OFF;
bluetooth.getBluetoothState() == BluetoothAdapter.STATE_OFF;
} catch (RemoteException ex) {
Log.e(TAG, "RemoteException during bluetooth shutdown", ex);
bluetoothOff = true;

View File

@@ -362,7 +362,7 @@ public class StatusBarPolicy {
|| action.equals(Intent.ACTION_POWER_CONNECTED)) {
onBatteryOkay(intent);
}
else if (action.equals(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION) ||
else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED) ||
action.equals(BluetoothIntent.HEADSET_STATE_CHANGED_ACTION) ||
action.equals(BluetoothA2dp.SINK_STATE_CHANGED_ACTION) ||
action.equals(BluetoothPbap.PBAP_STATE_CHANGED_ACTION)) {
@@ -507,7 +507,7 @@ public class StatusBarPolicy {
filter.addAction(Intent.ACTION_SYNC_STATE_CHANGED);
filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
filter.addAction(AudioManager.VIBRATE_SETTING_CHANGED_ACTION);
filter.addAction(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION);
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
filter.addAction(BluetoothIntent.HEADSET_STATE_CHANGED_ACTION);
filter.addAction(BluetoothA2dp.SINK_STATE_CHANGED_ACTION);
filter.addAction(BluetoothPbap.PBAP_STATE_CHANGED_ACTION);
@@ -1072,10 +1072,10 @@ public class StatusBarPolicy {
int iconId = com.android.internal.R.drawable.stat_sys_data_bluetooth;
String action = intent.getAction();
if (action.equals(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION)) {
int state = intent.getIntExtra(BluetoothIntent.BLUETOOTH_STATE,
if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
BluetoothError.ERROR);
mBluetoothEnabled = state == BluetoothAdapter.BLUETOOTH_STATE_ON;
mBluetoothEnabled = state == BluetoothAdapter.STATE_ON;
} else if (action.equals(BluetoothIntent.HEADSET_STATE_CHANGED_ACTION)) {
mBluetoothHeadsetState = intent.getIntExtra(BluetoothIntent.HEADSET_STATE,
BluetoothHeadset.STATE_ERROR);