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 | |
| 19 | import java.io.FileDescriptor; |
| 20 | import java.io.PrintWriter; |
| 21 | |
| 22 | import android.app.Service; |
| 23 | import android.content.BroadcastReceiver; |
| 24 | import android.content.Context; |
| 25 | import android.content.Intent; |
| 26 | import android.content.pm.PackageManager; |
Daniel Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 27 | import android.content.res.Configuration; |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 28 | import android.os.Binder; |
| 29 | import android.os.IBinder; |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 30 | import android.os.RemoteException; |
| 31 | import android.os.ServiceManager; |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 32 | import android.util.Slog; |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 33 | import android.view.IWindowManager; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 34 | import android.view.WindowManagerGlobal; |
Svetoslav Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 35 | import android.view.accessibility.AccessibilityManager; |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 36 | |
| 37 | public 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 Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 44 | 0, // system bar or status bar, filled in below. |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 45 | com.android.systemui.power.PowerUI.class, |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 46 | com.android.systemui.media.RingtonePlayer.class, |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 47 | }; |
| 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 Ganov | 58d37b5 | 2012-09-18 12:04:19 -0700 | [diff] [blame] | 71 | // 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 Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 75 | // Pick status bar or system bar. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 76 | IWindowManager wm = WindowManagerGlobal.getWindowManagerService(); |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 77 | try { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 78 | SERVICES[0] = wm.hasSystemNavBar() |
| 79 | ? R.string.config_systemBarComponent |
| 80 | : R.string.config_statusBarComponent; |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 81 | } catch (RemoteException e) { |
| 82 | Slog.w(TAG, "Failing checking whether status bar can hide", e); |
| 83 | } |
| 84 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 85 | 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 Sandler | 0ad460b | 2010-12-14 12:14:53 -0500 | [diff] [blame] | 103 | @Override |
| 104 | public void onConfigurationChanged(Configuration newConfig) { |
| 105 | for (SystemUI ui: mServices) { |
| 106 | ui.onConfigurationChanged(newConfig); |
| 107 | } |
| 108 | } |
| 109 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 110 | /** |
| 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 Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 120 | 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 Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | } |
| 136 | |