Add shell command handler for account manager to allow enabling service
binding for instant app. Test: cts-tradefed run cts -m CtsAccountManagerTestCases cts-instant-tradefed run cts-instant -m CtsAccountManagerTestCases Bug: 79367659 Change-Id: I3ac968ebc20be68da08293d9b685a01920f11b76
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user