SystemUIService.java revision f3c3c4fd14cb4185ec6df5a4355aab8b9f4039dc
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.os.Binder; 28import android.os.IBinder; 29import android.util.Slog; 30 31public class SystemUIService extends Service { 32 static final String TAG = "SystemUIService"; 33 34 /** 35 * The class names of the stuff to start. 36 */ 37 final Object[] SERVICES = new Object[] { 38 R.string.config_statusBarComponent, 39 }; 40 41 /** 42 * Hold a reference on the stuff we start. 43 */ 44 SystemUI[] mServices; 45 46 private Class chooseClass(Object o) { 47 if (o instanceof Integer) { 48 final String cl = getString((Integer)o); 49 try { 50 return getClassLoader().loadClass(cl); 51 } catch (ClassNotFoundException ex) { 52 throw new RuntimeException(ex); 53 } 54 } else if (o instanceof Class) { 55 return (Class)o; 56 } else { 57 throw new RuntimeException("Unknown system ui service: " + o); 58 } 59 } 60 61 @Override 62 public void onCreate() { 63 final int N = SERVICES.length; 64 mServices = new SystemUI[N]; 65 for (int i=0; i<N; i++) { 66 Class cl = chooseClass(SERVICES[i]); 67 Slog.d(TAG, "loading: " + cl); 68 try { 69 mServices[i] = (SystemUI)cl.newInstance(); 70 } catch (IllegalAccessException ex) { 71 throw new RuntimeException(ex); 72 } catch (InstantiationException ex) { 73 throw new RuntimeException(ex); 74 } 75 mServices[i].mContext = this; 76 Slog.d(TAG, "running: " + mServices[i]); 77 mServices[i].start(); 78 } 79 } 80 81 /** 82 * Nobody binds to us. 83 */ 84 @Override 85 public IBinder onBind(Intent intent) { 86 return null; 87 } 88 89 @Override 90 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 91 if (checkCallingOrSelfPermission(android.Manifest.permission.DUMP) 92 != PackageManager.PERMISSION_GRANTED) { 93 pw.println("Permission Denial: can't dump StatusBar from from pid=" 94 + Binder.getCallingPid() 95 + ", uid=" + Binder.getCallingUid()); 96 return; 97 } 98 99 for (SystemUI ui: mServices) { 100 pw.println("dumping service: " + ui.getClass().getName()); 101 ui.dump(fd, pw, args); 102 } 103 } 104} 105 106