blob: d8c030d7aacf69042b62fdf9f121ccef35903fe2 [file] [log] [blame]
Kenny Root15a4d2f2010-03-11 18:20:12 -08001/*
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
Tobias Haamel53332882010-02-18 16:15:43 -080017package android.app;
18
Alan Viverette5794a5b2016-01-12 15:04:18 -050019import android.annotation.IntDef;
Tyler Gunndaef6682019-09-30 15:12:24 -070020import android.annotation.IntRange;
21import android.annotation.Nullable;
22import android.annotation.RequiresPermission;
23import android.annotation.SystemApi;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060024import android.annotation.SystemService;
Keun-young Park078f9b92016-03-02 02:18:19 +000025import android.annotation.TestApi;
Mathew Inwood4fb17d12018-08-14 14:25:44 +010026import android.annotation.UnsupportedAppUsage;
Dianne Hackborn7299c412010-03-04 18:41:49 -080027import android.content.Context;
28import android.content.res.Configuration;
Tobias Haamel53332882010-02-18 16:15:43 -080029import android.os.RemoteException;
30import android.os.ServiceManager;
Jeff Sharkey49ca5292016-05-10 12:54:45 -060031import android.os.ServiceManager.ServiceNotFoundException;
Tobias Haamel53332882010-02-18 16:15:43 -080032
Alan Viverette5794a5b2016-01-12 15:04:18 -050033import java.lang.annotation.Retention;
34import java.lang.annotation.RetentionPolicy;
35
Tobias Haamel53332882010-02-18 16:15:43 -080036/**
37 * This class provides access to the system uimode services. These services
38 * allow applications to control UI modes of the device.
39 * It provides functionality to disable the car mode and it gives access to the
40 * night mode settings.
Dianne Hackborn7299c412010-03-04 18:41:49 -080041 *
42 * <p>These facilities are built on top of the underlying
43 * {@link android.content.Intent#ACTION_DOCK_EVENT} broadcasts that are sent when the user
44 * physical places the device into and out of a dock. When that happens,
45 * the UiModeManager switches the system {@link android.content.res.Configuration}
46 * to the appropriate UI mode, sends broadcasts about the mode switch, and
47 * starts the corresponding mode activity if appropriate. See the
48 * broadcasts {@link #ACTION_ENTER_CAR_MODE} and
49 * {@link #ACTION_ENTER_DESK_MODE} for more information.
50 *
51 * <p>In addition, the user may manually switch the system to car mode without
52 * physically being in a dock. While in car mode -- whether by manual action
53 * from the user or being physically placed in a dock -- a notification is
54 * displayed allowing the user to exit dock mode. Thus the dock mode
55 * represented here may be different than the current state of the underlying
56 * dock event broadcast.
Tobias Haamel53332882010-02-18 16:15:43 -080057 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060058@SystemService(Context.UI_MODE_SERVICE)
Tobias Haamel53332882010-02-18 16:15:43 -080059public class UiModeManager {
60 private static final String TAG = "UiModeManager";
61
Dianne Hackborn7299c412010-03-04 18:41:49 -080062 /**
63 * Broadcast sent when the device's UI has switched to car mode, either
64 * by being placed in a car dock or explicit action of the user. After
65 * sending the broadcast, the system will start the intent
66 * {@link android.content.Intent#ACTION_MAIN} with category
67 * {@link android.content.Intent#CATEGORY_CAR_DOCK}
68 * to display the car UI, which typically what an application would
69 * implement to provide their own interface. However, applications can
70 * also monitor this Intent in order to be informed of mode changes or
71 * prevent the normal car UI from being displayed by setting the result
72 * of the broadcast to {@link Activity#RESULT_CANCELED}.
73 */
74 public static String ACTION_ENTER_CAR_MODE = "android.app.action.ENTER_CAR_MODE";
Tyler Gunndaef6682019-09-30 15:12:24 -070075
76 /**
77 * Broadcast sent when the device's UI has switched to car mode, either by being placed in a car
78 * dock or explicit action of the user.
79 * <p>
80 * In addition to the behavior for {@link #ACTION_ENTER_CAR_MODE}, this broadcast includes the
81 * package name of the app which requested to enter car mode in the
82 * {@link #EXTRA_CALLING_PACKAGE}. If an app requested to enter car mode using
83 * {@link #enableCarMode(int, int)} and specified a priority this will be specified in the
84 * {@link #EXTRA_PRIORITY}.
85 *
86 * This is primarily intended to be received by other components of the Android OS.
87 * <p>
88 * Receiver requires permission: {@link android.Manifest.permission.HANDLE_CAR_MODE_CHANGES}
89 * @hide
90 */
91 @SystemApi
92 public static final String ACTION_ENTER_CAR_MODE_PRIORITIZED =
93 "android.app.action.ENTER_CAR_MODE_PRIORITIZED";
Dianne Hackborn7299c412010-03-04 18:41:49 -080094
95 /**
96 * Broadcast sent when the device's UI has switch away from car mode back
97 * to normal mode. Typically used by a car mode app, to dismiss itself
98 * when the user exits car mode.
99 */
100 public static String ACTION_EXIT_CAR_MODE = "android.app.action.EXIT_CAR_MODE";
Tyler Gunndaef6682019-09-30 15:12:24 -0700101
102 /**
103 * Broadcast sent when the device's UI has switched away from car mode back to normal mode.
104 * Typically used by a car mode app, to dismiss itself when the user exits car mode.
105 * <p>
106 * In addition to the behavior for {@link #ACTION_EXIT_CAR_MODE}, this broadcast includes the
107 * package name of the app which requested to exit car mode in {@link #EXTRA_CALLING_PACKAGE}.
108 * If an app requested to enter car mode using {@link #enableCarMode(int, int)} and specified a
109 * priority this will be specified in the {@link #EXTRA_PRIORITY} when exiting car mode.
110 * <p>
111 * If {@link #DISABLE_CAR_MODE_ALL_PRIORITIES} is used when disabling car mode (i.e. this is
112 * initiated by the user via the persistent car mode notification), this broadcast is sent once
113 * for each priority level for which car mode is being disabled.
114 * <p>
115 * This is primarily intended to be received by other components of the Android OS.
116 * <p>
117 * Receiver requires permission: {@link android.Manifest.permission.HANDLE_CAR_MODE_CHANGES}
118 * @hide
119 */
120 @SystemApi
121 public static final String ACTION_EXIT_CAR_MODE_PRIORITIZED =
122 "android.app.action.EXIT_CAR_MODE_PRIORITIZED";
Dianne Hackborn7299c412010-03-04 18:41:49 -0800123
124 /**
125 * Broadcast sent when the device's UI has switched to desk mode,
126 * by being placed in a desk dock. After
127 * sending the broadcast, the system will start the intent
128 * {@link android.content.Intent#ACTION_MAIN} with category
129 * {@link android.content.Intent#CATEGORY_DESK_DOCK}
130 * to display the desk UI, which typically what an application would
131 * implement to provide their own interface. However, applications can
132 * also monitor this Intent in order to be informed of mode changes or
133 * prevent the normal desk UI from being displayed by setting the result
134 * of the broadcast to {@link Activity#RESULT_CANCELED}.
135 */
136 public static String ACTION_ENTER_DESK_MODE = "android.app.action.ENTER_DESK_MODE";
137
138 /**
Daniel Sandlerb999abc2010-03-11 15:19:53 -0500139 * Broadcast sent when the device's UI has switched away from desk mode back
140 * to normal mode. Typically used by a desk mode app, to dismiss itself
141 * when the user exits desk mode.
Dianne Hackborn7299c412010-03-04 18:41:49 -0800142 */
143 public static String ACTION_EXIT_DESK_MODE = "android.app.action.EXIT_DESK_MODE";
Alan Viverette5794a5b2016-01-12 15:04:18 -0500144
Tyler Gunndaef6682019-09-30 15:12:24 -0700145 /**
146 * String extra used with {@link #ACTION_ENTER_CAR_MODE_PRIORITIZED} and
147 * {@link #ACTION_EXIT_CAR_MODE_PRIORITIZED} to indicate the package name of the app which
148 * requested to enter or exit car mode.
149 * @hide
150 */
151 @SystemApi
152 public static final String EXTRA_CALLING_PACKAGE = "android.app.extra.CALLING_PACKAGE";
153
154 /**
155 * Integer extra used with {@link #ACTION_ENTER_CAR_MODE_PRIORITIZED} and
156 * {@link #ACTION_EXIT_CAR_MODE_PRIORITIZED} to indicate the priority level at which car mode
157 * is being disabled.
158 * @hide
159 */
160 @SystemApi
161 public static final String EXTRA_PRIORITY = "android.app.extra.PRIORITY";
162
Alan Viverette5794a5b2016-01-12 15:04:18 -0500163 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700164 @IntDef(prefix = { "MODE_" }, value = {
165 MODE_NIGHT_AUTO,
166 MODE_NIGHT_NO,
167 MODE_NIGHT_YES
168 })
Alan Viverette5794a5b2016-01-12 15:04:18 -0500169 @Retention(RetentionPolicy.SOURCE)
170 public @interface NightMode {}
171
172 /**
173 * Constant for {@link #setNightMode(int)} and {@link #getNightMode()}:
Dianne Hackborn7299c412010-03-04 18:41:49 -0800174 * automatically switch night mode on and off based on the time.
175 */
176 public static final int MODE_NIGHT_AUTO = Configuration.UI_MODE_NIGHT_UNDEFINED >> 4;
177
Alan Viverette5794a5b2016-01-12 15:04:18 -0500178 /**
179 * Constant for {@link #setNightMode(int)} and {@link #getNightMode()}:
Dianne Hackborn7299c412010-03-04 18:41:49 -0800180 * never run in night mode.
181 */
182 public static final int MODE_NIGHT_NO = Configuration.UI_MODE_NIGHT_NO >> 4;
183
Alan Viverette5794a5b2016-01-12 15:04:18 -0500184 /**
185 * Constant for {@link #setNightMode(int)} and {@link #getNightMode()}:
Dianne Hackborn7299c412010-03-04 18:41:49 -0800186 * always run in night mode.
187 */
188 public static final int MODE_NIGHT_YES = Configuration.UI_MODE_NIGHT_YES >> 4;
Tobias Haamel53332882010-02-18 16:15:43 -0800189
190 private IUiModeManager mService;
191
Tyler Gunndaef6682019-09-30 15:12:24 -0700192 /**
193 * Context required for getting the opPackageName of API caller; maybe be {@code null} if the
194 * old constructor marked with UnSupportedAppUsage is used.
195 */
196 private @Nullable Context mContext;
197
Mathew Inwood4fb17d12018-08-14 14:25:44 +0100198 @UnsupportedAppUsage
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600199 /*package*/ UiModeManager() throws ServiceNotFoundException {
Tyler Gunndaef6682019-09-30 15:12:24 -0700200 this(null /* context */);
201 }
202
203 /*package*/ UiModeManager(Context context) throws ServiceNotFoundException {
Tobias Haamel53332882010-02-18 16:15:43 -0800204 mService = IUiModeManager.Stub.asInterface(
Jeff Sharkey49ca5292016-05-10 12:54:45 -0600205 ServiceManager.getServiceOrThrow(Context.UI_MODE_SERVICE));
Tyler Gunndaef6682019-09-30 15:12:24 -0700206 mContext = context;
Tobias Haamel53332882010-02-18 16:15:43 -0800207 }
208
209 /**
Dianne Hackbornf5c5d222010-04-09 13:14:48 -0700210 * Flag for use with {@link #enableCarMode(int)}: go to the car
211 * home activity as part of the enable. Enabling this way ensures
212 * a clean transition between the current activity (in non-car-mode) and
213 * the car home activity that will serve as home while in car mode. This
214 * will switch to the car home activity even if we are already in car mode.
Tobias Haamel53332882010-02-18 16:15:43 -0800215 */
Dianne Hackbornf5c5d222010-04-09 13:14:48 -0700216 public static final int ENABLE_CAR_MODE_GO_CAR_HOME = 0x0001;
keunyoung1d0a7cc2014-07-28 13:12:50 -0700217
218 /**
keunyoungc093bf22014-08-11 18:51:15 -0700219 * Flag for use with {@link #enableCarMode(int)}: allow sleep mode while in car mode.
220 * By default, when this flag is not set, the system may hold a full wake lock to keep the
221 * screen turned on and prevent the system from entering sleep mode while in car mode.
222 * Setting this flag disables such behavior and the system may enter sleep mode
223 * if there is no other user activity and no other wake lock held.
keunyoung1d0a7cc2014-07-28 13:12:50 -0700224 * Setting this flag can be relevant for a car dock application that does not require the
225 * screen kept on.
226 */
keunyoungc093bf22014-08-11 18:51:15 -0700227 public static final int ENABLE_CAR_MODE_ALLOW_SLEEP = 0x0002;
keunyoung1d0a7cc2014-07-28 13:12:50 -0700228
Tyler Gunndaef6682019-09-30 15:12:24 -0700229 /** @hide */
230 @IntDef(prefix = { "ENABLE_CAR_MODE_" }, value = {
231 ENABLE_CAR_MODE_GO_CAR_HOME,
232 ENABLE_CAR_MODE_ALLOW_SLEEP
233 })
234 @Retention(RetentionPolicy.SOURCE)
235 public @interface EnableCarMode {}
236
Dianne Hackbornd49258f2010-03-26 00:44:29 -0700237 /**
Dianne Hackborn9c9c5322010-03-30 23:12:22 -0700238 * Force device into car mode, like it had been placed in the car dock.
239 * This will cause the device to switch to the car home UI as part of
240 * the mode switch.
241 * @param flags Must be 0.
242 */
243 public void enableCarMode(int flags) {
Tyler Gunndaef6682019-09-30 15:12:24 -0700244 enableCarMode(DEFAULT_PRIORITY, flags);
245 }
246
247 /**
248 * Force device into car mode, like it had been placed in the car dock. This will cause the
249 * device to switch to the car home UI as part of the mode switch.
250 * <p>
251 * An app may request to enter car mode when the system is already in car mode. The app may
252 * specify a "priority" when entering car mode. The device will remain in car mode
253 * (i.e. {@link #getCurrentModeType()} is {@link Configuration#UI_MODE_TYPE_CAR}) as long as
254 * there is a priority level at which car mode have been enabled. For example assume app A
255 * enters car mode at priority level 100, and then app B enters car mode at the default priority
256 * (0). If app A exits car mode, the device will remain in car mode until app B exits car mode.
257 * <p>
258 * Specifying a priority level when entering car mode is important in cases where multiple apps
259 * on a device implement a car-mode {@link android.telecom.InCallService} (see
260 * {@link android.telecom.TelecomManager#METADATA_IN_CALL_SERVICE_CAR_MODE_UI}). The
261 * {@link android.telecom.InCallService} associated with the highest priority app which entered
262 * car mode will be bound to by Telecom and provided with information about ongoing calls on
263 * the device.
264 * <p>
265 * System apps holding the required permission can enable car mode when the app determines the
266 * correct conditions exist for that app to be in car mode. The device maker should ensure that
267 * where multiple apps exist on the device which can potentially enter car mode, appropriate
268 * priorities are used to ensure that calls delivered by the
269 * {@link android.telecom.InCallService} API are delivered to the highest priority app.
270 * If app A and app B can both potentially enable car mode, and it is desired that app B is the
271 * one which should receive call information, the priority for app B should be higher than the
272 * one for app A.
273 * <p>
274 * When an app uses a priority to enable car mode, they can disable car mode at the specified
275 * priority level using {@link #disableCarMode(int)}. An app may only enable car mode at a
276 * single priority.
277 * <p>
278 * Public apps are assumed to enter/exit car mode at {@link #DEFAULT_PRIORITY}.
279 *
280 * @param priority The declared priority for the caller.
281 * @param flags Car mode flags.
282 * @hide
283 */
284 @SystemApi
285 @TestApi
286 @RequiresPermission(android.Manifest.permission.ENTER_CAR_MODE_PRIORITIZED)
287 public void enableCarMode(@IntRange(from = 0) int priority, @EnableCarMode int flags) {
Dianne Hackborn9c9c5322010-03-30 23:12:22 -0700288 if (mService != null) {
289 try {
Tyler Gunndaef6682019-09-30 15:12:24 -0700290 mService.enableCarMode(flags, priority,
291 mContext == null ? null : mContext.getOpPackageName());
Dianne Hackborn9c9c5322010-03-30 23:12:22 -0700292 } catch (RemoteException e) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700293 throw e.rethrowFromSystemServer();
Dianne Hackborn9c9c5322010-03-30 23:12:22 -0700294 }
295 }
296 }
297
298 /**
Dianne Hackbornf5c5d222010-04-09 13:14:48 -0700299 * Flag for use with {@link #disableCarMode(int)}: go to the normal
300 * home activity as part of the disable. Disabling this way ensures
301 * a clean transition between the current activity (in car mode) and
302 * the original home activity (which was typically last running without
303 * being in car mode).
304 */
305 public static final int DISABLE_CAR_MODE_GO_HOME = 0x0001;
Tyler Gunndaef6682019-09-30 15:12:24 -0700306
307 /**
308 * Flag for use with {@link #disableCarMode(int)}: Disables car mode at ALL priority levels.
309 * Primarily intended for use from {@link com.android.internal.app.DisableCarModeActivity} to
310 * provide the user with a means to exit car mode at all priority levels.
311 * @hide
312 */
313 public static final int DISABLE_CAR_MODE_ALL_PRIORITIES = 0x0002;
314
315 /** @hide */
316 @IntDef(prefix = { "DISABLE_CAR_MODE_" }, value = {
317 DISABLE_CAR_MODE_GO_HOME
318 })
319 @Retention(RetentionPolicy.SOURCE)
320 public @interface DisableCarMode {}
321
322 /**
323 * The default priority used for entering car mode.
324 * <p>
325 * Callers of the {@link UiModeManager#enableCarMode(int)} priority will be assigned the
326 * default priority.
327 * <p>
328 * System apps can specify a priority other than the default priority when using
329 * {@link UiModeManager#enableCarMode(int, int)} to enable car mode.
330 * @hide
331 */
332 @SystemApi
333 public static final int DEFAULT_PRIORITY = 0;
Dianne Hackbornf5c5d222010-04-09 13:14:48 -0700334
335 /**
Dianne Hackbornd49258f2010-03-26 00:44:29 -0700336 * Turn off special mode if currently in car mode.
Tyler Gunndaef6682019-09-30 15:12:24 -0700337 * @param flags One of the disable car mode flags.
Dianne Hackbornd49258f2010-03-26 00:44:29 -0700338 */
Tyler Gunndaef6682019-09-30 15:12:24 -0700339 public void disableCarMode(@DisableCarMode int flags) {
Tobias Haamel53332882010-02-18 16:15:43 -0800340 if (mService != null) {
341 try {
Tyler Gunndaef6682019-09-30 15:12:24 -0700342 mService.disableCarModeByCallingPackage(flags,
343 mContext == null ? null : mContext.getOpPackageName());
Tobias Haamel53332882010-02-18 16:15:43 -0800344 } catch (RemoteException e) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700345 throw e.rethrowFromSystemServer();
Tobias Haamel53332882010-02-18 16:15:43 -0800346 }
347 }
348 }
349
350 /**
Dianne Hackborn7299c412010-03-04 18:41:49 -0800351 * Return the current running mode type. May be one of
352 * {@link Configuration#UI_MODE_TYPE_NORMAL Configuration.UI_MODE_TYPE_NORMAL},
John Spurlock6c191292014-04-03 16:37:27 -0400353 * {@link Configuration#UI_MODE_TYPE_DESK Configuration.UI_MODE_TYPE_DESK},
354 * {@link Configuration#UI_MODE_TYPE_CAR Configuration.UI_MODE_TYPE_CAR},
355 * {@link Configuration#UI_MODE_TYPE_TELEVISION Configuration.UI_MODE_TYPE_TELEVISION},
Zak Cohen1a6acdb2016-12-12 15:21:21 -0800356 * {@link Configuration#UI_MODE_TYPE_APPLIANCE Configuration.UI_MODE_TYPE_APPLIANCE},
357 * {@link Configuration#UI_MODE_TYPE_WATCH Configuration.UI_MODE_TYPE_WATCH}, or
358 * {@link Configuration#UI_MODE_TYPE_VR_HEADSET Configuration.UI_MODE_TYPE_VR_HEADSET}.
Dianne Hackborn7299c412010-03-04 18:41:49 -0800359 */
360 public int getCurrentModeType() {
361 if (mService != null) {
362 try {
363 return mService.getCurrentModeType();
364 } catch (RemoteException e) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700365 throw e.rethrowFromSystemServer();
Dianne Hackborn7299c412010-03-04 18:41:49 -0800366 }
367 }
368 return Configuration.UI_MODE_TYPE_NORMAL;
369 }
370
371 /**
Lucas Dupinb01c3902018-09-19 09:51:02 -0700372 * Sets the system-wide night mode.
Alan Viverette5794a5b2016-01-12 15:04:18 -0500373 * <p>
374 * The mode can be one of:
Tobias Haamel53332882010-02-18 16:15:43 -0800375 * <ul>
Alan Viverette5794a5b2016-01-12 15:04:18 -0500376 * <li><em>{@link #MODE_NIGHT_NO}<em> sets the device into
377 * {@code notnight} mode</li>
378 * <li><em>{@link #MODE_NIGHT_YES}</em> sets the device into
379 * {@code night} mode</li>
380 * <li><em>{@link #MODE_NIGHT_AUTO}</em> automatically switches between
381 * {@code night} and {@code notnight} based on the device's current
382 * location and certain other sensors</li>
Dianne Hackborn7299c412010-03-04 18:41:49 -0800383 * </ul>
Alan Viverette5794a5b2016-01-12 15:04:18 -0500384 * <p>
385 * <strong>Note:</strong> On API 22 and below, changes to the night mode
386 * are only effective when the {@link Configuration#UI_MODE_TYPE_CAR car}
387 * or {@link Configuration#UI_MODE_TYPE_DESK desk} mode is enabled on a
Winsonadc69672019-01-28 14:56:12 -0800388 * device. On API 23 through API 28, changes to night mode are always effective.
389 * <p>
390 * Starting in API 29, when the device is in car mode and this method is called, night mode
391 * will change, but the new setting is not persisted and the previously persisted setting
392 * will be restored when the device exits car mode.
Lucas Dupinb01c3902018-09-19 09:51:02 -0700393 * <p>
394 * Changes to night mode take effect globally and will result in a configuration change
395 * (and potentially an Activity lifecycle event) being applied to all running apps.
396 * Developers interested in an app-local implementation of night mode should consider using
Nan Zhang99adf3c2018-09-21 14:51:38 -0700397 * {@link android.support.v7.app.AppCompatDelegate#setDefaultNightMode(int)} to manage the
Lucas Dupinb01c3902018-09-19 09:51:02 -0700398 * -night qualifier locally.
Alan Viverette5794a5b2016-01-12 15:04:18 -0500399 *
400 * @param mode the night mode to set
401 * @see #getNightMode()
Tobias Haamel53332882010-02-18 16:15:43 -0800402 */
Alan Viverette5794a5b2016-01-12 15:04:18 -0500403 public void setNightMode(@NightMode int mode) {
Tobias Haamel53332882010-02-18 16:15:43 -0800404 if (mService != null) {
405 try {
406 mService.setNightMode(mode);
407 } catch (RemoteException e) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700408 throw e.rethrowFromSystemServer();
Tobias Haamel53332882010-02-18 16:15:43 -0800409 }
410 }
411 }
412
413 /**
Alan Viverette5794a5b2016-01-12 15:04:18 -0500414 * Returns the currently configured night mode.
415 * <p>
416 * May be one of:
417 * <ul>
418 * <li>{@link #MODE_NIGHT_NO}</li>
419 * <li>{@link #MODE_NIGHT_YES}</li>
420 * <li>{@link #MODE_NIGHT_AUTO}</li>
421 * <li>{@code -1} on error</li>
422 * </ul>
423 *
424 * @return the current night mode, or {@code -1} on error
425 * @see #setNightMode(int)
Tobias Haamel53332882010-02-18 16:15:43 -0800426 */
Alan Viverette5794a5b2016-01-12 15:04:18 -0500427 public @NightMode int getNightMode() {
Tobias Haamel53332882010-02-18 16:15:43 -0800428 if (mService != null) {
429 try {
430 return mService.getNightMode();
431 } catch (RemoteException e) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700432 throw e.rethrowFromSystemServer();
Tobias Haamel53332882010-02-18 16:15:43 -0800433 }
434 }
435 return -1;
436 }
keunyounga7710492015-09-23 11:33:58 -0700437
438 /**
439 * @return If UI mode is locked or not. When UI mode is locked, calls to change UI mode
440 * like {@link #enableCarMode(int)} will silently fail.
Keun-young Park078f9b92016-03-02 02:18:19 +0000441 * @hide
keunyounga7710492015-09-23 11:33:58 -0700442 */
Keun-young Park078f9b92016-03-02 02:18:19 +0000443 @TestApi
keunyounga7710492015-09-23 11:33:58 -0700444 public boolean isUiModeLocked() {
445 if (mService != null) {
446 try {
447 return mService.isUiModeLocked();
448 } catch (RemoteException e) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700449 throw e.rethrowFromSystemServer();
keunyounga7710492015-09-23 11:33:58 -0700450 }
451 }
452 return true;
453 }
454
455 /**
Alan Viverette5794a5b2016-01-12 15:04:18 -0500456 * Returns whether night mode is locked or not.
457 * <p>
458 * When night mode is locked, only privileged system components may change
459 * night mode and calls from non-privileged applications to change night
460 * mode will fail silently.
461 *
462 * @return {@code true} if night mode is locked or {@code false} otherwise
Keun-young Park078f9b92016-03-02 02:18:19 +0000463 * @hide
keunyounga7710492015-09-23 11:33:58 -0700464 */
Keun-young Park078f9b92016-03-02 02:18:19 +0000465 @TestApi
keunyounga7710492015-09-23 11:33:58 -0700466 public boolean isNightModeLocked() {
467 if (mService != null) {
468 try {
469 return mService.isNightModeLocked();
470 } catch (RemoteException e) {
Jeff Sharkeyc53962d2016-03-01 19:27:23 -0700471 throw e.rethrowFromSystemServer();
keunyounga7710492015-09-23 11:33:58 -0700472 }
473 }
474 return true;
475 }
Jay Aliomer8b2671b2019-10-24 13:18:06 -0400476
477 /**
478 * @hide*
479 */
480 public boolean setNightModeActivated(boolean active) {
481 if (mService != null) {
482 try {
483 return mService.setNightModeActivated(active);
484 } catch (RemoteException e) {
485 throw e.rethrowFromSystemServer();
486 }
487 }
488 return false;
489 }
Tobias Haamel53332882010-02-18 16:15:43 -0800490}