Home | History | Annotate | Download | only in svc
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.commands.svc;
     18 
     19 import android.content.Context;
     20 import android.nfc.INfcAdapter;
     21 import android.os.RemoteException;
     22 import android.os.ServiceManager;
     23 
     24 public class NfcCommand extends Svc.Command {
     25 
     26     public NfcCommand() {
     27         super("nfc");
     28     }
     29 
     30     @Override
     31     public String shortHelp() {
     32         return "Control NFC functions";
     33     }
     34 
     35     @Override
     36     public String longHelp() {
     37         return shortHelp() + "\n"
     38                 + "\n"
     39                 + "usage: svc nfc [enable|disable]\n"
     40                 + "         Turn NFC on or off.\n\n";
     41     }
     42 
     43     @Override
     44     public void run(String[] args) {
     45         INfcAdapter adapter = INfcAdapter.Stub.asInterface(
     46                 ServiceManager.getService(Context.NFC_SERVICE));
     47 
     48         if (adapter == null) {
     49             System.err.println("Got a null NfcAdapter, is the system running?");
     50             return;
     51         }
     52 
     53         try {
     54             if (args.length == 2 && "enable".equals(args[1])) {
     55                 adapter.enable();
     56                 return;
     57             } else if (args.length == 2 && "disable".equals(args[1])) {
     58                 adapter.disable(true);
     59                 return;
     60             }
     61         } catch (RemoteException e) {
     62             System.err.println("NFC operation failed: " + e);
     63             return;
     64         }
     65 
     66         System.err.println(longHelp());
     67     }
     68 
     69 }
     70