Home | History | Annotate | Download | only in systemui
      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 import android.view.WindowManagerGlobal;
     35 import android.view.accessibility.AccessibilityManager;
     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[] {
     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             com.android.systemui.settings.SettingsUI.class,
     48         };
     49 
     50     /**
     51      * Hold a reference on the stuff we start.
     52      */
     53     SystemUI[] mServices;
     54 
     55     private Class chooseClass(Object o) {
     56         if (o instanceof Integer) {
     57             final String cl = getString((Integer)o);
     58             try {
     59                 return getClassLoader().loadClass(cl);
     60             } catch (ClassNotFoundException ex) {
     61                 throw new RuntimeException(ex);
     62             }
     63         } else if (o instanceof Class) {
     64             return (Class)o;
     65         } else {
     66             throw new RuntimeException("Unknown system ui service: " + o);
     67         }
     68     }
     69 
     70     @Override
     71     public void onCreate() {
     72         // Tell the accessibility layer that this process will
     73         // run as the current user, i.e. run across users.
     74         AccessibilityManager.createAsSharedAcrossUsers(this);
     75 
     76         // Pick status bar or system bar.
     77         IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
     78         try {
     79             SERVICES[0] = wm.hasSystemNavBar()
     80                     ? R.string.config_systemBarComponent
     81                     : R.string.config_statusBarComponent;
     82         } catch (RemoteException e) {
     83             Slog.w(TAG, "Failing checking whether status bar can hide", e);
     84         }
     85 
     86         final int N = SERVICES.length;
     87         mServices = new SystemUI[N];
     88         for (int i=0; i<N; i++) {
     89             Class cl = chooseClass(SERVICES[i]);
     90             Slog.d(TAG, "loading: " + cl);
     91             try {
     92                 mServices[i] = (SystemUI)cl.newInstance();
     93             } catch (IllegalAccessException ex) {
     94                 throw new RuntimeException(ex);
     95             } catch (InstantiationException ex) {
     96                 throw new RuntimeException(ex);
     97             }
     98             mServices[i].mContext = this;
     99             Slog.d(TAG, "running: " + mServices[i]);
    100             mServices[i].start();
    101         }
    102     }
    103 
    104     @Override
    105     public void onConfigurationChanged(Configuration newConfig) {
    106         for (SystemUI ui: mServices) {
    107             ui.onConfigurationChanged(newConfig);
    108         }
    109     }
    110 
    111     /**
    112      * Nobody binds to us.
    113      */
    114     @Override
    115     public IBinder onBind(Intent intent) {
    116         return null;
    117     }
    118 
    119     @Override
    120     protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    121         if (args == null || args.length == 0) {
    122             for (SystemUI ui: mServices) {
    123                 pw.println("dumping service: " + ui.getClass().getName());
    124                 ui.dump(fd, pw, args);
    125             }
    126         } else {
    127             String svc = args[0];
    128             for (SystemUI ui: mServices) {
    129                 String name = ui.getClass().getName();
    130                 if (name.endsWith(svc)) {
    131                     ui.dump(fd, pw, args);
    132                 }
    133             }
    134         }
    135     }
    136 }
    137 
    138