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

Commit 12058cb9 authored by Roshan Pius's avatar Roshan Pius
Browse files

svc(nfc): Use NfcAdapter API to enable/disable

Bug: 303286040
Test: adb shell svc nfc enable
Change-Id: I678d01c7c86defb7eb071d66cb2aede4983ab506
parent 5ed8f129
Loading
Loading
Loading
Loading
+15 −18
Original line number Diff line number Diff line
@@ -16,10 +16,10 @@

package com.android.commands.svc;

import android.app.ActivityThread;
import android.content.Context;
import android.nfc.INfcAdapter;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.nfc.NfcAdapter;
import android.nfc.NfcManager;

public class NfcCommand extends Svc.Command {

@@ -42,15 +42,17 @@ public class NfcCommand extends Svc.Command {

    @Override
    public void run(String[] args) {
        INfcAdapter adapter = INfcAdapter.Stub.asInterface(
                ServiceManager.getService(Context.NFC_SERVICE));

        Context context = ActivityThread.systemMain().getSystemContext();
        NfcManager nfcManager = context.getSystemService(NfcManager.class);
        if (nfcManager == null) {
            System.err.println("Got a null NfcManager, is the system running?");
            return;
        }
        NfcAdapter adapter = nfcManager.getDefaultAdapter();
        if (adapter == null) {
            System.err.println("Got a null NfcAdapter, is the system running?");
            return;
        }

        try {
        if (args.length == 2 && "enable".equals(args[1])) {
            adapter.enable();
            return;
@@ -58,11 +60,6 @@ public class NfcCommand extends Svc.Command {
            adapter.disable(true);
            return;
        }
        } catch (RemoteException e) {
            System.err.println("NFC operation failed: " + e);
            return;
        }

        System.err.println(longHelp());
    }