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

Unverified Commit 860ba56a authored by Oliver Scott's avatar Oliver Scott Committed by Michael Bestas
Browse files

Split network policy XML parsing into read/write helper functions

Bug: https://issuetracker.google.com/issues/207800947
Change-Id: I360bfad4c549c24f56201164442056f842708124
(cherry picked from commit 15357070f3d6e039443c383b00c66a59b5f979ec)
(cherry picked from commit 052aba23e06a8ac1b05bbfe55f02f710c762e0ca)
parent b0b99d46
Loading
Loading
Loading
Loading
+247 −240
Original line number Diff line number Diff line
@@ -2495,6 +2495,19 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
        FileInputStream fis = null;
        try {
            fis = mPolicyFile.openRead();
            readPolicyXml(fis);

        } catch (FileNotFoundException e) {
            // missing policy is okay, probably first boot
            upgradeDefaultBackgroundDataUL();
        } catch (Exception e) {
            Log.wtf(TAG, "problem reading network policy", e);
        } finally {
            IoUtils.closeQuietly(fis);
        }
    }

    private void readPolicyXml(FileInputStream fis) {
        final TypedXmlPullParser in = Xml.resolvePullParser(fis);

        // Must save the <restrict-background> tags and convert them to <uid-policy> later,
@@ -2668,15 +2681,6 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
                Slog.w(TAG, "unable to update policy on UID " + uid);
            }
        }

        } catch (FileNotFoundException e) {
            // missing policy is okay, probably first boot
            upgradeDefaultBackgroundDataUL();
        } catch (Exception e) {
            Log.wtf(TAG, "problem reading network policy", e);
        } finally {
            IoUtils.closeQuietly(fis);
        }
    }

    /**
@@ -2756,7 +2760,17 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
        FileOutputStream fos = null;
        try {
            fos = mPolicyFile.startWrite();
            writePolicyXml(fos);

            mPolicyFile.finishWrite(fos);
        } catch (IOException e) {
            if (fos != null) {
                mPolicyFile.failWrite(fos);
            }
        }
    }

    private void writePolicyXml(FileOutputStream fos) {
        TypedXmlSerializer out = Xml.resolveSerializer(fos);
        out.startDocument(null, true);

@@ -2833,13 +2847,6 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
        out.endTag(null, TAG_WHITELIST);

        out.endDocument();

            mPolicyFile.finishWrite(fos);
        } catch (IOException e) {
            if (fos != null) {
                mPolicyFile.failWrite(fos);
            }
        }
    }

    @Override