Replace ANNOperandType::ExtraParams with a function call.

Exending ANeuralNetworkOperandType struct with new fields may be problematic
and difficult to maintain in longer term. This change turns recently introduced
ANNOperandType.extraParams field into a function call:

ANeuralNetworksModel_setOperandSymmPerChannelQuant(...)

that associates ANeuralNetworksSymmPerChannelQuant struct with an operand.

+ added to NeuralNetworks.h an ANDROID_Q ifdef for operand types added in Q.

Bug: 119249581
Test: NeuralNetworksTest_static
Change-Id: Idebe86ce1ca8f3a31dbfe7b21de4dd45df380a38
Merged-In: Idebe86ce1ca8f3a31dbfe7b21de4dd45df380a38
(cherry picked from commit 2df5477fecc92ed93459b79f5b1b1d2de309ae86)
diff --git a/runtime/NeuralNetworks.cpp b/runtime/NeuralNetworks.cpp
index 6044b39..bed6530 100644
--- a/runtime/NeuralNetworks.cpp
+++ b/runtime/NeuralNetworks.cpp
@@ -278,22 +278,18 @@
               "ANeuralNetworksOperandType.scale offset != 8 + sizeof(void*)");
 static_assert(offsetof(ANeuralNetworksOperandType, zeroPoint) == 12 + sizeof(void*),
               "ANeuralNetworksOperandType.zeroPoint offset != 12 + sizeof(void*)");
-static_assert(offsetof(ANeuralNetworksOperandType, extraParams) == 16 + sizeof(void*),
-              "ANeuralNetworksOperandType.extraParams offset != 16 + sizeof(void*)");
-static_assert(sizeof(ANeuralNetworksOperandType) ==
-                      offsetof(ANeuralNetworksOperandType, extraParams) +
-                              sizeof(ANeuralNetworksOperandType::extraParams),
+static_assert(sizeof(ANeuralNetworksOperandType) == 16 + sizeof(void*),
               "ANeuralNetworksOperandType size changed");
 static_assert(alignof(ANeuralNetworksOperandType) == alignof(void*),
               "ANeuralNetworksOperandType alignment changed");
 
 // Asserts for ANeuralNetworksSymmPerChannelQuantParams memory layout
-static_assert(offsetof(ANeuralNetworksSymmPerChannelQuantParams, scales) == 0,
-              "ANeuralNetworksSymmPerChannelQuantParams.scales offset != 0");
-static_assert(offsetof(ANeuralNetworksSymmPerChannelQuantParams, scaleCount) == sizeof(void*),
-              "ANeuralNetworksSymmPerChannelQuantParams.scaleCount offset != sizeof(void*)");
-static_assert(offsetof(ANeuralNetworksSymmPerChannelQuantParams, channelDim) == 4 + sizeof(void*),
+static_assert(offsetof(ANeuralNetworksSymmPerChannelQuantParams, channelDim) == 0,
               "ANeuralNetworksSymmPerChannelQuantParams.channelDim offset != 4 + sizeof(void*)");
+static_assert(offsetof(ANeuralNetworksSymmPerChannelQuantParams, scaleCount) == 4,
+              "ANeuralNetworksSymmPerChannelQuantParams.scaleCount offset != 0");
+static_assert(offsetof(ANeuralNetworksSymmPerChannelQuantParams, scales) == 8,
+              "ANeuralNetworksSymmPerChannelQuantParams.scales offset != 4");
 static_assert(sizeof(ANeuralNetworksSymmPerChannelQuantParams) == 8 + sizeof(void*),
               "ANeuralNetworksSymmPerChannelQuantParams size != 8 + sizeof(void*)");
 static_assert(alignof(ANeuralNetworksSymmPerChannelQuantParams) == alignof(void*),
@@ -575,6 +571,19 @@
     return m->addOperation(type, inputCount, inputs, outputCount, outputs);
 }
 
+int ANeuralNetworksModel_setOperandSymmPerChannelQuantParams(
+        ANeuralNetworksModel* model, int32_t index,
+        const ANeuralNetworksSymmPerChannelQuantParams* channelQuant) {
+    NNTRACE_RT(NNTRACE_PHASE_PREPARATION,
+               "ANeuralNetworksModel_setOperandSymmPerChannelQuantParams");
+    if (!model || !channelQuant) {
+        LOG(ERROR) << "ANeuralNetworksModel_setOperandSymmPerChannelQuantParams passed a nullptr";
+        return ANEURALNETWORKS_UNEXPECTED_NULL;
+    }
+    ModelBuilder* m = reinterpret_cast<ModelBuilder*>(model);
+    return m->setOperandSymmPerChannelQuantParams(index, *channelQuant);
+}
+
 int ANeuralNetworksModel_identifyInputsAndOutputs(ANeuralNetworksModel* model, uint32_t inputCount,
                                                   const uint32_t* inputs, uint32_t outputCount,
                                                   const uint32_t* outputs) {