Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Merge "Revert "svc(nfc): Use NfcAdapter API to enable/disable"" into …
Browse files Browse the repository at this point in the history
…main
  • Loading branch information
rpius authored and Gerrit Code Review committed Oct 23, 2023
2 parents 867815f + 8140652 commit 47be3bb
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions cmds/svc/src/com/android/commands/svc/NfcCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package com.android.commands.svc;

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

public class NfcCommand extends Svc.Command {

Expand All @@ -42,24 +42,27 @@ public String longHelp() {

@Override
public void run(String[] args) {
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();
INfcAdapter adapter = INfcAdapter.Stub.asInterface(
ServiceManager.getService(Context.NFC_SERVICE));

if (adapter == null) {
System.err.println("Got a null NfcAdapter, is the system running?");
return;
}
if (args.length == 2 && "enable".equals(args[1])) {
adapter.enable();
return;
} else if (args.length == 2 && "disable".equals(args[1])) {
adapter.disable(true);

try {
if (args.length == 2 && "enable".equals(args[1])) {
adapter.enable();
return;
} else if (args.length == 2 && "disable".equals(args[1])) {
adapter.disable(true);
return;
}
} catch (RemoteException e) {
System.err.println("NFC operation failed: " + e);
return;
}

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

Expand Down

0 comments on commit 47be3bb

Please sign in to comment.