blob: 1f3e942ae21a98c299e17650151a02f0253bfc60 [file] [log] [blame]
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001/*
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;
Daniel Sandler0ad460b2010-12-14 12:14:53 -050027import android.content.res.Configuration;
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040028import android.os.Binder;
29import android.os.IBinder;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070030import android.os.RemoteException;
31import android.os.ServiceManager;
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040032import android.util.Slog;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070033import android.view.IWindowManager;
Jeff Brown98365d72012-08-19 20:30:52 -070034import android.view.WindowManagerGlobal;
Svetoslav Ganov58d37b52012-09-18 12:04:19 -070035import android.view.accessibility.AccessibilityManager;
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040036
37public class SystemUIService extends Service {
38 static final String TAG = "SystemUIService";
39
40 /**
41 * The class names of the stuff to start.
42 */
43 final Object[] SERVICES = new Object[] {
Dianne Hackborn81e56d52011-05-26 00:55:58 -070044 0, // system bar or status bar, filled in below.
Joe Onorato10523b4d2010-10-25 10:42:46 -070045 com.android.systemui.power.PowerUI.class,
Jeff Sharkey098d5802012-04-26 17:30:34 -070046 com.android.systemui.media.RingtonePlayer.class,
Michael Wright0087a142013-02-05 16:29:39 -080047 com.android.systemui.settings.SettingsUI.class,
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040048 };
49
50 /**
51 * Hold a reference on the stuff we start.
52 */
53 SystemUI[] mServices;
54
55 private Class chooseClass(Object o) {
56 if (o instanceof Integer) {
57 final String cl = getString((Integer)o);
58 try {
59 return getClassLoader().loadClass(cl);
60 } catch (ClassNotFoundException ex) {
61 throw new RuntimeException(ex);
62 }
63 } else if (o instanceof Class) {
64 return (Class)o;
65 } else {
66 throw new RuntimeException("Unknown system ui service: " + o);
67 }
68 }
69
70 @Override
71 public void onCreate() {
Svetoslav Ganov58d37b52012-09-18 12:04:19 -070072 // Tell the accessibility layer that this process will
73 // run as the current user, i.e. run across users.
74 AccessibilityManager.createAsSharedAcrossUsers(this);
75
Dianne Hackborn81e56d52011-05-26 00:55:58 -070076 // Pick status bar or system bar.
Jeff Brown98365d72012-08-19 20:30:52 -070077 IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
Dianne Hackborn81e56d52011-05-26 00:55:58 -070078 try {
Dianne Hackbornf87d1962012-04-04 12:48:24 -070079 SERVICES[0] = wm.hasSystemNavBar()
80 ? R.string.config_systemBarComponent
81 : R.string.config_statusBarComponent;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070082 } catch (RemoteException e) {
83 Slog.w(TAG, "Failing checking whether status bar can hide", e);
84 }
85
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040086 final int N = SERVICES.length;
87 mServices = new SystemUI[N];
88 for (int i=0; i<N; i++) {
89 Class cl = chooseClass(SERVICES[i]);
90 Slog.d(TAG, "loading: " + cl);
91 try {
92 mServices[i] = (SystemUI)cl.newInstance();
93 } catch (IllegalAccessException ex) {
94 throw new RuntimeException(ex);
95 } catch (InstantiationException ex) {
96 throw new RuntimeException(ex);
97 }
98 mServices[i].mContext = this;
99 Slog.d(TAG, "running: " + mServices[i]);
100 mServices[i].start();
101 }
102 }
103
Daniel Sandler0ad460b2010-12-14 12:14:53 -0500104 @Override
105 public void onConfigurationChanged(Configuration newConfig) {
106 for (SystemUI ui: mServices) {
107 ui.onConfigurationChanged(newConfig);
108 }
109 }
110
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400111 /**
112 * Nobody binds to us.
113 */
114 @Override
115 public IBinder onBind(Intent intent) {
116 return null;
117 }
118
119 @Override
120 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Joe Onorato10523b4d2010-10-25 10:42:46 -0700121 if (args == null || args.length == 0) {
122 for (SystemUI ui: mServices) {
123 pw.println("dumping service: " + ui.getClass().getName());
124 ui.dump(fd, pw, args);
125 }
126 } else {
127 String svc = args[0];
128 for (SystemUI ui: mServices) {
129 String name = ui.getClass().getName();
130 if (name.endsWith(svc)) {
131 ui.dump(fd, pw, args);
132 }
133 }
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400134 }
135 }
136}
137