SystemUIService.java revision cd686b5b6d4166b510df8e32138479a9559bc117
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.Intent;
24import android.content.res.Configuration;
25import android.os.IBinder;
26import android.os.RemoteException;
27import android.util.Log;
28import android.view.IWindowManager;
29import android.view.WindowManagerGlobal;
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            0, // system bar or status bar, filled in below.
39            com.android.systemui.power.PowerUI.class,
40            com.android.systemui.media.RingtonePlayer.class,
41            com.android.systemui.settings.SettingsUI.class,
42        };
43
44    /**
45     * Hold a reference on the stuff we start.
46     */
47    SystemUI[] mServices;
48
49    private Class chooseClass(Object o) {
50        if (o instanceof Integer) {
51            final String cl = getString((Integer)o);
52            try {
53                return getClassLoader().loadClass(cl);
54            } catch (ClassNotFoundException ex) {
55                throw new RuntimeException(ex);
56            }
57        } else if (o instanceof Class) {
58            return (Class)o;
59        } else {
60            throw new RuntimeException("Unknown system ui service: " + o);
61        }
62    }
63
64    @Override
65    public void onCreate() {
66        // Pick status bar or system bar.
67        IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
68        try {
69            SERVICES[0] = wm.hasSystemNavBar()
70                    ? R.string.config_systemBarComponent
71                    : R.string.config_statusBarComponent;
72        } catch (RemoteException e) {
73            Log.w(TAG, "Failing checking whether status bar can hide", e);
74        }
75
76        final int N = SERVICES.length;
77        mServices = new SystemUI[N];
78        for (int i=0; i<N; i++) {
79            Class cl = chooseClass(SERVICES[i]);
80            Log.d(TAG, "loading: " + cl);
81            try {
82                mServices[i] = (SystemUI)cl.newInstance();
83            } catch (IllegalAccessException ex) {
84                throw new RuntimeException(ex);
85            } catch (InstantiationException ex) {
86                throw new RuntimeException(ex);
87            }
88            mServices[i].mContext = this;
89            Log.d(TAG, "running: " + mServices[i]);
90            mServices[i].start();
91        }
92    }
93
94    @Override
95    public void onConfigurationChanged(Configuration newConfig) {
96        for (SystemUI ui: mServices) {
97            ui.onConfigurationChanged(newConfig);
98        }
99    }
100
101    /**
102     * Nobody binds to us.
103     */
104    @Override
105    public IBinder onBind(Intent intent) {
106        return null;
107    }
108
109    @Override
110    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
111        if (args == null || args.length == 0) {
112            for (SystemUI ui: mServices) {
113                pw.println("dumping service: " + ui.getClass().getName());
114                ui.dump(fd, pw, args);
115            }
116        } else {
117            String svc = args[0];
118            for (SystemUI ui: mServices) {
119                String name = ui.getClass().getName();
120                if (name.endsWith(svc)) {
121                    ui.dump(fd, pw, args);
122                }
123            }
124        }
125    }
126}
127
128