DO NOT MERGE: OMAParser: throw IOException when parsing a null XML string

This avoids a NullPointerException when parsing a null XML string.
OMAParser.parse is only used by PasspointManagementObjectManager for
adding/building/modifying a HomeSP from a XML string.

It is fine to use IOException since it is already being handled
gracefully by its upstream callers.

Bug: 31497435
Test: unit tests
Test: Verify system server crashes when executing the command below without the fix
      and doesn't crash with the fix:
              "adb shell service call wifi 8 i32 0"

Change-Id: If2ad13b8573d49ba0ccbea2427f3c63d841f866d
(cherry picked from commit 309374f8d5839a5af7399aced0e976241b0ef62d)
diff --git a/service/java/com/android/server/wifi/hotspot2/omadm/OMAParser.java b/service/java/com/android/server/wifi/hotspot2/omadm/OMAParser.java
index cbcd81d..d39fa33 100644
--- a/service/java/com/android/server/wifi/hotspot2/omadm/OMAParser.java
+++ b/service/java/com/android/server/wifi/hotspot2/omadm/OMAParser.java
@@ -26,6 +26,9 @@
     }
 
     public MOTree parse(String text, String urn) throws IOException, SAXException {
+        if (text == null) {
+          throw new IOException("Missing text string");
+        }
         try {
             SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
             parser.parse(new InputSource(new StringReader(text)), this);
diff --git a/service/tests/wifitests/src/com/android/server/wifi/PasspointManagementObjectManagerTest.java b/service/tests/wifitests/src/com/android/server/wifi/PasspointManagementObjectManagerTest.java
index c76bf91..d3022b9 100644
--- a/service/tests/wifitests/src/com/android/server/wifi/PasspointManagementObjectManagerTest.java
+++ b/service/tests/wifitests/src/com/android/server/wifi/PasspointManagementObjectManagerTest.java
@@ -193,6 +193,21 @@
         assertEquals("testIdentity1", homeSP.getCredential().getUserName());
     }
 
+    /** Verify IOException is thrown when trying to add a SP from a null XML string. */
+    @Test(expected = IOException.class)
+    public void addSPFromNullXmlString() throws Exception {
+        File file = tempFolder.newFile("PerProviderSubscription.conf");
+        PasspointManagementObjectManager moMgr = new PasspointManagementObjectManager(file, true);
+        String xml = null;  // Needed to avoid ambiguity on function call.
+        moMgr.addSP(xml);
+    }
+
+    /** Verify IOException is thrown when trying to build a SP from a null XML string. */
+    @Test(expected = IOException.class)
+    public void buildSPFromNullXmlString() throws Exception {
+        PasspointManagementObjectManager.buildSP(null);
+    }
+
     /** verify that xml serialization/deserialization works */
     public void checkXml() throws Exception {
         InputStream in = getClass().getClassLoader().getResourceAsStream(R2_TTLS_XML_FILE);
@@ -268,6 +283,27 @@
         assertEquals(9, homeSP.getUpdateIdentifier());
     }
 
+    /** Verify IOException is thrown when trying to modify a SP using a null XML string. */
+    @Test(expected = IOException.class)
+    public void modifySPFromNullXmlString() throws Exception {
+        File file = createFileFromResource(R2_CONFIG_FILE);
+        PasspointManagementObjectManager moMgr = new PasspointManagementObjectManager(file, true);
+        List<HomeSP> homeSPs = moMgr.loadAllSPs();
+        assertEquals(2, homeSPs.size());
+
+        /* PasspointManagementObjectDefinition with null xmlTree. */
+        String urn = "wfa:mo:hotspot2dot0-perprovidersubscription:1.0";
+        String baseUri = "./Wi-Fi/wi-fi.org/PerProviderSubscription/UpdateIdentifier";
+        String xmlTree = null;
+
+        PasspointManagementObjectDefinition moDef =
+                new PasspointManagementObjectDefinition(baseUri, urn, xmlTree);
+        List<PasspointManagementObjectDefinition> moDefs =
+                new ArrayList<PasspointManagementObjectDefinition>();
+        moDefs.add(moDef);
+        moMgr.modifySP("wi-fi.org", moDefs);
+    }
+
     /** verify removing an existing service provider works */
     @Test
     public void removeSP() throws Exception {