Java Code Examples for android.view.Display#STATE_ON
The following examples show how to use
android.view.Display#STATE_ON .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DisplayPowerState.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public DisplayPowerState(DisplayBlanker blanker, ColorFade colorFade) { mHandler = new Handler(true /*async*/); mChoreographer = Choreographer.getInstance(); mBlanker = blanker; mColorFade = colorFade; mPhotonicModulator = new PhotonicModulator(); mPhotonicModulator.start(); // At boot time, we know that the screen is on and the electron beam // animation is not playing. We don't know the screen's brightness though, // so prepare to set it to a known state when the state is next applied. // Although we set the brightness to full on here, the display power controller // will reset the brightness to a new level immediately before the changes // actually have a chance to be applied. mScreenState = Display.STATE_ON; mScreenBrightness = PowerManager.BRIGHTNESS_ON; scheduleScreenUpdate(); mColorFadePrepared = false; mColorFadeLevel = 1.0f; mColorFadeReady = true; }
Example 2
Source File: PowerManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public void setDozeOverrideFromDreamManager(int screenState, int screenBrightness) { switch (screenState) { case Display.STATE_UNKNOWN: case Display.STATE_OFF: case Display.STATE_DOZE: case Display.STATE_DOZE_SUSPEND: case Display.STATE_ON_SUSPEND: case Display.STATE_ON: case Display.STATE_VR: break; default: screenState = Display.STATE_UNKNOWN; break; } if (screenBrightness < PowerManager.BRIGHTNESS_DEFAULT || screenBrightness > PowerManager.BRIGHTNESS_ON) { screenBrightness = PowerManager.BRIGHTNESS_DEFAULT; } setDozeOverrideFromDreamManagerInternal(screenState, screenBrightness); }
Example 3
Source File: DisplayContent.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
boolean okToDisplay() { if (mDisplayId == DEFAULT_DISPLAY) { return !mService.mDisplayFrozen && mService.mDisplayEnabled && mService.mPolicy.isScreenOn(); } return mDisplayInfo.state == Display.STATE_ON; }
Example 4
Source File: FlutterIncallManagerPlugin.java From flutter-incall-manager with ISC License | 5 votes |
private void debugScreenPowerState() { String isDeviceIdleMode = "unknow"; // --- API 23 String isIgnoringBatteryOptimizations = "unknow"; // --- API 23 String isPowerSaveMode = "unknow"; // --- API 21 String isInteractive = "unknow"; // --- API 20 ( before since API 7 is: isScreenOn()) String screenState = "unknow"; // --- API 20 if (Build.VERSION.SDK_INT >= 23) { isDeviceIdleMode = String.format("%s", mPowerManager.isDeviceIdleMode()); isIgnoringBatteryOptimizations = String.format("%s", mPowerManager.isIgnoringBatteryOptimizations(mPackageName)); } if (Build.VERSION.SDK_INT >= 21) { isPowerSaveMode = String.format("%s", mPowerManager.isPowerSaveMode()); } if (Build.VERSION.SDK_INT >= 20) { isInteractive = String.format("%s", mPowerManager.isInteractive()); Display display = mWindowManager.getDefaultDisplay(); switch (display.getState()) { case Display.STATE_OFF: screenState = "STATE_OFF"; break; case Display.STATE_ON: screenState = "STATE_ON"; break; case Display.STATE_DOZE: screenState = "STATE_DOZE"; break; case Display.STATE_DOZE_SUSPEND: screenState = "STATE_DOZE_SUSPEND"; break; default: break; } } else { isInteractive = String.format("%s", mPowerManager.isScreenOn()); } Log.d(TAG, String.format("debugScreenPowerState(): screenState='%s', isInteractive='%s', isPowerSaveMode='%s', isDeviceIdleMode='%s', isIgnoringBatteryOptimizations='%s'", screenState, isInteractive, isPowerSaveMode, isDeviceIdleMode, isIgnoringBatteryOptimizations)); }
Example 5
Source File: StatusbarClock.java From GravityBox with Apache License 2.0 | 5 votes |
private void updateSecondsHandler() { if (mClock == null) return; if (mShowSeconds && mClock.getDisplay() != null) { mSecondsHandler = new Handler(); if (mClock.getDisplay().getState() == Display.STATE_ON && !mClockHidden) { mSecondsHandler.postAtTime(mSecondTick, SystemClock.uptimeMillis() / 1000 * 1000 + 1000); } } else if (mSecondsHandler != null) { mSecondsHandler.removeCallbacks(mSecondTick); mSecondsHandler = null; updateClock(); } }
Example 6
Source File: Utils.java From ForceDoze with GNU General Public License v3.0 | 5 votes |
public static boolean isScreenOn(Context context) { DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE); for (Display display : dm.getDisplays()) { if (display.getState() == Display.STATE_ON || display.getState() == Display.STATE_UNKNOWN) { return true; } } return false; }
Example 7
Source File: InCallManagerModule.java From react-native-incall-manager with ISC License | 5 votes |
private void debugScreenPowerState() { String isDeviceIdleMode = "unknow"; // --- API 23 String isIgnoringBatteryOptimizations = "unknow"; // --- API 23 String isPowerSaveMode = "unknow"; // --- API 21 String isInteractive = "unknow"; // --- API 20 ( before since API 7 is: isScreenOn()) String screenState = "unknow"; // --- API 20 if (android.os.Build.VERSION.SDK_INT >= 23) { isDeviceIdleMode = String.format("%s", mPowerManager.isDeviceIdleMode()); isIgnoringBatteryOptimizations = String.format("%s", mPowerManager.isIgnoringBatteryOptimizations(mPackageName)); } if (android.os.Build.VERSION.SDK_INT >= 21) { isPowerSaveMode = String.format("%s", mPowerManager.isPowerSaveMode()); } if (android.os.Build.VERSION.SDK_INT >= 20) { isInteractive = String.format("%s", mPowerManager.isInteractive()); Display display = mWindowManager.getDefaultDisplay(); switch (display.getState()) { case Display.STATE_OFF: screenState = "STATE_OFF"; break; case Display.STATE_ON: screenState = "STATE_ON"; break; case Display.STATE_DOZE: screenState = "STATE_DOZE"; break; case Display.STATE_DOZE_SUSPEND: screenState = "STATE_DOZE_SUSPEND"; break; default: break; } } else { isInteractive = String.format("%s", mPowerManager.isScreenOn()); } Log.d(TAG, String.format("debugScreenPowerState(): screenState='%s', isInteractive='%s', isPowerSaveMode='%s', isDeviceIdleMode='%s', isIgnoringBatteryOptimizations='%s'", screenState, isInteractive, isPowerSaveMode, isDeviceIdleMode, isIgnoringBatteryOptimizations)); }
Example 8
Source File: DisplayManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
private void requestGlobalDisplayStateInternal(int state, int brightness) { if (state == Display.STATE_UNKNOWN) { state = Display.STATE_ON; } if (state == Display.STATE_OFF) { brightness = PowerManager.BRIGHTNESS_OFF; } else if (brightness < 0) { brightness = PowerManager.BRIGHTNESS_DEFAULT; } else if (brightness > PowerManager.BRIGHTNESS_ON) { brightness = PowerManager.BRIGHTNESS_ON; } synchronized (mTempDisplayStateWorkQueue) { try { // Update the display state within the lock. // Note that we do not need to schedule traversals here although it // may happen as a side-effect of displays changing state. synchronized (mSyncRoot) { if (mGlobalDisplayState == state && mGlobalDisplayBrightness == brightness) { return; // no change } Trace.traceBegin(Trace.TRACE_TAG_POWER, "requestGlobalDisplayState(" + Display.stateToString(state) + ", brightness=" + brightness + ")"); mGlobalDisplayState = state; mGlobalDisplayBrightness = brightness; applyGlobalDisplayStateLocked(mTempDisplayStateWorkQueue); } // Setting the display power state can take hundreds of milliseconds // to complete so we defer the most expensive part of the work until // after we have exited the critical section to avoid blocking other // threads for a long time. for (int i = 0; i < mTempDisplayStateWorkQueue.size(); i++) { mTempDisplayStateWorkQueue.get(i).run(); } Trace.traceEnd(Trace.TRACE_TAG_POWER); } finally { mTempDisplayStateWorkQueue.clear(); } } }
Example 9
Source File: VirtualDisplayAdapter.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
@Override public DisplayDeviceInfo getDisplayDeviceInfoLocked() { if (mInfo == null) { mInfo = new DisplayDeviceInfo(); mInfo.name = mName; mInfo.uniqueId = getUniqueId(); mInfo.width = mWidth; mInfo.height = mHeight; mInfo.modeId = mMode.getModeId(); mInfo.defaultModeId = mMode.getModeId(); mInfo.supportedModes = new Display.Mode[] { mMode }; mInfo.densityDpi = mDensityDpi; mInfo.xDpi = mDensityDpi; mInfo.yDpi = mDensityDpi; mInfo.presentationDeadlineNanos = 1000000000L / (int) REFRESH_RATE; // 1 frame mInfo.flags = 0; if ((mFlags & VIRTUAL_DISPLAY_FLAG_PUBLIC) == 0) { mInfo.flags |= DisplayDeviceInfo.FLAG_PRIVATE | DisplayDeviceInfo.FLAG_NEVER_BLANK; } if ((mFlags & VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR) != 0) { mInfo.flags &= ~DisplayDeviceInfo.FLAG_NEVER_BLANK; } else { mInfo.flags |= DisplayDeviceInfo.FLAG_OWN_CONTENT_ONLY; } if ((mFlags & VIRTUAL_DISPLAY_FLAG_SECURE) != 0) { mInfo.flags |= DisplayDeviceInfo.FLAG_SECURE; } if ((mFlags & VIRTUAL_DISPLAY_FLAG_PRESENTATION) != 0) { mInfo.flags |= DisplayDeviceInfo.FLAG_PRESENTATION; if ((mFlags & VIRTUAL_DISPLAY_FLAG_PUBLIC) != 0) { // For demonstration purposes, allow rotation of the external display. // In the future we might allow the user to configure this directly. if ("portrait".equals(SystemProperties.get( "persist.demo.remoterotation"))) { mInfo.rotation = Surface.ROTATION_270; } } } if ((mFlags & VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD) != 0) { mInfo.flags |= DisplayDeviceInfo.FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD; } if ((mFlags & VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT) != 0) { mInfo.flags |= DisplayDeviceInfo.FLAG_ROTATES_WITH_CONTENT; } if ((mFlags & VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL) != 0) { mInfo.flags |= DisplayDeviceInfo.FLAG_DESTROY_CONTENT_ON_REMOVAL; } mInfo.type = Display.TYPE_VIRTUAL; mInfo.touch = ((mFlags & VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH) == 0) ? DisplayDeviceInfo.TOUCH_NONE : DisplayDeviceInfo.TOUCH_VIRTUAL; mInfo.state = mSurface != null ? Display.STATE_ON : Display.STATE_OFF; mInfo.ownerUid = mOwnerUid; mInfo.ownerPackageName = mOwnerPackageName; } return mInfo; }
Example 10
Source File: PowerManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * Updates the display power state asynchronously. * When the update is finished, mDisplayReady will be set to true. The display * controller posts a message to tell us when the actual display power state * has been updated so we come back here to double-check and finish up. * * This function recalculates the display power state each time. * * @return True if the display became ready. */ private boolean updateDisplayPowerStateLocked(int dirty) { final boolean oldDisplayReady = mDisplayReady; if ((dirty & (DIRTY_WAKE_LOCKS | DIRTY_USER_ACTIVITY | DIRTY_WAKEFULNESS | DIRTY_ACTUAL_DISPLAY_POWER_STATE_UPDATED | DIRTY_BOOT_COMPLETED | DIRTY_SETTINGS | DIRTY_SCREEN_BRIGHTNESS_BOOST | DIRTY_VR_MODE_CHANGED | DIRTY_QUIESCENT)) != 0) { mDisplayPowerRequest.policy = getDesiredScreenPolicyLocked(); // Determine appropriate screen brightness and auto-brightness adjustments. final boolean autoBrightness; final int screenBrightnessOverride; if (!mBootCompleted) { // Keep the brightness steady during boot. This requires the // bootloader brightness and the default brightness to be identical. autoBrightness = false; screenBrightnessOverride = mScreenBrightnessSettingDefault; } else if (isValidBrightness(mScreenBrightnessOverrideFromWindowManager)) { autoBrightness = false; screenBrightnessOverride = mScreenBrightnessOverrideFromWindowManager; } else { autoBrightness = (mScreenBrightnessModeSetting == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC); screenBrightnessOverride = -1; } // Update display power request. mDisplayPowerRequest.screenBrightnessOverride = screenBrightnessOverride; mDisplayPowerRequest.useAutoBrightness = autoBrightness; mDisplayPowerRequest.useProximitySensor = shouldUseProximitySensorLocked(); mDisplayPowerRequest.boostScreenBrightness = shouldBoostScreenBrightness(); updatePowerRequestFromBatterySaverPolicy(mDisplayPowerRequest); if (mDisplayPowerRequest.policy == DisplayPowerRequest.POLICY_DOZE) { mDisplayPowerRequest.dozeScreenState = mDozeScreenStateOverrideFromDreamManager; if ((mWakeLockSummary & WAKE_LOCK_DRAW) != 0 && !mDrawWakeLockOverrideFromSidekick) { if (mDisplayPowerRequest.dozeScreenState == Display.STATE_DOZE_SUSPEND) { mDisplayPowerRequest.dozeScreenState = Display.STATE_DOZE; } if (mDisplayPowerRequest.dozeScreenState == Display.STATE_ON_SUSPEND) { mDisplayPowerRequest.dozeScreenState = Display.STATE_ON; } } mDisplayPowerRequest.dozeScreenBrightness = mDozeScreenBrightnessOverrideFromDreamManager; } else { mDisplayPowerRequest.dozeScreenState = Display.STATE_UNKNOWN; mDisplayPowerRequest.dozeScreenBrightness = PowerManager.BRIGHTNESS_DEFAULT; } mDisplayReady = mDisplayManagerInternal.requestPowerState(mDisplayPowerRequest, mRequestWaitForNegativeProximity); mRequestWaitForNegativeProximity = false; if ((dirty & DIRTY_QUIESCENT) != 0) { sQuiescent = false; } if (DEBUG_SPEW) { Slog.d(TAG, "updateDisplayPowerStateLocked: mDisplayReady=" + mDisplayReady + ", policy=" + mDisplayPowerRequest.policy + ", mWakefulness=" + mWakefulness + ", mWakeLockSummary=0x" + Integer.toHexString(mWakeLockSummary) + ", mUserActivitySummary=0x" + Integer.toHexString(mUserActivitySummary) + ", mBootCompleted=" + mBootCompleted + ", screenBrightnessOverride=" + screenBrightnessOverride + ", useAutoBrightness=" + autoBrightness + ", mScreenBrightnessBoostInProgress=" + mScreenBrightnessBoostInProgress + ", mIsVrModeEnabled= " + mIsVrModeEnabled + ", sQuiescent=" + sQuiescent); } } return mDisplayReady && !oldDisplayReady; }
Example 11
Source File: RecoverySystem.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * If the package hasn't been processed (i.e. uncrypt'd), set up * UNCRYPT_PACKAGE_FILE and delete BLOCK_MAP_FILE to trigger uncrypt during the * reboot. * * @param context the Context to use * @param packageFile the update package to install. Must be on a * partition mountable by recovery. * @param processed if the package has been processed (uncrypt'd). * * @throws IOException if writing the recovery command file fails, or if * the reboot itself fails. * * @hide */ @SystemApi @RequiresPermission(android.Manifest.permission.RECOVERY) public static void installPackage(Context context, File packageFile, boolean processed) throws IOException { synchronized (sRequestLock) { LOG_FILE.delete(); // Must delete the file in case it was created by system server. UNCRYPT_PACKAGE_FILE.delete(); String filename = packageFile.getCanonicalPath(); Log.w(TAG, "!!! REBOOTING TO INSTALL " + filename + " !!!"); // If the package name ends with "_s.zip", it's a security update. boolean securityUpdate = filename.endsWith("_s.zip"); // If the package is on the /data partition, the package needs to // be processed (i.e. uncrypt'd). The caller specifies if that has // been done in 'processed' parameter. if (filename.startsWith("/data/")) { if (processed) { if (!BLOCK_MAP_FILE.exists()) { Log.e(TAG, "Package claimed to have been processed but failed to find " + "the block map file."); throw new IOException("Failed to find block map file"); } } else { FileWriter uncryptFile = new FileWriter(UNCRYPT_PACKAGE_FILE); try { uncryptFile.write(filename + "\n"); } finally { uncryptFile.close(); } // UNCRYPT_PACKAGE_FILE needs to be readable and writable // by system server. if (!UNCRYPT_PACKAGE_FILE.setReadable(true, false) || !UNCRYPT_PACKAGE_FILE.setWritable(true, false)) { Log.e(TAG, "Error setting permission for " + UNCRYPT_PACKAGE_FILE); } BLOCK_MAP_FILE.delete(); } // If the package is on the /data partition, use the block map // file as the package name instead. filename = "@/cache/recovery/block.map"; } final String filenameArg = "--update_package=" + filename + "\n"; final String localeArg = "--locale=" + Locale.getDefault().toLanguageTag() + "\n"; final String securityArg = "--security\n"; String command = filenameArg + localeArg; if (securityUpdate) { command += securityArg; } RecoverySystem rs = (RecoverySystem) context.getSystemService( Context.RECOVERY_SERVICE); if (!rs.setupBcb(command)) { throw new IOException("Setup BCB failed"); } // Having set up the BCB (bootloader control block), go ahead and reboot PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); String reason = PowerManager.REBOOT_RECOVERY_UPDATE; // On TV, reboot quiescently if the screen is off if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); if (wm.getDefaultDisplay().getState() != Display.STATE_ON) { reason += ",quiescent"; } } pm.reboot(reason); throw new IOException("Reboot failed (no permissions?)"); } }
Example 12
Source File: NotificationService.java From an2linuxclient with GNU General Public License v3.0 | 4 votes |
private boolean filter(StatusBarNotification sbn) { String packageName = sbn.getPackageName(); if (!globalEnabled() || !appEnabled(packageName)) { return false; } boolean usingCustomSettings = isUsingCustomSettings(packageName); SharedPreferences sp; if (usingCustomSettings) { sp = getSharedPreferences(getString(R.string.notification_settings_custom), MODE_PRIVATE); } else { sp = getSharedPreferences(getString(R.string.notification_settings_global), MODE_PRIVATE); } boolean isAn2linuxTestNotification = packageName.startsWith("kiwi.root.an2linuxclient"); if (dontSendIfScreenIsOn(sp, packageName, usingCustomSettings) && !isAn2linuxTestNotification) { boolean screenIsOn = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { DisplayManager dm = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE); for (Display display : dm.getDisplays()) { if (display.getState() == Display.STATE_ON) { // private as in samsung always-on feature, not sure if this is how it works // https://stackoverflow.com/questions/2474367/how-can-i-tell-if-the-screen-is-on-in-android#comment71534994_17348755 boolean displayIsPrivate = (display.getFlags() & Display.FLAG_PRIVATE) == Display.FLAG_PRIVATE; if (!displayIsPrivate) { screenIsOn = true; break; } } } } else { PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); if (powerManager.isScreenOn()){ screenIsOn = true; } } if (screenIsOn) { return false; } } int flags = sbn.getNotification().flags; if (isOngoing(flags) && blockOngoing(sp, packageName, usingCustomSettings)){ return false; } if (isForeground(flags) && blockForeground(sp, packageName, usingCustomSettings)){ return false; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH){ if (isGroupSummary(flags) && blockGroupSummary(sp, packageName, usingCustomSettings)){ return false; } if (isLocalOnly(flags) && blockLocalOnly(sp, packageName, usingCustomSettings)){ return false; } } return priorityAllowed(sp, packageName, usingCustomSettings, sbn.getNotification().priority); }
Example 13
Source File: NotificationService.java From an2linuxclient with GNU General Public License v3.0 | 4 votes |
private boolean filter(StatusBarNotification sbn) { String packageName = sbn.getPackageName(); if (!globalEnabled() || !appEnabled(packageName)) { return false; } boolean usingCustomSettings = isUsingCustomSettings(packageName); SharedPreferences sp; if (usingCustomSettings) { sp = getSharedPreferences(getString(R.string.notification_settings_custom), MODE_PRIVATE); } else { sp = getSharedPreferences(getString(R.string.notification_settings_global), MODE_PRIVATE); } boolean isAn2linuxTestNotification = packageName.startsWith("kiwi.root.an2linuxclient"); if (dontSendIfScreenIsOn(sp, packageName, usingCustomSettings) && !isAn2linuxTestNotification) { boolean screenIsOn = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { DisplayManager dm = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE); for (Display display : dm.getDisplays()) { if (display.getState() == Display.STATE_ON) { // private as in samsung always-on feature, not sure if this is how it works // https://stackoverflow.com/questions/2474367/how-can-i-tell-if-the-screen-is-on-in-android#comment71534994_17348755 boolean displayIsPrivate = (display.getFlags() & Display.FLAG_PRIVATE) == Display.FLAG_PRIVATE; if (!displayIsPrivate) { screenIsOn = true; break; } } } } else { PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); if (powerManager.isScreenOn()){ screenIsOn = true; } } if (screenIsOn) { return false; } } int flags = sbn.getNotification().flags; if (isOngoing(flags) && blockOngoing(sp, packageName, usingCustomSettings)){ return false; } if (isForeground(flags) && blockForeground(sp, packageName, usingCustomSettings)){ return false; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH){ if (isGroupSummary(flags) && blockGroupSummary(sp, packageName, usingCustomSettings)){ return false; } if (isLocalOnly(flags) && blockLocalOnly(sp, packageName, usingCustomSettings)){ return false; } } return priorityAllowed(sp, packageName, usingCustomSettings, sbn.getNotification().priority); }
Example 14
Source File: PowerUtils.java From AcDisplay with GNU General Public License v2.0 | 4 votes |
@SuppressLint("NewApi") public static boolean isScreenOn(@NonNull Context context) { display_api: if (Device.hasKitKatWatchApi()) { DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE); Display[] displays = dm.getDisplays(null); Display display = null; if (displays == null || displays.length == 0) { break display_api; } else if (displays.length > 1) { Timber.tag(TAG).i("The number of logical displays is " + displays.length); } for (Display d : displays) { final boolean virtual = Operator.bitAnd(d.getFlags(), Display.FLAG_PRESENTATION); if (d.isValid() && !virtual) { display = d; final int type; try { Method method = Display.class.getDeclaredMethod("getType"); method.setAccessible(true); type = (int) method.invoke(d); } catch (Exception e) { continue; } if (type == 1 /* built-in display */) { break; } } } if (display == null) { return false; } Timber.tag(TAG).i("Display state=" + display.getState()); return display.getState() == Display.STATE_ON; } PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); return isInteractive(pm); }