Search in sources :

Example 76 with KeyguardManager

use of android.app.KeyguardManager in project android_packages_apps_Settings by DirtyUnicorns.

the class Utils method confirmWorkProfileCredentials.

private static boolean confirmWorkProfileCredentials(Context context, int userId) {
    final KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
    final Intent unlockIntent = km.createConfirmDeviceCredentialIntent(null, null, userId);
    if (unlockIntent != null) {
        context.startActivity(unlockIntent);
        return true;
    } else {
        return false;
    }
}
Also used : Intent(android.content.Intent) KeyguardManager(android.app.KeyguardManager)

Example 77 with KeyguardManager

use of android.app.KeyguardManager in project vlc-android by GeoffreyMetais.

the class VideoPlayerActivity method loadMedia.

/**
 * External extras:
 * - position (long) - position of the video to start with (in ms)
 * - subtitles_location (String) - location of a subtitles file to load
 * - from_start (boolean) - Whether playback should start from start or from resume point
 * - title (String) - video title, will be guessed from file if not set.
 */
@SuppressLint("SdCardPath")
@TargetApi(12)
@SuppressWarnings({ "unchecked" })
protected void loadMedia() {
    if (mService == null)
        return;
    mUri = null;
    mIsPlaying = false;
    String title = null;
    boolean fromStart = false;
    String itemTitle = null;
    int positionInPlaylist = -1;
    final Intent intent = getIntent();
    final Bundle extras = intent.getExtras();
    long savedTime = 0L;
    final boolean hasMedia = mService.hasMedia();
    final boolean isPlaying = mService.isPlaying();
    /*
         * If the activity has been paused by pressing the power button, then
         * pressing it again will show the lock screen.
         * But onResume will also be called, even if vlc-android is still in
         * the background.
         * To workaround this, pause playback if the lockscreen is displayed.
         */
    final KeyguardManager km = (KeyguardManager) getApplicationContext().getSystemService(KEYGUARD_SERVICE);
    if (km != null && km.inKeyguardRestrictedInputMode())
        mWasPaused = true;
    if (mWasPaused && BuildConfig.DEBUG)
        Log.d(TAG, "Video was previously paused, resuming in paused mode");
    if (intent.getData() != null)
        mUri = intent.getData();
    if (extras != null) {
        if (intent.hasExtra(Constants.PLAY_EXTRA_ITEM_LOCATION))
            mUri = extras.getParcelable(Constants.PLAY_EXTRA_ITEM_LOCATION);
        fromStart = extras.getBoolean(Constants.PLAY_EXTRA_FROM_START, false);
        // Consume fromStart option after first use to prevent
        // restarting again when playback is paused.
        intent.putExtra(Constants.PLAY_EXTRA_FROM_START, false);
        mAskResume &= !fromStart;
        // position passed in by intent (ms)
        savedTime = fromStart ? 0L : extras.getLong(Constants.PLAY_EXTRA_START_TIME);
        if (!fromStart && savedTime == 0L)
            savedTime = extras.getInt(Constants.PLAY_EXTRA_START_TIME);
        positionInPlaylist = extras.getInt(Constants.PLAY_EXTRA_OPENED_POSITION, -1);
        if (intent.hasExtra(Constants.PLAY_EXTRA_SUBTITLES_LOCATION))
            synchronized (mSubtitleSelectedFiles) {
                mSubtitleSelectedFiles.add(extras.getString(Constants.PLAY_EXTRA_SUBTITLES_LOCATION));
            }
        if (intent.hasExtra(Constants.PLAY_EXTRA_ITEM_TITLE))
            itemTitle = extras.getString(Constants.PLAY_EXTRA_ITEM_TITLE);
    }
    final boolean restorePlayback = hasMedia && mService.getCurrentMediaWrapper().getUri().equals(mUri);
    MediaWrapper openedMedia = null;
    final boolean resumePlaylist = mService.isValidIndex(positionInPlaylist);
    final boolean continueplayback = isPlaying && (restorePlayback || positionInPlaylist == mService.getCurrentMediaPosition());
    if (resumePlaylist) {
        // Provided externally from AudioService
        if (BuildConfig.DEBUG)
            Log.d(TAG, "Continuing playback from PlaybackService at index " + positionInPlaylist);
        openedMedia = mService.getMedias().get(positionInPlaylist);
        if (openedMedia == null) {
            encounteredError();
            return;
        }
        itemTitle = openedMedia.getTitle();
        updateSeekable(mService.isSeekable());
        updatePausable(mService.isPausable());
    }
    mService.addCallback(this);
    if (mUri != null) {
        MediaWrapper media = null;
        if (!continueplayback) {
            if (!resumePlaylist) {
                // restore last position
                media = mMedialibrary.getMedia(mUri);
                if (media == null && TextUtils.equals(mUri.getScheme(), "file") && mUri.getPath() != null && mUri.getPath().startsWith("/sdcard")) {
                    mUri = FileUtils.convertLocalUri(mUri);
                    media = mMedialibrary.getMedia(mUri);
                }
                if (media != null && media.getId() != 0L && media.getTime() == 0L)
                    media.setTime(media.getMetaLong(MediaWrapper.META_PROGRESS));
            } else
                media = openedMedia;
            if (media != null) {
                // in media library
                if (mAskResume && !fromStart && positionInPlaylist == -1 && media.getTime() > 0) {
                    showConfirmResumeDialog();
                    return;
                }
                mLastAudioTrack = media.getAudioTrack();
                mLastSpuTrack = media.getSpuTrack();
            } else if (!fromStart) {
                // not in media library
                if (mAskResume && savedTime > 0L) {
                    showConfirmResumeDialog();
                    return;
                } else {
                    long rTime = mSettings.getLong(PreferencesActivity.VIDEO_RESUME_TIME, -1);
                    if (rTime > 0) {
                        if (mAskResume) {
                            showConfirmResumeDialog();
                            return;
                        } else {
                            mSettings.edit().putLong(PreferencesActivity.VIDEO_RESUME_TIME, -1).apply();
                            savedTime = rTime;
                        }
                    }
                }
            }
        }
        // Start playback & seek
        /* prepare playback */
        final boolean medialoaded = media != null;
        if (!medialoaded) {
            if (hasMedia)
                media = mService.getCurrentMediaWrapper();
            else
                media = new MediaWrapper(mUri);
        }
        if (mWasPaused)
            media.addFlags(MediaWrapper.MEDIA_PAUSED);
        if (intent.hasExtra(Constants.PLAY_DISABLE_HARDWARE))
            media.addFlags(MediaWrapper.MEDIA_NO_HWACCEL);
        media.removeFlags(MediaWrapper.MEDIA_FORCE_AUDIO);
        media.addFlags(MediaWrapper.MEDIA_VIDEO);
        // Set resume point
        if (!continueplayback) {
            if (!fromStart && savedTime <= 0L && media.getTime() > 0L)
                savedTime = media.getTime();
            if (savedTime > 0L)
                mService.saveStartTime(savedTime);
        }
        // Handle playback
        if (resumePlaylist) {
            if (continueplayback) {
                if (mDisplayManager.isPrimary())
                    mService.flush();
                onPlaying();
            } else
                mService.playIndex(positionInPlaylist);
        } else if (medialoaded)
            mService.load(media);
        else
            mService.loadUri(mUri);
        // Get possible subtitles
        getSubtitles();
        // Get the title
        if (itemTitle == null && !TextUtils.equals(mUri.getScheme(), "content"))
            title = mUri.getLastPathSegment();
    } else if (mService.hasMedia() && mService.hasRenderer()) {
        onPlaying();
    } else {
        mService.loadLastPlaylist(Constants.PLAYLIST_TYPE_VIDEO);
    }
    if (itemTitle != null)
        title = itemTitle;
    mTitle.setText(title);
    if (mWasPaused) {
        // XXX: Workaround to update the seekbar position
        mForcedTime = savedTime;
        mForcedTime = -1;
        showOverlay(true);
    }
    enableSubs();
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) Bundle(android.os.Bundle) Intent(android.content.Intent) KeyguardManager(android.app.KeyguardManager) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint) TargetApi(android.annotation.TargetApi)

Example 78 with KeyguardManager

use of android.app.KeyguardManager in project android_packages_apps_Settings by crdroidandroid.

the class Utils method confirmWorkProfileCredentials.

private static boolean confirmWorkProfileCredentials(Context context, int userId) {
    final KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
    final Intent unlockIntent = km.createConfirmDeviceCredentialIntent(null, null, userId);
    if (unlockIntent != null) {
        context.startActivity(unlockIntent);
        return true;
    } else {
        return false;
    }
}
Also used : Intent(android.content.Intent) KeyguardManager(android.app.KeyguardManager)

Example 79 with KeyguardManager

use of android.app.KeyguardManager in project android_packages_apps_Dialer by MoKee.

the class SpecialCharSequenceMgr method handleAdnEntry.

/**
 * Handle ADN requests by filling in the SIM contact number into the requested
 * EditText.
 *
 * This code works alongside the Asynchronous query handler {@link QueryHandler}
 * and query cancel handler implemented in {@link SimContactQueryCookie}.
 */
static boolean handleAdnEntry(Context context, String input, EditText textField) {
    /* ADN entries are of the form "N(N)(N)#" */
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager == null || telephonyManager.getPhoneType() != TelephonyManager.PHONE_TYPE_GSM) {
        return false;
    }
    // if the phone is keyguard-restricted, then just ignore this
    // input.  We want to make sure that sim card contacts are NOT
    // exposed unless the phone is unlocked, and this code can be
    // accessed from the emergency dialer.
    KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
    if (keyguardManager.inKeyguardRestrictedInputMode()) {
        return false;
    }
    int len = input.length();
    if ((len > 1) && (len < 5) && (input.endsWith("#"))) {
        try {
            // get the ordinal number of the sim contact
            final int index = Integer.parseInt(input.substring(0, len - 1));
            // The original code that navigated to a SIM Contacts list view did not
            // highlight the requested contact correctly, a requirement for PTCRB
            // certification.  This behaviour is consistent with the UI paradigm
            // for touch-enabled lists, so it does not make sense to try to work
            // around it.  Instead we fill in the the requested phone number into
            // the dialer text field.
            // create the async query handler
            final QueryHandler handler = new QueryHandler(context.getContentResolver());
            // create the cookie object
            final SimContactQueryCookie sc = new SimContactQueryCookie(index - 1, handler, ADN_QUERY_TOKEN);
            // setup the cookie fields
            sc.contactNum = index - 1;
            sc.setTextField(textField);
            // create the progress dialog
            sc.progressDialog = new ProgressDialog(context);
            sc.progressDialog.setTitle(R.string.simContacts_title);
            sc.progressDialog.setMessage(context.getText(R.string.simContacts_emptyLoading));
            sc.progressDialog.setIndeterminate(true);
            sc.progressDialog.setCancelable(true);
            sc.progressDialog.setOnCancelListener(sc);
            sc.progressDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
            List<PhoneAccountHandle> subscriptionAccountHandles = PhoneAccountUtils.getSubscriptionPhoneAccounts(context);
            Context applicationContext = context.getApplicationContext();
            boolean hasUserSelectedDefault = subscriptionAccountHandles.contains(TelecomUtil.getDefaultOutgoingPhoneAccount(applicationContext, PhoneAccount.SCHEME_TEL));
            if (subscriptionAccountHandles.size() <= 1 || hasUserSelectedDefault) {
                Uri uri = TelecomUtil.getAdnUriForPhoneAccount(applicationContext, null);
                handleAdnQuery(handler, sc, uri);
            } else {
                SelectPhoneAccountListener callback = new HandleAdnEntryAccountSelectedCallback(applicationContext, handler, sc);
                DialogFragment dialogFragment = SelectPhoneAccountDialogFragment.newInstance(subscriptionAccountHandles, callback);
                dialogFragment.show(((Activity) context).getFragmentManager(), TAG_SELECT_ACCT_FRAGMENT);
            }
            return true;
        } catch (NumberFormatException ex) {
        // Ignore
        }
    }
    return false;
}
Also used : Context(android.content.Context) NoNullCursorAsyncQueryHandler(com.android.contacts.common.database.NoNullCursorAsyncQueryHandler) PhoneAccountHandle(android.telecom.PhoneAccountHandle) DialogFragment(android.app.DialogFragment) SelectPhoneAccountDialogFragment(com.android.contacts.common.widget.SelectPhoneAccountDialogFragment) ProgressDialog(android.app.ProgressDialog) Uri(android.net.Uri) TelephonyManager(android.telephony.TelephonyManager) SelectPhoneAccountListener(com.android.contacts.common.widget.SelectPhoneAccountDialogFragment.SelectPhoneAccountListener) KeyguardManager(android.app.KeyguardManager)

Example 80 with KeyguardManager

use of android.app.KeyguardManager in project MagiskManager by topjohnwu.

the class FingerprintHelper method canUseFingerprint.

public static boolean canUseFingerprint() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
        return false;
    MagiskManager mm = MagiskManager.get();
    KeyguardManager km = mm.getSystemService(KeyguardManager.class);
    FingerprintManager fm = mm.getSystemService(FingerprintManager.class);
    return km.isKeyguardSecure() && fm != null && fm.isHardwareDetected() && fm.hasEnrolledFingerprints();
}
Also used : MagiskManager(com.topjohnwu.magisk.MagiskManager) FingerprintManager(android.hardware.fingerprint.FingerprintManager) KeyguardManager(android.app.KeyguardManager)

Aggregations

KeyguardManager (android.app.KeyguardManager)94 Intent (android.content.Intent)44 PendingIntent (android.app.PendingIntent)18 PowerManager (android.os.PowerManager)17 Context (android.content.Context)12 SuppressLint (android.annotation.SuppressLint)10 IIntentSender (android.content.IIntentSender)10 IntentSender (android.content.IntentSender)10 FingerprintManager (android.hardware.fingerprint.FingerprintManager)7 Resources (android.content.res.Resources)5 TelephonyManager (android.telephony.TelephonyManager)5 TargetApi (android.annotation.TargetApi)4 ConnectivityManager (android.net.ConnectivityManager)4 RemoteException (android.os.RemoteException)4 Activity (android.app.Activity)3 NotificationManager (android.app.NotificationManager)3 Bitmap (android.graphics.Bitmap)3 NetworkInfo (android.net.NetworkInfo)3 DialogFragment (android.app.DialogFragment)2 Notification (android.app.Notification)2