blob: 427fe91740bf94e2c3b6da9a3d12fa7ffa851584 [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,
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040047 };
48
49 /**
50 * Hold a reference on the stuff we start.
51 */
52 SystemUI[] mServices;
53
54 private Class chooseClass(Object o) {
55 if (o instanceof Integer) {
56 final String cl = getString((Integer)o);
57 try {
58 return getClassLoader().loadClass(cl);
59 } catch (ClassNotFoundException ex) {
60 throw new RuntimeException(ex);
61 }
62 } else if (o instanceof Class) {
63 return (Class)o;
64 } else {
65 throw new RuntimeException("Unknown system ui service: " + o);
66 }
67 }
68
69 @Override
70 public void onCreate() {
Svetoslav Ganov58d37b52012-09-18 12:04:19 -070071 // Tell the accessibility layer that this process will
72 // run as the current user, i.e. run across users.
73 AccessibilityManager.createAsSharedAcrossUsers(this);
74
Dianne Hackborn81e56d52011-05-26 00:55:58 -070075 // Pick status bar or system bar.
Jeff Brown98365d72012-08-19 20:30:52 -070076 IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
Dianne Hackborn81e56d52011-05-26 00:55:58 -070077 try {
Dianne Hackbornf87d1962012-04-04 12:48:24 -070078 SERVICES[0] = wm.hasSystemNavBar()
79 ? R.string.config_systemBarComponent
80 : R.string.config_statusBarComponent;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070081 } catch (RemoteException e) {
82 Slog.w(TAG, "Failing checking whether status bar can hide", e);
83 }
84
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040085 final int N = SERVICES.length;
86 mServices = new SystemUI[N];
87 for (int i=0; i<N; i++) {
88 Class cl = chooseClass(SERVICES[i]);
89 Slog.d(TAG, "loading: " + cl);
90 try {
91 mServices[i] = (SystemUI)cl.newInstance();
92 } catch (IllegalAccessException ex) {
93 throw new RuntimeException(ex);
94 } catch (InstantiationException ex) {
95 throw new RuntimeException(ex);
96 }
97 mServices[i].mContext = this;
98 Slog.d(TAG, "running: " + mServices[i]);
99 mServices[i].start();
100 }
101 }
102
Daniel Sandler0ad460b2010-12-14 12:14:53 -0500103 @Override
104 public void onConfigurationChanged(Configuration newConfig) {
105 for (SystemUI ui: mServices) {
106 ui.onConfigurationChanged(newConfig);
107 }
108 }
109
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400110 /**
111 * Nobody binds to us.
112 */
113 @Override
114 public IBinder onBind(Intent intent) {
115 return null;
116 }
117
118 @Override
119 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Joe Onorato10523b4d2010-10-25 10:42:46 -0700120 if (args == null || args.length == 0) {
121 for (SystemUI ui: mServices) {
122 pw.println("dumping service: " + ui.getClass().getName());
123 ui.dump(fd, pw, args);
124 }
125 } else {
126 String svc = args[0];
127 for (SystemUI ui: mServices) {
128 String name = ui.getClass().getName();
129 if (name.endsWith(svc)) {
130 ui.dump(fd, pw, args);
131 }
132 }
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400133 }
134 }
135}
136