Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 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 | |
| 17 | package com.android.systemui; |
| 18 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 19 | import android.app.Service; |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 20 | import android.content.Intent; |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 21 | import android.content.res.Configuration; |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 22 | import android.os.IBinder; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 23 | import android.util.Log; |
John Spurlock | b0e49fc | 2013-06-12 15:50:50 -0400 | [diff] [blame^] | 24 | |
| 25 | import java.io.FileDescriptor; |
| 26 | import java.io.PrintWriter; |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 27 | |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 28 | import java.io.FileDescriptor; |
| 29 | import java.io.PrintWriter; |
| 30 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 31 | public 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 Spurlock | b0e49fc | 2013-06-12 15:50:50 -0400 | [diff] [blame^] | 38 | R.string.config_statusBarComponent, |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 39 | com.android.systemui.power.PowerUI.class, |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 40 | com.android.systemui.media.RingtonePlayer.class, |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 41 | com.android.systemui.settings.SettingsUI.class, |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 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 | 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 Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 70 | Log.d(TAG, "loading: " + cl); |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 71 | 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 Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 79 | Log.d(TAG, "running: " + mServices[i]); |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 80 | mServices[i].start(); |
| 81 | } |
| 82 | } |
| 83 | |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 84 | @Override |
| 85 | public void onConfigurationChanged(Configuration newConfig) { |
| 86 | for (SystemUI ui: mServices) { |
| 87 | ui.onConfigurationChanged(newConfig); |
| 88 | } |
| 89 | } |
| 90 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 91 | /** |
| 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 Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 101 | 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 Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 114 | } |
| 115 | } |
| 116 | } |
| 117 | |