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

Commit 41dabc58 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 10791906 from 58a1d61a to udc-qpr1-release

Change-Id: Ie2686983dba80d7d69f883c97306981fd187db10
parents cf229d1d 58a1d61a
Loading
Loading
Loading
Loading
+58 −17
Original line number Original line Diff line number Diff line
@@ -94,6 +94,7 @@ final class SettingsState {


    static final int SETTINGS_VERSION_NEW_ENCODING = 121;
    static final int SETTINGS_VERSION_NEW_ENCODING = 121;


    public static final int MAX_LENGTH_PER_STRING = 32768;
    private static final long WRITE_SETTINGS_DELAY_MILLIS = 200;
    private static final long WRITE_SETTINGS_DELAY_MILLIS = 200;
    private static final long MAX_WRITE_SETTINGS_DELAY_MILLIS = 2000;
    private static final long MAX_WRITE_SETTINGS_DELAY_MILLIS = 2000;


@@ -430,6 +431,19 @@ final class SettingsState {
            return false;
            return false;
        }
        }


        final boolean isNameTooLong = name.length() > SettingsState.MAX_LENGTH_PER_STRING;
        final boolean isValueTooLong =
                value != null && value.length() > SettingsState.MAX_LENGTH_PER_STRING;
        if (isNameTooLong || isValueTooLong) {
            // only print the first few bytes of the name in case it is long
            final String errorMessage = "The " + (isNameTooLong ? "name" : "value")
                    + " of your setting ["
                    + (name.length() > 20 ? (name.substring(0, 20) + "...") : name)
                    + "] is too long. The max length allowed for the string is "
                    + MAX_LENGTH_PER_STRING + ".";
            throw new IllegalArgumentException(errorMessage);
        }

        Setting oldState = mSettings.get(name);
        Setting oldState = mSettings.get(name);
        String oldValue = (oldState != null) ? oldState.value : null;
        String oldValue = (oldState != null) ? oldState.value : null;
        String oldDefaultValue = (oldState != null) ? oldState.defaultValue : null;
        String oldDefaultValue = (oldState != null) ? oldState.defaultValue : null;
@@ -831,6 +845,7 @@ final class SettingsState {


    private void doWriteState() {
    private void doWriteState() {
        boolean wroteState = false;
        boolean wroteState = false;
        String settingFailedToBePersisted = null;
        final int version;
        final int version;
        final ArrayMap<String, Setting> settings;
        final ArrayMap<String, Setting> settings;
        final ArrayMap<String, String> namespaceBannedHashes;
        final ArrayMap<String, String> namespaceBannedHashes;
@@ -860,7 +875,6 @@ final class SettingsState {


                final int settingCount = settings.size();
                final int settingCount = settings.size();
                for (int i = 0; i < settingCount; i++) {
                for (int i = 0; i < settingCount; i++) {

                    Setting setting = settings.valueAt(i);
                    Setting setting = settings.valueAt(i);
                    if (setting.isTransient()) {
                    if (setting.isTransient()) {
                        if (DEBUG_PERSISTENCE) {
                        if (DEBUG_PERSISTENCE) {
@@ -869,8 +883,11 @@ final class SettingsState {
                        continue;
                        continue;
                    }
                    }


                    if (writeSingleSetting(mVersion, serializer, setting.getId(), setting.getName(),
                    try {
                            setting.getValue(), setting.getDefaultValue(), setting.getPackageName(),
                        if (writeSingleSetting(mVersion, serializer, setting.getId(),
                                setting.getName(),
                                setting.getValue(), setting.getDefaultValue(),
                                setting.getPackageName(),
                                setting.getTag(), setting.isDefaultFromSystem(),
                                setting.getTag(), setting.isDefaultFromSystem(),
                                setting.isValuePreservedInRestore())) {
                                setting.isValuePreservedInRestore())) {
                            if (DEBUG_PERSISTENCE) {
                            if (DEBUG_PERSISTENCE) {
@@ -878,6 +895,16 @@ final class SettingsState {
                                        + setting.getValue());
                                        + setting.getValue());
                            }
                            }
                        }
                        }
                    } catch (IOException ex) {
                        Slog.e(LOG_TAG, "[ABORT PERSISTING]" + setting.getName()
                                + " due to error writing to disk", ex);
                        // A setting failed to be written. Abort the serialization to avoid leaving
                        // a partially serialized setting on disk, which can cause parsing errors.
                        // Note down the problematic setting, so that we can delete it before trying
                        // again to persist the rest of the settings.
                        settingFailedToBePersisted = setting.getName();
                        throw ex;
                    }
                }
                }
                serializer.endTag(null, TAG_SETTINGS);
                serializer.endTag(null, TAG_SETTINGS);


@@ -902,14 +929,14 @@ final class SettingsState {
                    Slog.i(LOG_TAG, "[PERSIST END]");
                    Slog.i(LOG_TAG, "[PERSIST END]");
                }
                }
            } catch (Throwable t) {
            } catch (Throwable t) {
                Slog.wtf(LOG_TAG, "Failed to write settings, restoring backup", t);
                Slog.wtf(LOG_TAG, "Failed to write settings, restoring old file", t);
                if (t instanceof IOException) {
                if (t instanceof IOException) {
                    if (t.getMessage().contains("Couldn't create directory")) {
                        if (DEBUG) {
                        if (DEBUG) {
                            // we failed to create a directory, so log the permissions and existence
                            // we failed to create a directory, so log the permissions and existence
                            // state for the settings file and directory
                            // state for the settings file and directory
                            logSettingsDirectoryInformation(destination.getBaseFile());
                            logSettingsDirectoryInformation(destination.getBaseFile());
                        }
                        }
                    if (t.getMessage().contains("Couldn't create directory")) {
                        // attempt to create the directory with Files.createDirectories, which
                        // attempt to create the directory with Files.createDirectories, which
                        // throws more informative errors than File.mkdirs.
                        // throws more informative errors than File.mkdirs.
                        Path parentPath = destination.getBaseFile().getParentFile().toPath();
                        Path parentPath = destination.getBaseFile().getParentFile().toPath();
@@ -930,7 +957,15 @@ final class SettingsState {
            }
            }
        }
        }


        if (wroteState) {
        if (!wroteState) {
            if (settingFailedToBePersisted != null) {
                synchronized (mLock) {
                    // Delete the problematic setting. This will schedule a write as well.
                    deleteSettingLocked(settingFailedToBePersisted);
                }
            }
        } else {
            // success
            synchronized (mLock) {
            synchronized (mLock) {
                addHistoricalOperationLocked(HISTORICAL_OPERATION_PERSIST, null);
                addHistoricalOperationLocked(HISTORICAL_OPERATION_PERSIST, null);
            }
            }
@@ -1090,8 +1125,11 @@ final class SettingsState {
        } catch (FileNotFoundException fnfe) {
        } catch (FileNotFoundException fnfe) {
            final String message = "No fallback file found for: " + mStatePersistFile;
            final String message = "No fallback file found for: " + mStatePersistFile;
            Slog.wtf(LOG_TAG, message);
            Slog.wtf(LOG_TAG, message);
            if (!isConfigSettingsKey(mKey)) {
                // Allow partially deserialized config settings because they can be updated later
                throw new IllegalStateException(message);
                throw new IllegalStateException(message);
            }
            }
        }
        if (parseStateFromXmlStreamLocked(in)) {
        if (parseStateFromXmlStreamLocked(in)) {
            // Parsed state from fallback file. Restore original file with fallback file
            // Parsed state from fallback file. Restore original file with fallback file
            try {
            try {
@@ -1102,9 +1140,12 @@ final class SettingsState {
        } else {
        } else {
            final String message = "Failed parsing settings file: " + mStatePersistFile;
            final String message = "Failed parsing settings file: " + mStatePersistFile;
            Slog.wtf(LOG_TAG, message);
            Slog.wtf(LOG_TAG, message);
            if (!isConfigSettingsKey(mKey)) {
                // Allow partially deserialized config settings because they can be updated later
                throw new IllegalStateException(message);
                throw new IllegalStateException(message);
            }
            }
        }
        }
    }


    @GuardedBy("mLock")
    @GuardedBy("mLock")
    private boolean parseStateFromXmlStreamLocked(FileInputStream in) {
    private boolean parseStateFromXmlStreamLocked(FileInputStream in) {
+66 −20
Original line number Original line Diff line number Diff line
@@ -408,4 +408,50 @@ public class SettingsStateTest extends AndroidTestCase {
        }
        }
        assertEquals(expectedMemUsage, settingsState.getMemoryUsage(TEST_PACKAGE));
        assertEquals(expectedMemUsage, settingsState.getMemoryUsage(TEST_PACKAGE));
    }
    }

    public void testLargeSettingKey() {
        SettingsState settingsState = new SettingsState(getContext(), mLock, mSettingsFile, 1,
                SettingsState.MAX_BYTES_PER_APP_PACKAGE_LIMITED, Looper.getMainLooper());
        final String largeKey = Strings.repeat("A", SettingsState.MAX_LENGTH_PER_STRING + 1);
        final String testValue = "testValue";
        synchronized (mLock) {
            // Test system package
            try {
                settingsState.insertSettingLocked(largeKey, testValue, null, true, SYSTEM_PACKAGE);
                fail("Should throw because it exceeded max string length");
            } catch (IllegalArgumentException ex) {
                assertTrue(ex.getMessage().contains("The max length allowed for the string is "));
            }
            // Test non system package
            try {
                settingsState.insertSettingLocked(largeKey, testValue, null, true, TEST_PACKAGE);
                fail("Should throw because it exceeded max string length");
            } catch (IllegalArgumentException ex) {
                assertTrue(ex.getMessage().contains("The max length allowed for the string is "));
            }
        }
    }

    public void testLargeSettingValue() {
        SettingsState settingsState = new SettingsState(getContext(), mLock, mSettingsFile, 1,
                SettingsState.MAX_BYTES_PER_APP_PACKAGE_UNLIMITED, Looper.getMainLooper());
        final String testKey = "testKey";
        final String largeValue = Strings.repeat("A", SettingsState.MAX_LENGTH_PER_STRING + 1);
        synchronized (mLock) {
            // Test system package
            try {
                settingsState.insertSettingLocked(testKey, largeValue, null, true, SYSTEM_PACKAGE);
                fail("Should throw because it exceeded max string length");
            } catch (IllegalArgumentException ex) {
                assertTrue(ex.getMessage().contains("The max length allowed for the string is "));
            }
            // Test non system package
            try {
                settingsState.insertSettingLocked(testKey, largeValue, null, true, TEST_PACKAGE);
                fail("Should throw because it exceeded max string length");
            } catch (IllegalArgumentException ex) {
                assertTrue(ex.getMessage().contains("The max length allowed for the string is "));
            }
        }
    }
}
}
+1 −0
Original line number Original line Diff line number Diff line
@@ -1231,6 +1231,7 @@
    <dimen name="magnification_setting_image_button_open_in_full_padding_horizontal">28dp</dimen>
    <dimen name="magnification_setting_image_button_open_in_full_padding_horizontal">28dp</dimen>
    <dimen name="magnification_setting_drag_corner_radius">28dp</dimen>
    <dimen name="magnification_setting_drag_corner_radius">28dp</dimen>
    <dimen name="magnification_setting_drag_size">56dp</dimen>
    <dimen name="magnification_setting_drag_size">56dp</dimen>
    <fraction name="magnification_resize_window_size_amount">10%</fraction>


    <!-- Seekbar with icon buttons -->
    <!-- Seekbar with icon buttons -->
    <dimen name="seekbar_icon_size">24dp</dimen>
    <dimen name="seekbar_icon_size">24dp</dimen>
+4 −0
Original line number Original line Diff line number Diff line
@@ -172,6 +172,10 @@
    <item type="id" name="accessibility_action_move_right"/>
    <item type="id" name="accessibility_action_move_right"/>
    <item type="id" name="accessibility_action_move_up"/>
    <item type="id" name="accessibility_action_move_up"/>
    <item type="id" name="accessibility_action_move_down"/>
    <item type="id" name="accessibility_action_move_down"/>
    <item type="id" name="accessibility_action_increase_window_width"/>
    <item type="id" name="accessibility_action_decrease_window_width"/>
    <item type="id" name="accessibility_action_increase_window_height"/>
    <item type="id" name="accessibility_action_decrease_window_height"/>


    <!-- Accessibility actions for Accessibility floating menu. -->
    <!-- Accessibility actions for Accessibility floating menu. -->
    <item type="id" name="action_move_top_left"/>
    <item type="id" name="action_move_top_left"/>
+10 −0
Original line number Original line Diff line number Diff line
@@ -2398,6 +2398,16 @@
    <string name="accessibility_control_move_left">Move left</string>
    <string name="accessibility_control_move_left">Move left</string>
    <!-- Action in accessibility menu to move the magnification window right. [CHAR LIMIT=30] -->
    <!-- Action in accessibility menu to move the magnification window right. [CHAR LIMIT=30] -->
    <string name="accessibility_control_move_right">Move right</string>
    <string name="accessibility_control_move_right">Move right</string>

    <!-- Action in accessibility menu to increase the magnification window width. [CHAR LIMIT=NONE] -->
    <string name="accessibility_control_increase_window_width">Increase width of magnifier</string>
    <!-- Action in accessibility menu to decrease the magnification window width. [CHAR LIMIT=NONE] -->
    <string name="accessibility_control_decrease_window_width">Decrease width of magnifier</string>
    <!-- Action in accessibility menu to increase the magnification window height. [CHAR LIMIT=NONE] -->
    <string name="accessibility_control_increase_window_height">Increase height of magnifier</string>
    <!-- Action in accessibility menu to decrease the magnification window height. [CHAR LIMIT=NONE] -->
    <string name="accessibility_control_decrease_window_height">Decrease height of magnifier</string>

    <!-- Content description for magnification mode switch. [CHAR LIMIT=NONE] -->
    <!-- Content description for magnification mode switch. [CHAR LIMIT=NONE] -->
    <string name="magnification_mode_switch_description">Magnification switch</string>
    <string name="magnification_mode_switch_description">Magnification switch</string>
    <!-- A11y state description for magnification mode switch that device is in full-screen mode. [CHAR LIMIT=NONE] -->
    <!-- A11y state description for magnification mode switch that device is in full-screen mode. [CHAR LIMIT=NONE] -->
Loading