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; 27 import android.content.res.Configuration; 28 import android.os.Binder; 29 import android.os.IBinder; 30 import android.os.RemoteException; 31 import android.os.ServiceManager; 32 import android.util.Slog; 33 import android.view.IWindowManager; 34 35 public 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 }; 45 46 /** 47 * Hold a reference on the stuff we start. 48 */ 49 SystemUI[] mServices; 50 chooseClass(Object o)51 private Class chooseClass(Object o) { 52 if (o instanceof Integer) { 53 final String cl = getString((Integer)o); 54 try { 55 return getClassLoader().loadClass(cl); 56 } catch (ClassNotFoundException ex) { 57 throw new RuntimeException(ex); 58 } 59 } else if (o instanceof Class) { 60 return (Class)o; 61 } else { 62 throw new RuntimeException("Unknown system ui service: " + o); 63 } 64 } 65 66 @Override onCreate()67 public void onCreate() { 68 // Pick status bar or system bar. 69 IWindowManager wm = IWindowManager.Stub.asInterface( 70 ServiceManager.getService(Context.WINDOW_SERVICE)); 71 try { 72 SERVICES[0] = wm.canStatusBarHide() 73 ? R.string.config_statusBarComponent 74 : R.string.config_systemBarComponent; 75 } catch (RemoteException e) { 76 Slog.w(TAG, "Failing checking whether status bar can hide", e); 77 } 78 79 final int N = SERVICES.length; 80 mServices = new SystemUI[N]; 81 for (int i=0; i<N; i++) { 82 Class cl = chooseClass(SERVICES[i]); 83 Slog.d(TAG, "loading: " + cl); 84 try { 85 mServices[i] = (SystemUI)cl.newInstance(); 86 } catch (IllegalAccessException ex) { 87 throw new RuntimeException(ex); 88 } catch (InstantiationException ex) { 89 throw new RuntimeException(ex); 90 } 91 mServices[i].mContext = this; 92 Slog.d(TAG, "running: " + mServices[i]); 93 mServices[i].start(); 94 } 95 } 96 97 @Override onConfigurationChanged(Configuration newConfig)98 public void onConfigurationChanged(Configuration newConfig) { 99 for (SystemUI ui: mServices) { 100 ui.onConfigurationChanged(newConfig); 101 } 102 } 103 104 /** 105 * Nobody binds to us. 106 */ 107 @Override onBind(Intent intent)108 public IBinder onBind(Intent intent) { 109 return null; 110 } 111 112 @Override dump(FileDescriptor fd, PrintWriter pw, String[] args)113 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 114 if (checkCallingOrSelfPermission(android.Manifest.permission.DUMP) 115 != PackageManager.PERMISSION_GRANTED) { 116 pw.println("Permission Denial: can't dump StatusBar from from pid=" 117 + Binder.getCallingPid() 118 + ", uid=" + Binder.getCallingUid()); 119 return; 120 } 121 122 if (args == null || args.length == 0) { 123 for (SystemUI ui: mServices) { 124 pw.println("dumping service: " + ui.getClass().getName()); 125 ui.dump(fd, pw, args); 126 } 127 } else { 128 String svc = args[0]; 129 for (SystemUI ui: mServices) { 130 String name = ui.getClass().getName(); 131 if (name.endsWith(svc)) { 132 ui.dump(fd, pw, args); 133 } 134 } 135 } 136 } 137 } 138 139