Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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.server; |
| 18 | |
MÃ¥rten Kongstad | 2e0d0f3 | 2016-06-02 09:35:31 +0200 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 20 | import android.content.Context; |
Wei Wang | c3a76d0 | 2017-07-14 11:39:30 -0700 | [diff] [blame] | 21 | import android.os.SystemClock; |
Yasuhiro Matsuda | 1ab43d5 | 2015-06-30 17:07:32 +0900 | [diff] [blame] | 22 | import android.os.Trace; |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 23 | import android.util.Slog; |
| 24 | |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 25 | import java.lang.reflect.Constructor; |
| 26 | import java.lang.reflect.InvocationTargetException; |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 27 | import java.util.ArrayList; |
| 28 | |
| 29 | /** |
Adam Lesinski | b102b2c | 2013-12-20 11:46:14 -0800 | [diff] [blame] | 30 | * Manages creating, starting, and other lifecycle events of |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 31 | * {@link com.android.server.SystemService system services}. |
Adam Lesinski | b102b2c | 2013-12-20 11:46:14 -0800 | [diff] [blame] | 32 | * |
| 33 | * {@hide} |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 34 | */ |
| 35 | public class SystemServiceManager { |
| 36 | private static final String TAG = "SystemServiceManager"; |
Fyodor Kupolov | 701a85f | 2017-04-25 12:52:08 -0700 | [diff] [blame] | 37 | private static final int SERVICE_CALL_WARN_TIME_MS = 50; |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 38 | |
| 39 | private final Context mContext; |
Amith Yamasani | 9158825 | 2013-11-22 08:25:26 -0800 | [diff] [blame] | 40 | private boolean mSafeMode; |
Fyodor Kupolov | 1d87e40 | 2017-01-10 18:34:10 -0800 | [diff] [blame] | 41 | private boolean mRuntimeRestarted; |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 42 | |
| 43 | // Services that should receive lifecycle events. |
| 44 | private final ArrayList<SystemService> mServices = new ArrayList<SystemService>(); |
| 45 | |
| 46 | private int mCurrentPhase = -1; |
| 47 | |
Fyodor Kupolov | 1d87e40 | 2017-01-10 18:34:10 -0800 | [diff] [blame] | 48 | SystemServiceManager(Context context) { |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 49 | mContext = context; |
| 50 | } |
| 51 | |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 52 | /** |
Adam Lesinski | 2cb6c60 | 2014-02-14 17:19:56 -0800 | [diff] [blame] | 53 | * Starts a service by class name. |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 54 | * |
Adam Lesinski | 2cb6c60 | 2014-02-14 17:19:56 -0800 | [diff] [blame] | 55 | * @return The service instance. |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 56 | */ |
| 57 | @SuppressWarnings("unchecked") |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 58 | public SystemService startService(String className) { |
| 59 | final Class<SystemService> serviceClass; |
| 60 | try { |
| 61 | serviceClass = (Class<SystemService>)Class.forName(className); |
| 62 | } catch (ClassNotFoundException ex) { |
| 63 | Slog.i(TAG, "Starting " + className); |
| 64 | throw new RuntimeException("Failed to create service " + className |
| 65 | + ": service class not found, usually indicates that the caller should " |
| 66 | + "have called PackageManager.hasSystemFeature() to check whether the " |
| 67 | + "feature is available on this device before trying to start the " |
| 68 | + "services that implement it", ex); |
| 69 | } |
| 70 | return startService(serviceClass); |
Amith Yamasani | 9158825 | 2013-11-22 08:25:26 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 73 | /** |
| 74 | * Creates and starts a system service. The class must be a subclass of |
| 75 | * {@link com.android.server.SystemService}. |
| 76 | * |
| 77 | * @param serviceClass A Java class that implements the SystemService interface. |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 78 | * @return The service instance, never null. |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 79 | * @throws RuntimeException if the service fails to start. |
| 80 | */ |
Jeff Brown | 6f357d3 | 2014-01-15 20:40:55 -0800 | [diff] [blame] | 81 | @SuppressWarnings("unchecked") |
| 82 | public <T extends SystemService> T startService(Class<T> serviceClass) { |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 83 | try { |
Yasuhiro Matsuda | 1ab43d5 | 2015-06-30 17:07:32 +0900 | [diff] [blame] | 84 | final String name = serviceClass.getName(); |
| 85 | Slog.i(TAG, "Starting " + name); |
| 86 | Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "StartService " + name); |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 87 | |
Yasuhiro Matsuda | 1ab43d5 | 2015-06-30 17:07:32 +0900 | [diff] [blame] | 88 | // Create the service. |
| 89 | if (!SystemService.class.isAssignableFrom(serviceClass)) { |
| 90 | throw new RuntimeException("Failed to create " + name |
| 91 | + ": service must extend " + SystemService.class.getName()); |
| 92 | } |
| 93 | final T service; |
| 94 | try { |
| 95 | Constructor<T> constructor = serviceClass.getConstructor(Context.class); |
| 96 | service = constructor.newInstance(mContext); |
| 97 | } catch (InstantiationException ex) { |
| 98 | throw new RuntimeException("Failed to create service " + name |
| 99 | + ": service could not be instantiated", ex); |
| 100 | } catch (IllegalAccessException ex) { |
| 101 | throw new RuntimeException("Failed to create service " + name |
| 102 | + ": service must have a public constructor with a Context argument", ex); |
| 103 | } catch (NoSuchMethodException ex) { |
| 104 | throw new RuntimeException("Failed to create service " + name |
| 105 | + ": service must have a public constructor with a Context argument", ex); |
| 106 | } catch (InvocationTargetException ex) { |
| 107 | throw new RuntimeException("Failed to create service " + name |
| 108 | + ": service constructor threw an exception", ex); |
| 109 | } |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 110 | |
MÃ¥rten Kongstad | 2e0d0f3 | 2016-06-02 09:35:31 +0200 | [diff] [blame] | 111 | startService(service); |
Yasuhiro Matsuda | 1ab43d5 | 2015-06-30 17:07:32 +0900 | [diff] [blame] | 112 | return service; |
| 113 | } finally { |
| 114 | Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 115 | } |
| 116 | } |
| 117 | |
MÃ¥rten Kongstad | 2e0d0f3 | 2016-06-02 09:35:31 +0200 | [diff] [blame] | 118 | public void startService(@NonNull final SystemService service) { |
| 119 | // Register it. |
| 120 | mServices.add(service); |
| 121 | // Start it. |
Wei Wang | c3a76d0 | 2017-07-14 11:39:30 -0700 | [diff] [blame] | 122 | long time = SystemClock.elapsedRealtime(); |
MÃ¥rten Kongstad | 2e0d0f3 | 2016-06-02 09:35:31 +0200 | [diff] [blame] | 123 | try { |
| 124 | service.onStart(); |
| 125 | } catch (RuntimeException ex) { |
| 126 | throw new RuntimeException("Failed to start service " + service.getClass().getName() |
| 127 | + ": onStart threw an exception", ex); |
| 128 | } |
Wei Wang | c3a76d0 | 2017-07-14 11:39:30 -0700 | [diff] [blame] | 129 | warnIfTooLong(SystemClock.elapsedRealtime() - time, service, "onStart"); |
MÃ¥rten Kongstad | 2e0d0f3 | 2016-06-02 09:35:31 +0200 | [diff] [blame] | 130 | } |
| 131 | |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 132 | /** |
| 133 | * Starts the specified boot phase for all system services that have been started up to |
| 134 | * this point. |
| 135 | * |
| 136 | * @param phase The boot phase to start. |
| 137 | */ |
| 138 | public void startBootPhase(final int phase) { |
| 139 | if (phase <= mCurrentPhase) { |
| 140 | throw new IllegalArgumentException("Next phase must be larger than previous"); |
| 141 | } |
| 142 | mCurrentPhase = phase; |
| 143 | |
| 144 | Slog.i(TAG, "Starting phase " + mCurrentPhase); |
Yasuhiro Matsuda | 1ab43d5 | 2015-06-30 17:07:32 +0900 | [diff] [blame] | 145 | try { |
| 146 | Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "OnBootPhase " + phase); |
| 147 | final int serviceLen = mServices.size(); |
| 148 | for (int i = 0; i < serviceLen; i++) { |
| 149 | final SystemService service = mServices.get(i); |
Wei Wang | c3a76d0 | 2017-07-14 11:39:30 -0700 | [diff] [blame] | 150 | long time = SystemClock.elapsedRealtime(); |
Philip Cuadra | 4345c0d | 2016-08-17 18:02:24 -0700 | [diff] [blame] | 151 | Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, service.getClass().getName()); |
Yasuhiro Matsuda | 1ab43d5 | 2015-06-30 17:07:32 +0900 | [diff] [blame] | 152 | try { |
| 153 | service.onBootPhase(mCurrentPhase); |
| 154 | } catch (Exception ex) { |
| 155 | throw new RuntimeException("Failed to boot service " |
| 156 | + service.getClass().getName() |
| 157 | + ": onBootPhase threw an exception during phase " |
| 158 | + mCurrentPhase, ex); |
| 159 | } |
Wei Wang | c3a76d0 | 2017-07-14 11:39:30 -0700 | [diff] [blame] | 160 | warnIfTooLong(SystemClock.elapsedRealtime() - time, service, "onBootPhase"); |
Philip Cuadra | 4345c0d | 2016-08-17 18:02:24 -0700 | [diff] [blame] | 161 | Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 162 | } |
Yasuhiro Matsuda | 1ab43d5 | 2015-06-30 17:07:32 +0900 | [diff] [blame] | 163 | } finally { |
| 164 | Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | |
Keun-young Park | 4136d2d | 2017-05-08 14:51:59 -0700 | [diff] [blame] | 168 | /** |
| 169 | * @return true if system has completed the boot; false otherwise. |
| 170 | */ |
| 171 | public boolean isBootCompleted() { |
| 172 | return mCurrentPhase >= SystemService.PHASE_BOOT_COMPLETED; |
| 173 | } |
| 174 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 175 | public void startUser(final int userHandle) { |
Fyodor Kupolov | 701a85f | 2017-04-25 12:52:08 -0700 | [diff] [blame] | 176 | Slog.i(TAG, "Calling onStartUser u" + userHandle); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 177 | final int serviceLen = mServices.size(); |
| 178 | for (int i = 0; i < serviceLen; i++) { |
| 179 | final SystemService service = mServices.get(i); |
Philip Cuadra | ca3329c | 2016-06-24 12:02:06 -0700 | [diff] [blame] | 180 | Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "onStartUser " |
| 181 | + service.getClass().getName()); |
Wei Wang | c3a76d0 | 2017-07-14 11:39:30 -0700 | [diff] [blame] | 182 | long time = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 183 | try { |
| 184 | service.onStartUser(userHandle); |
| 185 | } catch (Exception ex) { |
| 186 | Slog.wtf(TAG, "Failure reporting start of user " + userHandle |
| 187 | + " to service " + service.getClass().getName(), ex); |
| 188 | } |
Wei Wang | c3a76d0 | 2017-07-14 11:39:30 -0700 | [diff] [blame] | 189 | warnIfTooLong(SystemClock.elapsedRealtime() - time, service, "onStartUser "); |
Philip Cuadra | ca3329c | 2016-06-24 12:02:06 -0700 | [diff] [blame] | 190 | Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 194 | public void unlockUser(final int userHandle) { |
Fyodor Kupolov | 701a85f | 2017-04-25 12:52:08 -0700 | [diff] [blame] | 195 | Slog.i(TAG, "Calling onUnlockUser u" + userHandle); |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 196 | final int serviceLen = mServices.size(); |
| 197 | for (int i = 0; i < serviceLen; i++) { |
| 198 | final SystemService service = mServices.get(i); |
Philip Cuadra | ca3329c | 2016-06-24 12:02:06 -0700 | [diff] [blame] | 199 | Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "onUnlockUser " |
| 200 | + service.getClass().getName()); |
Wei Wang | c3a76d0 | 2017-07-14 11:39:30 -0700 | [diff] [blame] | 201 | long time = SystemClock.elapsedRealtime(); |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 202 | try { |
| 203 | service.onUnlockUser(userHandle); |
| 204 | } catch (Exception ex) { |
| 205 | Slog.wtf(TAG, "Failure reporting unlock of user " + userHandle |
| 206 | + " to service " + service.getClass().getName(), ex); |
| 207 | } |
Wei Wang | c3a76d0 | 2017-07-14 11:39:30 -0700 | [diff] [blame] | 208 | warnIfTooLong(SystemClock.elapsedRealtime() - time, service, "onUnlockUser "); |
Philip Cuadra | ca3329c | 2016-06-24 12:02:06 -0700 | [diff] [blame] | 209 | Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 213 | public void switchUser(final int userHandle) { |
Fyodor Kupolov | 701a85f | 2017-04-25 12:52:08 -0700 | [diff] [blame] | 214 | Slog.i(TAG, "Calling switchUser u" + userHandle); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 215 | final int serviceLen = mServices.size(); |
| 216 | for (int i = 0; i < serviceLen; i++) { |
| 217 | final SystemService service = mServices.get(i); |
Philip Cuadra | ca3329c | 2016-06-24 12:02:06 -0700 | [diff] [blame] | 218 | Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "onSwitchUser " |
| 219 | + service.getClass().getName()); |
Wei Wang | c3a76d0 | 2017-07-14 11:39:30 -0700 | [diff] [blame] | 220 | long time = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 221 | try { |
| 222 | service.onSwitchUser(userHandle); |
| 223 | } catch (Exception ex) { |
| 224 | Slog.wtf(TAG, "Failure reporting switch of user " + userHandle |
| 225 | + " to service " + service.getClass().getName(), ex); |
| 226 | } |
Wei Wang | c3a76d0 | 2017-07-14 11:39:30 -0700 | [diff] [blame] | 227 | warnIfTooLong(SystemClock.elapsedRealtime() - time, service, "onSwitchUser"); |
Philip Cuadra | ca3329c | 2016-06-24 12:02:06 -0700 | [diff] [blame] | 228 | Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | |
| 232 | public void stopUser(final int userHandle) { |
Fyodor Kupolov | 701a85f | 2017-04-25 12:52:08 -0700 | [diff] [blame] | 233 | Slog.i(TAG, "Calling onStopUser u" + userHandle); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 234 | final int serviceLen = mServices.size(); |
| 235 | for (int i = 0; i < serviceLen; i++) { |
| 236 | final SystemService service = mServices.get(i); |
Philip Cuadra | ca3329c | 2016-06-24 12:02:06 -0700 | [diff] [blame] | 237 | Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "onStopUser " |
| 238 | + service.getClass().getName()); |
Wei Wang | c3a76d0 | 2017-07-14 11:39:30 -0700 | [diff] [blame] | 239 | long time = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 240 | try { |
| 241 | service.onStopUser(userHandle); |
| 242 | } catch (Exception ex) { |
| 243 | Slog.wtf(TAG, "Failure reporting stop of user " + userHandle |
| 244 | + " to service " + service.getClass().getName(), ex); |
| 245 | } |
Wei Wang | c3a76d0 | 2017-07-14 11:39:30 -0700 | [diff] [blame] | 246 | warnIfTooLong(SystemClock.elapsedRealtime() - time, service, "onStopUser"); |
Philip Cuadra | ca3329c | 2016-06-24 12:02:06 -0700 | [diff] [blame] | 247 | Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | |
| 251 | public void cleanupUser(final int userHandle) { |
Fyodor Kupolov | 701a85f | 2017-04-25 12:52:08 -0700 | [diff] [blame] | 252 | Slog.i(TAG, "Calling onCleanupUser u" + userHandle); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 253 | final int serviceLen = mServices.size(); |
| 254 | for (int i = 0; i < serviceLen; i++) { |
| 255 | final SystemService service = mServices.get(i); |
Philip Cuadra | ca3329c | 2016-06-24 12:02:06 -0700 | [diff] [blame] | 256 | Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "onCleanupUser " |
| 257 | + service.getClass().getName()); |
Wei Wang | c3a76d0 | 2017-07-14 11:39:30 -0700 | [diff] [blame] | 258 | long time = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 259 | try { |
| 260 | service.onCleanupUser(userHandle); |
| 261 | } catch (Exception ex) { |
| 262 | Slog.wtf(TAG, "Failure reporting cleanup of user " + userHandle |
| 263 | + " to service " + service.getClass().getName(), ex); |
| 264 | } |
Wei Wang | c3a76d0 | 2017-07-14 11:39:30 -0700 | [diff] [blame] | 265 | warnIfTooLong(SystemClock.elapsedRealtime() - time, service, "onCleanupUser"); |
Philip Cuadra | ca3329c | 2016-06-24 12:02:06 -0700 | [diff] [blame] | 266 | Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | |
Amith Yamasani | 9158825 | 2013-11-22 08:25:26 -0800 | [diff] [blame] | 270 | /** Sets the safe mode flag for services to query. */ |
Fyodor Kupolov | 1d87e40 | 2017-01-10 18:34:10 -0800 | [diff] [blame] | 271 | void setSafeMode(boolean safeMode) { |
Amith Yamasani | 9158825 | 2013-11-22 08:25:26 -0800 | [diff] [blame] | 272 | mSafeMode = safeMode; |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * Returns whether we are booting into safe mode. |
| 277 | * @return safe mode flag |
| 278 | */ |
| 279 | public boolean isSafeMode() { |
| 280 | return mSafeMode; |
| 281 | } |
| 282 | |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 283 | /** |
Fyodor Kupolov | 1d87e40 | 2017-01-10 18:34:10 -0800 | [diff] [blame] | 284 | * @return true if runtime was restarted, false if it's normal boot |
| 285 | */ |
| 286 | public boolean isRuntimeRestarted() { |
| 287 | return mRuntimeRestarted; |
| 288 | } |
| 289 | |
| 290 | void setRuntimeRestarted(boolean runtimeRestarted) { |
| 291 | mRuntimeRestarted = runtimeRestarted; |
| 292 | } |
| 293 | |
Fyodor Kupolov | 701a85f | 2017-04-25 12:52:08 -0700 | [diff] [blame] | 294 | private void warnIfTooLong(long duration, SystemService service, String operation) { |
| 295 | if (duration > SERVICE_CALL_WARN_TIME_MS) { |
| 296 | Slog.w(TAG, "Service " + service.getClass().getName() + " took " + duration + " ms in " |
| 297 | + operation); |
| 298 | } |
| 299 | } |
Fyodor Kupolov | 1d87e40 | 2017-01-10 18:34:10 -0800 | [diff] [blame] | 300 | |
| 301 | /** |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 302 | * Outputs the state of this manager to the System log. |
| 303 | */ |
| 304 | public void dump() { |
| 305 | StringBuilder builder = new StringBuilder(); |
| 306 | builder.append("Current phase: ").append(mCurrentPhase).append("\n"); |
| 307 | builder.append("Services:\n"); |
| 308 | final int startedLen = mServices.size(); |
| 309 | for (int i = 0; i < startedLen; i++) { |
| 310 | final SystemService service = mServices.get(i); |
| 311 | builder.append("\t") |
| 312 | .append(service.getClass().getSimpleName()) |
| 313 | .append("\n"); |
| 314 | } |
| 315 | |
| 316 | Slog.e(TAG, builder.toString()); |
| 317 | } |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 318 | } |