Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 89369b29 authored by Robin Lee's avatar Robin Lee Committed by Android (Google) Code Review
Browse files

Merge "Delete locksettings files for toplevel users only" into lmp-dev

parents 9547fd4a 1096cf86
Loading
Loading
Loading
Loading
+15 −10
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@ public class LockSettingsService extends ILockSettings.Stub {
        @Override
        public void onReceive(Context context, Intent intent) {
            // Update keystore settings for profiles which use the same password as their parent
            if (Intent.ACTION_USER_STARTED.equals(intent.getAction())) {
            if (Intent.ACTION_USER_ADDED.equals(intent.getAction())) {
                final int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
                final UserManager um = (UserManager) mContext.getSystemService(USER_SERVICE);
                final UserInfo parentInfo = um.getProfileParent(userHandle);
@@ -319,17 +319,18 @@ public class LockSettingsService extends ILockSettings.Stub {
        String dataSystemDirectory =
                android.os.Environment.getDataDirectory().getAbsolutePath() +
                SYSTEM_DIRECTORY;
        userId = getUserParentOrSelfId(userId);
        if (userId == 0) {
            // Leave it in the same place for user 0
            return dataSystemDirectory + LOCK_PATTERN_FILE;
        } else {
            userId = getUserParentOrSelfId(userId);
            return  new File(Environment.getUserSystemDirectory(userId), LOCK_PATTERN_FILE)
                    .getAbsolutePath();
        }
    }

    private String getLockPasswordFilename(int userId) {
        userId = getUserParentOrSelfId(userId);
        String dataSystemDirectory =
                android.os.Environment.getDataDirectory().getAbsolutePath() +
                SYSTEM_DIRECTORY;
@@ -337,7 +338,6 @@ public class LockSettingsService extends ILockSettings.Stub {
            // Leave it in the same place for user 0
            return dataSystemDirectory + LOCK_PASSWORD_FILE;
        } else {
            userId = getUserParentOrSelfId(userId);
            return new File(Environment.getUserSystemDirectory(userId), LOCK_PASSWORD_FILE)
                    .getAbsolutePath();
        }
@@ -510,6 +510,10 @@ public class LockSettingsService extends ILockSettings.Stub {

        SQLiteDatabase db = mOpenHelper.getWritableDatabase();
        try {
            final UserManager um = (UserManager) mContext.getSystemService(USER_SERVICE);
            final UserInfo parentInfo = um.getProfileParent(userId);
            if (parentInfo == null) {
                // This user owns its lock settings files - safe to delete them
                File file = new File(getLockPasswordFilename(userId));
                if (file.exists()) {
                    file.delete();
@@ -518,6 +522,7 @@ public class LockSettingsService extends ILockSettings.Stub {
                if (file.exists()) {
                    file.delete();
                }
            }

            db.beginTransaction();
            db.delete(TABLE, COLUMN_USERID + "='" + userId + "'", null);