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
This commit is contained in:
Suprabh Shukla
2016-08-08 16:22:44 -07:00
parent c2fe7f7279
commit c5e057c736

View File

@@ -95,7 +95,7 @@ import com.android.internal.widget.LockPatternUtils;
import com.android.server.LocalServices;
import com.android.server.SystemService;
import com.android.server.am.UserState;
import com.android.server.storage.DeviceStorageMonitorInternal;
import libcore.io.IoUtils;
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.");
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);
}