diff options
| author | Dianne Hackborn <hackbod@google.com> | 2013-08-04 16:50:16 -0700 |
|---|---|---|
| committer | Dianne Hackborn <hackbod@google.com> | 2013-08-05 16:53:26 -0700 |
| commit | 221ea892dcc661bd07d6f36ff012edca2c48aed4 (patch) | |
| tree | 33a29861257497ebd865fe5565c9e3bfbde3cb1a /core/java/android/bluetooth/BluetoothInputDevice.java | |
| parent | 33041bd90301d50c61e6375bbd9bb6da2f1c8cba (diff) | |
| download | frameworks_base-221ea892dcc661bd07d6f36ff012edca2c48aed4.zip frameworks_base-221ea892dcc661bd07d6f36ff012edca2c48aed4.tar.gz frameworks_base-221ea892dcc661bd07d6f36ff012edca2c48aed4.tar.bz2 | |
Start restricting service calls with implicit intents.
The bindService() and startService() calls have always had
undefined behavior when used with an implicit Intent and there
are multiple matching services. Because of this, it is not
safe for applications to use such Intents when interacting with
services, yet the platform would merrily go about doing... something.
In KLP I want to cause this case to be invalid, resulting in
an exception thrown back to the app. Unfortunately there are
lots of (scary) things relying on this behavior, so we can't
immediately turn it into an exception, even one qualified by the
caller's target SDK version.
In this change, we start loggin a WTF when such a call happens,
and clean up some stuff in Bluetooth that was doing this behavior.
Change-Id: I62e25d07890588d2362104e20b054aebb6c0e007
Diffstat (limited to 'core/java/android/bluetooth/BluetoothInputDevice.java')
| -rw-r--r-- | core/java/android/bluetooth/BluetoothInputDevice.java | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/core/java/android/bluetooth/BluetoothInputDevice.java b/core/java/android/bluetooth/BluetoothInputDevice.java index db7e424..f9c789c 100644 --- a/core/java/android/bluetooth/BluetoothInputDevice.java +++ b/core/java/android/bluetooth/BluetoothInputDevice.java @@ -206,9 +206,7 @@ public final class BluetoothInputDevice implements BluetoothProfile { try { if (mService == null) { if (VDBG) Log.d(TAG,"Binding service..."); - if (!mContext.bindService(new Intent(IBluetoothInputDevice.class.getName()), mConnection, 0)) { - Log.e(TAG, "Could not bind to Bluetooth HID Service"); - } + doBind(); } } catch (Exception re) { Log.e(TAG,"",re); @@ -237,10 +235,18 @@ public final class BluetoothInputDevice implements BluetoothProfile { } } - if (!context.bindService(new Intent(IBluetoothInputDevice.class.getName()), - mConnection, 0)) { - Log.e(TAG, "Could not bind to Bluetooth HID Service"); + doBind(); + } + + boolean doBind() { + Intent intent = new Intent(IBluetoothInputDevice.class.getName()); + ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0); + intent.setComponent(comp); + if (comp == null || !mContext.bindService(intent, mConnection, 0)) { + Log.e(TAG, "Could not bind to Bluetooth HID Service with " + intent); + return false; } + return true; } /*package*/ void close() { |
