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

Commit f4eb0620 authored by Dennis Shen's avatar Dennis Shen Committed by Gerrit Code Review
Browse files

Merge "Route flag requests to both sockets if mainline aconfigd is also enabled" into main

parents 88142e1c bc4826ce
Loading
Loading
Loading
Loading
+35 −26
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.aconfigd.Aconfigd.StorageRequestMessages;
import android.aconfigd.Aconfigd.StorageReturnMessage;
import android.aconfigd.Aconfigd.StorageReturnMessages;
import static com.android.aconfig_new_storage.Flags.enableAconfigStorageDaemon;
import static com.android.aconfig_new_storage.Flags.enableAconfigdFromMainline;

import java.io.DataInputStream;
import java.io.DataOutputStream;
@@ -388,16 +389,38 @@ public class SettingsToPropertiesMapper {
     * @param requests: request proto output stream
     * @return aconfigd socket return as proto input stream
     */
    static ProtoInputStream sendAconfigdRequests(ProtoOutputStream requests) {
    static void sendAconfigdRequests(ProtoOutputStream requests) {
        ProtoInputStream returns = sendAconfigdRequests("aconfigd_system", requests);
        try {
          parseAndLogAconfigdReturn(returns);
        } catch (IOException ioe) {
          logErr("failed to parse aconfigd return", ioe);
        }
        if (enableAconfigdFromMainline()) {
            returns = sendAconfigdRequests("aconfigd_mainline", requests);
            try {
              parseAndLogAconfigdReturn(returns);
            } catch (IOException ioe) {
              logErr("failed to parse aconfigd return", ioe);
            }
        }
    }

    /**
     * apply flag local override in aconfig new storage
     * @param socketName: the socket to send to
     * @param requests: request proto output stream
     * @return aconfigd socket return as proto input stream
     */
    static ProtoInputStream sendAconfigdRequests(String socketName, ProtoOutputStream requests) {
        // connect to aconfigd socket
        LocalSocket client = new LocalSocket();
        String socketName = "aconfigd_system";
        try {
            client.connect(new LocalSocketAddress(
                socketName, LocalSocketAddress.Namespace.RESERVED));
            Slog.d(TAG, "connected to aconfigd socket");
            Slog.d(TAG, "connected to " + socketName + " socket");
        } catch (IOException ioe) {
            logErr("failed to connect to aconfigd socket", ioe);
            logErr("failed to connect to " + socketName + " socket", ioe);
            return null;
        }

@@ -416,9 +439,9 @@ public class SettingsToPropertiesMapper {
            byte[] requests_bytes = requests.getBytes();
            outputStream.writeInt(requests_bytes.length);
            outputStream.write(requests_bytes, 0, requests_bytes.length);
            Slog.d(TAG, "flag override requests sent to aconfigd");
            Slog.d(TAG, "flag override requests sent to " + socketName);
        } catch (IOException ioe) {
            logErr("failed to send requests to aconfigd", ioe);
            logErr("failed to send requests to " + socketName, ioe);
            return null;
        }

@@ -426,10 +449,10 @@ public class SettingsToPropertiesMapper {
        try {
            int num_bytes = inputStream.readInt();
            ProtoInputStream returns = new ProtoInputStream(inputStream);
            Slog.d(TAG, "received " + num_bytes + " bytes back from aconfigd");
            Slog.d(TAG, "received " + num_bytes + " bytes back from " + socketName);
            return returns;
        } catch (IOException ioe) {
            logErr("failed to read requests return from aconfigd", ioe);
            logErr("failed to read requests return from " + socketName, ioe);
            return null;
        }
    }
@@ -524,15 +547,8 @@ public class SettingsToPropertiesMapper {
          return;
        }

        // send requests to aconfigd and obtain the return byte buffer
        ProtoInputStream returns = sendAconfigdRequests(requests);

        // deserialize back using proto input stream
        try {
          parseAndLogAconfigdReturn(returns);
        } catch (IOException ioe) {
            logErr("failed to parse aconfigd return", ioe);
        }
        // send requests to aconfigd
        sendAconfigdRequests(requests);
    }

    public static SettingsToPropertiesMapper start(ContentResolver contentResolver) {
@@ -642,15 +658,8 @@ public class SettingsToPropertiesMapper {
          return;
        }

        // send requests to aconfigd and obtain the return
        ProtoInputStream returns = sendAconfigdRequests(requests);

        // deserialize back using proto input stream
        try {
            parseAndLogAconfigdReturn(returns);
        } catch (IOException ioe) {
            logErr("failed to parse aconfigd return", ioe);
        }
        // send requests to aconfigd
        sendAconfigdRequests(requests);
    }

    /**