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 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 19 | import android.app.Service; |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 20 | import android.content.Intent; |
Jeff Sharkey | fe6f85c | 2017-01-20 10:42:57 -0700 | [diff] [blame] | 21 | import android.os.Build; |
Dave Mankoff | 6711ec9 | 2019-11-19 21:24:34 -0500 | [diff] [blame] | 22 | import android.os.Handler; |
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; |
Ned Burns | e33b495 | 2020-02-12 22:38:05 -0500 | [diff] [blame] | 26 | import android.os.UserHandle; |
Dan Sandler | dc2ddd7 | 2018-01-24 16:09:53 -0500 | [diff] [blame] | 27 | import android.util.Slog; |
John Spurlock | b0e49fc | 2013-06-12 15:50:50 -0400 | [diff] [blame] | 28 | |
Dan Sandler | dc2ddd7 | 2018-01-24 16:09:53 -0500 | [diff] [blame] | 29 | import com.android.internal.os.BinderInternal; |
Ned Burns | 9feeca5 | 2020-05-29 01:19:38 -0400 | [diff] [blame] | 30 | import com.android.systemui.broadcast.BroadcastDispatcher; |
Dave Mankoff | 00e8a2f | 2019-12-18 16:59:49 -0500 | [diff] [blame] | 31 | import com.android.systemui.dagger.qualifiers.Main; |
Ned Burns | 0840364 | 2020-05-18 19:38:13 -0400 | [diff] [blame] | 32 | import com.android.systemui.dump.DumpHandler; |
Ned Burns | 9feeca5 | 2020-05-29 01:19:38 -0400 | [diff] [blame] | 33 | import com.android.systemui.dump.LogBufferFreezer; |
Ned Burns | e33b495 | 2020-02-12 22:38:05 -0500 | [diff] [blame] | 34 | import com.android.systemui.dump.SystemUIAuxiliaryDumpService; |
Dan Sandler | dc2ddd7 | 2018-01-24 16:09:53 -0500 | [diff] [blame] | 35 | |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 36 | import java.io.FileDescriptor; |
| 37 | import java.io.PrintWriter; |
| 38 | |
Dave Mankoff | 6711ec9 | 2019-11-19 21:24:34 -0500 | [diff] [blame] | 39 | import javax.inject.Inject; |
| 40 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 41 | public class SystemUIService extends Service { |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 42 | |
Dave Mankoff | 6711ec9 | 2019-11-19 21:24:34 -0500 | [diff] [blame] | 43 | private final Handler mMainHandler; |
Ned Burns | 0840364 | 2020-05-18 19:38:13 -0400 | [diff] [blame] | 44 | private final DumpHandler mDumpHandler; |
Ned Burns | 9feeca5 | 2020-05-29 01:19:38 -0400 | [diff] [blame] | 45 | private final BroadcastDispatcher mBroadcastDispatcher; |
| 46 | private final LogBufferFreezer mLogBufferFreezer; |
Dave Mankoff | 6711ec9 | 2019-11-19 21:24:34 -0500 | [diff] [blame] | 47 | |
| 48 | @Inject |
Ned Burns | c7cfa69 | 2020-02-12 21:38:50 -0500 | [diff] [blame] | 49 | public SystemUIService( |
| 50 | @Main Handler mainHandler, |
Ned Burns | 9feeca5 | 2020-05-29 01:19:38 -0400 | [diff] [blame] | 51 | DumpHandler dumpHandler, |
| 52 | BroadcastDispatcher broadcastDispatcher, |
| 53 | LogBufferFreezer logBufferFreezer) { |
Dave Mankoff | 6711ec9 | 2019-11-19 21:24:34 -0500 | [diff] [blame] | 54 | super(); |
| 55 | mMainHandler = mainHandler; |
Ned Burns | 0840364 | 2020-05-18 19:38:13 -0400 | [diff] [blame] | 56 | mDumpHandler = dumpHandler; |
Ned Burns | 9feeca5 | 2020-05-29 01:19:38 -0400 | [diff] [blame] | 57 | mBroadcastDispatcher = broadcastDispatcher; |
| 58 | mLogBufferFreezer = logBufferFreezer; |
Dave Mankoff | 6711ec9 | 2019-11-19 21:24:34 -0500 | [diff] [blame] | 59 | } |
| 60 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 61 | @Override |
Jorim Jaggi | 3beffdf | 2014-04-03 17:37:37 +0200 | [diff] [blame] | 62 | public void onCreate() { |
| 63 | super.onCreate(); |
Ned Burns | 9feeca5 | 2020-05-29 01:19:38 -0400 | [diff] [blame] | 64 | |
| 65 | // Start all of SystemUI |
Jorim Jaggi | 3beffdf | 2014-04-03 17:37:37 +0200 | [diff] [blame] | 66 | ((SystemUIApplication) getApplication()).startServicesIfNeeded(); |
Jeff Sharkey | fe6f85c | 2017-01-20 10:42:57 -0700 | [diff] [blame] | 67 | |
Ned Burns | 9feeca5 | 2020-05-29 01:19:38 -0400 | [diff] [blame] | 68 | // Finish initializing dump logic |
| 69 | mLogBufferFreezer.attach(mBroadcastDispatcher); |
| 70 | |
Jeff Sharkey | fe6f85c | 2017-01-20 10:42:57 -0700 | [diff] [blame] | 71 | // For debugging RescueParty |
| 72 | if (Build.IS_DEBUGGABLE && SystemProperties.getBoolean("debug.crash_sysui", false)) { |
| 73 | throw new RuntimeException(); |
| 74 | } |
Dan Sandler | dc2ddd7 | 2018-01-24 16:09:53 -0500 | [diff] [blame] | 75 | |
| 76 | if (Build.IS_DEBUGGABLE) { |
| 77 | // b/71353150 - looking for leaked binder proxies |
| 78 | BinderInternal.nSetBinderProxyCountEnabled(true); |
| 79 | BinderInternal.nSetBinderProxyCountWatermarks(1000,900); |
| 80 | BinderInternal.setBinderProxyCountCallback( |
| 81 | new BinderInternal.BinderProxyLimitListener() { |
| 82 | @Override |
| 83 | public void onLimitReached(int uid) { |
| 84 | Slog.w(SystemUIApplication.TAG, |
| 85 | "uid " + uid + " sent too many Binder proxies to uid " |
| 86 | + Process.myUid()); |
| 87 | } |
Dave Mankoff | 6711ec9 | 2019-11-19 21:24:34 -0500 | [diff] [blame] | 88 | }, mMainHandler); |
Dan Sandler | dc2ddd7 | 2018-01-24 16:09:53 -0500 | [diff] [blame] | 89 | } |
Ned Burns | e33b495 | 2020-02-12 22:38:05 -0500 | [diff] [blame] | 90 | |
| 91 | // Bind the dump service so we can dump extra info during a bug report |
| 92 | startServiceAsUser( |
| 93 | new Intent(getApplicationContext(), SystemUIAuxiliaryDumpService.class), |
| 94 | UserHandle.SYSTEM); |
Jorim Jaggi | 3beffdf | 2014-04-03 17:37:37 +0200 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | @Override |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 98 | public IBinder onBind(Intent intent) { |
| 99 | return null; |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Ned Burns | c7cfa69 | 2020-02-12 21:38:50 -0500 | [diff] [blame] | 104 | // If no args are passed, assume we're being dumped as part of a bug report (sadly, we have |
| 105 | // no better way to guess whether this is taking place). Set the appropriate dump priority |
| 106 | // (CRITICAL) to reflect that this is taking place. |
| 107 | String[] massagedArgs = args; |
| 108 | if (args.length == 0) { |
| 109 | massagedArgs = new String[] { |
Ned Burns | 0840364 | 2020-05-18 19:38:13 -0400 | [diff] [blame] | 110 | DumpHandler.PRIORITY_ARG, |
| 111 | DumpHandler.PRIORITY_ARG_CRITICAL}; |
Ned Burns | c478deb | 2019-10-29 20:27:07 -0400 | [diff] [blame] | 112 | } |
Hyunyoung Song | 8f9d34c | 2019-08-30 14:47:43 -0700 | [diff] [blame] | 113 | |
Ned Burns | 0840364 | 2020-05-18 19:38:13 -0400 | [diff] [blame] | 114 | mDumpHandler.dump(fd, pw, massagedArgs); |
Felipe Leme | 98e8118 | 2019-10-10 16:15:31 -0700 | [diff] [blame] | 115 | } |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 116 | } |