Snap for 11224086 from a68fb57f2037e5925eb0fad49ede637ab04e20e6 to mainline-tzdata5-release

Change-Id: Ife213c05a128f210d97b34b786962305c13b7f25
diff --git a/runtime/Manager.cpp b/runtime/Manager.cpp
index 75f6243..c3fada3 100644
--- a/runtime/Manager.cpp
+++ b/runtime/Manager.cpp
@@ -91,7 +91,9 @@
 
 bool getWhetherPlatformTelemetryIsEnabled() {
 #if !defined(NN_COMPATIBILITY_LIBRARY_BUILD) && !defined(NN_EXPERIMENTAL_FEATURE)
-    return getServerTelemetryEnableFlag();
+    // b/287186978, force enable telemetry on the platform NNAPI
+    // return getServerTelemetryEnableFlag();
+    return true;
 #else   // !defined(NN_COMPATIBILITY_LIBRARY_BUILD) && !defined(NN_EXPERIMENTAL_FEATURE)
     return false;
 #endif  // !defined(NN_COMPATIBILITY_LIBRARY_BUILD) && !defined(NN_EXPERIMENTAL_FEATURE)
diff --git a/runtime/test/TestTrivialModel.cpp b/runtime/test/TestTrivialModel.cpp
index 999a27d..9c168df 100644
--- a/runtime/test/TestTrivialModel.cpp
+++ b/runtime/test/TestTrivialModel.cpp
@@ -37,7 +37,8 @@
     virtual void SetUp() {}
 
 #if defined(__ANDROID__)
-    void testAddTwoWithHardwareBufferInput(uint64_t additionalAhwbUsage);
+    void testAddTwoWithHardwareBufferInput(uint64_t additionalAhwbUsage,
+                                           bool allowAllocationFailure);
 #endif
 
     const Matrix3x4 matrix1 = {{1.f, 2.f, 3.f, 4.f}, {5.f, 6.f, 7.f, 8.f}, {9.f, 10.f, 11.f, 12.f}};
@@ -133,7 +134,8 @@
 // Hardware buffers are an Android concept, which aren't necessarily
 // available on other platforms such as ChromeOS, which also build NNAPI.
 #if defined(__ANDROID__)
-void TrivialTest::testAddTwoWithHardwareBufferInput(uint64_t additionalAhwbUsage) {
+void TrivialTest::testAddTwoWithHardwareBufferInput(uint64_t additionalAhwbUsage,
+                                                    bool allowAllocationFailure) {
     Model modelAdd2;
     CreateAddTwoTensorModel(&modelAdd2);
 
@@ -147,7 +149,11 @@
             .usage = cpuUsage | additionalAhwbUsage,
     };
     AHardwareBuffer* matrix1Buffer = nullptr;
-    ASSERT_EQ(AHardwareBuffer_allocate(&desc, &matrix1Buffer), 0);
+    int err = AHardwareBuffer_allocate(&desc, &matrix1Buffer);
+    if (allowAllocationFailure && err != 0) {
+        GTEST_SKIP() << "Test skipped: AHardwareBuffer_allocate failed";
+    }
+    ASSERT_EQ(err, 0);
     auto allocateGuard = android::base::make_scope_guard(
             [matrix1Buffer]() { AHardwareBuffer_release(matrix1Buffer); });
 
@@ -194,11 +200,13 @@
 }
 
 TEST_F(TrivialTest, AddTwoWithHardwareBufferInput) {
-    testAddTwoWithHardwareBufferInput(/* no additional usage */ 0u);
+    testAddTwoWithHardwareBufferInput(/* no additional usage */ 0u,
+                                      /*allowAllocationFailure=*/false);
 }
 
 TEST_F(TrivialTest, AddTwoWithHardwareBufferInputWithGPUUsage) {
-    testAddTwoWithHardwareBufferInput(AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER);
+    testAddTwoWithHardwareBufferInput(AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER,
+                                      /*allowAllocationFailure=*/true);
 }
 #endif
 
diff --git a/shim_and_sl/ShimConverter.cpp b/shim_and_sl/ShimConverter.cpp
index ed3cda2..9914af1 100644
--- a/shim_and_sl/ShimConverter.cpp
+++ b/shim_and_sl/ShimConverter.cpp
@@ -154,6 +154,10 @@
                 break;
             }
             case OperandLifeTime::CONSTANT_POOL: {
+                if (operand.location.poolIndex >= memoryPools.size()) {
+                    *errorStatus = ErrorStatus::INVALID_ARGUMENT;
+                    return nullptr;
+                }
                 resultModel.setOperandValueFromMemory(
                         i, memoryPools[operand.location.poolIndex].get(), operand.location.offset,
                         operand.location.length);