diff options
author | William Escande <wescande@google.com> | 2021-12-09 15:14:14 +0100 |
---|---|---|
committer | William Escande <wescande@google.com> | 2021-12-14 16:01:01 +0000 |
commit | 26454b57c77ef192b879d3b9ad24710e393885d2 (patch) | |
tree | abb851550f9a62269951b7366153c90cd16a91aa /framework/java/android/bluetooth/BluetoothProfileConnector.java | |
parent | 896b6e91580950a192c27de71e38d9d58c6c09cf (diff) |
Pbap use profileConnector, resolveSystemService api fix
* All profiles use the BluetoothProfileConnector but not Pbap.
I reproduced the changes that were made in aosp/932813 for all other
profiles. This allow pbap to no longer call resolveSystemService.
* `Intent.resolveSystemService` is an hidden API and can no longer be
called from Bluetooth as we aim to become mainline. It's code is simple
enough to be copied.
Tag: #refactor
Bug: 200200870
Test: atest BluetoothInstrumentationTests
Merged-In: I838b910c633b3ca943fec01f3ccca466ff65f892
Change-Id: I838b910c633b3ca943fec01f3ccca466ff65f892
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothProfileConnector.java')
-rw-r--r-- | framework/java/android/bluetooth/BluetoothProfileConnector.java | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/framework/java/android/bluetooth/BluetoothProfileConnector.java b/framework/java/android/bluetooth/BluetoothProfileConnector.java index ecd5e4077d..79373f1a32 100644 --- a/framework/java/android/bluetooth/BluetoothProfileConnector.java +++ b/framework/java/android/bluetooth/BluetoothProfileConnector.java @@ -16,12 +16,16 @@ package android.bluetooth; +import android.annotation.NonNull; +import android.annotation.Nullable; import android.annotation.SuppressLint; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; +import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.os.Build; import android.os.IBinder; import android.os.RemoteException; @@ -29,6 +33,7 @@ import android.os.UserHandle; import android.util.CloseGuard; import android.util.Log; +import java.util.List; /** * Connector for Bluetooth profile proxies to bind manager service and * profile services @@ -57,6 +62,29 @@ public abstract class BluetoothProfileConnector<T> { } }; + private @Nullable ComponentName resolveSystemService(@NonNull Intent intent, + @NonNull PackageManager pm, @PackageManager.ComponentInfoFlags int flags) { + List<ResolveInfo> results = pm.queryIntentServices(intent, flags); + if (results == null) { + return null; + } + ComponentName comp = null; + for (int i = 0; i < results.size(); i++) { + ResolveInfo ri = results.get(i); + if ((ri.serviceInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { + continue; + } + ComponentName foundComp = new ComponentName(ri.serviceInfo.applicationInfo.packageName, + ri.serviceInfo.name); + if (comp != null) { + throw new IllegalStateException("Multiple system services handle " + intent + + ": " + comp + ", " + foundComp); + } + comp = foundComp; + } + return comp; + } + private final ServiceConnection mConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { logDebug("Proxy object connected"); @@ -99,8 +127,8 @@ public abstract class BluetoothProfileConnector<T> { mCloseGuard.open("doUnbind"); try { Intent intent = new Intent(mServiceName); - ComponentName comp = intent.resolveSystemService( - mContext.getPackageManager(), 0); + ComponentName comp = resolveSystemService(intent, mContext.getPackageManager(), + 0); intent.setComponent(comp); if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0, UserHandle.CURRENT)) { |