1/* 2 * Copyright (C) 2008 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 17package com.android.commands.svc; 18 19import android.os.ServiceManager; 20import android.os.RemoteException; 21import android.net.wifi.IWifiManager; 22import android.content.Context; 23 24public class WifiCommand extends Svc.Command { 25 public WifiCommand() { 26 super("wifi"); 27 } 28 29 public String shortHelp() { 30 return "Control the Wi-Fi manager"; 31 } 32 33 public String longHelp() { 34 return shortHelp() + "\n" 35 + "\n" 36 + "usage: svc wifi [enable|disable]\n" 37 + " Turn Wi-Fi on or off.\n\n"; 38 } 39 40 public void run(String[] args) { 41 boolean validCommand = false; 42 if (args.length >= 2) { 43 boolean flag = false; 44 if ("enable".equals(args[1])) { 45 flag = true; 46 validCommand = true; 47 } else if ("disable".equals(args[1])) { 48 flag = false; 49 validCommand = true; 50 } 51 if (validCommand) { 52 IWifiManager wifiMgr 53 = IWifiManager.Stub.asInterface(ServiceManager.getService(Context.WIFI_SERVICE)); 54 try { 55 wifiMgr.setWifiEnabled(flag); 56 } 57 catch (RemoteException e) { 58 System.err.println("Wi-Fi operation failed: " + e); 59 } 60 return; 61 } 62 } 63 System.err.println(longHelp()); 64 } 65} 66