1/*
2 * Copyright (C) 2012 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.internal.telephony;
18
19import android.util.Log;
20
21import java.io.FileDescriptor;
22import java.io.PrintWriter;
23
24/**
25 * A debug service that will dump telephony's state
26 *
27 * Currently this "Service" has a proxy in the phone app
28 * com.android.phone.TelephonyDebugService which actually
29 * invokes the dump method.
30 */
31public class DebugService {
32    private static String TAG = "DebugService";
33
34    /** Constructor */
35    public DebugService() {
36        log("DebugService:");
37    }
38
39    /**
40     * Dump the state of various objects, add calls to other objects as desired.
41     */
42    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
43        log("dump: +");
44        PhoneProxy phoneProxy = null;
45        PhoneBase phoneBase = null;
46
47        try {
48            phoneProxy = (PhoneProxy) PhoneFactory.getDefaultPhone();
49        } catch (Exception e) {
50            pw.println("Telephony DebugService: Could not getDefaultPhone e=" + e);
51            return;
52        }
53        try {
54            phoneBase = (PhoneBase)phoneProxy.getActivePhone();
55        } catch (Exception e) {
56            pw.println("Telephony DebugService: Could not PhoneBase e=" + e);
57            return;
58        }
59
60        /**
61         * Surround each of the sub dump's with try/catch so even
62         * if one fails we'll be able to dump the next ones.
63         */
64        pw.println();
65        pw.println("++++++++++++++++++++++++++++++++");
66        pw.flush();
67        try {
68            phoneBase.dump(fd, pw, args);
69        } catch (Exception e) {
70            e.printStackTrace();
71        }
72        pw.flush();
73        pw.println("++++++++++++++++++++++++++++++++");
74        try {
75            phoneBase.mDataConnectionTracker.dump(fd, pw, args);
76        } catch (Exception e) {
77            e.printStackTrace();
78        }
79        pw.flush();
80        pw.println("++++++++++++++++++++++++++++++++");
81        try {
82            phoneBase.getServiceStateTracker().dump(fd, pw, args);
83        } catch (Exception e) {
84            e.printStackTrace();
85        }
86        pw.flush();
87        pw.println("++++++++++++++++++++++++++++++++");
88        try {
89            phoneBase.getCallTracker().dump(fd, pw, args);
90        } catch (Exception e) {
91            e.printStackTrace();
92        }
93        pw.flush();
94        pw.println("++++++++++++++++++++++++++++++++");
95        try {
96            ((RIL)phoneBase.mCM).dump(fd, pw, args);
97        } catch (Exception e) {
98            e.printStackTrace();
99        }
100        pw.flush();
101        pw.println("++++++++++++++++++++++++++++++++");
102        log("dump: -");
103    }
104
105    private static void log(String s) {
106        Log.d(TAG, "DebugService " + s);
107    }
108}
109