summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmds/servicemanager/service_manager.c1
-rw-r--r--core/java/android/app/ContextImpl.java6
-rw-r--r--core/java/android/content/Context.java9
-rw-r--r--core/java/android/os/Process.java6
-rw-r--r--services/java/com/android/server/pm/PackageManagerService.java2
-rw-r--r--services/java/com/android/server/power/ShutdownThread.java63
6 files changed, 85 insertions, 2 deletions
diff --git a/cmds/servicemanager/service_manager.c b/cmds/servicemanager/service_manager.c
index 71c5622..3314dc3 100644
--- a/cmds/servicemanager/service_manager.c
+++ b/cmds/servicemanager/service_manager.c
@@ -33,6 +33,7 @@ static struct {
{ AID_MEDIA, "media.audio_policy" },
{ AID_DRM, "drm.drmManager" },
{ AID_NFC, "nfc" },
+ { AID_BLUETOOTH, "bluetooth" },
{ AID_RADIO, "radio.phone" },
{ AID_RADIO, "radio.sms" },
{ AID_RADIO, "radio.phonesubinfo" },
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index 5e21403..44b8d3a 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -18,6 +18,7 @@ package android.app;
import com.android.internal.policy.PolicyManager;
+import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
@@ -294,6 +295,11 @@ class ContextImpl extends Context {
return new MediaRouter(ctx);
}});
+ registerService(BLUETOOTH_SERVICE, new ServiceFetcher() {
+ public Object createService(ContextImpl ctx) {
+ return BluetoothAdapter.getDefaultAdapter();
+ }});
+
registerService(CLIPBOARD_SERVICE, new ServiceFetcher() {
public Object createService(ContextImpl ctx) {
return new ClipboardManager(ctx.getOuterContext(),
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index 66fed818..490165d 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -1907,6 +1907,15 @@ public abstract class Context {
/**
* Use with {@link #getSystemService} to retrieve a
+ * {@link android.bluetooth.BluetoothAdapter} for using Bluetooth.
+ *
+ * @see #getSystemService
+ * @hide
+ */
+ public static final String BLUETOOTH_SERVICE = "bluetooth";
+
+ /**
+ * Use with {@link #getSystemService} to retrieve a
* {@link android.net.sip.SipManager} for accessing the SIP related service.
*
* @see #getSystemService
diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java
index 6ab4dc1..a04ad93 100644
--- a/core/java/android/os/Process.java
+++ b/core/java/android/os/Process.java
@@ -116,6 +116,12 @@ public class Process {
public static final int NFC_UID = 1027;
/**
+ * Defines the UID/GID for the Bluetooth service process.
+ * @hide
+ */
+ public static final int BLUETOOTH_UID = 1002;
+
+ /**
* Defines the GID for the group that allows write access to the internal media storage.
* @hide
*/
diff --git a/services/java/com/android/server/pm/PackageManagerService.java b/services/java/com/android/server/pm/PackageManagerService.java
index e1ab58b..ffb3fa6 100644
--- a/services/java/com/android/server/pm/PackageManagerService.java
+++ b/services/java/com/android/server/pm/PackageManagerService.java
@@ -173,6 +173,7 @@ public class PackageManagerService extends IPackageManager.Stub {
private static final int RADIO_UID = Process.PHONE_UID;
private static final int LOG_UID = Process.LOG_UID;
private static final int NFC_UID = Process.NFC_UID;
+ private static final int BLUETOOTH_UID = Process.BLUETOOTH_UID;
private static final boolean GET_CERTIFICATES = true;
@@ -903,6 +904,7 @@ public class PackageManagerService extends IPackageManager.Stub {
mSettings.addSharedUserLPw("android.uid.phone", RADIO_UID, ApplicationInfo.FLAG_SYSTEM);
mSettings.addSharedUserLPw("android.uid.log", LOG_UID, ApplicationInfo.FLAG_SYSTEM);
mSettings.addSharedUserLPw("android.uid.nfc", NFC_UID, ApplicationInfo.FLAG_SYSTEM);
+ mSettings.addSharedUserLPw("android.uid.bluetooth", BLUETOOTH_UID, ApplicationInfo.FLAG_SYSTEM);
String separateProcesses = SystemProperties.get("debug.separate_processes");
if (separateProcesses != null && separateProcesses.length() > 0) {
diff --git a/services/java/com/android/server/power/ShutdownThread.java b/services/java/com/android/server/power/ShutdownThread.java
index 5f2f428..82f72f7 100644
--- a/services/java/com/android/server/power/ShutdownThread.java
+++ b/services/java/com/android/server/power/ShutdownThread.java
@@ -324,9 +324,68 @@ public final class ShutdownThread extends Thread {
} catch (RemoteException e) {
}
}
+
+ final ITelephony phone =
+ ITelephony.Stub.asInterface(ServiceManager.checkService("phone"));
+ final IBluetooth bluetooth =
+ IBluetooth.Stub.asInterface(ServiceManager.checkService(
+ BluetoothAdapter.BLUETOOTH_SERVICE));
+
+ final IMountService mount =
+ IMountService.Stub.asInterface(
+ ServiceManager.checkService("mount"));
+
+ try {
+ bluetoothOff = bluetooth == null ||
+ bluetooth.getState() == BluetoothAdapter.STATE_OFF;
+ if (!bluetoothOff) {
+ Log.w(TAG, "Disabling Bluetooth...");
+ //TODO(BT)
+ bluetooth.disable(); // disable but don't persist new state
+ }
+ } catch (RemoteException ex) {
+ Log.e(TAG, "RemoteException during bluetooth shutdown", ex);
+ bluetoothOff = true;
+ }
- // Shutdown radios.
- shutdownRadios(MAX_RADIO_WAIT_TIME);
+ try {
+ radioOff = phone == null || !phone.isRadioOn();
+ if (!radioOff) {
+ Log.w(TAG, "Turning off radio...");
+ phone.setRadio(false);
+ }
+ } catch (RemoteException ex) {
+ Log.e(TAG, "RemoteException during radio shutdown", ex);
+ radioOff = true;
+ }
+
+ Log.i(TAG, "Waiting for Bluetooth and Radio...");
+
+ // Wait a max of 32 seconds for clean shutdown
+ for (int i = 0; i < MAX_NUM_PHONE_STATE_READS; i++) {
+ if (!bluetoothOff) {
+ try {
+ bluetoothOff =
+ bluetooth.getState() == BluetoothAdapter.STATE_OFF;
+ } catch (RemoteException ex) {
+ Log.e(TAG, "RemoteException during bluetooth shutdown", ex);
+ bluetoothOff = true;
+ }
+ }
+ if (!radioOff) {
+ try {
+ radioOff = !phone.isRadioOn();
+ } catch (RemoteException ex) {
+ Log.e(TAG, "RemoteException during radio shutdown", ex);
+ radioOff = true;
+ }
+ }
+ if (radioOff && bluetoothOff) {
+ Log.i(TAG, "Radio and Bluetooth shutdown complete.");
+ break;
+ }
+ SystemClock.sleep(PHONE_STATE_POLL_SLEEP_MSEC);
+ }
// Shutdown MountService to ensure media is in a safe state
IMountShutdownObserver observer = new IMountShutdownObserver.Stub() {