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 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; 27import android.content.res.Configuration; 28import android.os.Binder; 29import android.os.IBinder; 30import android.os.RemoteException; 31import android.os.ServiceManager; 32import android.util.Slog; 33import android.view.IWindowManager; 34import android.view.WindowManagerGlobal; 35import android.view.accessibility.AccessibilityManager; 36 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[] { 44 0, // system bar or status bar, filled in below. 45 com.android.systemui.power.PowerUI.class, 46 com.android.systemui.media.RingtonePlayer.class, 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() { 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 75 // Pick status bar or system bar. 76 IWindowManager wm = WindowManagerGlobal.getWindowManagerService(); 77 try { 78 SERVICES[0] = wm.hasSystemNavBar() 79 ? R.string.config_systemBarComponent 80 : R.string.config_statusBarComponent; 81 } catch (RemoteException e) { 82 Slog.w(TAG, "Failing checking whether status bar can hide", e); 83 } 84 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 103 @Override 104 public void onConfigurationChanged(Configuration newConfig) { 105 for (SystemUI ui: mServices) { 106 ui.onConfigurationChanged(newConfig); 107 } 108 } 109 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) { 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 } 133 } 134 } 135} 136 137