PageRenderTime 18ms CodeModel.GetById 8ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/packages/SystemUI/src/com/android/systemui/SystemUIService.java

https://github.com/aizuzi/platform_frameworks_base
Java | 103 lines | 68 code | 11 blank | 24 comment | 10 complexity | 1274ff764f707069f92c0577579eafdc MD5 | raw file
  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 android.app.Service;
 20import android.content.Intent;
 21import android.content.res.Configuration;
 22import android.os.IBinder;
 23import android.util.Log;
 24
 25import java.io.FileDescriptor;
 26import java.io.PrintWriter;
 27import java.util.HashMap;
 28
 29public class SystemUIService extends Service {
 30    private static final String TAG = "SystemUIService";
 31
 32    /**
 33     * The classes of the stuff to start.
 34     */
 35    private final Class<?>[] SERVICES = new Class[] {
 36            com.android.systemui.recent.Recents.class,
 37            com.android.systemui.statusbar.SystemBars.class,
 38            com.android.systemui.usb.StorageNotification.class,
 39            com.android.systemui.power.PowerUI.class,
 40            com.android.systemui.media.RingtonePlayer.class,
 41            com.android.systemui.settings.SettingsUI.class,
 42        };
 43
 44    /**
 45     * Hold a reference on the stuff we start.
 46     */
 47    private final SystemUI[] mServices = new SystemUI[SERVICES.length];
 48
 49    @Override
 50    public void onCreate() {
 51        HashMap<Class<?>, Object> components = new HashMap<Class<?>, Object>();
 52        final int N = SERVICES.length;
 53        for (int i=0; i<N; i++) {
 54            Class<?> cl = SERVICES[i];
 55            Log.d(TAG, "loading: " + cl);
 56            try {
 57                mServices[i] = (SystemUI)cl.newInstance();
 58            } catch (IllegalAccessException ex) {
 59                throw new RuntimeException(ex);
 60            } catch (InstantiationException ex) {
 61                throw new RuntimeException(ex);
 62            }
 63            mServices[i].mContext = this;
 64            mServices[i].mComponents = components;
 65            Log.d(TAG, "running: " + mServices[i]);
 66            mServices[i].start();
 67        }
 68    }
 69
 70    @Override
 71    public void onConfigurationChanged(Configuration newConfig) {
 72        for (SystemUI ui: mServices) {
 73            ui.onConfigurationChanged(newConfig);
 74        }
 75    }
 76
 77    /**
 78     * Nobody binds to us.
 79     */
 80    @Override
 81    public IBinder onBind(Intent intent) {
 82        return null;
 83    }
 84
 85    @Override
 86    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
 87        if (args == null || args.length == 0) {
 88            for (SystemUI ui: mServices) {
 89                pw.println("dumping service: " + ui.getClass().getName());
 90                ui.dump(fd, pw, args);
 91            }
 92        } else {
 93            String svc = args[0];
 94            for (SystemUI ui: mServices) {
 95                String name = ui.getClass().getName();
 96                if (name.endsWith(svc)) {
 97                    ui.dump(fd, pw, args);
 98                }
 99            }
100        }
101    }
102}
103