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

Commit 2c978920 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "[Nfc framework] API to include/exclude Other category service...

Merge "[Nfc framework] API to include/exclude Other category service component" into main am: 8c7eea40

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2803133



Change-Id: Id1a59849765e22203414b6cc9be843a1c7c9823c
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 47a697e6 8c7eea40
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -40,5 +40,6 @@ interface INfcCardEmulation
    boolean unsetPreferredService();
    boolean supportsAidPrefixRegistration();
    ApduServiceInfo getPreferredPaymentService(int userHandle);
    boolean setServiceEnabledForCategoryOther(int userHandle, in ComponentName app, boolean status);
    boolean isDefaultPaymentRegistered();
}
+80 −35
Original line number Diff line number Diff line
@@ -126,6 +126,11 @@ public final class ApduServiceInfo implements Parcelable {
     */
    private final String mSettingsActivityName;

    /**
     * State of the service for CATEGORY_OTHER selection
     */
    private boolean mOtherServiceSelectionState;

    /**
     * @hide
     */
@@ -133,9 +138,22 @@ public final class ApduServiceInfo implements Parcelable {
            List<AidGroup> staticAidGroups, List<AidGroup> dynamicAidGroups,
            boolean requiresUnlock, int bannerResource, int uid,
            String settingsActivityName, String offHost, String staticOffHost) {
        this(info, onHost, description, staticAidGroups, dynamicAidGroups,
                requiresUnlock, bannerResource, uid, settingsActivityName,
                offHost, staticOffHost, false);
    }

    /**
     * @hide
     */
    public ApduServiceInfo(ResolveInfo info, boolean onHost, String description,
            List<AidGroup> staticAidGroups, List<AidGroup> dynamicAidGroups,
            boolean requiresUnlock, int bannerResource, int uid,
            String settingsActivityName, String offHost, String staticOffHost,
            boolean isSelected) {
        this(info, onHost, description, staticAidGroups, dynamicAidGroups,
                requiresUnlock, onHost ? true : false, bannerResource, uid,
                settingsActivityName, offHost, staticOffHost);
                settingsActivityName, offHost, staticOffHost, isSelected);
    }

    /**
@@ -144,7 +162,7 @@ public final class ApduServiceInfo implements Parcelable {
    public ApduServiceInfo(ResolveInfo info, boolean onHost, String description,
            List<AidGroup> staticAidGroups, List<AidGroup> dynamicAidGroups,
            boolean requiresUnlock, boolean requiresScreenOn, int bannerResource, int uid,
            String settingsActivityName, String offHost, String staticOffHost) {
            String settingsActivityName, String offHost, String staticOffHost, boolean isSelected) {
        this.mService = info;
        this.mDescription = description;
        this.mStaticAidGroups = new HashMap<String, AidGroup>();
@@ -163,6 +181,8 @@ public final class ApduServiceInfo implements Parcelable {
        this.mBannerResourceId = bannerResource;
        this.mUid = uid;
        this.mSettingsActivityName = settingsActivityName;
        this.mOtherServiceSelectionState = isSelected;

    }

    /**
@@ -351,6 +371,9 @@ public final class ApduServiceInfo implements Parcelable {
        }
        // Set uid
        mUid = si.applicationInfo.uid;

        mOtherServiceSelectionState = false;    // support other category

    }

    /**
@@ -720,6 +743,8 @@ public final class ApduServiceInfo implements Parcelable {
        dest.writeInt(mBannerResourceId);
        dest.writeInt(mUid);
        dest.writeString(mSettingsActivityName);

        dest.writeInt(mOtherServiceSelectionState ? 1 : 0);
    };

    @FlaggedApi(Flags.FLAG_ENABLE_NFC_MAINLINE)
@@ -747,9 +772,11 @@ public final class ApduServiceInfo implements Parcelable {
                    int bannerResource = source.readInt();
                    int uid = source.readInt();
                    String settingsActivityName = source.readString();
                    boolean isSelected = source.readInt() != 0;
                    return new ApduServiceInfo(info, onHost, description, staticAidGroups,
                            dynamicAidGroups, requiresUnlock, requiresScreenOn, bannerResource, uid,
                    settingsActivityName, offHostName, staticOffHostName);
                            settingsActivityName, offHostName, staticOffHostName,
                            isSelected);
                }

                @Override
@@ -779,14 +806,16 @@ public final class ApduServiceInfo implements Parcelable {
        }
        pw.println("    Static AID groups:");
        for (AidGroup group : mStaticAidGroups.values()) {
            pw.println("        Category: " + group.getCategory());
            pw.println("        Category: " + group.getCategory()
                    + "(selected: " + mOtherServiceSelectionState + ")");
            for (String aid : group.getAids()) {
                pw.println("            AID: " + aid);
            }
        }
        pw.println("    Dynamic AID groups:");
        for (AidGroup group : mDynamicAidGroups.values()) {
            pw.println("        Category: " + group.getCategory());
            pw.println("        Category: " + group.getCategory()
                    + "(selected: " + mOtherServiceSelectionState + ")");
            for (String aid : group.getAids()) {
                pw.println("            AID: " + aid);
            }
@@ -796,6 +825,22 @@ public final class ApduServiceInfo implements Parcelable {
        pw.println("    Requires Device ScreenOn: " + mRequiresDeviceScreenOn);
    }


    /**
     * @hide
     */
    public void setOtherServiceState(boolean selected) {
        mOtherServiceSelectionState = selected;
    }


    /**
     * @hide
     */
    public boolean isSelectedOtherService() {
        return mOtherServiceSelectionState;
    }

    /**
     * Dump debugging info as ApduServiceInfoProto.
     *
+33 −0
Original line number Diff line number Diff line
@@ -947,6 +947,39 @@ public final class CardEmulation {
        return true;
    }

    /**
     * Allows to set or unset preferred service (category other) to avoid  AID Collision.
     *
     * @param service The ComponentName of the service
     * @param status  true to enable, false to disable
     * @return set service for the category and true if service is already set return false.
     *
     * @hide
     */
    public boolean setServiceEnabledForCategoryOther(ComponentName service, boolean status) {
        if (service == null) {
            throw new NullPointerException("activity or service or category is null");
        }
        int userId = mContext.getUser().getIdentifier();

        try {
            return sService.setServiceEnabledForCategoryOther(userId, service, status);
        } catch (RemoteException e) {
            // Try one more time
            recoverService();
            if (sService == null) {
                Log.e(TAG, "Failed to recover CardEmulationService.");
                return false;
            }
            try {
                return sService.setServiceEnabledForCategoryOther(userId, service, status);
            } catch (RemoteException ee) {
                Log.e(TAG, "Failed to reach CardEmulationService.");
                return false;
            }
        }
    }

    void recoverService() {
        NfcAdapter adapter = NfcAdapter.getDefaultAdapter(mContext);
        sService = adapter.getCardEmulationService();