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; |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 27 | import java.util.HashMap; |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 28 | |
| 29 | public class SystemUIService extends Service { |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 30 | private static final String TAG = "SystemUIService"; |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 31 | |
| 32 | /** |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 33 | * The classes of the stuff to start. |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 34 | */ |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 35 | private final Class<?>[] SERVICES = new Class[] { |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 36 | com.android.systemui.recent.Recents.class, |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 37 | com.android.systemui.statusbar.SystemBars.class, |
John Spurlock | 3e309b2 | 2013-06-25 11:01:29 -0400 | [diff] [blame] | 38 | com.android.systemui.usb.StorageNotification.class, |
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 | */ |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 47 | private final SystemUI[] mServices = new SystemUI[SERVICES.length]; |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 48 | |
| 49 | @Override |
| 50 | public void onCreate() { |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 51 | HashMap<Class<?>, Object> components = new HashMap<Class<?>, Object>(); |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 52 | final int N = SERVICES.length; |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 53 | for (int i=0; i<N; i++) { |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 54 | Class<?> cl = SERVICES[i]; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 55 | Log.d(TAG, "loading: " + cl); |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 56 | try { |
| 57 | mServices[i] = (SystemUI)cl.newInstance(); |
| 58 | } catch (IllegalAccessException ex) { |
| 59 | throw new RuntimeException(ex); |
| 60 | } catch (InstantiationException ex) { |
| 61 | throw new RuntimeException(ex); |
| 62 | } |
| 63 | mServices[i].mContext = this; |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 64 | mServices[i].mComponents = components; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 65 | Log.d(TAG, "running: " + mServices[i]); |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 66 | mServices[i].start(); |
| 67 | } |
| 68 | } |
| 69 | |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 70 | @Override |
| 71 | public void onConfigurationChanged(Configuration newConfig) { |
| 72 | for (SystemUI ui: mServices) { |
| 73 | ui.onConfigurationChanged(newConfig); |
| 74 | } |
| 75 | } |
| 76 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 77 | /** |
| 78 | * Nobody binds to us. |
| 79 | */ |
| 80 | @Override |
| 81 | public IBinder onBind(Intent intent) { |
| 82 | return null; |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 87 | if (args == null || args.length == 0) { |
| 88 | for (SystemUI ui: mServices) { |
| 89 | pw.println("dumping service: " + ui.getClass().getName()); |
| 90 | ui.dump(fd, pw, args); |
| 91 | } |
| 92 | } else { |
| 93 | String svc = args[0]; |
| 94 | for (SystemUI ui: mServices) { |
| 95 | String name = ui.getClass().getName(); |
| 96 | if (name.endsWith(svc)) { |
| 97 | ui.dump(fd, pw, args); |
| 98 | } |
| 99 | } |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | } |
| 103 | |