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