diff --git a/core/api/current.txt b/core/api/current.txt index d615436e0693e..23fb27ca294ee 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -39179,6 +39179,7 @@ package android.service.quickaccesswallet { public abstract class QuickAccessWalletService extends android.app.Service { ctor public QuickAccessWalletService(); method @Nullable public android.app.PendingIntent getTargetActivityPendingIntent(); + method public final boolean getUseTargetActivityForQuickAccess(); method @Nullable public android.os.IBinder onBind(@NonNull android.content.Intent); method public abstract void onWalletCardSelected(@NonNull android.service.quickaccesswallet.SelectWalletCardRequest); method public abstract void onWalletCardsRequested(@NonNull android.service.quickaccesswallet.GetWalletCardsRequest, @NonNull android.service.quickaccesswallet.GetWalletCardsCallback); diff --git a/core/java/android/service/quickaccesswallet/QuickAccessWalletService.java b/core/java/android/service/quickaccesswallet/QuickAccessWalletService.java index 70ccd6fbd590f..1d74a6470a841 100644 --- a/core/java/android/service/quickaccesswallet/QuickAccessWalletService.java +++ b/core/java/android/service/quickaccesswallet/QuickAccessWalletService.java @@ -16,12 +16,20 @@ package android.service.quickaccesswallet; +import static android.content.pm.PackageManager.GET_META_DATA; +import static android.content.pm.PackageManager.MATCH_DEFAULT_ONLY; +import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AWARE; +import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_UNAWARE; + import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SdkConstant; import android.app.PendingIntent; import android.app.Service; import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.content.pm.ServiceInfo; import android.os.Build; import android.os.Handler; import android.os.IBinder; @@ -30,6 +38,8 @@ import android.os.RemoteException; import android.provider.Settings; import android.util.Log; +import java.util.List; + /** * A {@code QuickAccessWalletService} provides a list of {@code WalletCard}s shown in the Quick * Access Wallet. The Quick Access Wallet allows the user to change their selected payment method @@ -341,6 +351,45 @@ public abstract class QuickAccessWalletService extends Service { return null; } + /** + * Returns the value specified by the attribute + * {@link android.R.styleable#QuickAccessWalletService_useTargetActivityForQuickAccess} + * in the QuickAccessWalletService's metadata configuration. If the attribute or metadata is + * not supplied, returns false. + */ + public final boolean getUseTargetActivityForQuickAccess() { + Intent intent = new Intent(SERVICE_INTERFACE).setPackage(getPackageName()); + List matchedServices = getPackageManager() + .queryIntentServices(intent, + PackageManager.ResolveInfoFlags.of( + GET_META_DATA | MATCH_DIRECT_BOOT_UNAWARE | MATCH_DIRECT_BOOT_AWARE + | MATCH_DEFAULT_ONLY)); + + ResolveInfo resolveInfo = null; + + for (ResolveInfo info : matchedServices) { + ServiceInfo serviceInfo = info.serviceInfo; + if (serviceInfo == null) { + continue; + } + String serviceName = serviceInfo.name; + if (serviceName == null) { + continue; + } + if (serviceName.equals(getClass().getCanonicalName())) { + resolveInfo = info; + } + } + + if (resolveInfo == null || resolveInfo.serviceInfo == null) { + Log.i(TAG, "Matching QuickAccessWalletService not found."); + return false; + } + QuickAccessWalletServiceInfo.ServiceMetadata serviceMetadata = + QuickAccessWalletServiceInfo.parseServiceMetadata(this, resolveInfo.serviceInfo); + return serviceMetadata != null && serviceMetadata.mUseTargetActivityForQuickAccess; + } + private void sendWalletServiceEventInternal(WalletServiceEvent serviceEvent) { if (mEventListener == null) { Log.i(TAG, "No dismiss listener registered"); diff --git a/core/java/android/service/quickaccesswallet/QuickAccessWalletServiceInfo.java b/core/java/android/service/quickaccesswallet/QuickAccessWalletServiceInfo.java index cf4be739e05af..cc393a4ce6053 100644 --- a/core/java/android/service/quickaccesswallet/QuickAccessWalletServiceInfo.java +++ b/core/java/android/service/quickaccesswallet/QuickAccessWalletServiceInfo.java @@ -135,7 +135,7 @@ class QuickAccessWalletServiceInfo { return null; } - private static class ServiceMetadata { + static class ServiceMetadata { @Nullable private final String mSettingsActivity; @Nullable @@ -144,7 +144,7 @@ class QuickAccessWalletServiceInfo { private final CharSequence mShortcutShortLabel; @Nullable private final CharSequence mShortcutLongLabel; - private final boolean mUseTargetActivityForQuickAccess; + final boolean mUseTargetActivityForQuickAccess; private static ServiceMetadata empty() { return new ServiceMetadata(null, null, null, null, false); @@ -164,7 +164,7 @@ class QuickAccessWalletServiceInfo { } } - private static ServiceMetadata parseServiceMetadata(Context context, ServiceInfo serviceInfo) { + static ServiceMetadata parseServiceMetadata(Context context, ServiceInfo serviceInfo) { PackageManager pm = context.getPackageManager(); final XmlResourceParser parser = serviceInfo.loadXmlMetaData(pm, QuickAccessWalletService.SERVICE_META_DATA);