Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 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 | |
Felipe Leme | 98e8118 | 2019-10-10 16:15:31 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 20 | import android.app.Service; |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 21 | import android.content.Intent; |
Jeff Sharkey | fe6f85c | 2017-01-20 10:42:57 -0700 | [diff] [blame] | 22 | import android.os.Build; |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 23 | import android.os.IBinder; |
Dan Sandler | dc2ddd7 | 2018-01-24 16:09:53 -0500 | [diff] [blame] | 24 | import android.os.Process; |
Jeff Sharkey | fe6f85c | 2017-01-20 10:42:57 -0700 | [diff] [blame] | 25 | import android.os.SystemProperties; |
Dan Sandler | dc2ddd7 | 2018-01-24 16:09:53 -0500 | [diff] [blame] | 26 | import android.util.Slog; |
John Spurlock | b0e49fc | 2013-06-12 15:50:50 -0400 | [diff] [blame] | 27 | |
Dan Sandler | dc2ddd7 | 2018-01-24 16:09:53 -0500 | [diff] [blame] | 28 | import com.android.internal.os.BinderInternal; |
Tony Wickham | 023cb19 | 2018-09-13 15:23:04 -0700 | [diff] [blame] | 29 | import com.android.systemui.shared.plugins.PluginManager; |
| 30 | import com.android.systemui.shared.plugins.PluginManagerImpl; |
Dan Sandler | dc2ddd7 | 2018-01-24 16:09:53 -0500 | [diff] [blame] | 31 | |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 32 | import java.io.FileDescriptor; |
| 33 | import java.io.PrintWriter; |
| 34 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 35 | public class SystemUIService extends Service { |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 36 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 37 | @Override |
Jorim Jaggi | 3beffdf | 2014-04-03 17:37:37 +0200 | [diff] [blame] | 38 | public void onCreate() { |
| 39 | super.onCreate(); |
| 40 | ((SystemUIApplication) getApplication()).startServicesIfNeeded(); |
Jeff Sharkey | fe6f85c | 2017-01-20 10:42:57 -0700 | [diff] [blame] | 41 | |
| 42 | // For debugging RescueParty |
| 43 | if (Build.IS_DEBUGGABLE && SystemProperties.getBoolean("debug.crash_sysui", false)) { |
| 44 | throw new RuntimeException(); |
| 45 | } |
Dan Sandler | dc2ddd7 | 2018-01-24 16:09:53 -0500 | [diff] [blame] | 46 | |
| 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 Jaggi | 3beffdf | 2014-04-03 17:37:37 +0200 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | @Override |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 64 | public IBinder onBind(Intent intent) { |
| 65 | return null; |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Felipe Leme | 98e8118 | 2019-10-10 16:15:31 -0700 | [diff] [blame] | 70 | if (args != null && args.length > 0 && args[0].equals("--config")) { |
| 71 | dumpConfig(pw); |
| 72 | return; |
| 73 | } |
| 74 | |
Dave Mankoff | 037d9fc | 2019-08-09 11:08:52 -0400 | [diff] [blame] | 75 | dumpServices(((SystemUIApplication) getApplication()).getServices(), fd, pw, args); |
Felipe Leme | 98e8118 | 2019-10-10 16:15:31 -0700 | [diff] [blame] | 76 | dumpConfig(pw); |
Dave Mankoff | 037d9fc | 2019-08-09 11:08:52 -0400 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static void dumpServices( |
| 80 | SystemUI[] services, FileDescriptor fd, PrintWriter pw, String[] args) { |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 81 | if (args == null || args.length == 0) { |
Dave Mankoff | 037d9fc | 2019-08-09 11:08:52 -0400 | [diff] [blame] | 82 | pw.println("dumping service: " + Dependency.class.getName()); |
| 83 | Dependency.staticDump(fd, pw, args); |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 84 | for (SystemUI ui: services) { |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 85 | pw.println("dumping service: " + ui.getClass().getName()); |
| 86 | ui.dump(fd, pw, args); |
| 87 | } |
Dan Sandler | c6dff3d | 2018-02-14 22:46:25 -0500 | [diff] [blame] | 88 | if (Build.IS_DEBUGGABLE) { |
| 89 | pw.println("dumping plugins:"); |
| 90 | ((PluginManagerImpl) Dependency.get(PluginManager.class)).dump(fd, pw, args); |
| 91 | } |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 92 | } else { |
Winson Chung | e8e4bdb | 2019-04-17 15:42:40 -0700 | [diff] [blame] | 93 | String svc = args[0].toLowerCase(); |
Dave Mankoff | 037d9fc | 2019-08-09 11:08:52 -0400 | [diff] [blame] | 94 | if (Dependency.class.getName().endsWith(svc)) { |
| 95 | Dependency.staticDump(fd, pw, args); |
| 96 | } |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 97 | for (SystemUI ui: services) { |
Winson Chung | e8e4bdb | 2019-04-17 15:42:40 -0700 | [diff] [blame] | 98 | String name = ui.getClass().getName().toLowerCase(); |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 99 | if (name.endsWith(svc)) { |
| 100 | ui.dump(fd, pw, args); |
| 101 | } |
| 102 | } |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 103 | } |
| 104 | } |
Felipe Leme | 98e8118 | 2019-10-10 16:15:31 -0700 | [diff] [blame] | 105 | |
| 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 Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 129 | } |
| 130 | |