IVGCVSW-6073 Add protected mode to ArmNN CreationOptions

 * Adds logic to the Runtime to activate protected mode
 * Adds ProtectedContentAllocation backend capability to ClBackend
   It's not fully activated yet because the CustomAllocator is
   missing. Will print an error message and won't register the backend
   but won't fail.
 * Extends IBackendInternal with an UseCustomAllocator function.
 * Adds related unit tests

Signed-off-by: Jan Eilers <jan.eilers@arm.com>
Change-Id: I64f465c5800eb104aa90db1bbf772a4148b5072f
diff --git a/src/armnn/Runtime.cpp b/src/armnn/Runtime.cpp
index f16d186..c2b7486 100644
--- a/src/armnn/Runtime.cpp
+++ b/src/armnn/Runtime.cpp
@@ -6,6 +6,7 @@
 
 #include <armnn/Version.hpp>
 #include <armnn/BackendRegistry.hpp>
+#include <armnn/BackendHelper.hpp>
 #include <armnn/Logging.hpp>
 #include <armnn/utility/Timer.hpp>
 
@@ -282,6 +283,32 @@
             auto backend = factoryFun();
             ARMNN_ASSERT(backend.get() != nullptr);
 
+            // If the runtime is created in protected mode only add backends that support this mode
+            if (options.m_ProtectedMode)
+            {
+                // check if backend supports ProtectedMode
+                using BackendCapability = BackendOptions::BackendOption;
+                BackendCapability protectedContentCapability {"ProtectedContentAllocation", true};
+                if (!HasCapability(protectedContentCapability, id))
+                {
+                    // Protected Content Allocation is not supported by the backend
+                    // backend should not be registered
+                    ARMNN_LOG(warning) << "Backend "
+                                       << id
+                                       << " is not registered as does not support protected content allocation \n";
+                    continue;
+                }
+                std::string err;
+                if (!backend->UseCustomMemoryAllocator(err))
+                {
+                    ARMNN_LOG(error) << "The backend "
+                                     << id
+                                     << " reported an error when entering protected mode. Backend won't be used."
+                                     << " ErrorMsg: " << err;
+                    continue;
+                }
+            }
+
             auto context = backend->CreateBackendContext(options);
 
             // backends are allowed to return nullptrs if they