blob: 150a40abde7f1da6a9918f7319d2b33db094e07c [file] [log] [blame]
Joe Onoratof3c3c4f2010-10-21 11:09:02 -04001/*
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
Felipe Leme98e81182019-10-10 16:15:31 -070019import android.annotation.NonNull;
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040020import android.app.Service;
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040021import android.content.Intent;
Jeff Sharkeyfe6f85c2017-01-20 10:42:57 -070022import android.os.Build;
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040023import android.os.IBinder;
Dan Sandlerdc2ddd72018-01-24 16:09:53 -050024import android.os.Process;
Jeff Sharkeyfe6f85c2017-01-20 10:42:57 -070025import android.os.SystemProperties;
Dan Sandlerdc2ddd72018-01-24 16:09:53 -050026import android.util.Slog;
John Spurlockb0e49fc2013-06-12 15:50:50 -040027
Dan Sandlerdc2ddd72018-01-24 16:09:53 -050028import com.android.internal.os.BinderInternal;
Tony Wickham023cb192018-09-13 15:23:04 -070029import com.android.systemui.shared.plugins.PluginManager;
30import com.android.systemui.shared.plugins.PluginManagerImpl;
Dan Sandlerdc2ddd72018-01-24 16:09:53 -050031
Gus Prevasab336792018-11-14 13:52:20 -050032import java.io.FileDescriptor;
33import java.io.PrintWriter;
34
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040035public class SystemUIService extends Service {
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040036
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040037 @Override
Jorim Jaggi3beffdf2014-04-03 17:37:37 +020038 public void onCreate() {
39 super.onCreate();
40 ((SystemUIApplication) getApplication()).startServicesIfNeeded();
Jeff Sharkeyfe6f85c2017-01-20 10:42:57 -070041
42 // For debugging RescueParty
43 if (Build.IS_DEBUGGABLE && SystemProperties.getBoolean("debug.crash_sysui", false)) {
44 throw new RuntimeException();
45 }
Dan Sandlerdc2ddd72018-01-24 16:09:53 -050046
47 if (Build.IS_DEBUGGABLE) {
48 // b/71353150 - looking for leaked binder proxies
49 BinderInternal.nSetBinderProxyCountEnabled(true);
50 BinderInternal.nSetBinderProxyCountWatermarks(1000,900);
51 BinderInternal.setBinderProxyCountCallback(
52 new BinderInternal.BinderProxyLimitListener() {
53 @Override
54 public void onLimitReached(int uid) {
55 Slog.w(SystemUIApplication.TAG,
56 "uid " + uid + " sent too many Binder proxies to uid "
57 + Process.myUid());
58 }
59 }, Dependency.get(Dependency.MAIN_HANDLER));
60 }
Jorim Jaggi3beffdf2014-04-03 17:37:37 +020061 }
62
63 @Override
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040064 public IBinder onBind(Intent intent) {
65 return null;
66 }
67
68 @Override
69 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Felipe Leme98e81182019-10-10 16:15:31 -070070 if (args != null && args.length > 0 && args[0].equals("--config")) {
71 dumpConfig(pw);
72 return;
73 }
74
Dave Mankoff037d9fc2019-08-09 11:08:52 -040075 dumpServices(((SystemUIApplication) getApplication()).getServices(), fd, pw, args);
Felipe Leme98e81182019-10-10 16:15:31 -070076 dumpConfig(pw);
Dave Mankoff037d9fc2019-08-09 11:08:52 -040077 }
78
79 static void dumpServices(
80 SystemUI[] services, FileDescriptor fd, PrintWriter pw, String[] args) {
Joe Onorato10523b4d2010-10-25 10:42:46 -070081 if (args == null || args.length == 0) {
Dave Mankoff037d9fc2019-08-09 11:08:52 -040082 pw.println("dumping service: " + Dependency.class.getName());
83 Dependency.staticDump(fd, pw, args);
Jorim Jaggicff0acb2014-03-31 16:35:15 +020084 for (SystemUI ui: services) {
Joe Onorato10523b4d2010-10-25 10:42:46 -070085 pw.println("dumping service: " + ui.getClass().getName());
86 ui.dump(fd, pw, args);
87 }
Dan Sandlerc6dff3d2018-02-14 22:46:25 -050088 if (Build.IS_DEBUGGABLE) {
89 pw.println("dumping plugins:");
90 ((PluginManagerImpl) Dependency.get(PluginManager.class)).dump(fd, pw, args);
91 }
Joe Onorato10523b4d2010-10-25 10:42:46 -070092 } else {
Winson Chunge8e4bdb2019-04-17 15:42:40 -070093 String svc = args[0].toLowerCase();
Dave Mankoff037d9fc2019-08-09 11:08:52 -040094 if (Dependency.class.getName().endsWith(svc)) {
95 Dependency.staticDump(fd, pw, args);
96 }
Jorim Jaggicff0acb2014-03-31 16:35:15 +020097 for (SystemUI ui: services) {
Winson Chunge8e4bdb2019-04-17 15:42:40 -070098 String name = ui.getClass().getName().toLowerCase();
Joe Onorato10523b4d2010-10-25 10:42:46 -070099 if (name.endsWith(svc)) {
100 ui.dump(fd, pw, args);
101 }
102 }
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400103 }
104 }
Felipe Leme98e81182019-10-10 16:15:31 -0700105
106 private void dumpConfig(@NonNull PrintWriter pw) {
107 pw.println("SystemUiServiceComponents configuration:");
108
109 pw.print("vendor component: ");
110 pw.println(getResources().getString(R.string.config_systemUIVendorServiceComponent));
111
112 dumpConfig(pw, "global", R.array.config_systemUIServiceComponents);
113 dumpConfig(pw, "per-user", R.array.config_systemUIServiceComponentsPerUser);
114 }
115
116 private void dumpConfig(@NonNull PrintWriter pw, @NonNull String type, int resId) {
117 final String[] services = getResources().getStringArray(resId);
118 pw.print(type); pw.print(": ");
119 if (services == null) {
120 pw.println("N/A");
121 return;
122 }
123 pw.print(services.length);
124 pw.println(" services");
125 for (int i = 0; i < services.length; i++) {
126 pw.print(" "); pw.print(i); pw.print(": "); pw.println(services[i]);
127 }
128 }
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400129}
130