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

Commit 7e359a70 authored by Alisher Alikhodjaev's avatar Alisher Alikhodjaev Committed by Gerrit Code Review
Browse files

Merge "Implement NfcServiceManager and NfcFrameworkInitializer"

parents 917ae5dc 08b7d527
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -5416,6 +5416,8 @@ android.nfc.NfcAdapter$CreateNdefMessageCallback
android.nfc.NfcAdapter
android.nfc.NfcControllerAlwaysOnListener
android.nfc.NfcManager
android.nfc.NfcServiceManager$ServiceRegisterer
android.nfc.NfcServiceManager
android.nfc.Tag$1
android.nfc.Tag
android.nfc.TechListParcel$1
+24 −0
Original line number Diff line number Diff line
@@ -297,6 +297,30 @@ package android.net.netstats {

}

package android.nfc {

  public class NfcFrameworkInitializer {
    method public static void registerServiceWrappers();
    method public static void setNfcServiceManager(@NonNull android.nfc.NfcServiceManager);
  }

  public class NfcServiceManager {
    method @NonNull public android.nfc.NfcServiceManager.ServiceRegisterer getNfcManagerServiceRegisterer();
  }

  public static class NfcServiceManager.ServiceNotFoundException extends java.lang.Exception {
    ctor public NfcServiceManager.ServiceNotFoundException(@NonNull String);
  }

  public static final class NfcServiceManager.ServiceRegisterer {
    method @Nullable public android.os.IBinder get();
    method @NonNull public android.os.IBinder getOrThrow() throws android.nfc.NfcServiceManager.ServiceNotFoundException;
    method public void register(@NonNull android.os.IBinder);
    method @Nullable public android.os.IBinder tryGet();
  }

}

package android.os {

  public final class BatteryStatsManager {
+3 −0
Original line number Diff line number Diff line
@@ -109,6 +109,8 @@ import android.net.ConnectivityManager;
import android.net.Proxy;
import android.net.TrafficStats;
import android.net.Uri;
import android.nfc.NfcFrameworkInitializer;
import android.nfc.NfcServiceManager;
import android.os.AsyncTask;
import android.os.Binder;
import android.os.BluetoothServiceManager;
@@ -7908,6 +7910,7 @@ public final class ActivityThread extends ClientTransactionHandler
        BluetoothFrameworkInitializer.setBluetoothServiceManager(new BluetoothServiceManager());
        BluetoothFrameworkInitializer.setBinderCallsStatsInitializer(context -> {
            BinderCallsStats.startForBluetooth(context); });
        NfcFrameworkInitializer.setNfcServiceManager(new NfcServiceManager());
    }

    private void purgePendingResources() {
+2 −8
Original line number Diff line number Diff line
@@ -148,7 +148,7 @@ import android.net.vcn.IVcnManagementService;
import android.net.vcn.VcnManager;
import android.net.wifi.WifiFrameworkInitializer;
import android.net.wifi.nl80211.WifiNl80211Manager;
import android.nfc.NfcManager;
import android.nfc.NfcFrameworkInitializer;
import android.ondevicepersonalization.OnDevicePersonalizationFrameworkInitializer;
import android.os.BatteryManager;
import android.os.BatteryStats;
@@ -457,13 +457,6 @@ public final class SystemServiceRegistry {
                return new BatteryManager(ctx, stats, registrar);
            }});

        registerService(Context.NFC_SERVICE, NfcManager.class,
                new CachedServiceFetcher<NfcManager>() {
            @Override
            public NfcManager createService(ContextImpl ctx) {
                return new NfcManager(ctx);
            }});

        registerService(Context.DROPBOX_SERVICE, DropBoxManager.class,
                new CachedServiceFetcher<DropBoxManager>() {
            @Override
@@ -1514,6 +1507,7 @@ public final class SystemServiceRegistry {
            JobSchedulerFrameworkInitializer.registerServiceWrappers();
            BlobStoreManagerFrameworkInitializer.initialize();
            BluetoothFrameworkInitializer.registerServiceWrappers();
            NfcFrameworkInitializer.registerServiceWrappers();
            TelephonyFrameworkInitializer.registerServiceWrappers();
            AppSearchManagerFrameworkInitializer.initialize();
            WifiFrameworkInitializer.registerServiceWrappers();
+14 −7
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;

import java.io.IOException;
@@ -424,6 +423,7 @@ public final class NfcAdapter {
    // recovery
    @UnsupportedAppUsage
    static INfcAdapter sService;
    static NfcServiceManager.ServiceRegisterer sServiceRegisterer;
    static INfcTag sTagService;
    static INfcCardEmulation sCardEmulationService;
    static INfcFCardEmulation sNfcFCardEmulationService;
@@ -622,6 +622,12 @@ public final class NfcAdapter {
                Log.v(TAG, "this device does not have NFC support");
                throw new UnsupportedOperationException();
            }
            NfcServiceManager manager = NfcFrameworkInitializer.getNfcServiceManager();
            if (manager == null) {
                Log.e(TAG, "NfcServiceManager is null");
                throw new UnsupportedOperationException();
            }
            sServiceRegisterer = manager.getNfcManagerServiceRegisterer();
            sService = getServiceInterface();
            if (sService == null) {
                Log.e(TAG, "could not retrieve NFC service");
@@ -663,7 +669,7 @@ public final class NfcAdapter {
    /** get handle to NFC service interface */
    private static INfcAdapter getServiceInterface() {
        /* get a handle to NFC service */
        IBinder b = ServiceManager.getService("nfc");
        IBinder b = sServiceRegisterer.get();
        if (b == null) {
            return null;
        }
@@ -693,12 +699,13 @@ public final class NfcAdapter {
                    "context not associated with any application (using a mock context?)");
        }

        if (getServiceInterface() == null) {
            // NFC is not available
            return null;
        if (sIsInitialized && sServiceRegisterer.tryGet() == null) {
            synchronized (NfcAdapter.class) {
                /* Stale sService pointer */
                if (sIsInitialized) sIsInitialized = false;
            }

        /* use getSystemService() for consistency */
        }
        /* Try to initialize the service */
        NfcManager manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
        if (manager == null) {
            // NFC not available
Loading