Search in sources :

Example 66 with LockPatternUtils

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

the class SettingsBackupAgent method restoreLockSettings.

/**
     * Restores the owner info enabled and owner info settings in LockSettings.
     *
     * @param buffer
     * @param nBytes
     */
private void restoreLockSettings(byte[] buffer, int nBytes) {
    final LockPatternUtils lockPatternUtils = new LockPatternUtils(this);
    ByteArrayInputStream bais = new ByteArrayInputStream(buffer, 0, nBytes);
    DataInputStream in = new DataInputStream(bais);
    try {
        String key;
        // Read until empty string marker
        while ((key = in.readUTF()).length() > 0) {
            final String value = in.readUTF();
            if (DEBUG_BACKUP) {
                Log.v(TAG, "Restoring lock_settings " + key + " = " + value);
            }
            switch(key) {
                case KEY_LOCK_SETTINGS_OWNER_INFO_ENABLED:
                    lockPatternUtils.setOwnerInfoEnabled("1".equals(value), UserHandle.myUserId());
                    break;
                case KEY_LOCK_SETTINGS_OWNER_INFO:
                    lockPatternUtils.setOwnerInfo(value, UserHandle.myUserId());
                    break;
            }
        }
        in.close();
    } catch (IOException ioe) {
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) LockPatternUtils(com.android.internal.widget.LockPatternUtils) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 67 with LockPatternUtils

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

the class SettingsBackupAgent method getLockSettings.

/**
     * Serialize the owner info settings
     */
private byte[] getLockSettings() {
    final LockPatternUtils lockPatternUtils = new LockPatternUtils(this);
    final boolean ownerInfoEnabled = lockPatternUtils.isOwnerInfoEnabled(UserHandle.myUserId());
    final String ownerInfo = lockPatternUtils.getOwnerInfo(UserHandle.myUserId());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(baos);
    try {
        out.writeUTF(KEY_LOCK_SETTINGS_OWNER_INFO_ENABLED);
        out.writeUTF(ownerInfoEnabled ? "1" : "0");
        if (ownerInfo != null) {
            out.writeUTF(KEY_LOCK_SETTINGS_OWNER_INFO);
            out.writeUTF(ownerInfo != null ? ownerInfo : "");
        }
        // End marker
        out.writeUTF("");
        out.flush();
    } catch (IOException ioe) {
    }
    return baos.toByteArray();
}
Also used : DataOutputStream(java.io.DataOutputStream) LockPatternUtils(com.android.internal.widget.LockPatternUtils) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 68 with LockPatternUtils

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

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.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 69 with LockPatternUtils

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

the class KeyguardViewMediator method setupLocked.

private void setupLocked() {
    mPM = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
    mWM = WindowManagerGlobal.getWindowManagerService();
    mTrustManager = (TrustManager) mContext.getSystemService(Context.TRUST_SERVICE);
    mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard");
    mShowKeyguardWakeLock.setReferenceCounted(false);
    IntentFilter filter = new IntentFilter();
    filter.addAction(DELAYED_KEYGUARD_ACTION);
    filter.addAction(DELAYED_LOCK_PROFILE_ACTION);
    filter.addAction(Intent.ACTION_SHUTDOWN);
    mContext.registerReceiver(mBroadcastReceiver, filter);
    mKeyguardDisplayManager = new KeyguardDisplayManager(mContext);
    mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
    mUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
    mLockPatternUtils = new LockPatternUtils(mContext);
    KeyguardUpdateMonitor.setCurrentUser(ActivityManager.getCurrentUser());
    // Assume keyguard is showing (unless it's disabled) until we know for sure...
    setShowingLocked(!shouldWaitForProvisioning() && !mLockPatternUtils.isLockScreenDisabled(KeyguardUpdateMonitor.getCurrentUser()));
    updateInputRestrictedLocked();
    mTrustManager.reportKeyguardShowingChanged();
    mStatusBarKeyguardViewManager = SystemUIFactory.getInstance().createStatusBarKeyguardViewManager(mContext, mViewMediatorCallback, mLockPatternUtils);
    final ContentResolver cr = mContext.getContentResolver();
    mDeviceInteractive = mPM.isInteractive();
    mLockSounds = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0);
    String soundPath = Settings.Global.getString(cr, Settings.Global.LOCK_SOUND);
    if (soundPath != null) {
        mLockSoundId = mLockSounds.load(soundPath, 1);
    }
    if (soundPath == null || mLockSoundId == 0) {
        Log.w(TAG, "failed to load lock sound from " + soundPath);
    }
    soundPath = Settings.Global.getString(cr, Settings.Global.UNLOCK_SOUND);
    if (soundPath != null) {
        mUnlockSoundId = mLockSounds.load(soundPath, 1);
    }
    if (soundPath == null || mUnlockSoundId == 0) {
        Log.w(TAG, "failed to load unlock sound from " + soundPath);
    }
    soundPath = Settings.Global.getString(cr, Settings.Global.TRUSTED_SOUND);
    if (soundPath != null) {
        mTrustedSoundId = mLockSounds.load(soundPath, 1);
    }
    if (soundPath == null || mTrustedSoundId == 0) {
        Log.w(TAG, "failed to load trusted sound from " + soundPath);
    }
    int lockSoundDefaultAttenuation = mContext.getResources().getInteger(com.android.internal.R.integer.config_lockSoundVolumeDb);
    mLockSoundVolume = (float) Math.pow(10, (float) lockSoundDefaultAttenuation / 20);
    mHideAnimation = AnimationUtils.loadAnimation(mContext, com.android.internal.R.anim.lock_screen_behind_enter);
}
Also used : IntentFilter(android.content.IntentFilter) KeyguardDisplayManager(com.android.keyguard.KeyguardDisplayManager) LockPatternUtils(com.android.internal.widget.LockPatternUtils) SoundPool(android.media.SoundPool) ContentResolver(android.content.ContentResolver)

Example 70 with LockPatternUtils

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

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)

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