Alert when kernel version is missing vhost-vsock

The alert prevents users from launching Cuttlefish with
an error that tells the user to upgrade their kernel version
to 4.8 which is the minimum version required for vhost-vsock.
This is required for Cuttlefish to run properly, otherwise
users were reporting a black screen and unable to connect via
ADB.

Bug: 141558130
Test: local build and boot
Change-Id: Iad66b39378731ef615f88d940fde0e6b70dcccf0
diff --git a/host/libs/vm_manager/vm_manager.cpp b/host/libs/vm_manager/vm_manager.cpp
index d613a56..ac5531a 100644
--- a/host/libs/vm_manager/vm_manager.cpp
+++ b/host/libs/vm_manager/vm_manager.cpp
@@ -19,6 +19,7 @@
 #include <memory>
 
 #include <glog/logging.h>
+#include <sys/utsname.h>
 
 #include "common/libs/utils/users.h"
 #include "host/libs/config/cuttlefish_config.h"
@@ -126,12 +127,31 @@
   return true;
 }
 
+bool VmManager::LinuxVersionAtLeast4_8(std::vector<std::string>* config_commands) {
+  struct utsname info;
+  if (!uname(&info)) {
+    char* digit = strtok(info.release, "+.-");
+    int major = atoi(digit);
+    if (digit) {
+      digit = strtok(NULL, "+.-");
+      int minor = atoi(digit);
+      if (major > 4 || (major == 4 && minor >= 8)) {
+        return true;
+      }
+    }
+  }
+  LOG(ERROR) << "Kernel version must be >=4.8";
+  config_commands->push_back("# Please upgrade your kernel to >=4.8");
+  return false;
+}
+
 bool VmManager::ValidateHostConfiguration(
     std::vector<std::string>* config_commands) const {
   // the check for cvdnetwork needs to happen even if the user is not in kvm, so
-  // we cant just say UserInGroup("kvm") && UserInGroup("cvdnetwork")
+  // we can't just say UserInGroup("kvm") && UserInGroup("cvdnetwork")
   auto in_kvm = VmManager::UserInGroup("kvm", config_commands);
   auto in_cvdnetwork = VmManager::UserInGroup("cvdnetwork", config_commands);
-  return in_kvm && in_cvdnetwork;
+  auto linux_ver_4_8 = VmManager::LinuxVersionAtLeast4_8(config_commands);
+  return in_kvm && in_cvdnetwork && linux_ver_4_8;
 }
 }  // namespace vm_manager
diff --git a/host/libs/vm_manager/vm_manager.h b/host/libs/vm_manager/vm_manager.h
index 79d5bbd..62adbf8 100644
--- a/host/libs/vm_manager/vm_manager.h
+++ b/host/libs/vm_manager/vm_manager.h
@@ -54,6 +54,8 @@
  protected:
   static bool UserInGroup(const std::string& group,
                           std::vector<std::string>* config_commands);
+  static bool LinuxVersionAtLeast4_8(std::vector<std::string>* config_commands);
+
   const vsoc::CuttlefishConfig* config_;
   VmManager(const vsoc::CuttlefishConfig* config);