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