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

Commit cd575992 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Delay vold connectors until published, fix NPE.

If they connect too quickly, PackageManager could end up trying to
obtain the yet-unpublished MountService.

Fix NPE in UserManagerService when trying to persist fingerprints,
and fix write ordering to always write [id].xml before userlist.xml
to avoid battery pull issues.  Simlarly, delete [id].xml only after
updating userlist.xml.

Bug: 27869443
Change-Id: I43d8552e5e37b9ca4137cca3e3e76684c7dee605
parent 4c78ba65
Loading
Loading
Loading
Loading
+12 −6
Original line number Original line Diff line number Diff line
@@ -165,6 +165,7 @@ class MountService extends IMountService.Stub
        public void onStart() {
        public void onStart() {
            mMountService = new MountService(getContext());
            mMountService = new MountService(getContext());
            publishBinderService("mount", mMountService);
            publishBinderService("mount", mMountService);
            mMountService.start();
        }
        }


        @Override
        @Override
@@ -430,9 +431,13 @@ class MountService extends IMountService.Stub
        = { "password", "default", "pattern", "pin" };
        = { "password", "default", "pattern", "pin" };


    private final Context mContext;
    private final Context mContext;

    private final NativeDaemonConnector mConnector;
    private final NativeDaemonConnector mConnector;
    private final NativeDaemonConnector mCryptConnector;
    private final NativeDaemonConnector mCryptConnector;


    private final Thread mConnectorThread;
    private final Thread mCryptConnectorThread;

    private volatile boolean mSystemReady = false;
    private volatile boolean mSystemReady = false;
    private volatile boolean mBootCompleted = false;
    private volatile boolean mBootCompleted = false;
    private volatile boolean mDaemonConnected = false;
    private volatile boolean mDaemonConnected = false;
@@ -1494,17 +1499,13 @@ class MountService extends IMountService.Stub
                null);
                null);
        mConnector.setDebug(true);
        mConnector.setDebug(true);
        mConnector.setWarnIfHeld(mLock);
        mConnector.setWarnIfHeld(mLock);

        mConnectorThread = new Thread(mConnector, VOLD_TAG);
        Thread thread = new Thread(mConnector, VOLD_TAG);
        thread.start();


        // Reuse parameters from first connector since they are tested and safe
        // Reuse parameters from first connector since they are tested and safe
        mCryptConnector = new NativeDaemonConnector(this, "cryptd",
        mCryptConnector = new NativeDaemonConnector(this, "cryptd",
                MAX_CONTAINERS * 2, CRYPTD_TAG, 25, null);
                MAX_CONTAINERS * 2, CRYPTD_TAG, 25, null);
        mCryptConnector.setDebug(true);
        mCryptConnector.setDebug(true);

        mCryptConnectorThread = new Thread(mCryptConnector, CRYPTD_TAG);
        Thread crypt_thread = new Thread(mCryptConnector, CRYPTD_TAG);
        crypt_thread.start();


        final IntentFilter userFilter = new IntentFilter();
        final IntentFilter userFilter = new IntentFilter();
        userFilter.addAction(Intent.ACTION_USER_ADDED);
        userFilter.addAction(Intent.ACTION_USER_ADDED);
@@ -1521,6 +1522,11 @@ class MountService extends IMountService.Stub
        }
        }
    }
    }


    private void start() {
        mConnectorThread.start();
        mCryptConnectorThread.start();
    }

    private void systemReady() {
    private void systemReady() {
        mSystemReady = true;
        mSystemReady = true;
        mHandler.obtainMessage(H_SYSTEM_READY).sendToTarget();
        mHandler.obtainMessage(H_SYSTEM_READY).sendToTarget();
+13 −11
Original line number Original line Diff line number Diff line
@@ -31,7 +31,6 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.UserInfo;
import android.content.pm.UserInfo;
@@ -924,12 +923,12 @@ public class UserManagerService extends IUserManager.Stub {
        }
        }
        // Don't call them within the mRestrictionsLock.
        // Don't call them within the mRestrictionsLock.
        synchronized (mPackagesLock) {
        synchronized (mPackagesLock) {
            if (globalChanged) {
                writeUserListLP();
            }
            if (localChanged) {
            if (localChanged) {
                writeUserLP(getUserDataNoChecks(userId));
                writeUserLP(getUserDataNoChecks(userId));
            }
            }
            if (globalChanged) {
                writeUserListLP();
            }
        }
        }


        synchronized (mRestrictionsLock) {
        synchronized (mRestrictionsLock) {
@@ -1491,8 +1490,8 @@ public class UserManagerService extends IUserManager.Stub {
        updateUserIds();
        updateUserIds();
        initDefaultGuestRestrictions();
        initDefaultGuestRestrictions();


        writeUserListLP();
        writeUserLP(userData);
        writeUserLP(userData);
        writeUserListLP();
    }
    }


    private String getOwnerName() {
    private String getOwnerName() {
@@ -1542,8 +1541,10 @@ public class UserManagerService extends IUserManager.Stub {
            serializer.attribute(null, ATTR_CREATION_TIME, Long.toString(userInfo.creationTime));
            serializer.attribute(null, ATTR_CREATION_TIME, Long.toString(userInfo.creationTime));
            serializer.attribute(null, ATTR_LAST_LOGGED_IN_TIME,
            serializer.attribute(null, ATTR_LAST_LOGGED_IN_TIME,
                    Long.toString(userInfo.lastLoggedInTime));
                    Long.toString(userInfo.lastLoggedInTime));
            if (userInfo.lastLoggedInFingerprint != null) {
                serializer.attribute(null, ATTR_LAST_LOGGED_IN_FINGERPRINT,
                serializer.attribute(null, ATTR_LAST_LOGGED_IN_FINGERPRINT,
                        userInfo.lastLoggedInFingerprint);
                        userInfo.lastLoggedInFingerprint);
            }
            if (userInfo.iconPath != null) {
            if (userInfo.iconPath != null) {
                serializer.attribute(null,  ATTR_ICON_PATH, userInfo.iconPath);
                serializer.attribute(null,  ATTR_ICON_PATH, userInfo.iconPath);
            }
            }
@@ -1599,7 +1600,7 @@ public class UserManagerService extends IUserManager.Stub {
            serializer.endDocument();
            serializer.endDocument();
            userFile.finishWrite(fos);
            userFile.finishWrite(fos);
        } catch (Exception ioe) {
        } catch (Exception ioe) {
            Slog.e(LOG_TAG, "Error writing user info " + userData.info.id + "\n" + ioe);
            Slog.e(LOG_TAG, "Error writing user info " + userData.info.id, ioe);
            userFile.failWrite(fos);
            userFile.failWrite(fos);
        }
        }
    }
    }
@@ -1944,6 +1945,7 @@ public class UserManagerService extends IUserManager.Stub {
                    userData.info = userInfo;
                    userData.info = userInfo;
                    mUsers.put(userId, userData);
                    mUsers.put(userId, userData);
                }
                }
                writeUserLP(userData);
                writeUserListLP();
                writeUserListLP();
                if (parent != null) {
                if (parent != null) {
                    if (isManagedProfile) {
                    if (isManagedProfile) {
@@ -2217,13 +2219,13 @@ public class UserManagerService extends IUserManager.Stub {
            mCachedEffectiveUserRestrictions.remove(userHandle);
            mCachedEffectiveUserRestrictions.remove(userHandle);
            mDevicePolicyLocalUserRestrictions.remove(userHandle);
            mDevicePolicyLocalUserRestrictions.remove(userHandle);
        }
        }
        // Remove user file
        AtomicFile userFile = new AtomicFile(new File(mUsersDir, userHandle + XML_SUFFIX));
        userFile.delete();
        // Update the user list
        // Update the user list
        synchronized (mPackagesLock) {
        synchronized (mPackagesLock) {
            writeUserListLP();
            writeUserListLP();
        }
        }
        // Remove user file
        AtomicFile userFile = new AtomicFile(new File(mUsersDir, userHandle + XML_SUFFIX));
        userFile.delete();
        updateUserIds();
        updateUserIds();
        File userDir = Environment.getUserSystemDirectory(userHandle);
        File userDir = Environment.getUserSystemDirectory(userHandle);
        File renamedUserDir = Environment.getUserSystemDirectory(UserHandle.USER_NULL - userHandle);
        File renamedUserDir = Environment.getUserSystemDirectory(UserHandle.USER_NULL - userHandle);