Java Code Examples for android.os.PowerManager#isInteractive()

The following examples show how to use android.os.PowerManager#isInteractive() . 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: BatterySaverController.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void updateBatterySavingStats() {
    final PowerManager pm = getPowerManager();
    if (pm == null) {
        Slog.wtf(TAG, "PowerManager not initialized");
        return;
    }
    final boolean isInteractive = pm.isInteractive();
    final int dozeMode =
            pm.isDeviceIdleMode() ? DozeState.DEEP
                    : pm.isLightDeviceIdleMode() ? DozeState.LIGHT
                    : DozeState.NOT_DOZING;

    synchronized (mLock) {
        if (mIsPluggedIn) {
            mBatterySavingStats.startCharging();
            return;
        }
        mBatterySavingStats.transitionState(
                mEnabled ? BatterySaverState.ON : BatterySaverState.OFF,
                isInteractive ? InteractiveState.INTERACTIVE : InteractiveState.NON_INTERACTIVE,
                dozeMode);
    }
}
 
Example 2
Source File: Tools.java    From trojandroid_app with GNU General Public License v3.0 6 votes vote down vote up
public static boolean isScreenOn(Context context){
    PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (android.os.Build.VERSION.SDK_INT >= 20){
        if (powerManager.isInteractive()){
            return true;
        }else {
            return false;
        }
    }else if (android.os.Build.VERSION.SDK_INT < 20){
        if (powerManager.isScreenOn()){
            return true;
        }else {
            return false;
        }
    }else {
        return false;
    }
}
 
Example 3
Source File: Device.java    From android-job with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public static boolean isIdle(Context context) {
    PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        /*
         * isDeviceIdleMode() is a very strong requirement and could cause a job
         * to be never run. isDeviceIdleMode() returns true in doze mode, but jobs
         * are delayed until the device leaves doze mode
         */
        return powerManager.isDeviceIdleMode() || !powerManager.isInteractive();
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        return !powerManager.isInteractive();
    } else {
        return !powerManager.isScreenOn();
    }
}
 
Example 4
Source File: Util.java    From android-notification-log with MIT License 6 votes vote down vote up
public static boolean isScreenOn(Context context) {
	PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
	if(pm != null) {
		try {
			if(Build.VERSION.SDK_INT >= 20) {
				return pm.isInteractive();
			} else {
				//noinspection deprecation
				return pm.isScreenOn();
			}
		} catch (Exception e) {
			if(Const.DEBUG) e.printStackTrace();
		}
	}
	return false;
}
 
Example 5
Source File: ModLedControl.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
private static boolean isHeadsUpAllowed(StatusBarNotification sbn, Context context) {
    if (context == null) return false;

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    Notification n = sbn.getNotification();
    return (pm.isInteractive() &&
            keyguardAllowsHeadsUp(context) &&
            (!sbn.isOngoing() || n.fullScreenIntent != null || (n.extras.getInt("headsup", 0) != 0)));
}
 
Example 6
Source File: Util.java    From NetGuard with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isInteractive(Context context) {
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT_WATCH)
        return (pm != null && pm.isScreenOn());
    else
        return (pm != null && pm.isInteractive());
}
 
Example 7
Source File: TaskbarController.java    From Taskbar with Apache License 2.0 5 votes vote down vote up
private boolean isScreenOff() {
    if(U.isChromeOs(context))
        return false;

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    return !pm.isInteractive();
}
 
Example 8
Source File: BaseMethod.java    From KeyBlocker with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isScreenOn(Context context) {
    PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        //noinspection deprecation
        return powerManager.isScreenOn();
    } else {
        return powerManager.isInteractive();
    }
}
 
Example 9
Source File: DeviceUtils.java    From PrivacyStreams with Apache License 2.0 5 votes vote down vote up
/**
 * Get whether the device is interactive currently
 * @param context a Context instance
 * @return true if the device is interactive, otherwise false
 */
public static boolean isDeviceInteractive(Context context) {
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        return pm.isInteractive();
    } else {
        return pm.isScreenOn();
    }
}
 
Example 10
Source File: ApiCompatibilityUtils.java    From cronet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @return Whether the screen of the device is interactive.
 */
@SuppressWarnings("deprecation")
public static boolean isInteractive(Context context) {
    PowerManager manager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        return manager.isInteractive();
    } else {
        return manager.isScreenOn();
    }
}
 
Example 11
Source File: DeviceUtils.java    From JobSchedulerCompat with MIT License 5 votes vote down vote up
@SuppressWarnings({"deprecation", "ConstantConditions"})
public static boolean isIdle(Context context) {
    PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return powerManager.isDeviceIdleMode() || !powerManager.isInteractive();
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        return !powerManager.isInteractive();
    } else {
        return !powerManager.isScreenOn();
    }
}
 
Example 12
Source File: Compatibility.java    From Linphone4Android with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static boolean isScreenOn(PowerManager pm) {
	if (Version.sdkAboveOrEqual(20)) {
		return pm.isInteractive();
	} else {
		return pm.isScreenOn();
	}
}
 
Example 13
Source File: Requirements.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private boolean checkIdleRequirement(Context context) {
  if (!isIdleRequired()) {
    return true;
  }
  PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
  return Util.SDK_INT >= 23
      ? !powerManager.isDeviceIdleMode()
      : Util.SDK_INT >= 20 ? !powerManager.isInteractive() : !powerManager.isScreenOn();
}
 
Example 14
Source File: Util.java    From kcanotify with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isInteractive(Context context) {
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT_WATCH)
        return (pm != null && pm.isScreenOn());
    else
        return (pm != null && pm.isInteractive());
}
 
Example 15
Source File: FirebaseNotificationService.java    From weMessage with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);

    if(!powerManager.isInteractive()) {
        PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "WeMessageNotificationWakeLock");
        wakeLock.acquire(5 * 1000);
    }

    weMessage.get().getNotificationManager().showFirebaseNotification(this, remoteMessage);
}
 
Example 16
Source File: WidgetUtils.java    From your-local-weather with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isInteractive(Context context) {
    PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        return powerManager.isInteractive();
    } else {
        return powerManager.isScreenOn();
    }
}
 
Example 17
Source File: BackgroundModeExt.java    From cordova-plugin-background-mode with Apache License 2.0 5 votes vote down vote up
/**
 * Returns if the screen is active.
 */
@SuppressWarnings("deprecation")
private boolean isDimmed()
{
    PowerManager pm = (PowerManager) getService(POWER_SERVICE);

    if (SDK_INT < 20)
    {
        return !pm.isScreenOn();
    }

    return !pm.isInteractive();
}
 
Example 18
Source File: Requirements.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private boolean checkIdleRequirement(Context context) {
  if (!isIdleRequired()) {
    return true;
  }
  PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
  return Util.SDK_INT >= 23
      ? !powerManager.isDeviceIdleMode()
      : Util.SDK_INT >= 20 ? !powerManager.isInteractive() : !powerManager.isScreenOn();
}
 
Example 19
Source File: AlarmService.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
public static void setAlarm(@NonNull Context c, @Nullable Pair<Alarm, LocalDateTime> alarm) {

        MyAlarmManager am = MyAlarmManager.with(c);

        Intent i = new Intent(c, AlarmReceiver.class);
        if (alarm != null) {
            if (alarm.equals(sLastSchedule) && !BuildConfig.DEBUG)
                return;

            if (!Build.MANUFACTURER.equals("samsung")) {
                sLastSchedule = alarm;
            } else {
                PowerManager pm = (PowerManager) c.getSystemService(Context.POWER_SERVICE);
                if (pm.isInteractive()) {
                    sLastSchedule = alarm;
                }
            }

            long time = alarm.second.toDateTime().getMillis();
            if (BuildConfig.DEBUG) Log.e("ALARM", "Next Alarm: " + alarm.second.toString());
            i.putExtra(EXTRA_ALARMID, alarm.first.getId());
            i.putExtra(EXTRA_TIME, time);
            PendingIntent service = PendingIntent.getBroadcast(c, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);

            am.cancel(service);

            am.setExact(AlarmManager.RTC_WAKEUP, time, service);

        }

    }
 
Example 20
Source File: Utils.java    From EZScreenshot with Apache License 2.0 2 votes vote down vote up
/**
 * 判断屏幕是否点亮
 * @param context
 * @return
 */
public static boolean isScreenOn(Context context) {
    PowerManager powermanager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    return powermanager.isInteractive();
}