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

Commit c5e057c7 authored by Suprabh Shukla's avatar Suprabh Shukla
Browse files

Checking for storage space before adding user

If storage space is low, trying to create a user results in a crash.
Adding a check to abort user creation and log a warning in such a case.

Bug: 30270050
Change-Id: I121119aed340c7be337b2147c4386c9bb9f8ffdc
parent c2fe7f72
Loading
Loading
Loading
Loading
+7 −1
Original line number Original line Diff line number Diff line
@@ -95,7 +95,7 @@ import com.android.internal.widget.LockPatternUtils;
import com.android.server.LocalServices;
import com.android.server.LocalServices;
import com.android.server.SystemService;
import com.android.server.SystemService;
import com.android.server.am.UserState;
import com.android.server.am.UserState;

import com.android.server.storage.DeviceStorageMonitorInternal;
import libcore.io.IoUtils;
import libcore.io.IoUtils;
import libcore.util.Objects;
import libcore.util.Objects;


@@ -2184,6 +2184,12 @@ public class UserManagerService extends IUserManager.Stub {
            Log.w(LOG_TAG, "Cannot add user. DISALLOW_ADD_USER is enabled.");
            Log.w(LOG_TAG, "Cannot add user. DISALLOW_ADD_USER is enabled.");
            return null;
            return null;
        }
        }
        DeviceStorageMonitorInternal dsm = LocalServices
                .getService(DeviceStorageMonitorInternal.class);
        if (dsm.isMemoryLow()) {
            Log.w(LOG_TAG, "Cannot add user. Not enough space on disk.");
            return null;
        }
        return createUserInternalUnchecked(name, flags, parentId);
        return createUserInternalUnchecked(name, flags, parentId);
    }
    }