OSDN Git Service

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