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