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

Commit a7397883 authored by Martijn Coenen's avatar Martijn Coenen
Browse files

NFC: Host-based card emulation APIs.

- New INfcCardEmulation interface to allow apps to interface
  with card emulation system.
- New BIND_NFC_SERVICE permission to prevent malicious apps
  from binding to card emulation services.
- ApduServiceInfo is now in the framework.
- Added constants to Settings.Secure for storing defaults.
- Modified XML grammar a bit.

Change-Id: I56b3fa6b42eb5dc132c91c1386ab1e6bac779059
parent d8501485
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -143,6 +143,7 @@ LOCAL_SRC_FILES += \
	core/java/android/nfc/INfcAdapter.aidl \
	core/java/android/nfc/INfcAdapterExtras.aidl \
	core/java/android/nfc/INfcTag.aidl \
	core/java/android/nfc/INfcCardEmulation.aidl \
	core/java/android/os/IBatteryPropertiesListener.aidl \
	core/java/android/os/IBatteryPropertiesRegistrar.aidl \
	core/java/android/os/ICancellationSignal.aidl \
+13 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ package android {
    field public static final java.lang.String BIND_APPWIDGET = "android.permission.BIND_APPWIDGET";
    field public static final java.lang.String BIND_DEVICE_ADMIN = "android.permission.BIND_DEVICE_ADMIN";
    field public static final java.lang.String BIND_INPUT_METHOD = "android.permission.BIND_INPUT_METHOD";
    field public static final java.lang.String BIND_NFC_SERVICE = "android.permission.BIND_NFC_SERVICE";
    field public static final java.lang.String BIND_NOTIFICATION_LISTENER_SERVICE = "android.permission.BIND_NOTIFICATION_LISTENER_SERVICE";
    field public static final java.lang.String BIND_PRINT_SERVICE = "android.permission.BIND_PRINT_SERVICE";
    field public static final java.lang.String BIND_REMOTEVIEWS = "android.permission.BIND_REMOTEVIEWS";
@@ -14785,6 +14786,18 @@ package android.nfc {
package android.nfc.cardemulation {
  public final class CardEmulationManager {
    method public static synchronized android.nfc.cardemulation.CardEmulationManager getInstance(android.nfc.NfcAdapter);
    method public boolean isDefaultServiceForAid(android.content.ComponentName, java.lang.String);
    method public boolean isDefaultServiceForCategory(android.content.ComponentName, java.lang.String);
    method public boolean setDefaultServiceForCategory(android.content.ComponentName, java.lang.String);
    field public static final java.lang.String ACTION_CHANGE_DEFAULT = "android.nfc.cardemulation.ACTION_CHANGE_DEFAULT";
    field public static final java.lang.String CATEGORY_OTHER = "other";
    field public static final java.lang.String CATEGORY_PAYMENT = "payment";
    field public static final java.lang.String EXTRA_CATEGORY = "category";
    field public static final java.lang.String EXTRA_SERVICE_COMPONENT = "component";
  }
  public abstract class HostApduService extends android.app.Service {
    ctor public HostApduService();
    method public final android.os.IBinder onBind(android.content.Intent);
+2 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.nfc.TechListParcel;
import android.nfc.INdefPushCallback;
import android.nfc.INfcAdapterExtras;
import android.nfc.INfcTag;
import android.nfc.INfcCardEmulation;

/**
 * @hide
@@ -31,6 +32,7 @@ import android.nfc.INfcTag;
interface INfcAdapter
{
    INfcTag getNfcTagInterface();
    INfcCardEmulation getNfcCardEmulationInterface();
    INfcAdapterExtras getNfcAdapterExtrasInterface(in String pkg);

    int getState();
+32 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.nfc;

import android.content.ComponentName;
import android.nfc.cardemulation.ApduServiceInfo;
import android.os.RemoteCallback;

/**
 * @hide
 */
interface INfcCardEmulation
{
    boolean isDefaultServiceForCategory(int userHandle, in ComponentName service, String category);
    boolean isDefaultServiceForAid(int userHandle, in ComponentName service, String aid);
    boolean setDefaultServiceForCategory(int userHandle, in ComponentName service, String category);
    List<ApduServiceInfo> getServices(int userHandle, in String category);
}
+24 −0
Original line number Diff line number Diff line
@@ -227,6 +227,7 @@ public final class NfcAdapter {
    // recovery
    static INfcAdapter sService;
    static INfcTag sTagService;
    static INfcCardEmulation sCardEmulationService;

    /**
     * The NfcAdapter object for each application context.
@@ -348,6 +349,13 @@ public final class NfcAdapter {
                throw new UnsupportedOperationException();
            }

            try {
                sCardEmulationService = sService.getNfcCardEmulationInterface();
            } catch (RemoteException e) {
                Log.e(TAG, "could not retrieve card emulation service");
                throw new UnsupportedOperationException();
            }

            sIsInitialized = true;
        }
        if (context == null) {
@@ -455,6 +463,15 @@ public final class NfcAdapter {
        return sTagService;
    }

    /**
     * Returns the binder interface to the card emulation service.
     * @hide
     */
    public INfcCardEmulation getCardEmulationService() {
        isEnabled();
        return sCardEmulationService;
    }

    /**
     * NFC service dead - attempt best effort recovery
     * @hide
@@ -477,6 +494,13 @@ public final class NfcAdapter {
            Log.e(TAG, "could not retrieve NFC tag service during service recovery");
            // nothing more can be done now, sService is still stale, we'll hit
            // this recovery path again later
            return;
        }

        try {
            sCardEmulationService = service.getNfcCardEmulationInterface();
        } catch (RemoteException ee) {
            Log.e(TAG, "could not retrieve NFC card emulation service during service recovery");
        }

        return;
Loading