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