summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/content/pm/RegisteredServicesCache.java56
1 files changed, 47 insertions, 9 deletions
diff --git a/core/java/android/content/pm/RegisteredServicesCache.java b/core/java/android/content/pm/RegisteredServicesCache.java
index 56d61efdcb25..020e8c22b128 100644
--- a/core/java/android/content/pm/RegisteredServicesCache.java
+++ b/core/java/android/content/pm/RegisteredServicesCache.java
@@ -16,6 +16,7 @@
package android.content.pm;
+import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
@@ -40,9 +41,12 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.FastXmlSerializer;
+
import com.google.android.collect.Lists;
import com.google.android.collect.Maps;
+import libcore.io.IoUtils;
+
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
@@ -61,8 +65,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
-import libcore.io.IoUtils;
-
/**
* Cache of registered services. This cache is lazily built by interrogating
* {@link PackageManager} on a per-user basis. It's updated as packages are
@@ -72,7 +74,7 @@ import libcore.io.IoUtils;
* <p>
* The services are referred to by type V and are made available via the
* {@link #getServiceInfo} method.
- *
+ *
* @hide
*/
public abstract class RegisteredServicesCache<V> {
@@ -98,6 +100,8 @@ public abstract class RegisteredServicesCache<V> {
Map<V, ServiceInfo<V>> services = null;
@GuardedBy("mServicesLock")
boolean mPersistentServicesFileDidNotExist = true;
+ @GuardedBy("mServicesLock")
+ boolean mBindInstantServiceAllowed = false;
}
@GuardedBy("mServicesLock")
@@ -273,7 +277,7 @@ public abstract class RegisteredServicesCache<V> {
Log.d(TAG, "notifyListener: " + type + " is " + (removed ? "removed" : "added"));
}
RegisteredServicesCacheListener<V> listener;
- Handler handler;
+ Handler handler;
synchronized (this) {
listener = mListener;
handler = mHandler;
@@ -281,7 +285,7 @@ public abstract class RegisteredServicesCache<V> {
if (listener == null) {
return;
}
-
+
final RegisteredServicesCacheListener<V> listener2 = listener;
handler.post(new Runnable() {
public void run() {
@@ -387,6 +391,34 @@ public abstract class RegisteredServicesCache<V> {
}
}
+ /**
+ * @return whether the binding to service is allowed for instant apps.
+ */
+ public boolean getBindInstantServiceAllowed(int userId) {
+ mContext.enforceCallingOrSelfPermission(
+ Manifest.permission.MANAGE_BIND_INSTANT_SERVICE,
+ "getBindInstantServiceAllowed");
+
+ synchronized (mServicesLock) {
+ final UserServices<V> user = findOrCreateUserLocked(userId);
+ return user.mBindInstantServiceAllowed;
+ }
+ }
+
+ /**
+ * Set whether the binding to service is allowed or not for instant apps.
+ */
+ public void setBindInstantServiceAllowed(int userId, boolean allowed) {
+ mContext.enforceCallingOrSelfPermission(
+ Manifest.permission.MANAGE_BIND_INSTANT_SERVICE,
+ "setBindInstantServiceAllowed");
+
+ synchronized (mServicesLock) {
+ final UserServices<V> user = findOrCreateUserLocked(userId);
+ user.mBindInstantServiceAllowed = allowed;
+ }
+ }
+
@VisibleForTesting
protected boolean inSystemImage(int callerUid) {
String[] packages = mContext.getPackageManager().getPackagesForUid(callerUid);
@@ -409,10 +441,16 @@ public abstract class RegisteredServicesCache<V> {
@VisibleForTesting
protected List<ResolveInfo> queryIntentServices(int userId) {
final PackageManager pm = mContext.getPackageManager();
- return pm.queryIntentServicesAsUser(new Intent(mInterfaceName),
- PackageManager.GET_META_DATA | PackageManager.MATCH_DIRECT_BOOT_AWARE
- | PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
- userId);
+ int flags = PackageManager.GET_META_DATA
+ | PackageManager.MATCH_DIRECT_BOOT_AWARE
+ | PackageManager.MATCH_DIRECT_BOOT_UNAWARE;
+ synchronized (mServicesLock) {
+ final UserServices<V> user = findOrCreateUserLocked(userId);
+ if (user.mBindInstantServiceAllowed) {
+ flags |= PackageManager.MATCH_INSTANT;
+ }
+ }
+ return pm.queryIntentServicesAsUser(new Intent(mInterfaceName), flags, userId);
}
/**