Skip to content
Snippets Groups Projects
Commit dba2b42c authored by Roshan Pius's avatar Roshan Pius
Browse files

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

This reverts commit 8140652e.

Reason for revert: Added a fix for the failing code.

Change-Id: I729672340d52a745dd43121e1dbedf9d6d5ec34a
parent 47be3bb6
No related branches found
No related tags found
No related merge requests found
......@@ -16,10 +16,11 @@
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;
import android.os.Looper;
public class NfcCommand extends Svc.Command {
......@@ -42,27 +43,26 @@ public class NfcCommand extends Svc.Command {
@Override
public void run(String[] args) {
INfcAdapter adapter = INfcAdapter.Stub.asInterface(
ServiceManager.getService(Context.NFC_SERVICE));
Looper.prepareMainLooper();
ActivityThread.initializeMainlineModules();
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;
} else if (args.length == 2 && "disable".equals(args[1])) {
adapter.disable(true);
return;
}
} catch (RemoteException e) {
System.err.println("NFC operation failed: " + e);
if (args.length == 2 && "enable".equals(args[1])) {
adapter.enable();
return;
} else if (args.length == 2 && "disable".equals(args[1])) {
adapter.disable(true);
return;
}
System.err.println(longHelp());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment