SystemUIService.java revision 10523b4d0c99cec86647130426d470a1e02a44f6
1/*
2 * Copyright (C) 2010 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.systemui;
18
19import java.io.FileDescriptor;
20import java.io.PrintWriter;
21
22import android.app.Service;
23import android.content.BroadcastReceiver;
24import android.content.Context;
25import android.content.Intent;
26import android.content.pm.PackageManager;
27import android.os.Binder;
28import android.os.IBinder;
29import android.util.Slog;
30
31public class SystemUIService extends Service {
32    static final String TAG = "SystemUIService";
33
34    /**
35     * The class names of the stuff to start.
36     */
37    final Object[] SERVICES = new Object[] {
38            R.string.config_statusBarComponent,
39            com.android.systemui.power.PowerUI.class,
40        };
41
42    /**
43     * Hold a reference on the stuff we start.
44     */
45    SystemUI[] mServices;
46
47    private Class chooseClass(Object o) {
48        if (o instanceof Integer) {
49            final String cl = getString((Integer)o);
50            try {
51                return getClassLoader().loadClass(cl);
52            } catch (ClassNotFoundException ex) {
53                throw new RuntimeException(ex);
54            }
55        } else if (o instanceof Class) {
56            return (Class)o;
57        } else {
58            throw new RuntimeException("Unknown system ui service: " + o);
59        }
60    }
61
62    @Override
63    public void onCreate() {
64        final int N = SERVICES.length;
65        mServices = new SystemUI[N];
66        for (int i=0; i<N; i++) {
67            Class cl = chooseClass(SERVICES[i]);
68            Slog.d(TAG, "loading: " + cl);
69            try {
70                mServices[i] = (SystemUI)cl.newInstance();
71            } catch (IllegalAccessException ex) {
72                throw new RuntimeException(ex);
73            } catch (InstantiationException ex) {
74                throw new RuntimeException(ex);
75            }
76            mServices[i].mContext = this;
77            Slog.d(TAG, "running: " + mServices[i]);
78            mServices[i].start();
79        }
80    }
81
82    /**
83     * Nobody binds to us.
84     */
85    @Override
86    public IBinder onBind(Intent intent) {
87        return null;
88    }
89
90    @Override
91    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
92        if (checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
93                != PackageManager.PERMISSION_GRANTED) {
94            pw.println("Permission Denial: can't dump StatusBar from from pid="
95                    + Binder.getCallingPid()
96                    + ", uid=" + Binder.getCallingUid());
97            return;
98        }
99
100        if (args == null || args.length == 0) {
101            for (SystemUI ui: mServices) {
102                pw.println("dumping service: " + ui.getClass().getName());
103                ui.dump(fd, pw, args);
104            }
105        } else {
106            String svc = args[0];
107            for (SystemUI ui: mServices) {
108                String name = ui.getClass().getName();
109                if (name.endsWith(svc)) {
110                    ui.dump(fd, pw, args);
111                }
112            }
113        }
114    }
115}
116
117