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 android.app.Service; 20 import android.content.Intent; 21 import android.os.Build; 22 import android.os.Handler; 23 import android.os.IBinder; 24 import android.os.Process; 25 import android.os.SystemProperties; 26 import android.os.UserHandle; 27 import android.util.Slog; 28 29 import com.android.internal.os.BinderInternal; 30 import com.android.systemui.broadcast.BroadcastDispatcher; 31 import com.android.systemui.dagger.qualifiers.Main; 32 import com.android.systemui.dump.DumpHandler; 33 import com.android.systemui.dump.LogBufferFreezer; 34 import com.android.systemui.dump.SystemUIAuxiliaryDumpService; 35 import com.android.systemui.statusbar.policy.BatteryStateNotifier; 36 37 import java.io.FileDescriptor; 38 import java.io.PrintWriter; 39 40 import javax.inject.Inject; 41 42 public class SystemUIService extends Service { 43 44 private final Handler mMainHandler; 45 private final DumpHandler mDumpHandler; 46 private final BroadcastDispatcher mBroadcastDispatcher; 47 private final LogBufferFreezer mLogBufferFreezer; 48 private final BatteryStateNotifier mBatteryStateNotifier; 49 50 @Inject SystemUIService( @ain Handler mainHandler, DumpHandler dumpHandler, BroadcastDispatcher broadcastDispatcher, LogBufferFreezer logBufferFreezer, BatteryStateNotifier batteryStateNotifier)51 public SystemUIService( 52 @Main Handler mainHandler, 53 DumpHandler dumpHandler, 54 BroadcastDispatcher broadcastDispatcher, 55 LogBufferFreezer logBufferFreezer, 56 BatteryStateNotifier batteryStateNotifier) { 57 super(); 58 mMainHandler = mainHandler; 59 mDumpHandler = dumpHandler; 60 mBroadcastDispatcher = broadcastDispatcher; 61 mLogBufferFreezer = logBufferFreezer; 62 mBatteryStateNotifier = batteryStateNotifier; 63 } 64 65 @Override onCreate()66 public void onCreate() { 67 super.onCreate(); 68 69 // Start all of SystemUI 70 ((SystemUIApplication) getApplication()).startServicesIfNeeded(); 71 72 // Finish initializing dump logic 73 mLogBufferFreezer.attach(mBroadcastDispatcher); 74 mDumpHandler.init(); 75 76 // If configured, set up a battery notification 77 if (getResources().getBoolean(R.bool.config_showNotificationForUnknownBatteryState)) { 78 mBatteryStateNotifier.startListening(); 79 } 80 81 // For debugging RescueParty 82 if (Build.IS_DEBUGGABLE && SystemProperties.getBoolean("debug.crash_sysui", false)) { 83 throw new RuntimeException(); 84 } 85 86 if (Build.IS_DEBUGGABLE) { 87 // b/71353150 - looking for leaked binder proxies 88 BinderInternal.nSetBinderProxyCountEnabled(true); 89 BinderInternal.nSetBinderProxyCountWatermarks(1000,900); 90 BinderInternal.setBinderProxyCountCallback( 91 new BinderInternal.BinderProxyLimitListener() { 92 @Override 93 public void onLimitReached(int uid) { 94 Slog.w(SystemUIApplication.TAG, 95 "uid " + uid + " sent too many Binder proxies to uid " 96 + Process.myUid()); 97 } 98 }, mMainHandler); 99 } 100 101 // Bind the dump service so we can dump extra info during a bug report 102 startServiceAsUser( 103 new Intent(getApplicationContext(), SystemUIAuxiliaryDumpService.class), 104 UserHandle.SYSTEM); 105 } 106 107 @Override onBind(Intent intent)108 public IBinder onBind(Intent intent) { 109 return null; 110 } 111 112 @Override dump(FileDescriptor fd, PrintWriter pw, String[] args)113 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 114 // If no args are passed, assume we're being dumped as part of a bug report (sadly, we have 115 // no better way to guess whether this is taking place). Set the appropriate dump priority 116 // (CRITICAL) to reflect that this is taking place. 117 String[] massagedArgs = args; 118 if (args.length == 0) { 119 massagedArgs = new String[] { 120 DumpHandler.PRIORITY_ARG, 121 DumpHandler.PRIORITY_ARG_CRITICAL}; 122 } 123 124 mDumpHandler.dump(fd, pw, massagedArgs); 125 } 126 } 127