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

Commit 2cb2e8b3 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "LockSettings: fix the get password issue during boot up"

parents 494b5537 094c8cc9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -40,4 +40,5 @@ interface ILockSettings {
    void registerStrongAuthTracker(in IStrongAuthTracker tracker);
    void unregisterStrongAuthTracker(in IStrongAuthTracker tracker);
    void requireStrongAuth(int strongAuthReason, int userId);
    String getPassword();
}
+21 −1
Original line number Diff line number Diff line
@@ -388,7 +388,27 @@ public class LockSettingsService extends ILockSettings.Stub {
        }
    }

    private boolean checkCryptKeeperPermissions() {
        boolean permission_err = false;
        try {
            mContext.enforceCallingOrSelfPermission(
                       android.Manifest.permission.CRYPT_KEEPER,
                       "no permission to get the password");
        } catch (SecurityException e) {
            permission_err = true;
        }
        return permission_err;
    }

    public String getPassword() {
       /** if calling process does't have crypt keeper or admin permissions,
         * throw the exception.
         */
       if (checkCryptKeeperPermissions())
            mContext.enforceCallingOrSelfPermission(
                    android.Manifest.permission.MANAGE_DEVICE_ADMINS,
                    "no crypt_keeper or admin permission to get the password");

       return mSavePassword;
    }

+15 −3
Original line number Diff line number Diff line
@@ -101,6 +101,7 @@ import com.android.internal.util.Preconditions;
import com.android.server.NativeDaemonConnector.Command;
import com.android.server.NativeDaemonConnector.SensitiveArg;
import com.android.server.pm.PackageManagerService;
import com.android.internal.widget.ILockSettings;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -2460,13 +2461,24 @@ class MountService extends IMountService.Stub
            Slog.i(TAG, "changing encryption password...");
        }

        LockSettingsService lockSettings = new LockSettingsService(mContext);
        String currentPassword = lockSettings.getPassword();
        ILockSettings lockSettings = ILockSettings.Stub.asInterface(
                    ServiceManager.getService("lock_settings"));
        String currentPassword="default_password";
        try {
            currentPassword = lockSettings.getPassword();
        } catch (RemoteException e) {
            Slog.e(TAG, "Couldn't get password" + e);
        }

        try {
            NativeDaemonEvent event = mCryptConnector.execute("cryptfs", "changepw", CRYPTO_TYPES[type],
                        new SensitiveArg(currentPassword), new SensitiveArg(password));
            try {
                lockSettings.sanitizePassword();
            } catch (RemoteException e) {
                Slog.e(TAG, "Couldn't sanitize password" + e);
            }

            return Integer.parseInt(event.getMessage());
        } catch (NativeDaemonConnectorException e) {
            // Encryption failed