blob: 043b64c77862407645563a4d53c9647c9b2988a5 [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
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040019import android.app.Service;
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040020import android.content.Intent;
Daniel Sandler0ad460b2010-12-14 12:14:53 -050021import android.content.res.Configuration;
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040022import android.os.IBinder;
John Spurlockcd686b52013-06-05 10:13:46 -040023import android.util.Log;
John Spurlockb0e49fc2013-06-12 15:50:50 -040024
25import java.io.FileDescriptor;
26import java.io.PrintWriter;
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040027
John Spurlockde84f0e2013-06-12 12:41:00 -040028import java.io.FileDescriptor;
29import java.io.PrintWriter;
30
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040031public 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[] {
John Spurlockb0e49fc2013-06-12 15:50:50 -040038 R.string.config_statusBarComponent,
Joe Onorato10523b4d2010-10-25 10:42:46 -070039 com.android.systemui.power.PowerUI.class,
Jeff Sharkey098d5802012-04-26 17:30:34 -070040 com.android.systemui.media.RingtonePlayer.class,
Michael Wright0087a142013-02-05 16:29:39 -080041 com.android.systemui.settings.SettingsUI.class,
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040042 };
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 final int N = SERVICES.length;
67 mServices = new SystemUI[N];
68 for (int i=0; i<N; i++) {
69 Class cl = chooseClass(SERVICES[i]);
John Spurlockcd686b52013-06-05 10:13:46 -040070 Log.d(TAG, "loading: " + cl);
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040071 try {
72 mServices[i] = (SystemUI)cl.newInstance();
73 } catch (IllegalAccessException ex) {
74 throw new RuntimeException(ex);
75 } catch (InstantiationException ex) {
76 throw new RuntimeException(ex);
77 }
78 mServices[i].mContext = this;
John Spurlockcd686b52013-06-05 10:13:46 -040079 Log.d(TAG, "running: " + mServices[i]);
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040080 mServices[i].start();
81 }
82 }
83
Daniel Sandler0ad460b2010-12-14 12:14:53 -050084 @Override
85 public void onConfigurationChanged(Configuration newConfig) {
86 for (SystemUI ui: mServices) {
87 ui.onConfigurationChanged(newConfig);
88 }
89 }
90
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040091 /**
92 * Nobody binds to us.
93 */
94 @Override
95 public IBinder onBind(Intent intent) {
96 return null;
97 }
98
99 @Override
100 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Joe Onorato10523b4d2010-10-25 10:42:46 -0700101 if (args == null || args.length == 0) {
102 for (SystemUI ui: mServices) {
103 pw.println("dumping service: " + ui.getClass().getName());
104 ui.dump(fd, pw, args);
105 }
106 } else {
107 String svc = args[0];
108 for (SystemUI ui: mServices) {
109 String name = ui.getClass().getName();
110 if (name.endsWith(svc)) {
111 ui.dump(fd, pw, args);
112 }
113 }
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400114 }
115 }
116}
117