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

Commit 8a470ae1 authored by Roshan Pius's avatar Roshan Pius Committed by Automerger Merge Worker
Browse files

Merge "svc(nfc): Use NfcAdapter API to enable/disable" into main am:...

Merge "svc(nfc): Use NfcAdapter API to enable/disable" into main am: 6285b216 am: a5112d4e am: a06cea1c

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



Change-Id: I2d5f7257deadeebed9a40e797195ace16d99319a
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 85bd8746 a06cea1c
Loading
Loading
Loading
Loading
+15 −18
Original line number Original line Diff line number Diff line
@@ -16,10 +16,10 @@


package com.android.commands.svc;
package com.android.commands.svc;


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


public class NfcCommand extends Svc.Command {
public class NfcCommand extends Svc.Command {


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


    @Override
    @Override
    public void run(String[] args) {
    public void run(String[] args) {
        INfcAdapter adapter = INfcAdapter.Stub.asInterface(
        Context context = ActivityThread.systemMain().getSystemContext();
                ServiceManager.getService(Context.NFC_SERVICE));
        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) {
        if (adapter == null) {
            System.err.println("Got a null NfcAdapter, is the system running?");
            System.err.println("Got a null NfcAdapter, is the system running?");
            return;
            return;
        }
        }

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

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