Search in sources :

Example 31 with LockPatternUtils

use of com.android.internal.widget.LockPatternUtils in project android_frameworks_base by AOSPA.

the class RestrictedLockUtils method checkIfKeyguardFeaturesDisabled.

/**
     * Checks if keyguard features are disabled by policy.
     *
     * @param keyguardFeatures Could be any of keyguard features that can be
     * disabled by {@link android.app.admin.DevicePolicyManager#setKeyguardDisabledFeatures}.
     * @return EnforcedAdmin Object containing the enforced admin component and admin user details,
     * or {@code null} If the notification features are not disabled. If the restriction is set by
     * multiple admins, then the admin component will be set to {@code null} and userId to
     * {@link UserHandle#USER_NULL}.
     */
public static EnforcedAdmin checkIfKeyguardFeaturesDisabled(Context context, int keyguardFeatures, int userId) {
    final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (dpm == null) {
        return null;
    }
    final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
    LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
    EnforcedAdmin enforcedAdmin = null;
    if (um.getUserInfo(userId).isManagedProfile()) {
        final List<ComponentName> admins = dpm.getActiveAdminsAsUser(userId);
        if (admins == null) {
            return null;
        }
        for (ComponentName admin : admins) {
            if ((dpm.getKeyguardDisabledFeatures(admin, userId) & keyguardFeatures) != 0) {
                if (enforcedAdmin == null) {
                    enforcedAdmin = new EnforcedAdmin(admin, userId);
                } else {
                    return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN;
                }
            }
        }
    } else {
        // user that do not use a separate work challenge.
        for (UserInfo userInfo : um.getProfiles(userId)) {
            final List<ComponentName> admins = dpm.getActiveAdminsAsUser(userInfo.id);
            if (admins == null) {
                continue;
            }
            final boolean isSeparateProfileChallengeEnabled = lockPatternUtils.isSeparateProfileChallengeEnabled(userInfo.id);
            for (ComponentName admin : admins) {
                if (!isSeparateProfileChallengeEnabled) {
                    if ((dpm.getKeyguardDisabledFeatures(admin, userInfo.id) & keyguardFeatures) != 0) {
                        if (enforcedAdmin == null) {
                            enforcedAdmin = new EnforcedAdmin(admin, userInfo.id);
                        } else {
                            return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN;
                        }
                        // has set policy on the parent admin.
                        continue;
                    }
                }
                if (userInfo.isManagedProfile()) {
                    // If userInfo.id is a managed profile, we also need to look at
                    // the policies set on the parent.
                    DevicePolicyManager parentDpm = dpm.getParentProfileInstance(userInfo);
                    if ((parentDpm.getKeyguardDisabledFeatures(admin, userInfo.id) & keyguardFeatures) != 0) {
                        if (enforcedAdmin == null) {
                            enforcedAdmin = new EnforcedAdmin(admin, userInfo.id);
                        } else {
                            return EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN;
                        }
                    }
                }
            }
        }
    }
    return enforcedAdmin;
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) UserManager(android.os.UserManager) LockPatternUtils(com.android.internal.widget.LockPatternUtils) ComponentName(android.content.ComponentName) UserInfo(android.content.pm.UserInfo)

Example 32 with LockPatternUtils

use of com.android.internal.widget.LockPatternUtils in project android_frameworks_base by AOSPA.

the class KeyguardBottomAreaView method onFinishInflate.

@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    mLockPatternUtils = new LockPatternUtils(mContext);
    mPreviewContainer = (ViewGroup) findViewById(R.id.preview_container);
    mEmergencyButton = (EmergencyButton) findViewById(R.id.emergency_call_button);
    mCameraImageView = (KeyguardAffordanceView) findViewById(R.id.camera_button);
    mLeftAffordanceView = (KeyguardAffordanceView) findViewById(R.id.left_button);
    mLockIcon = (LockIcon) findViewById(R.id.lock_icon);
    mIndicationText = (TextView) findViewById(R.id.keyguard_indication_text);
    watchForCameraPolicyChanges();
    updateCameraVisibility();
    mUnlockMethodCache = UnlockMethodCache.getInstance(getContext());
    mUnlockMethodCache.addListener(this);
    mLockIcon.update();
    updateEmergencyButton();
    setClipChildren(false);
    setClipToPadding(false);
    mPreviewInflater = new PreviewInflater(mContext, new LockPatternUtils(mContext));
    inflateCameraPreview();
    mLockIcon.setOnClickListener(this);
    mLockIcon.setOnLongClickListener(this);
    mCameraImageView.setOnClickListener(this);
    mLeftAffordanceView.setOnClickListener(this);
    initAccessibility();
}
Also used : PreviewInflater(com.android.systemui.statusbar.policy.PreviewInflater) LockPatternUtils(com.android.internal.widget.LockPatternUtils)

Example 33 with LockPatternUtils

use of com.android.internal.widget.LockPatternUtils in project android_frameworks_base by crdroidandroid.

the class DatabaseHelper method upgradeLockPatternLocation.

private void upgradeLockPatternLocation(SQLiteDatabase db) {
    Cursor c = db.query(TABLE_SYSTEM, new String[] { "_id", "value" }, "name='lock_pattern'", null, null, null, null);
    if (c.getCount() > 0) {
        c.moveToFirst();
        String lockPattern = c.getString(1);
        if (!TextUtils.isEmpty(lockPattern)) {
            // Convert lock pattern
            try {
                LockPatternUtils lpu = new LockPatternUtils(mContext);
                List<LockPatternView.Cell> cellPattern = LockPatternUtils.stringToPattern(lockPattern, lpu.getLockPatternSize(mUserHandle));
                lpu.saveLockPattern(cellPattern, null, UserHandle.USER_SYSTEM);
            } catch (IllegalArgumentException e) {
            // Don't want corrupted lock pattern to hang the reboot process
            }
        }
        c.close();
        db.delete(TABLE_SYSTEM, "name='lock_pattern'", null);
    } else {
        c.close();
    }
}
Also used : LockPatternUtils(com.android.internal.widget.LockPatternUtils) Cursor(android.database.Cursor)

Example 34 with LockPatternUtils

use of com.android.internal.widget.LockPatternUtils in project android_frameworks_base by crdroidandroid.

the class TrustManagerService method refreshAgentList.

void refreshAgentList(int userIdOrAll) {
    if (DEBUG)
        Slog.d(TAG, "refreshAgentList(" + userIdOrAll + ")");
    if (!mTrustAgentsCanRun) {
        return;
    }
    if (userIdOrAll != UserHandle.USER_ALL && userIdOrAll < UserHandle.USER_SYSTEM) {
        Log.e(TAG, "refreshAgentList(userId=" + userIdOrAll + "): Invalid user handle," + " must be USER_ALL or a specific user.", new Throwable("here"));
        userIdOrAll = UserHandle.USER_ALL;
    }
    PackageManager pm = mContext.getPackageManager();
    List<UserInfo> userInfos;
    if (userIdOrAll == UserHandle.USER_ALL) {
        userInfos = mUserManager.getUsers(true);
    } else {
        userInfos = new ArrayList<>();
        userInfos.add(mUserManager.getUserInfo(userIdOrAll));
    }
    LockPatternUtils lockPatternUtils = mLockPatternUtils;
    ArraySet<AgentInfo> obsoleteAgents = new ArraySet<>();
    obsoleteAgents.addAll(mActiveAgents);
    for (UserInfo userInfo : userInfos) {
        if (userInfo == null || userInfo.partial || !userInfo.isEnabled() || userInfo.guestToRemove)
            continue;
        if (!userInfo.supportsSwitchToByUser())
            continue;
        if (!StorageManager.isUserKeyUnlocked(userInfo.id))
            continue;
        if (!mActivityManager.isUserRunning(userInfo.id))
            continue;
        if (!lockPatternUtils.isSecure(userInfo.id))
            continue;
        if (!mStrongAuthTracker.canAgentsRunForUser(userInfo.id))
            continue;
        DevicePolicyManager dpm = lockPatternUtils.getDevicePolicyManager();
        int disabledFeatures = dpm.getKeyguardDisabledFeatures(null, userInfo.id);
        final boolean disableTrustAgents = (disabledFeatures & DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS) != 0;
        List<ComponentName> enabledAgents = lockPatternUtils.getEnabledTrustAgents(userInfo.id);
        if (enabledAgents == null) {
            continue;
        }
        List<ResolveInfo> resolveInfos = resolveAllowedTrustAgents(pm, userInfo.id);
        for (ResolveInfo resolveInfo : resolveInfos) {
            ComponentName name = getComponentName(resolveInfo);
            if (!enabledAgents.contains(name))
                continue;
            if (disableTrustAgents) {
                List<PersistableBundle> config = dpm.getTrustAgentConfiguration(null, /* admin */
                name, userInfo.id);
                // Disable agent if no features are enabled.
                if (config == null || config.isEmpty())
                    continue;
            }
            AgentInfo agentInfo = new AgentInfo();
            agentInfo.component = name;
            agentInfo.userId = userInfo.id;
            if (!mActiveAgents.contains(agentInfo)) {
                agentInfo.label = resolveInfo.loadLabel(pm);
                agentInfo.icon = resolveInfo.loadIcon(pm);
                agentInfo.settings = getSettingsComponentName(pm, resolveInfo);
                agentInfo.agent = new TrustAgentWrapper(mContext, this, new Intent().setComponent(name), userInfo.getUserHandle());
                mActiveAgents.add(agentInfo);
            } else {
                obsoleteAgents.remove(agentInfo);
            }
        }
    }
    boolean trustMayHaveChanged = false;
    for (int i = 0; i < obsoleteAgents.size(); i++) {
        AgentInfo info = obsoleteAgents.valueAt(i);
        if (userIdOrAll == UserHandle.USER_ALL || userIdOrAll == info.userId) {
            if (info.agent.isManagingTrust()) {
                trustMayHaveChanged = true;
            }
            info.agent.destroy();
            mActiveAgents.remove(info);
        }
    }
    if (trustMayHaveChanged) {
        if (userIdOrAll == UserHandle.USER_ALL) {
            updateTrustAll();
        } else {
            updateTrust(userIdOrAll, 0);
        }
    }
}
Also used : DevicePolicyManager(android.app.admin.DevicePolicyManager) ArraySet(android.util.ArraySet) LockPatternUtils(com.android.internal.widget.LockPatternUtils) UserInfo(android.content.pm.UserInfo) Intent(android.content.Intent) ResolveInfo(android.content.pm.ResolveInfo) PersistableBundle(android.os.PersistableBundle) PackageManager(android.content.pm.PackageManager) ComponentName(android.content.ComponentName)

Example 35 with LockPatternUtils

use of com.android.internal.widget.LockPatternUtils in project android_frameworks_base by crdroidandroid.

the class KeyguardBottomAreaView method onFinishInflate.

@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    mLockPatternUtils = new LockPatternUtils(mContext);
    mPreviewContainer = (ViewGroup) findViewById(R.id.preview_container);
    mCameraImageView = (KeyguardAffordanceView) findViewById(R.id.camera_button);
    mLeftAffordanceView = (KeyguardAffordanceView) findViewById(R.id.left_button);
    mLockIcon = (LockIcon) findViewById(R.id.lock_icon);
    mIndicationText = (TextView) findViewById(R.id.keyguard_indication_text);
    mShortcutHelper = new LockscreenShortcutsHelper(mContext, this);
    watchForCameraPolicyChanges();
    updateCameraVisibility();
    updateLeftButtonVisibility();
    mUnlockMethodCache = UnlockMethodCache.getInstance(getContext());
    mUnlockMethodCache.addListener(this);
    mLockIcon.update();
    setClipChildren(false);
    setClipToPadding(false);
    mPreviewInflater = new PreviewInflater(mContext, new LockPatternUtils(mContext));
    mLockIcon.setOnClickListener(this);
    mLockIcon.setOnLongClickListener(this);
    mCameraImageView.setOnClickListener(this);
    mLeftAffordanceView.setOnClickListener(this);
    initAccessibility();
    updateCustomShortcuts();
}
Also used : PreviewInflater(com.android.systemui.statusbar.policy.PreviewInflater) LockPatternUtils(com.android.internal.widget.LockPatternUtils) LockscreenShortcutsHelper(com.android.systemui.cm.LockscreenShortcutsHelper)

Aggregations

LockPatternUtils (com.android.internal.widget.LockPatternUtils)96 ComponentName (android.content.ComponentName)24 UserInfo (android.content.pm.UserInfo)24 DevicePolicyManager (android.app.admin.DevicePolicyManager)19 UserManager (android.os.UserManager)16 IOException (java.io.IOException)11 IntentFilter (android.content.IntentFilter)10 Intent (android.content.Intent)9 View (android.view.View)9 Cursor (android.database.Cursor)6 RemoteException (android.os.RemoteException)6 ArrayList (java.util.ArrayList)6 ContentResolver (android.content.ContentResolver)5 Configuration (android.content.res.Configuration)5 Rect (android.graphics.Rect)5 SoundPool (android.media.SoundPool)5 IBinder (android.os.IBinder)5 IVrManager (android.service.vr.IVrManager)5 StatusBarIcon (com.android.internal.statusbar.StatusBarIcon)5 KeyguardDisplayManager (com.android.keyguard.KeyguardDisplayManager)5