Read `ro.product.device` in Adaptive CPU.

See b/222438951 for justification.

When model.inc is interpretting this enum, I think it should treat
UNKNOWN as e.g. RAVEN, so the model can still do something sensible.
I've left that to the model-side to make debugging the non-model code
easier.

Test: manual validation of counters: http://screen/Az9viP9e25eWQgL
Bug: 222438951
Change-Id: Id648b23d7bee4c34cdf077e93cf4a932265673c7
diff --git a/power-libperfmgr/Android.bp b/power-libperfmgr/Android.bp
index 3fccfcf..14ed87b 100644
--- a/power-libperfmgr/Android.bp
+++ b/power-libperfmgr/Android.bp
@@ -44,6 +44,7 @@
         "adaptivecpu/CpuFrequencyReader.cpp",
         "adaptivecpu/CpuLoadReaderProcStat.cpp",
         "adaptivecpu/CpuLoadReaderSysDevices.cpp",
+        "adaptivecpu/Device.cpp",
         "adaptivecpu/KernelCpuFeatureReader.cpp",
         "adaptivecpu/Model.cpp",
         "adaptivecpu/RealFilesystem.cpp",
diff --git a/power-libperfmgr/adaptivecpu/AdaptiveCpu.cpp b/power-libperfmgr/adaptivecpu/AdaptiveCpu.cpp
index ef1afea..ebd6d7c 100644
--- a/power-libperfmgr/adaptivecpu/AdaptiveCpu.cpp
+++ b/power-libperfmgr/adaptivecpu/AdaptiveCpu.cpp
@@ -143,11 +143,13 @@
                 mIsEnabled = false;
                 continue;
             }
+            mDevice = ReadDevice();
             mIsInitialized = true;
         }
 
         ModelInput modelInput;
         modelInput.previousThrottleDecision = previousThrottleDecision;
+        modelInput.device = mDevice;
 
         modelInput.workDurationFeatures = mWorkDurationProcessor.GetFeatures();
         LOG(VERBOSE) << "Got work durations: count=" << modelInput.workDurationFeatures.numDurations
diff --git a/power-libperfmgr/adaptivecpu/AdaptiveCpu.h b/power-libperfmgr/adaptivecpu/AdaptiveCpu.h
index dd0a915..f7328f6 100644
--- a/power-libperfmgr/adaptivecpu/AdaptiveCpu.h
+++ b/power-libperfmgr/adaptivecpu/AdaptiveCpu.h
@@ -26,6 +26,7 @@
 
 #include "AdaptiveCpuConfig.h"
 #include "AdaptiveCpuStats.h"
+#include "Device.h"
 #include "KernelCpuFeatureReader.h"
 #include "Model.h"
 #include "WorkDurationProcessor.h"
@@ -100,6 +101,7 @@
     bool mIsInitialized = false;
     volatile bool mShouldReloadConfig = false;
     std::chrono::nanoseconds mLastEnabledHintTime;
+    Device mDevice;
     AdaptiveCpuConfig mConfig = AdaptiveCpuConfig::DEFAULT;
 };
 
diff --git a/power-libperfmgr/adaptivecpu/Device.cpp b/power-libperfmgr/adaptivecpu/Device.cpp
new file mode 100644
index 0000000..54366fb
--- /dev/null
+++ b/power-libperfmgr/adaptivecpu/Device.cpp
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "powerhal-libperfmgr"
+#define ATRACE_TAG (ATRACE_TAG_POWER | ATRACE_TAG_HAL)
+
+#include "Device.h"
+
+#include <android-base/logging.h>
+#include <android-base/properties.h>
+#include <utils/Trace.h>
+
+namespace aidl {
+namespace google {
+namespace hardware {
+namespace power {
+namespace impl {
+namespace pixel {
+
+Device ReadDevice() {
+    ATRACE_CALL();
+    const std::string deviceProperty = ::android::base::GetProperty("ro.product.device", "");
+    Device device;
+    if (deviceProperty == "raven") {
+        device = Device::RAVEN;
+    } else if (deviceProperty == "oriole") {
+        device = Device::ORIOLE;
+    } else {
+        LOG(WARNING) << "Failed to parse device property, setting to UNKNOWN: " << deviceProperty;
+        device = Device::UNKNOWN;
+    }
+    LOG(DEBUG) << "Parsed device: deviceProperty=" << deviceProperty
+               << ", device=" << static_cast<uint32_t>(device);
+    return device;
+}
+
+}  // namespace pixel
+}  // namespace impl
+}  // namespace power
+}  // namespace hardware
+}  // namespace google
+}  // namespace aidl
diff --git a/power-libperfmgr/adaptivecpu/Device.h b/power-libperfmgr/adaptivecpu/Device.h
new file mode 100644
index 0000000..8e357a3
--- /dev/null
+++ b/power-libperfmgr/adaptivecpu/Device.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+namespace aidl {
+namespace google {
+namespace hardware {
+namespace power {
+namespace impl {
+namespace pixel {
+
+enum class Device { UNKNOWN = 0, RAVEN = 1, ORIOLE = 2 };
+
+Device ReadDevice();
+
+}  // namespace pixel
+}  // namespace impl
+}  // namespace power
+}  // namespace hardware
+}  // namespace google
+}  // namespace aidl
diff --git a/power-libperfmgr/adaptivecpu/Model.cpp b/power-libperfmgr/adaptivecpu/Model.cpp
index edc243d..4c1d2f2 100644
--- a/power-libperfmgr/adaptivecpu/Model.cpp
+++ b/power-libperfmgr/adaptivecpu/Model.cpp
@@ -71,6 +71,7 @@
                workDurationFeatures.numMissedDeadlines);
     ATRACE_INT("ModelInput_workDurations_numDurations", workDurationFeatures.numDurations);
     ATRACE_INT("ModelInput_prevThrottle", (int)previousThrottleDecision);
+    ATRACE_INT("ModelInput_device", static_cast<int>(device));
 }
 
 ThrottleDecision Model::Run(const std::deque<ModelInput> &modelInputs,
diff --git a/power-libperfmgr/adaptivecpu/Model.h b/power-libperfmgr/adaptivecpu/Model.h
index 44c4d0d..2a00a8f 100644
--- a/power-libperfmgr/adaptivecpu/Model.h
+++ b/power-libperfmgr/adaptivecpu/Model.h
@@ -26,6 +26,7 @@
 
 #include "AdaptiveCpuConfig.h"
 #include "CpuFrequencyReader.h"
+#include "Device.h"
 #include "ThrottleDecision.h"
 #include "WorkDurationProcessor.h"
 
@@ -47,6 +48,7 @@
     std::array<double, NUM_CPU_CORES> cpuCoreIdleTimesPercentage;
     WorkDurationFeatures workDurationFeatures;
     ThrottleDecision previousThrottleDecision;
+    Device device;
 
     bool SetCpuFreqiencies(
             const std::vector<CpuPolicyAverageFrequency> &cpuPolicyAverageFrequencies);