1 /*
2  * Copyright (C) 2017 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.bluetooth.BluetoothAdapter;
20 import android.os.RemoteException;
21 
22 public class BluetoothCommand extends Svc.Command {
23 
BluetoothCommand()24     public BluetoothCommand() {
25         super("bluetooth");
26     }
27 
28     @Override
shortHelp()29     public String shortHelp() {
30         return "Control Bluetooth service";
31     }
32 
33     @Override
longHelp()34     public String longHelp() {
35         return shortHelp() + "\n"
36                 + "\n"
37                 + "usage: svc bluetooth [enable|disable]\n"
38                 + "         Turn Bluetooth on or off.\n\n";
39     }
40 
41     @Override
run(String[] args)42     public void run(String[] args) {
43         BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
44 
45         if (adapter == null) {
46             System.err.println("Got a null BluetoothAdapter, is the system running?");
47             return;
48         }
49 
50         if (args.length == 2 && "enable".equals(args[1])) {
51             adapter.enable();
52         } else if (args.length == 2 && "disable".equals(args[1])) {
53             adapter.disable();
54         } else {
55             System.err.println(longHelp());
56         }
57     }
58 }
59