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.content.Context;
22import com.android.internal.telephony.ITelephony;
23
24public class DataCommand extends Svc.Command {
25    public DataCommand() {
26        super("data");
27    }
28
29    public String shortHelp() {
30        return "Control mobile data connectivity";
31    }
32
33    public String longHelp() {
34        return shortHelp() + "\n"
35                + "\n"
36                + "usage: svc data [enable|disable]\n"
37                + "         Turn mobile data 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                ITelephony phoneMgr
53                        = ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE));
54                try {
55                    if (flag) {
56                        phoneMgr.enableDataConnectivity();
57                    } else
58                        phoneMgr.disableDataConnectivity();
59                }
60                catch (RemoteException e) {
61                    System.err.println("Mobile data operation failed: " + e);
62                }
63                return;
64            }
65        }
66        System.err.println(longHelp());
67    }
68}
69