Check if anyone could possibly provide service.

am: f6e9b95127

Change-Id: I979716e66e6b5ca068e4a0de3cf2432cbbf25c37
This commit is contained in:
Jeff Sharkey
2016-09-21 01:23:55 +00:00
committed by android-build-merger

View File

@@ -141,8 +141,12 @@ public class ServiceWatcher implements ServiceConnection {
* <p> * <p>
* Note that if there are no matching encryption-aware services, we may not * Note that if there are no matching encryption-aware services, we may not
* bind to a real service until after the current user is unlocked. * bind to a real service until after the current user is unlocked.
*
* @returns {@code true} if a potential service implementation was found.
*/ */
public boolean start() { public boolean start() {
if (isServiceMissing()) return false;
synchronized (mLock) { synchronized (mLock) {
bindBestPackageLocked(mServicePackageName, false); bindBestPackageLocked(mServicePackageName, false);
} }
@@ -173,6 +177,17 @@ public class ServiceWatcher implements ServiceConnection {
return true; return true;
} }
/**
* Check if any instance of this service is present on the device,
* regardless of it being encryption-aware or not.
*/
private boolean isServiceMissing() {
final Intent intent = new Intent(mAction);
final int flags = PackageManager.MATCH_DIRECT_BOOT_AWARE
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE;
return mPm.queryIntentServicesAsUser(intent, flags, mCurrentUserId).isEmpty();
}
/** /**
* Searches and binds to the best package, or do nothing if the best package * Searches and binds to the best package, or do nothing if the best package
* is already bound, unless force rebinding is requested. * is already bound, unless force rebinding is requested.
@@ -181,7 +196,7 @@ public class ServiceWatcher implements ServiceConnection {
* packages if it is {@code null}. * packages if it is {@code null}.
* @param forceRebind Force a rebinding to the best package if it's already * @param forceRebind Force a rebinding to the best package if it's already
* bound. * bound.
* @return {@code true} if a valid package was found to bind to. * @returns {@code true} if a valid package was found to bind to.
*/ */
private boolean bindBestPackageLocked(String justCheckThisPackage, boolean forceRebind) { private boolean bindBestPackageLocked(String justCheckThisPackage, boolean forceRebind) {
Intent intent = new Intent(mAction); Intent intent = new Intent(mAction);