Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ae0b98ae authored by John Johnson's avatar John Johnson Committed by Android (Google) Code Review
Browse files

Merge "Add list of locations to WalletCard" into udc-dev

parents c9b8f31d e8d0abe6
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -12740,6 +12740,7 @@ package android.content.pm {
    field public static final String FEATURE_VULKAN_HARDWARE_COMPUTE = "android.hardware.vulkan.compute";
    field public static final String FEATURE_VULKAN_HARDWARE_COMPUTE = "android.hardware.vulkan.compute";
    field public static final String FEATURE_VULKAN_HARDWARE_LEVEL = "android.hardware.vulkan.level";
    field public static final String FEATURE_VULKAN_HARDWARE_LEVEL = "android.hardware.vulkan.level";
    field public static final String FEATURE_VULKAN_HARDWARE_VERSION = "android.hardware.vulkan.version";
    field public static final String FEATURE_VULKAN_HARDWARE_VERSION = "android.hardware.vulkan.version";
    field public static final String FEATURE_WALLET_LOCATION_BASED_SUGGESTIONS = "android.software.wallet_location_based_suggestions";
    field public static final String FEATURE_WATCH = "android.hardware.type.watch";
    field public static final String FEATURE_WATCH = "android.hardware.type.watch";
    field public static final String FEATURE_WEBVIEW = "android.software.webview";
    field public static final String FEATURE_WEBVIEW = "android.software.webview";
    field public static final String FEATURE_WIFI = "android.hardware.wifi";
    field public static final String FEATURE_WIFI = "android.hardware.wifi";
@@ -41117,6 +41118,7 @@ package android.service.quickaccesswallet {
    method @NonNull public String getCardId();
    method @NonNull public String getCardId();
    method @NonNull public android.graphics.drawable.Icon getCardImage();
    method @NonNull public android.graphics.drawable.Icon getCardImage();
    method @Nullable public CharSequence getCardLabel();
    method @Nullable public CharSequence getCardLabel();
    method @NonNull public java.util.List<android.location.Location> getCardLocations();
    method @NonNull public int getCardType();
    method @NonNull public int getCardType();
    method @NonNull public CharSequence getContentDescription();
    method @NonNull public CharSequence getContentDescription();
    method @Nullable public android.graphics.drawable.Icon getNonPaymentCardSecondaryImage();
    method @Nullable public android.graphics.drawable.Icon getNonPaymentCardSecondaryImage();
@@ -41134,6 +41136,7 @@ package android.service.quickaccesswallet {
    method @NonNull public android.service.quickaccesswallet.WalletCard build();
    method @NonNull public android.service.quickaccesswallet.WalletCard build();
    method @NonNull public android.service.quickaccesswallet.WalletCard.Builder setCardIcon(@Nullable android.graphics.drawable.Icon);
    method @NonNull public android.service.quickaccesswallet.WalletCard.Builder setCardIcon(@Nullable android.graphics.drawable.Icon);
    method @NonNull public android.service.quickaccesswallet.WalletCard.Builder setCardLabel(@Nullable CharSequence);
    method @NonNull public android.service.quickaccesswallet.WalletCard.Builder setCardLabel(@Nullable CharSequence);
    method @NonNull public android.service.quickaccesswallet.WalletCard.Builder setCardLocations(@NonNull java.util.List<android.location.Location>);
    method @NonNull public android.service.quickaccesswallet.WalletCard.Builder setNonPaymentCardSecondaryImage(@Nullable android.graphics.drawable.Icon);
    method @NonNull public android.service.quickaccesswallet.WalletCard.Builder setNonPaymentCardSecondaryImage(@Nullable android.graphics.drawable.Icon);
  }
  }
+12 −5
Original line number Original line Diff line number Diff line
@@ -4353,19 +4353,26 @@ public abstract class PackageManager {
    public static final String FEATURE_CREDENTIALS = "android.software.credentials";
    public static final String FEATURE_CREDENTIALS = "android.software.credentials";


    /**
    /**
     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: The device
     * The device supports locking (for example, by a financing provider in case of a missed
     * supports locking (for example, by a financing provider in case of a missed payment).
     * payment).
     */
     */
    @SdkConstant(SdkConstantType.FEATURE)
    @SdkConstant(SdkConstantType.FEATURE)
    public static final String FEATURE_DEVICE_LOCK = "android.software.device_lock";
    public static final String FEATURE_DEVICE_LOCK = "android.software.device_lock";


    /**
     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: The device
     * supports showing location-based suggestions for wallet cards provided by the default payment
     * app.
     */
    @SdkConstant(SdkConstantType.FEATURE)
    public static final String FEATURE_WALLET_LOCATION_BASED_SUGGESTIONS =
            "android.software.wallet_location_based_suggestions";

    /** @hide */
    /** @hide */
    public static final boolean APP_ENUMERATION_ENABLED_BY_DEFAULT = true;
    public static final boolean APP_ENUMERATION_ENABLED_BY_DEFAULT = true;


    /**
    /**
     * Extra field name for the URI to a verification file. Passed to a package
     * Extra field name for the URI to a verification file. Passed to a package verifier.
     * verifier.
     *
     *
     * @hide
     * @hide
     */
     */
+23 −4
Original line number Original line Diff line number Diff line
@@ -17,6 +17,8 @@
package android.service.quickaccesswallet;
package android.service.quickaccesswallet;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Bitmap;
import android.graphics.drawable.Icon;
import android.graphics.drawable.Icon;
import android.os.Handler;
import android.os.Handler;
@@ -36,13 +38,18 @@ final class GetWalletCardsCallbackImpl implements GetWalletCardsCallback {
    private final IQuickAccessWalletServiceCallbacks mCallback;
    private final IQuickAccessWalletServiceCallbacks mCallback;
    private final GetWalletCardsRequest mRequest;
    private final GetWalletCardsRequest mRequest;
    private final Handler mHandler;
    private final Handler mHandler;
    private final Context mContext;
    private boolean mCalled;
    private boolean mCalled;


    GetWalletCardsCallbackImpl(GetWalletCardsRequest request,
    GetWalletCardsCallbackImpl(
            IQuickAccessWalletServiceCallbacks callback, Handler handler) {
            GetWalletCardsRequest request,
            IQuickAccessWalletServiceCallbacks callback,
            Handler handler,
            Context context) {
        mRequest = request;
        mRequest = request;
        mCallback = callback;
        mCallback = callback;
        mHandler = handler;
        mHandler = handler;
        mContext = context;
    }
    }


    /**
    /**
@@ -50,11 +57,17 @@ final class GetWalletCardsCallbackImpl implements GetWalletCardsCallback {
     * was successfully handled by the service.
     * was successfully handled by the service.
     *
     *
     * @param response The response contains the list of {@link WalletCard walletCards} to be shown
     * @param response The response contains the list of {@link WalletCard walletCards} to be shown
     *                 to the user as well as the index of the card that should initially be
     *     to the user as well as the index of the card that should initially be presented as the
     *                 presented as the selected card.
     *     selected card.
     */
     */
    public void onSuccess(@NonNull GetWalletCardsResponse response) {
    public void onSuccess(@NonNull GetWalletCardsResponse response) {
        if (isValidResponse(response)) {
        if (isValidResponse(response)) {
            // Strip location info from response if the feature is not enabled.
            if (!mContext.getPackageManager()
                    .hasSystemFeature(PackageManager.FEATURE_WALLET_LOCATION_BASED_SUGGESTIONS)) {
                removeLocationsFromResponse(response);
            }

            mHandler.post(() -> onSuccessInternal(response));
            mHandler.post(() -> onSuccessInternal(response));
        } else {
        } else {
            Log.w(TAG, "Invalid GetWalletCards response");
            Log.w(TAG, "Invalid GetWalletCards response");
@@ -152,4 +165,10 @@ final class GetWalletCardsCallbackImpl implements GetWalletCardsCallback {
        }
        }
        return true;
        return true;
    }
    }

    private void removeLocationsFromResponse(@NonNull GetWalletCardsResponse response) {
        for (WalletCard card : response.getWalletCards()) {
            card.removeCardLocations();
        }
    }
}
}
+2 −2
Original line number Original line Diff line number Diff line
@@ -262,8 +262,8 @@ public abstract class QuickAccessWalletService extends Service {
    private void onWalletCardsRequestedInternal(
    private void onWalletCardsRequestedInternal(
            GetWalletCardsRequest request,
            GetWalletCardsRequest request,
            IQuickAccessWalletServiceCallbacks callback) {
            IQuickAccessWalletServiceCallbacks callback) {
        onWalletCardsRequested(request,
        onWalletCardsRequested(
                new GetWalletCardsCallbackImpl(request, callback, mHandler));
                request, new GetWalletCardsCallbackImpl(request, callback, mHandler, this));
    }
    }


    private void onTargetActivityIntentRequestedInternal(
    private void onTargetActivityIntentRequestedInternal(
+55 −16
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.app.PendingIntent;
import android.app.PendingIntent;
import android.graphics.drawable.Icon;
import android.graphics.drawable.Icon;
import android.location.Location;
import android.os.Parcel;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable;
import android.text.TextUtils;
import android.text.TextUtils;
@@ -29,7 +30,8 @@ import com.android.internal.util.Preconditions;


import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.RetentionPolicy;

import java.util.ArrayList;
import java.util.List;


/**
/**
 * A {@link WalletCard} can represent anything that a user might carry in their wallet -- a credit
 * A {@link WalletCard} can represent anything that a user might carry in their wallet -- a credit
@@ -67,6 +69,7 @@ public final class WalletCard implements Parcelable {
    private final Icon mCardIcon;
    private final Icon mCardIcon;
    private final CharSequence mCardLabel;
    private final CharSequence mCardLabel;
    private final Icon mNonPaymentCardSecondaryImage;
    private final Icon mNonPaymentCardSecondaryImage;
    private List<Location> mCardLocations;


    private WalletCard(Builder builder) {
    private WalletCard(Builder builder) {
        this.mCardId = builder.mCardId;
        this.mCardId = builder.mCardId;
@@ -77,6 +80,7 @@ public final class WalletCard implements Parcelable {
        this.mCardIcon = builder.mCardIcon;
        this.mCardIcon = builder.mCardIcon;
        this.mCardLabel = builder.mCardLabel;
        this.mCardLabel = builder.mCardLabel;
        this.mNonPaymentCardSecondaryImage = builder.mNonPaymentCardSecondaryImage;
        this.mNonPaymentCardSecondaryImage = builder.mNonPaymentCardSecondaryImage;
        this.mCardLocations = builder.mCardLocations;
    }
    }


    /**
    /**
@@ -106,7 +110,7 @@ public final class WalletCard implements Parcelable {
        writeIconIfNonNull(mCardIcon, dest, flags);
        writeIconIfNonNull(mCardIcon, dest, flags);
        TextUtils.writeToParcel(mCardLabel, dest, flags);
        TextUtils.writeToParcel(mCardLabel, dest, flags);
        writeIconIfNonNull(mNonPaymentCardSecondaryImage, dest, flags);
        writeIconIfNonNull(mNonPaymentCardSecondaryImage, dest, flags);

        dest.writeTypedList(mCardLocations, flags);
    }
    }


    /** Utility function called by writeToParcel
    /** Utility function called by writeToParcel
@@ -128,15 +132,20 @@ public final class WalletCard implements Parcelable {
        PendingIntent pendingIntent = PendingIntent.readPendingIntentOrNullFromParcel(source);
        PendingIntent pendingIntent = PendingIntent.readPendingIntentOrNullFromParcel(source);
        Icon cardIcon = source.readByte() == 0 ? null : Icon.CREATOR.createFromParcel(source);
        Icon cardIcon = source.readByte() == 0 ? null : Icon.CREATOR.createFromParcel(source);
        CharSequence cardLabel = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
        CharSequence cardLabel = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
        Icon nonPaymentCardSecondaryImage = source.readByte() == 0 ? null :
        Icon nonPaymentCardSecondaryImage =
                Icon.CREATOR.createFromParcel(source);
                source.readByte() == 0 ? null : Icon.CREATOR.createFromParcel(source);
        Builder builder = new Builder(cardId, cardType, cardImage, contentDesc, pendingIntent)
        Builder builder =
                new Builder(cardId, cardType, cardImage, contentDesc, pendingIntent)
                        .setCardIcon(cardIcon)
                        .setCardIcon(cardIcon)
                        .setCardLabel(cardLabel);
                        .setCardLabel(cardLabel);
        if (cardType == CARD_TYPE_NON_PAYMENT) {
            builder.setNonPaymentCardSecondaryImage(nonPaymentCardSecondaryImage);
        }
        List<Location> cardLocations = new ArrayList<>();
        source.readTypedList(cardLocations, Location.CREATOR);
        builder.setCardLocations(cardLocations);


        return cardType == CARD_TYPE_NON_PAYMENT
        return builder.build();
                ? builder.setNonPaymentCardSecondaryImage(nonPaymentCardSecondaryImage).build() :
                 builder.build();
    }
    }


    @NonNull
    @NonNull
@@ -233,6 +242,22 @@ public final class WalletCard implements Parcelable {
        return mNonPaymentCardSecondaryImage;
        return mNonPaymentCardSecondaryImage;
    }
    }


    /** List of locations that this card might be useful at. */
    @NonNull
    public List<Location> getCardLocations() {
        return mCardLocations;
    }

    /**
     * Removes locations from card. Should be called if {@link
     * PackageManager.FEATURE_WALLET_LOCATION_BASED_SUGGESTIONS} is disabled.
     *
     * @hide
     */
    public void removeCardLocations() {
        mCardLocations = new ArrayList<>();
    }

    /**
    /**
     * Builder for {@link WalletCard} objects. You must provide cardId, cardImage,
     * Builder for {@link WalletCard} objects. You must provide cardId, cardImage,
     * contentDescription, and pendingIntent. If the card is opaque and should be shown with
     * contentDescription, and pendingIntent. If the card is opaque and should be shown with
@@ -247,6 +272,7 @@ public final class WalletCard implements Parcelable {
        private Icon mCardIcon;
        private Icon mCardIcon;
        private CharSequence mCardLabel;
        private CharSequence mCardLabel;
        private Icon mNonPaymentCardSecondaryImage;
        private Icon mNonPaymentCardSecondaryImage;
        private List<Location> mCardLocations = new ArrayList<>();


        /**
        /**
         * @param cardId             The card id must be non-null and unique within the list of
         * @param cardId             The card id must be non-null and unique within the list of
@@ -336,14 +362,27 @@ public final class WalletCard implements Parcelable {
         * unique to the card, such as a barcode or number. Only valid for CARD_TYPE_NON_PAYMENT.
         * unique to the card, such as a barcode or number. Only valid for CARD_TYPE_NON_PAYMENT.
         */
         */
        @NonNull
        @NonNull
        public Builder
        public Builder setNonPaymentCardSecondaryImage(
                setNonPaymentCardSecondaryImage(@Nullable Icon nonPaymentCardSecondaryImage) {
                @Nullable Icon nonPaymentCardSecondaryImage) {
            Preconditions.checkState(mCardType == CARD_TYPE_NON_PAYMENT,
            Preconditions.checkState(
                    mCardType == CARD_TYPE_NON_PAYMENT,
                    "This field can only be set on non-payment cards");
                    "This field can only be set on non-payment cards");
            mNonPaymentCardSecondaryImage = nonPaymentCardSecondaryImage;
            mNonPaymentCardSecondaryImage = nonPaymentCardSecondaryImage;
            return this;
            return this;
        }
        }


        /**
         * Set of locations this card might be useful at. If {@link
         * PackageManager.FEATURE_WALLET_LOCATION_BASED_SUGGESTIONS} is enabled, the card might be
         * shown to the user when a user is near one of these locations.
         */
        @NonNull
        public Builder setCardLocations(@NonNull List<Location> cardLocations) {
            Preconditions.checkCollectionElementsNotNull(cardLocations, "cardLocations");
            mCardLocations = cardLocations;
            return this;
        }

        /**
        /**
         * Builds a new {@link WalletCard} instance.
         * Builds a new {@link WalletCard} instance.
         *
         *