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

Commit be952611 authored by Eric Biggers's avatar Eric Biggers Committed by Automerger Merge Worker
Browse files

[RESTRICT AUTOMERGE] Ignore errors preparing user storage for existing users am: e03e9873

parents 4eadb461 e03e9873
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -279,4 +279,12 @@ public abstract class UserManagerInternal {
     * Gets all {@link UserInfo UserInfos}.
     */
    public abstract @NonNull UserInfo[] getUserInfos();

    /**
     * Returns {@code true} if the system should ignore errors when preparing
     * the storage directories for the user with ID {@code userId}. This will
     * return {@code false} for all new users; it will only return {@code true}
     * for users that already existed on-disk from an older version of Android.
     */
    public abstract boolean shouldIgnorePrepareStorageErrors(int userId);
}
+10 −1
Original line number Diff line number Diff line
@@ -3389,11 +3389,20 @@ class StorageManagerService extends IStorageManager.Stub
                    mInstaller.tryMountDataMirror(volumeUuid);
                }
            }
        } catch (RemoteException | Installer.InstallerException e) {
        } catch (Exception e) {
            Slog.wtf(TAG, e);
            // Make sure to re-throw this exception; we must not ignore failure
            // to prepare the user storage as it could indicate that encryption
            // wasn't successfully set up.
            //
            // Very unfortunately, these errors need to be ignored for broken
            // users that already existed on-disk from older Android versions.
            UserManagerInternal umInternal = LocalServices.getService(UserManagerInternal.class);
            if (umInternal.shouldIgnorePrepareStorageErrors(userId)) {
                Slog.wtf(TAG, "ignoring error preparing storage for existing user " + userId
                        + "; device may be insecure!");
                return;
            }
            throw new RuntimeException(e);
        }
    }
+42 −0
Original line number Diff line number Diff line
@@ -198,6 +198,8 @@ public class UserManagerService extends IUserManager.Stub {
    private static final String TAG_SEED_ACCOUNT_OPTIONS = "seedAccountOptions";
    private static final String TAG_LAST_REQUEST_QUIET_MODE_ENABLED_CALL =
            "lastRequestQuietModeEnabledCall";
    private static final String TAG_IGNORE_PREPARE_STORAGE_ERRORS =
            "ignorePrepareStorageErrors";
    private static final String ATTR_KEY = "key";
    private static final String ATTR_VALUE_TYPE = "type";
    private static final String ATTR_MULTIPLE = "m";
@@ -298,6 +300,14 @@ public class UserManagerService extends IUserManager.Stub {

        private long mLastRequestQuietModeEnabledMillis;

        /**
         * {@code true} if the system should ignore errors when preparing the
         * storage directories for this user. This is {@code false} for all new
         * users; it will only be {@code true} for users that already existed
         * on-disk from an older version of Android.
         */
        private boolean mIgnorePrepareStorageErrors;

        void setLastRequestQuietModeEnabledMillis(long millis) {
            mLastRequestQuietModeEnabledMillis = millis;
        }
@@ -306,6 +316,14 @@ public class UserManagerService extends IUserManager.Stub {
            return mLastRequestQuietModeEnabledMillis;
        }

        boolean getIgnorePrepareStorageErrors() {
            return mIgnorePrepareStorageErrors;
        }

        void setIgnorePrepareStorageErrors() {
            mIgnorePrepareStorageErrors = true;
        }

        void clearSeedAccountData() {
            seedAccountName = null;
            seedAccountType = null;
@@ -2955,6 +2973,10 @@ public class UserManagerService extends IUserManager.Stub {
            serializer.endTag(/* namespace */ null, TAG_LAST_REQUEST_QUIET_MODE_ENABLED_CALL);
        }

        serializer.startTag(/* namespace */ null, TAG_IGNORE_PREPARE_STORAGE_ERRORS);
        serializer.text(String.valueOf(userData.getIgnorePrepareStorageErrors()));
        serializer.endTag(/* namespace */ null, TAG_IGNORE_PREPARE_STORAGE_ERRORS);

        serializer.endTag(null, TAG_USER);

        serializer.endDocument();
@@ -3067,6 +3089,7 @@ public class UserManagerService extends IUserManager.Stub {
        Bundle legacyLocalRestrictions = null;
        RestrictionsSet localRestrictions = null;
        Bundle globalRestrictions = null;
        boolean ignorePrepareStorageErrors = true; // default is true for old users

        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(is, StandardCharsets.UTF_8.name());
@@ -3158,6 +3181,11 @@ public class UserManagerService extends IUserManager.Stub {
                    if (type == XmlPullParser.TEXT) {
                        lastRequestQuietModeEnabledTimestamp = Long.parseLong(parser.getText());
                    }
                } else if (TAG_IGNORE_PREPARE_STORAGE_ERRORS.equals(tag)) {
                    type = parser.next();
                    if (type == XmlPullParser.TEXT) {
                        ignorePrepareStorageErrors = Boolean.parseBoolean(parser.getText());
                    }
                }
            }
        }
@@ -3185,6 +3213,9 @@ public class UserManagerService extends IUserManager.Stub {
        userData.persistSeedData = persistSeedData;
        userData.seedAccountOptions = seedAccountOptions;
        userData.setLastRequestQuietModeEnabledMillis(lastRequestQuietModeEnabledTimestamp);
        if (ignorePrepareStorageErrors) {
            userData.setIgnorePrepareStorageErrors();
        }

        synchronized (mRestrictionsLock) {
            if (baseRestrictions != null) {
@@ -4829,6 +4860,9 @@ public class UserManagerService extends IUserManager.Stub {
                            pw.println();
                        }
                    }

                    pw.println("    Ignore errors preparing storage: "
                            + userData.getIgnorePrepareStorageErrors());
                }
            }
            pw.println();
@@ -5254,6 +5288,14 @@ public class UserManagerService extends IUserManager.Stub {
                return allInfos;
            }
        }

        @Override
        public boolean shouldIgnorePrepareStorageErrors(int userId) {
            synchronized (mUsersLock) {
                UserData userData = mUsers.get(userId);
                return userData != null && userData.getIgnorePrepareStorageErrors();
            }
        }
    }

    /**