blob: 708002d5b94603bcdd97719d77d757398b72c870 [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
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040019import android.app.Service;
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040020import android.content.Intent;
Jeff Sharkeyfe6f85c2017-01-20 10:42:57 -070021import android.os.Build;
Dave Mankoff6711ec92019-11-19 21:24:34 -050022import android.os.Handler;
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;
Ned Burnse33b4952020-02-12 22:38:05 -050026import android.os.UserHandle;
Dan Sandlerdc2ddd72018-01-24 16:09:53 -050027import android.util.Slog;
John Spurlockb0e49fc2013-06-12 15:50:50 -040028
Dan Sandlerdc2ddd72018-01-24 16:09:53 -050029import com.android.internal.os.BinderInternal;
Ned Burns9feeca52020-05-29 01:19:38 -040030import com.android.systemui.broadcast.BroadcastDispatcher;
Dave Mankoff00e8a2f2019-12-18 16:59:49 -050031import com.android.systemui.dagger.qualifiers.Main;
Ned Burns08403642020-05-18 19:38:13 -040032import com.android.systemui.dump.DumpHandler;
Ned Burns9feeca52020-05-29 01:19:38 -040033import com.android.systemui.dump.LogBufferFreezer;
Ned Burnse33b4952020-02-12 22:38:05 -050034import com.android.systemui.dump.SystemUIAuxiliaryDumpService;
Dan Sandlerdc2ddd72018-01-24 16:09:53 -050035
Gus Prevasab336792018-11-14 13:52:20 -050036import java.io.FileDescriptor;
37import java.io.PrintWriter;
38
Dave Mankoff6711ec92019-11-19 21:24:34 -050039import javax.inject.Inject;
40
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040041public class SystemUIService extends Service {
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040042
Dave Mankoff6711ec92019-11-19 21:24:34 -050043 private final Handler mMainHandler;
Ned Burns08403642020-05-18 19:38:13 -040044 private final DumpHandler mDumpHandler;
Ned Burns9feeca52020-05-29 01:19:38 -040045 private final BroadcastDispatcher mBroadcastDispatcher;
46 private final LogBufferFreezer mLogBufferFreezer;
Dave Mankoff6711ec92019-11-19 21:24:34 -050047
48 @Inject
Ned Burnsc7cfa692020-02-12 21:38:50 -050049 public SystemUIService(
50 @Main Handler mainHandler,
Ned Burns9feeca52020-05-29 01:19:38 -040051 DumpHandler dumpHandler,
52 BroadcastDispatcher broadcastDispatcher,
53 LogBufferFreezer logBufferFreezer) {
Dave Mankoff6711ec92019-11-19 21:24:34 -050054 super();
55 mMainHandler = mainHandler;
Ned Burns08403642020-05-18 19:38:13 -040056 mDumpHandler = dumpHandler;
Ned Burns9feeca52020-05-29 01:19:38 -040057 mBroadcastDispatcher = broadcastDispatcher;
58 mLogBufferFreezer = logBufferFreezer;
Dave Mankoff6711ec92019-11-19 21:24:34 -050059 }
60
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040061 @Override
Jorim Jaggi3beffdf2014-04-03 17:37:37 +020062 public void onCreate() {
63 super.onCreate();
Ned Burns9feeca52020-05-29 01:19:38 -040064
65 // Start all of SystemUI
Jorim Jaggi3beffdf2014-04-03 17:37:37 +020066 ((SystemUIApplication) getApplication()).startServicesIfNeeded();
Jeff Sharkeyfe6f85c2017-01-20 10:42:57 -070067
Ned Burns9feeca52020-05-29 01:19:38 -040068 // Finish initializing dump logic
69 mLogBufferFreezer.attach(mBroadcastDispatcher);
70
Jeff Sharkeyfe6f85c2017-01-20 10:42:57 -070071 // For debugging RescueParty
72 if (Build.IS_DEBUGGABLE && SystemProperties.getBoolean("debug.crash_sysui", false)) {
73 throw new RuntimeException();
74 }
Dan Sandlerdc2ddd72018-01-24 16:09:53 -050075
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 Mankoff6711ec92019-11-19 21:24:34 -050088 }, mMainHandler);
Dan Sandlerdc2ddd72018-01-24 16:09:53 -050089 }
Ned Burnse33b4952020-02-12 22:38:05 -050090
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 Jaggi3beffdf2014-04-03 17:37:37 +020095 }
96
97 @Override
Joe Onoratof3c3c4f2010-10-21 11:09:02 -040098 public IBinder onBind(Intent intent) {
99 return null;
100 }
101
102 @Override
103 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Ned Burnsc7cfa692020-02-12 21:38:50 -0500104 // 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 Burns08403642020-05-18 19:38:13 -0400110 DumpHandler.PRIORITY_ARG,
111 DumpHandler.PRIORITY_ARG_CRITICAL};
Ned Burnsc478deb2019-10-29 20:27:07 -0400112 }
Hyunyoung Song8f9d34c2019-08-30 14:47:43 -0700113
Ned Burns08403642020-05-18 19:38:13 -0400114 mDumpHandler.dump(fd, pw, massagedArgs);
Felipe Leme98e81182019-10-10 16:15:31 -0700115 }
Joe Onoratof3c3c4f2010-10-21 11:09:02 -0400116}