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

Commit f6e6b8f1 authored by Annie Meng's avatar Annie Meng Committed by android-build-team Robot
Browse files

Fix NPE in ComponentNameValidator

In general, we should consider null component names as invalid settings,
meaning that we don't restore.

b/79925290 to allow restoring null component names for specific
settings where null has semantic meaning.

Bug: 79910479
Test: 1) atest SettingsValidatorsTest
2) Manual:
- In Settings UI, select "None" for autofill service and accessibility
shortcut target
- "adb backup -keyvalue -f nullsettings.ab com.android.providers.settings"
- "adb restore nullsettings.ab" and verify no crashes
Change-Id: Iffecbe7d26a93a816e7be42f564ba471f9681876
(cherry picked from commit 5d26b8c0)
parent 05fd3cae
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ public class SettingsValidators {
    public static final Validator COMPONENT_NAME_VALIDATOR = new Validator() {
        @Override
        public boolean validate(String value) {
            return ComponentName.unflattenFromString(value) != null;
            return value != null && ComponentName.unflattenFromString(value) != null;
        }
    };

+6 −1
Original line number Diff line number Diff line
@@ -16,9 +16,9 @@

package android.provider;

import static org.junit.Assert.fail;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import android.platform.test.annotations.Presubmit;
import android.provider.SettingsValidators.Validator;
@@ -62,6 +62,11 @@ public class SettingsValidatorsTest {
        assertFalse(SettingsValidators.COMPONENT_NAME_VALIDATOR.validate("rectangle"));
    }

    @Test
    public void testComponentNameValidator_onNullValue_doesNotThrow() {
        assertFalse(SettingsValidators.COMPONENT_NAME_VALIDATOR.validate(null));
    }

    @Test
    public void testLocaleValidator() {
        assertTrue(SettingsValidators.LOCALE_VALIDATOR.validate("en_US"));