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

Commit 1096cf86 authored by Robin Lee's avatar Robin Lee
Browse files

Delete locksettings files for toplevel users only

Fixes an issue created by change:
    I7941707ca66ac25bd122fd22e5e0f639e7af697e

Bug: 16233206
Change-Id: Ia905d153e94303acd611178333adc77c68933711
parent 56d3cb30
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);