android.app.KeyguardManager#inKeyguardRestrictedInputMode ( )源码实例Demo

下面列出了android.app.KeyguardManager#inKeyguardRestrictedInputMode ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Maying   文件: ShadowsocksRunnerActivity.java
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
    boolean locked = km.inKeyguardRestrictedInputMode();
    if (locked) {
        IntentFilter filter = new IntentFilter(Intent.ACTION_USER_PRESENT);
        receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if (Intent.ACTION_USER_PRESENT.equals(intent.getAction())) {
                    mServiceBoundContext.attachService();
                }
            }
        };
        registerReceiver(receiver, filter);
    } else {
        mServiceBoundContext.attachService();
    }
    finish();
}
 
源代码2 项目: linphone-android   文件: MainActivity.java
private void requestPermissionsIfNotGranted(String[] perms, int resultCode) {
    ArrayList<String> permissionsToAskFor = new ArrayList<>();
    if (perms != null) { // This is created (or not) by the child activity
        for (String permissionToHave : perms) {
            if (!checkPermission(permissionToHave)) {
                permissionsToAskFor.add(permissionToHave);
            }
        }
    }

    if (permissionsToAskFor.size() > 0) {
        for (String permission : permissionsToAskFor) {
            Log.i("[Permission] Requesting " + permission + " permission");
        }
        String[] permissions = new String[permissionsToAskFor.size()];
        permissions = permissionsToAskFor.toArray(permissions);

        KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
        boolean locked = km.inKeyguardRestrictedInputMode();
        if (!locked) {
            // This is to workaround an infinite loop of pause/start in Activity issue
            // if incoming call ends while screen if off and locked
            ActivityCompat.requestPermissions(this, permissions, resultCode);
        }
    }
}
 
源代码3 项目: heads-up   文件: OverlayServiceCommon.java
private boolean isLocked() {
    if (preferences.getBoolean("off_as_locked", false)) {
        initPowerManager();
        if (!powerManager.isScreenOn()) {
            isLocked = true;
            return isLocked;
        }
    }

    KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
    final boolean isKeyguardLocked;
    if (Build.VERSION.SDK_INT >= 16)
         isKeyguardLocked = keyguardManager.isKeyguardLocked();
    else isKeyguardLocked = keyguardManager.inKeyguardRestrictedInputMode();

    Mlog.v(logTag, isKeyguardLocked + " " + LOCKSCREEN_APPS.contains(currentPackage));
    isLocked = isKeyguardLocked || (currentPackage != null && LOCKSCREEN_APPS.contains(currentPackage));
    return isLocked;
}
 
private void handleIntent(Intent intent) {
    KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
    if (km.inKeyguardRestrictedInputMode() || !ApplicationLoader.isScreenOn) {
        getWindow().addFlags(
                WindowManager.LayoutParams.FLAG_DIM_BEHIND |
                        WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                        WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
                        WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    } else {
        getWindow().addFlags(
                WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                        WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
                        WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    }

    if (currentMessageObject == null) {
        currentMessageNum = 0;
    }
    getNewMessage();
}
 
源代码5 项目: BambooPlayer   文件: VideoActivity.java
@Override
public void onResume() {
	super.onResume();
	if (!mCreated)
		return;
	if (isInitialized()) {
		KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
		if (!keyguardManager.inKeyguardRestrictedInputMode()) {
			startPlayer();
		}
	} else {
		if (mCloseComplete) {
			reOpen();
		}
	}
}
 
源代码6 项目: linphone-android   文件: MainActivity.java
public void requestPermissionIfNotGranted(String permission) {
    if (!checkPermission(permission)) {
        Log.i("[Permission] Requesting " + permission + " permission");

        String[] permissions = new String[] {permission};
        KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
        boolean locked = km.inKeyguardRestrictedInputMode();
        if (!locked) {
            // This is to workaround an infinite loop of pause/start in Activity issue
            // if incoming call ends while screen if off and locked
            ActivityCompat.requestPermissions(this, permissions, FRAGMENT_SPECIFIC_PERMISSION);
        }
    }
}
 
源代码7 项目: Telegram   文件: PopupNotificationActivity.java
private void handleIntent(Intent intent) {
    isReply = intent != null && intent.getBooleanExtra("force", false);
    popupMessages.clear();
    if (isReply) {
        int account = intent != null ? intent.getIntExtra("currentAccount", UserConfig.selectedAccount) : UserConfig.selectedAccount;
        popupMessages.addAll(NotificationsController.getInstance(account).popupReplyMessages);
    } else {
        for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
            if (UserConfig.getInstance(a).isClientActivated()) {
                popupMessages.addAll(NotificationsController.getInstance(a).popupMessages);
            }
        }
    }
    KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
    if (km.inKeyguardRestrictedInputMode() || !ApplicationLoader.isScreenOn) {
        getWindow().addFlags(
                WindowManager.LayoutParams.FLAG_DIM_BEHIND |
                        WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                        WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
                        WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    } else {
        getWindow().addFlags(
                WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                        WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
                        WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    }

    if (currentMessageObject == null) {
        currentMessageNum = 0;
    }
    getNewMessage();
}
 
源代码8 项目: DevUtils   文件: ScreenUtils.java
/**
 * 判断是否锁屏
 * @return {@code true} yes, {@code false} no
 */
public static boolean isScreenLock() {
    try {
        KeyguardManager keyguardManager = AppUtils.getKeyguardManager();
        return keyguardManager != null && keyguardManager.inKeyguardRestrictedInputMode();
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "isScreenLock");
    }
    return false;
}
 
源代码9 项目: Common   文件: ScreenUtils.java
/**
 * Return whether screen is locked.
 *
 * @return {@code true}: yes<br>{@code false}: no
 */
public static boolean isScreenLock(@NonNull final Context context) {
    KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
    if (km == null) {
        return false;
    }
    return km.inKeyguardRestrictedInputMode();
}
 
源代码10 项目: Telegram-FOSS   文件: PopupNotificationActivity.java
private void handleIntent(Intent intent) {
    isReply = intent != null && intent.getBooleanExtra("force", false);
    popupMessages.clear();
    if (isReply) {
        int account = intent != null ? intent.getIntExtra("currentAccount", UserConfig.selectedAccount) : UserConfig.selectedAccount;
        popupMessages.addAll(NotificationsController.getInstance(account).popupReplyMessages);
    } else {
        for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
            if (UserConfig.getInstance(a).isClientActivated()) {
                popupMessages.addAll(NotificationsController.getInstance(a).popupMessages);
            }
        }
    }
    KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
    if (km.inKeyguardRestrictedInputMode() || !ApplicationLoader.isScreenOn) {
        getWindow().addFlags(
                WindowManager.LayoutParams.FLAG_DIM_BEHIND |
                        WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                        WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
                        WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    } else {
        getWindow().addFlags(
                WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                        WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
                        WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    }

    if (currentMessageObject == null) {
        currentMessageNum = 0;
    }
    getNewMessage();
}
 
源代码11 项目: AndroidUtilCode   文件: ScreenUtils.java
/**
 * Return whether screen is locked.
 *
 * @return {@code true}: yes<br>{@code false}: no
 */
public static boolean isScreenLock() {
    KeyguardManager km =
            (KeyguardManager) Utils.getApp().getSystemService(Context.KEYGUARD_SERVICE);
    if (km == null) return false;
    return km.inKeyguardRestrictedInputMode();
}
 
源代码12 项目: media-button-router   文件: MediaButtonReceiver.java
/**
 * Shows the selector dialog that allows the user to decide which music
 * player should receiver the media button press intent.
 * 
 * @param context
 *            The context.
 * @param intent
 *            The intent to forward.
 * @param keyEvent
 *            The key event
 */
private void showSelector(Context context, Intent intent, KeyEvent keyEvent) {
    KeyguardManager manager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
    boolean locked = manager.inKeyguardRestrictedInputMode();

    Intent showForwardView = new Intent(Constants.INTENT_ACTION_VIEW_MEDIA_BUTTON_LIST);
    showForwardView.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    showForwardView.putExtras(intent);
    showForwardView.setClassName(context,
            locked ? ReceiverSelectorLocked.class.getName() : ReceiverSelector.class.getName());

    /* COMMENTED OUT FOR MARKET RELEASE Log.i(TAG, "Media Button Receiver: starting selector activity for keyevent: " + keyEvent); */

    if (locked) {

        // XXX See if this actually makes a difference, might
        // not be needed if we move more things to onCreate?
        PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        // acquire temp wake lock
        WakeLock wakeLock = powerManager.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP
                | PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG);
        wakeLock.setReferenceCounted(false);

        // Our app better display within 3 seconds or we have
        // bigger issues.
        wakeLock.acquire(3000);
    }
    context.startActivity(showForwardView);
}
 
源代码13 项目: sbt-android-protify   文件: ProtifyActivity.java
@Override
protected void onCreate(Bundle state) {
    super.onCreate(state);
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
    boolean isOn = Build.VERSION.SDK_INT < 7 || pm.isScreenOn();
    boolean isKG = km.inKeyguardRestrictedInputMode();
    if (!isOn || isKG) {
        finish();
        return;
    }
    TextView tv = new TextView(this);
    tv.setText("Protifying code...");
    float d = getResources().getDisplayMetrics().density;
    tv.setPadding(asDp(8, d), asDp(8, d), asDp(8, d), asDp(8, d));
    setContentView(tv);
    if (Build.VERSION.SDK_INT >= 11 &&
            (state == null || !state.getBoolean(STATE_SAVED, false))) {
        recreate();
    } else {
        new Handler().post(new Runnable() {
            @Override
            public void run() {
                finish();
            }
        });
    }
}
 
源代码14 项目: stynico   文件: AppCompatDlalog.java
/**
 * 系统是否在锁屏状态
 *
 * @return
 */
private boolean isScreenLocked()
{
    KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
    return keyguardManager.inKeyguardRestrictedInputMode();
}
 
源代码15 项目: always-on-amoled   文件: ScreenReceiver.java
@Override
public void onReceive(final Context context, Intent intent) {
    prefs = new Prefs(context);
    prefs.apply();
    this.context = context;
    if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
        MainService.isScreenOn = false;
        Globals.sensorIsScreenOff = true;
        Utils.logInfo(TAG, "Screen turned off\nShown:" + Globals.isShown);
        if (Globals.isShown && !MainService.isScreenOn) {
            // Screen turned off with service running, wake up device
            turnScreenOn(context, true);
        } else {
            //Checking if was killed by delay or naturally, if so, don't restart the service
            if (Globals.killedByDelay) {
                Globals.killedByDelay = false;
                Utils.logDebug(SCREEN_RECEIVER_LOG_TAG, "Killed by delay and won't restart");
                return;
            }
            // Start service when screen is off
            if (!Globals.inCall && prefs.enabled) {
                boolean toStart = shouldStart();
                Utils.logDebug("SHOULD START ", String.valueOf(toStart));
                if (toStart) {
                    if (prefs.startAfterLock) {
                        final KeyguardManager myKM = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
                        if (myKM.inKeyguardRestrictedInputMode()) {
                            //Screen is locked, start the service
                            Utils.logDebug(SCREEN_RECEIVER_LOG_TAG, "Device is locked");
                            context.startService(new Intent(context, MainService.class));
                            Globals.isShown = true;
                        } else {
                            //Screen is unlocked, wait until the lock timeout is over before starting the service.
                            int startDelay;
                            if (!doesDeviceHaveSecuritySetup(context)) {
                                Globals.noLock = true;
                                context.startService(new Intent(context, MainService.class));
                                Globals.isShown = true;
                                Utils.logDebug(SCREEN_RECEIVER_LOG_TAG, "Device is unlocked");
                            } else {
                                Utils.logDebug(SCREEN_RECEIVER_LOG_TAG, "Device is locked but has a timeout");
                                try {
                                    startDelay = Settings.Secure.getInt(context.getContentResolver(), "lock_screen_lock_after_timeout", 5000);
                                    if (startDelay == -1)
                                        startDelay = (int) Settings.Secure.getLong(context.getContentResolver(), "lock_screen_lock_after_timeout", 5000);
                                    Utils.logDebug(SCREEN_RECEIVER_LOG_TAG, "Lock time out " + String.valueOf(startDelay));
                                } catch (Exception settingNotFound) {
                                    startDelay = 0;
                                }
                                if (startDelay > 0) {
                                    new Handler().postDelayed(() -> {
                                        if (myKM.inKeyguardRestrictedInputMode()) {
                                            context.startService(new Intent(context, MainService.class));
                                            Globals.isShown = true;
                                        }
                                    }, startDelay);
                                } else {
                                    context.startService(new Intent(context, MainService.class));
                                    Globals.isShown = true;
                                }
                            }
                        }
                    } else {
                        context.startService(new Intent(context, MainService.class));
                        Globals.isShown = true;
                    }
                }
            }
        }
    } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
        MainService.isScreenOn = true;
        if (Globals.waitingForApp)
            Globals.waitingForApp = false;
        Utils.logInfo(TAG, "Screen turned on\nShown:" + Globals.isShown);
    }
}
 
源代码16 项目: WaterMonitor   文件: AppUtils.java
public static boolean isInLockScreen() {
    KeyguardManager keyguardManager = (KeyguardManager) AppApplication.getContext().getSystemService(KEYGUARD_SERVICE);
    return keyguardManager.inKeyguardRestrictedInputMode();
}
 
源代码17 项目: RxTools-master   文件: RxDeviceTool.java
/**
 * 判断是否锁屏
 *
 * @param context 上下文
 * @return {@code true}: 是<br>{@code false}: 否
 */
public static boolean isScreenLock(Context context) {
    KeyguardManager km = (KeyguardManager) context
            .getSystemService(Context.KEYGUARD_SERVICE);
    return km.inKeyguardRestrictedInputMode();
}
 
源代码18 项目: TitleLayout   文件: ScreenUtil.java
/**
 * 判断是否锁屏
 *
 * @return {@code true}: 是<br>{@code false}: 否
 */
public static boolean isScreenLock(Context context) {
    KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
    return km.inKeyguardRestrictedInputMode();
}
 
源代码19 项目: BigApp_Discuz_Android   文件: DeviceUtils.java
/**
 * 是否解锁
 *
 * @param context
 * @return
 */
public static boolean isKeyguard(Context context) {
    KeyguardManager mKeyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
    boolean flag = mKeyguardManager.inKeyguardRestrictedInputMode();
    return flag;
}
 
源代码20 项目: Utils   文件: AppHelper.java
/**
 * telephone is sleeping
 *
 * @param context
 * @return
 */
public static boolean isSleeping(Context context) {
    KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
    return keyguardManager.inKeyguardRestrictedInputMode();
}