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

Commit 9ed98bcd authored by Jason parks's avatar Jason parks
Browse files

Update encryption commands.

* Changed to inplace encryption.
* Changed decryption to return the proper error code. It will now return success or the number of failed attempts.
* Be lazy and post a message 2 seconds later to call restart. I don't feel like messing with binder interfaces for a proper callback.

Change-Id: Iae2de7057aa66f248fd2df3f29777ad3368442f0
parent 04fba96b
Loading
Loading
Loading
Loading
+25 −8
Original line number Diff line number Diff line
@@ -1644,13 +1644,30 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC
        }

        try {
            mConnector.doCommand(String.format("cryptfs checkpw %s", password));
            ArrayList<String> rsp = mConnector.doCommand("cryptfs checkpw " + password);
            String []tok = rsp.get(0).split(" ");

            if (tok == null || tok.length != 2) {
                return -1;
            }

            int code = Integer.parseInt(tok[1]);

            if (code == 0) {
                // Decrypt was successful. Post a delayed message before restarting in order
                // to let the UI to clear itself
                mHandler.postDelayed(new Runnable() {
                    public void run() {
                        mConnector.doCommand(String.format("cryptfs restart"));
                    }
                }, 2000); // 2 seconds
            }

            return code;
        } catch (NativeDaemonConnectorException e) {
            // Decryption failed
            return e.getCode();
        }

        return 0;
    }

    public int encryptStorage(String password) {
@@ -1667,7 +1684,7 @@ class MountService extends IMountService.Stub implements INativeDaemonConnectorC
        }

        try {
            mConnector.doCommand(String.format("cryptfs enablecrypto wipe %s", password));
            mConnector.doCommand(String.format("cryptfs enablecrypto inplace %s", password));
        } catch (NativeDaemonConnectorException e) {
            // Encryption failed
            return e.getCode();