SystemUIService.java revision 098d580cc2bb6c0891c756a4e5230c6c6b0d2376
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; 34 35public class SystemUIService extends Service { 36 static final String TAG = "SystemUIService"; 37 38 /** 39 * The class names of the stuff to start. 40 */ 41 final Object[] SERVICES = new Object[] { 42 0, // system bar or status bar, filled in below. 43 com.android.systemui.power.PowerUI.class, 44 com.android.systemui.media.RingtonePlayer.class, 45 }; 46 47 /** 48 * Hold a reference on the stuff we start. 49 */ 50 SystemUI[] mServices; 51 52 private Class chooseClass(Object o) { 53 if (o instanceof Integer) { 54 final String cl = getString((Integer)o); 55 try { 56 return getClassLoader().loadClass(cl); 57 } catch (ClassNotFoundException ex) { 58 throw new RuntimeException(ex); 59 } 60 } else if (o instanceof Class) { 61 return (Class)o; 62 } else { 63 throw new RuntimeException("Unknown system ui service: " + o); 64 } 65 } 66 67 @Override 68 public void onCreate() { 69 // Pick status bar or system bar. 70 IWindowManager wm = IWindowManager.Stub.asInterface( 71 ServiceManager.getService(Context.WINDOW_SERVICE)); 72 try { 73 SERVICES[0] = wm.hasSystemNavBar() 74 ? R.string.config_systemBarComponent 75 : R.string.config_statusBarComponent; 76 } catch (RemoteException e) { 77 Slog.w(TAG, "Failing checking whether status bar can hide", e); 78 } 79 80 final int N = SERVICES.length; 81 mServices = new SystemUI[N]; 82 for (int i=0; i<N; i++) { 83 Class cl = chooseClass(SERVICES[i]); 84 Slog.d(TAG, "loading: " + cl); 85 try { 86 mServices[i] = (SystemUI)cl.newInstance(); 87 } catch (IllegalAccessException ex) { 88 throw new RuntimeException(ex); 89 } catch (InstantiationException ex) { 90 throw new RuntimeException(ex); 91 } 92 mServices[i].mContext = this; 93 Slog.d(TAG, "running: " + mServices[i]); 94 mServices[i].start(); 95 } 96 } 97 98 @Override 99 public void onConfigurationChanged(Configuration newConfig) { 100 for (SystemUI ui: mServices) { 101 ui.onConfigurationChanged(newConfig); 102 } 103 } 104 105 /** 106 * Nobody binds to us. 107 */ 108 @Override 109 public IBinder onBind(Intent intent) { 110 return null; 111 } 112 113 @Override 114 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 115 if (args == null || args.length == 0) { 116 for (SystemUI ui: mServices) { 117 pw.println("dumping service: " + ui.getClass().getName()); 118 ui.dump(fd, pw, args); 119 } 120 } else { 121 String svc = args[0]; 122 for (SystemUI ui: mServices) { 123 String name = ui.getClass().getName(); 124 if (name.endsWith(svc)) { 125 ui.dump(fd, pw, args); 126 } 127 } 128 } 129 } 130} 131 132