summaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/BluetoothProfileConnector.java
diff options
context:
space:
mode:
authorWilliam Escande <wescande@google.com>2021-12-09 15:14:14 +0100
committerWilliam Escande <wescande@google.com>2021-12-14 16:59:13 +0100
commitaacad3c766c05e57f656b0c266a164ea172b732e (patch)
tree16cda21bbd25a63827c9203511acb6b9d19bc077 /framework/java/android/bluetooth/BluetoothProfileConnector.java
parent7fe30138bc3b3848f40a585886c84bf532bbfbc2 (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 Change-Id: I838b910c633b3ca943fec01f3ccca466ff65f892
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothProfileConnector.java')
-rw-r--r--framework/java/android/bluetooth/BluetoothProfileConnector.java32
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..a457679716 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,30 @@ public abstract class BluetoothProfileConnector<T> {
}
};
+ private @Nullable ComponentName resolveSystemService(@NonNull Intent intent,
+ @NonNull PackageManager pm) {
+ List<ResolveInfo> results = pm.queryIntentServices(intent,
+ PackageManager.ResolveInfoFlags.of(0));
+ 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 +128,7 @@ 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());
intent.setComponent(comp);
if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
UserHandle.CURRENT)) {