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

Commit ec16ecc6 authored by Robin Lee's avatar Robin Lee Committed by Android Git Automerger
Browse files

am 9b1fea82: am 0a803fcc: Merge "Reset keystore when user is added or removed" into lmp-dev

* commit '9b1fea82c7ed98b8189a61c37796e37631c923a1':
  Reset keystore when user is added or removed
parents 00f484f9 9686582f
Loading
Loading
Loading
Loading
+13 −5
Original line number Original line Diff line number Diff line
@@ -115,16 +115,20 @@ public class LockSettingsService extends ILockSettings.Stub {
    private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
    private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        @Override
        public void onReceive(Context context, Intent intent) {
        public void onReceive(Context context, Intent intent) {
            // Update keystore settings for profiles which use the same password as their parent
            if (Intent.ACTION_USER_ADDED.equals(intent.getAction())) {
            if (Intent.ACTION_USER_ADDED.equals(intent.getAction())) {
                final int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
                final int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
                final int userSysUid = UserHandle.getUid(userHandle, Process.SYSTEM_UID);
                final KeyStore ks = KeyStore.getInstance();

                // Clear up keystore in case anything was left behind by previous users
                ks.resetUid(userSysUid);

                // If this user has a parent, sync with its keystore password
                final UserManager um = (UserManager) mContext.getSystemService(USER_SERVICE);
                final UserManager um = (UserManager) mContext.getSystemService(USER_SERVICE);
                final UserInfo parentInfo = um.getProfileParent(userHandle);
                final UserInfo parentInfo = um.getProfileParent(userHandle);
                if (parentInfo != null) {
                if (parentInfo != null) {
                    final KeyStore ks = KeyStore.getInstance();
                    final int parentSysUid = UserHandle.getUid(parentInfo.id, Process.SYSTEM_UID);
                    final int profileUid = UserHandle.getUid(userHandle, Process.SYSTEM_UID);
                    ks.syncUid(parentSysUid, userSysUid);
                    final int parentUid = UserHandle.getUid(parentInfo.id, Process.SYSTEM_UID);
                    ks.syncUid(parentUid, profileUid);
                }
                }
            }
            }
        }
        }
@@ -530,6 +534,10 @@ public class LockSettingsService extends ILockSettings.Stub {
        } finally {
        } finally {
            db.endTransaction();
            db.endTransaction();
        }
        }

        final KeyStore ks = KeyStore.getInstance();
        final int userUid = UserHandle.getUid(userId, Process.SYSTEM_UID);
        ks.resetUid(userUid);
    }
    }


    private void writeFile(String name, byte[] hash) {
    private void writeFile(String name, byte[] hash) {