Rename PackageNameResolver to PackageInfoResolver.
Also move PackageInfoResolver out of the utils directory as there is
cross dependency with WatchdogServiceHelper.
Test: Tested with unit tests.
Bug: 167240592
Bug: 168155311
Change-Id: Ided1e999124ad472a346af151fe47711bffacb84
Merged-In: Ided1e999124ad472a346af151fe47711bffacb84
(cherry picked from commit cd5bca67ae73e8a5ec6584efab5b6d5f3ea5cad2)
diff --git a/cpp/watchdog/server/Android.bp b/cpp/watchdog/server/Android.bp
index c0b1c3b..b6f1ae8 100644
--- a/cpp/watchdog/server/Android.bp
+++ b/cpp/watchdog/server/Android.bp
@@ -42,9 +42,9 @@
}
cc_library {
- name: "libwatchdog_utils",
+ name: "libwatchdog_package_info_resolver",
srcs: [
- "src/utils/PackageNameResolver.cpp",
+ "src/PackageInfoResolver.cpp",
],
defaults: [
"carwatchdogd_defaults",
@@ -53,7 +53,7 @@
"libcutils",
],
export_include_dirs: [
- "src/utils",
+ "src",
],
}
@@ -62,7 +62,7 @@
shared_libs: [
"libcutils",
"libprocessgroup",
- "libwatchdog_utils",
+ "libwatchdog_package_info_resolver",
],
}
@@ -102,7 +102,7 @@
"tests/IoOveruseConfigsTest.cpp",
"tests/IoPerfCollectionTest.cpp",
"tests/LooperStub.cpp",
- "tests/PackageNameResolverTest.cpp",
+ "tests/PackageInfoResolverTest.cpp",
"tests/ProcPidDir.cpp",
"tests/ProcPidStatTest.cpp",
"tests/ProcStatTest.cpp",
@@ -119,7 +119,7 @@
"libwatchdog_binder_mediator",
"libwatchdog_perf_service",
"libwatchdog_process_service",
- "libwatchdog_utils",
+ "libwatchdog_package_info_resolver",
],
}
@@ -178,7 +178,7 @@
"libwatchdog_binder_mediator",
"libwatchdog_perf_service",
"libwatchdog_process_service",
- "libwatchdog_utils",
+ "libwatchdog_package_info_resolver",
],
vintf_fragments: ["carwatchdogd.xml"],
}
diff --git a/cpp/watchdog/server/src/IoOveruseConfigs.cpp b/cpp/watchdog/server/src/IoOveruseConfigs.cpp
index 9febd3d..4a43860 100644
--- a/cpp/watchdog/server/src/IoOveruseConfigs.cpp
+++ b/cpp/watchdog/server/src/IoOveruseConfigs.cpp
@@ -18,7 +18,7 @@
#include "IoOveruseConfigs.h"
-#include "utils/PackageNameResolver.h"
+#include "PackageInfoResolver.h"
#include <android-base/strings.h>
@@ -277,7 +277,7 @@
vendorPackagePrefixes.insert(std::string(String8(prefix)));
}
if (!updateConfig.vendorPackagePrefixes.empty()) {
- PackageNameResolver::getInstance()->setVendorPackagePrefixes(vendorPackagePrefixes);
+ PackageInfoResolver::getInstance()->setVendorPackagePrefixes(vendorPackagePrefixes);
}
} else if (!updateConfig.vendorPackagePrefixes.empty()) {
StringAppendF(&nonUpdatableConfigMsgs, "%svendor packages prefixes",
diff --git a/cpp/watchdog/server/src/IoOveruseMonitor.cpp b/cpp/watchdog/server/src/IoOveruseMonitor.cpp
index 6d1d834..d377d41 100644
--- a/cpp/watchdog/server/src/IoOveruseMonitor.cpp
+++ b/cpp/watchdog/server/src/IoOveruseMonitor.cpp
@@ -18,7 +18,7 @@
#include "IoOveruseMonitor.h"
-#include "utils/PackageNameResolver.h"
+#include "PackageInfoResolver.h"
namespace android {
namespace automotive {
@@ -39,7 +39,7 @@
// the image.
// TODO(b/167240592): Read the vendor package prefixes from disk before the below call.
- PackageNameResolver::getInstance()->setVendorPackagePrefixes(
+ PackageInfoResolver::getInstance()->setVendorPackagePrefixes(
mIoOveruseConfigs.vendorPackagePrefixes);
return {};
}
diff --git a/cpp/watchdog/server/src/IoPerfCollection.cpp b/cpp/watchdog/server/src/IoPerfCollection.cpp
index b161a9d..2d3ccb6 100644
--- a/cpp/watchdog/server/src/IoPerfCollection.cpp
+++ b/cpp/watchdog/server/src/IoPerfCollection.cpp
@@ -457,7 +457,7 @@
}
}
- const auto& uidToPackageNameMapping = mPackageNameResolver->getPackageNamesForUids(uids);
+ const auto& uidToPackageNameMapping = mPackageInfoResolver->getPackageNamesForUids(uids);
// Convert the top N I/O usage to UidIoPerfData.
for (const auto& usage : topNReads) {
@@ -556,7 +556,7 @@
}
}
- const auto& uidToPackageNameMapping = mPackageNameResolver->getPackageNamesForUids(uids);
+ const auto& uidToPackageNameMapping = mPackageInfoResolver->getPackageNamesForUids(uids);
// Convert the top N uid process stats to ProcessIoPerfData.
for (const auto& it : topNIoBlockedUids) {
diff --git a/cpp/watchdog/server/src/IoPerfCollection.h b/cpp/watchdog/server/src/IoPerfCollection.h
index 087e50e..7150116 100644
--- a/cpp/watchdog/server/src/IoPerfCollection.h
+++ b/cpp/watchdog/server/src/IoPerfCollection.h
@@ -17,11 +17,11 @@
#ifndef CPP_WATCHDOG_SERVER_SRC_IOPERFCOLLECTION_H_
#define CPP_WATCHDOG_SERVER_SRC_IOPERFCOLLECTION_H_
+#include "PackageInfoResolver.h"
#include "ProcPidStat.h"
#include "ProcStat.h"
#include "UidIoStats.h"
#include "WatchdogPerfService.h"
-#include "utils/PackageNameResolver.h"
#include <android-base/result.h>
#include <cutils/multiuser.h>
@@ -118,7 +118,7 @@
class IoPerfCollection : public DataProcessor {
public:
IoPerfCollection() :
- mPackageNameResolver(PackageNameResolver::getInstance()),
+ mPackageInfoResolver(PackageInfoResolver::getInstance()),
mBoottimeCollection({}),
mPeriodicCollection({}),
mCustomCollection({}),
@@ -183,8 +183,8 @@
// Top N per-process stats per subcategory.
int mTopNStatsPerSubcategory;
- // Local package name resolver instance. Useful to mock in tests.
- sp<IPackageNameResolverInterface> mPackageNameResolver;
+ // Local IPackageInfoResolverInterface instance. Useful to mock in tests.
+ sp<IPackageInfoResolverInterface> mPackageInfoResolver;
// Makes sure only one collection is running at any given time.
Mutex mMutex;
diff --git a/cpp/watchdog/server/src/utils/PackageNameResolver.cpp b/cpp/watchdog/server/src/PackageInfoResolver.cpp
similarity index 91%
rename from cpp/watchdog/server/src/utils/PackageNameResolver.cpp
rename to cpp/watchdog/server/src/PackageInfoResolver.cpp
index dbfa5f2..463c119 100644
--- a/cpp/watchdog/server/src/utils/PackageNameResolver.cpp
+++ b/cpp/watchdog/server/src/PackageInfoResolver.cpp
@@ -16,7 +16,7 @@
#define LOG_TAG "carwatchdogd"
-#include "PackageNameResolver.h"
+#include "PackageInfoResolver.h"
#include <android-base/strings.h>
#include <android/automotive/watchdog/internal/ApplicationCategoryType.h>
@@ -96,21 +96,21 @@
} // namespace
-sp<PackageNameResolver> PackageNameResolver::sInstance = nullptr;
-GetpwuidFunction PackageNameResolver::sGetpwuidHandler = &getpwuid;
+sp<PackageInfoResolver> PackageInfoResolver::sInstance = nullptr;
+GetpwuidFunction PackageInfoResolver::sGetpwuidHandler = &getpwuid;
-sp<IPackageNameResolverInterface> PackageNameResolver::getInstance() {
+sp<IPackageInfoResolverInterface> PackageInfoResolver::getInstance() {
if (sInstance == nullptr) {
- sInstance = new PackageNameResolver();
+ sInstance = new PackageInfoResolver();
}
return sInstance;
}
-void PackageNameResolver::terminate() {
+void PackageInfoResolver::terminate() {
sInstance.clear();
}
-Result<void> PackageNameResolver::initWatchdogServiceHelper(
+Result<void> PackageInfoResolver::initWatchdogServiceHelper(
const sp<WatchdogServiceHelperInterface>& watchdogServiceHelper) {
std::unique_lock writeLock(mRWMutex);
if (watchdogServiceHelper == nullptr) {
@@ -123,7 +123,7 @@
return {};
}
-void PackageNameResolver::setVendorPackagePrefixes(
+void PackageInfoResolver::setVendorPackagePrefixes(
const std::unordered_set<std::string>& prefixes) {
std::unique_lock writeLock(mRWMutex);
mVendorPackagePrefixes.clear();
@@ -133,7 +133,7 @@
mUidToPackageInfoMapping.clear();
}
-void PackageNameResolver::updatePackageInfos(const std::vector<uid_t>& uids) {
+void PackageInfoResolver::updatePackageInfos(const std::vector<uid_t>& uids) {
std::unique_lock writeLock(mRWMutex);
std::vector<int32_t> missingUids;
for (const uid_t uid : uids) {
@@ -145,7 +145,7 @@
continue;
}
auto result = getPackageInfoForNativeUid(uid, mVendorPackagePrefixes,
- PackageNameResolver::sGetpwuidHandler);
+ PackageInfoResolver::sGetpwuidHandler);
if (!result.ok()) {
missingUids.emplace_back(static_cast<int32_t>(uid));
continue;
@@ -182,7 +182,7 @@
}
}
-std::unordered_map<uid_t, std::string> PackageNameResolver::getPackageNamesForUids(
+std::unordered_map<uid_t, std::string> PackageInfoResolver::getPackageNamesForUids(
const std::vector<uid_t>& uids) {
std::unordered_map<uid_t, std::string> uidToPackageNameMapping;
if (uids.empty()) {
@@ -201,7 +201,7 @@
return uidToPackageNameMapping;
}
-std::unordered_map<uid_t, PackageInfo> PackageNameResolver::getPackageInfosForUids(
+std::unordered_map<uid_t, PackageInfo> PackageInfoResolver::getPackageInfosForUids(
const std::vector<uid_t>& uids) {
std::unordered_map<uid_t, PackageInfo> uidToPackageInfoMapping;
if (uids.empty()) {
diff --git a/cpp/watchdog/server/src/utils/PackageNameResolver.h b/cpp/watchdog/server/src/PackageInfoResolver.h
similarity index 75%
rename from cpp/watchdog/server/src/utils/PackageNameResolver.h
rename to cpp/watchdog/server/src/PackageInfoResolver.h
index 22a91e3..efb4f5c 100644
--- a/cpp/watchdog/server/src/utils/PackageNameResolver.h
+++ b/cpp/watchdog/server/src/PackageInfoResolver.h
@@ -14,10 +14,10 @@
* limitations under the License.
*/
-#ifndef CPP_WATCHDOG_SERVER_SRC_UTILS_PACKAGENAMERESOLVER_H_
-#define CPP_WATCHDOG_SERVER_SRC_UTILS_PACKAGENAMERESOLVER_H_
+#ifndef CPP_WATCHDOG_SERVER_SRC_PACKAGEINFORESOLVER_H_
+#define CPP_WATCHDOG_SERVER_SRC_PACKAGEINFORESOLVER_H_
-#include "src/WatchdogServiceHelper.h"
+#include "WatchdogServiceHelper.h"
#include <android-base/result.h>
#include <android/automotive/watchdog/internal/PackageInfo.h>
@@ -45,11 +45,11 @@
// Forward declaration for testing use only.
namespace internal {
-class PackageNameResolverPeer;
+class PackageInfoResolverPeer;
} // namespace internal
-class IPackageNameResolverInterface : public android::RefBase {
+class IPackageInfoResolverInterface : public android::RefBase {
public:
virtual std::unordered_map<uid_t, std::string> getPackageNamesForUids(
const std::vector<uid_t>& uids) = 0;
@@ -68,20 +68,20 @@
};
/*
- * PackageNameResolver maintains a cache of the UID to PackageName mapping in the CarWatchdog
- * daemon. PackageNameResolver is a singleton and must be accessed only via the public static
+ * PackageInfoResolver maintains a cache of the UID to PackageInfo mapping in the CarWatchdog
+ * daemon. PackageInfoResolver is a singleton and must be accessed only via the public static
* methods.
*
* TODO(b/158131194): Extend IUidObserver in WatchdogBinderMediator and use the onUidGone API to
* keep the local mapping cache up-to-date.
*/
-class PackageNameResolver : public IPackageNameResolverInterface {
+class PackageInfoResolver : public IPackageInfoResolverInterface {
public:
/*
- * Initializes the PackageNameResolver's singleton instance only on the first call. Main thread
+ * Initializes the PackageInfoResolver's singleton instance only on the first call. Main thread
* should make the first call as this method doesn't offer multi-threading protection.
*/
- static sp<IPackageNameResolverInterface> getInstance();
+ static sp<IPackageInfoResolverInterface> getInstance();
/*
* Resolves the given |uids| and returns a mapping of uids to package names. If the mapping
@@ -97,7 +97,7 @@
std::unordered_map<uid_t, android::automotive::watchdog::internal::PackageInfo>
getPackageInfosForUids(const std::vector<uid_t>& uids);
- ~PackageNameResolver() {
+ ~PackageInfoResolver() {
std::unique_lock writeLock(mRWMutex);
mWatchdogServiceHelper.clear();
mUidToPackageInfoMapping.clear();
@@ -112,8 +112,8 @@
void setVendorPackagePrefixes(const std::unordered_set<std::string>& prefixes);
private:
- // PackageNameResolver instance can only be obtained via |getInstance|.
- PackageNameResolver() :
+ // PackageInfoResolver instance can only be obtained via |getInstance|.
+ PackageInfoResolver() :
mWatchdogServiceHelper(nullptr),
mUidToPackageInfoMapping({}),
mVendorPackagePrefixes({}) {}
@@ -121,15 +121,16 @@
void updatePackageInfos(const std::vector<uid_t>& uids);
// Singleton instance.
- static android::sp<PackageNameResolver> sInstance;
+ static android::sp<PackageInfoResolver> sInstance;
mutable std::shared_mutex mRWMutex;
+
/*
- * ServiceManager::startServices initializes PackageNameResolver. However, between the
+ * ServiceManager::startServices initializes PackageInfoResolver. However, between the
* |getInstance| and |initWatchdogServiceHelper| calls it initializes few other services, which
- * may call |resolveUids| simultaneously on a separate thread. In order to avoid a race
- * condition between |initWatchdogServiceHelper| and |resolveUids| calls, mWatchdogServiceHelper
- * is guarded by a read-write lock.
+ * may call |getPackageNamesForUids| or |getPackageInfosForUids| simultaneously on a separate
+ * thread. In order to avoid a race condition between |initWatchdogServiceHelper| and
+ * |getPackage*ForUids| calls, mWatchdogServiceHelper is guarded by a read-write lock.
*/
android::sp<WatchdogServiceHelperInterface> mWatchdogServiceHelper GUARDED_BY(mRWMutex);
std::unordered_map<uid_t, android::automotive::watchdog::internal::PackageInfo>
@@ -143,14 +144,14 @@
// For unit tests.
static std::function<struct passwd*(uid_t)> sGetpwuidHandler;
- friend class internal::PackageNameResolverPeer;
- FRIEND_TEST(PackageNameResolverTest, TestResolvesNativeUid);
- FRIEND_TEST(PackageNameResolverTest, TestResolvesApplicationUidFromWatchdogServiceHelper);
- FRIEND_TEST(PackageNameResolverTest, TestResolvesApplicationUidFromLocalCache);
+ friend class internal::PackageInfoResolverPeer;
+ FRIEND_TEST(PackageInfoResolverTest, TestResolvesNativeUid);
+ FRIEND_TEST(PackageInfoResolverTest, TestResolvesApplicationUidFromWatchdogServiceHelper);
+ FRIEND_TEST(PackageInfoResolverTest, TestResolvesApplicationUidFromLocalCache);
};
} // namespace watchdog
} // namespace automotive
} // namespace android
-#endif // CPP_WATCHDOG_SERVER_SRC_UTILS_PACKAGENAMERESOLVER_H_
+#endif // CPP_WATCHDOG_SERVER_SRC_PACKAGEINFORESOLVER_H_
diff --git a/cpp/watchdog/server/src/ServiceManager.cpp b/cpp/watchdog/server/src/ServiceManager.cpp
index 9b7a519..4cc163f 100644
--- a/cpp/watchdog/server/src/ServiceManager.cpp
+++ b/cpp/watchdog/server/src/ServiceManager.cpp
@@ -19,7 +19,7 @@
#include "ServiceManager.h"
#include "IoPerfCollection.h"
-#include "utils/PackageNameResolver.h"
+#include "PackageInfoResolver.h"
namespace android {
namespace automotive {
@@ -45,12 +45,12 @@
return Error(INVALID_OPERATION) << "Cannot start services more than once";
}
/*
- * PackageNameResolver must be initialized first time on the main thread before starting any
- * other thread as the getInstance method isn't thread safe. Thus initialize PackageNameResolver
+ * PackageInfoResolver must be initialized first time on the main thread before starting any
+ * other thread as the getInstance method isn't thread safe. Thus initialize PackageInfoResolver
* by calling the getInstance method before starting other service as they may access
- * PackageNameResolver's instance during initialization.
+ * PackageInfoResolver's instance during initialization.
*/
- sp<IPackageNameResolverInterface> packageNameResolver = PackageNameResolver::getInstance();
+ sp<IPackageInfoResolverInterface> packageInfoResolver = PackageInfoResolver::getInstance();
auto result = startProcessAnrMonitor(looper);
if (!result.ok()) {
return result;
@@ -64,7 +64,7 @@
if (!result.ok()) {
return Error() << "Failed to initialize watchdog service helper: " << result.error();
}
- result = packageNameResolver->initWatchdogServiceHelper(sWatchdogServiceHelper);
+ result = packageInfoResolver->initWatchdogServiceHelper(sWatchdogServiceHelper);
if (!result.ok()) {
return Error() << "Failed to initialize package name resolver: " << result.error();
}
@@ -91,7 +91,7 @@
sWatchdogServiceHelper->terminate();
sWatchdogServiceHelper.clear();
}
- PackageNameResolver::terminate();
+ PackageInfoResolver::terminate();
}
Result<void> ServiceManager::startProcessAnrMonitor(const sp<Looper>& looper) {
diff --git a/cpp/watchdog/server/src/WatchdogPerfService.cpp b/cpp/watchdog/server/src/WatchdogPerfService.cpp
index bf5f9e8..a1a1b18 100644
--- a/cpp/watchdog/server/src/WatchdogPerfService.cpp
+++ b/cpp/watchdog/server/src/WatchdogPerfService.cpp
@@ -18,8 +18,6 @@
#include "WatchdogPerfService.h"
-#include "utils/PackageNameResolver.h"
-
#include <WatchdogProperties.sysprop.h>
#include <android-base/file.h>
#include <android-base/parseint.h>
diff --git a/cpp/watchdog/server/tests/IoPerfCollectionTest.cpp b/cpp/watchdog/server/tests/IoPerfCollectionTest.cpp
index f64b936..3ff7919 100644
--- a/cpp/watchdog/server/tests/IoPerfCollectionTest.cpp
+++ b/cpp/watchdog/server/tests/IoPerfCollectionTest.cpp
@@ -15,12 +15,12 @@
*/
#include "IoPerfCollection.h"
-#include "MockPackageNameResolver.h"
+#include "MockPackageInfoResolver.h"
#include "MockProcPidStat.h"
#include "MockProcStat.h"
#include "MockUidIoStats.h"
#include "MockWatchdogServiceHelper.h"
-#include "utils/PackageNameResolver.h"
+#include "PackageInfoResolver.h"
#include <WatchdogProperties.sysprop.h>
#include <android-base/file.h>
@@ -129,15 +129,15 @@
public:
explicit IoPerfCollectionPeer(sp<IoPerfCollection> collector) :
mCollector(collector),
- mMockPackageNameResolver(new MockPackageNameResolver()) {
- mCollector->mPackageNameResolver = mMockPackageNameResolver;
+ mMockPackageInfoResolver(new MockPackageInfoResolver()) {
+ mCollector->mPackageInfoResolver = mMockPackageInfoResolver;
}
IoPerfCollectionPeer() = delete;
~IoPerfCollectionPeer() {
mCollector->terminate();
mCollector.clear();
- mMockPackageNameResolver.clear();
+ mMockPackageInfoResolver.clear();
}
void setTopNStatsPerCategory(int value) { mCollector->mTopNStatsPerCategory = value; }
@@ -145,7 +145,7 @@
void setTopNStatsPerSubcategory(int value) { mCollector->mTopNStatsPerSubcategory = value; }
void injectUidToPackageNameMapping(std::unordered_map<uid_t, std::string> mapping) {
- EXPECT_CALL(*mMockPackageNameResolver, getPackageNamesForUids(_))
+ EXPECT_CALL(*mMockPackageInfoResolver, getPackageNamesForUids(_))
.WillRepeatedly(Return(mapping));
}
@@ -166,7 +166,7 @@
private:
sp<IoPerfCollection> mCollector;
- sp<MockPackageNameResolver> mMockPackageNameResolver;
+ sp<MockPackageInfoResolver> mMockPackageInfoResolver;
};
} // namespace internal
@@ -455,9 +455,9 @@
IoPerfCollection collector;
collector.mTopNStatsPerCategory = 2;
- sp<MockPackageNameResolver> mockPackageNameResolver = new MockPackageNameResolver();
- collector.mPackageNameResolver = mockPackageNameResolver;
- EXPECT_CALL(*mockPackageNameResolver, getPackageNamesForUids(_))
+ sp<MockPackageInfoResolver> mockPackageInfoResolver = new MockPackageInfoResolver();
+ collector.mPackageInfoResolver = mockPackageInfoResolver;
+ EXPECT_CALL(*mockPackageInfoResolver, getPackageNamesForUids(_))
.WillRepeatedly(Return<std::unordered_map<uid_t, std::string>>(
{{1009, "mount"}, {1001000, "shared:android.uid.system"}}));
@@ -618,9 +618,9 @@
collector.mTopNStatsPerCategory = 2;
collector.mTopNStatsPerSubcategory = 2;
- sp<MockPackageNameResolver> mockPackageNameResolver = new MockPackageNameResolver();
- collector.mPackageNameResolver = mockPackageNameResolver;
- EXPECT_CALL(*mockPackageNameResolver, getPackageNamesForUids(_))
+ sp<MockPackageInfoResolver> mockPackageInfoResolver = new MockPackageInfoResolver();
+ collector.mPackageInfoResolver = mockPackageInfoResolver;
+ EXPECT_CALL(*mockPackageInfoResolver, getPackageNamesForUids(_))
.WillRepeatedly(Return<std::unordered_map<uid_t, std::string>>(
{{0, "root"}, {1009, "mount"}, {1001000, "shared:android.uid.system"}}));
@@ -697,9 +697,9 @@
collector.mTopNStatsPerCategory = 5;
collector.mTopNStatsPerSubcategory = 3;
- sp<MockPackageNameResolver> mockPackageNameResolver = new MockPackageNameResolver();
- collector.mPackageNameResolver = mockPackageNameResolver;
- EXPECT_CALL(*mockPackageNameResolver, getPackageNamesForUids(_))
+ sp<MockPackageInfoResolver> mockPackageInfoResolver = new MockPackageInfoResolver();
+ collector.mPackageInfoResolver = mockPackageInfoResolver;
+ EXPECT_CALL(*mockPackageInfoResolver, getPackageNamesForUids(_))
.WillRepeatedly(Return<std::unordered_map<uid_t, std::string>>({{0, "root"}}));
struct ProcessIoPerfData actualProcessIoPerfData = {};
diff --git a/cpp/watchdog/server/tests/MockPackageNameResolver.h b/cpp/watchdog/server/tests/MockPackageInfoResolver.h
similarity index 82%
rename from cpp/watchdog/server/tests/MockPackageNameResolver.h
rename to cpp/watchdog/server/tests/MockPackageInfoResolver.h
index f30f072..f3e2fb6 100644
--- a/cpp/watchdog/server/tests/MockPackageNameResolver.h
+++ b/cpp/watchdog/server/tests/MockPackageInfoResolver.h
@@ -14,10 +14,10 @@
* limitations under the License.
*/
-#ifndef CPP_WATCHDOG_SERVER_TESTS_MOCKPACKAGENAMERESOLVER_H_
-#define CPP_WATCHDOG_SERVER_TESTS_MOCKPACKAGENAMERESOLVER_H_
+#ifndef CPP_WATCHDOG_SERVER_TESTS_MOCKPACKAGEINFORESOLVER_H_
+#define CPP_WATCHDOG_SERVER_TESTS_MOCKPACKAGEINFORESOLVER_H_
-#include "PackageNameResolver.h"
+#include "PackageInfoResolver.h"
#include <android-base/result.h>
#include <gmock/gmock.h>
@@ -29,9 +29,9 @@
namespace automotive {
namespace watchdog {
-class MockPackageNameResolver : public IPackageNameResolverInterface {
+class MockPackageInfoResolver : public IPackageInfoResolverInterface {
public:
- MockPackageNameResolver() {}
+ MockPackageInfoResolver() {}
MOCK_METHOD(android::base::Result<void>, initWatchdogServiceHelper,
(const android::sp<WatchdogServiceHelperInterface>& watchdogServiceHelper),
(override));
@@ -47,4 +47,4 @@
} // namespace automotive
} // namespace android
-#endif // CPP_WATCHDOG_SERVER_TESTS_MOCKPACKAGENAMERESOLVER_H_
+#endif // CPP_WATCHDOG_SERVER_TESTS_MOCKPACKAGEINFORESOLVER_H_
diff --git a/cpp/watchdog/server/tests/PackageNameResolverTest.cpp b/cpp/watchdog/server/tests/PackageInfoResolverTest.cpp
similarity index 85%
rename from cpp/watchdog/server/tests/PackageNameResolverTest.cpp
rename to cpp/watchdog/server/tests/PackageInfoResolverTest.cpp
index d7a31c2..af8d92b 100644
--- a/cpp/watchdog/server/tests/PackageNameResolverTest.cpp
+++ b/cpp/watchdog/server/tests/PackageInfoResolverTest.cpp
@@ -15,7 +15,7 @@
*/
#include "MockWatchdogServiceHelper.h"
-#include "PackageNameResolver.h"
+#include "PackageInfoResolver.h"
#include <android/automotive/watchdog/internal/ApplicationCategoryType.h>
#include <android/automotive/watchdog/internal/ComponentType.h>
@@ -61,32 +61,32 @@
namespace internal {
-class PackageNameResolverPeer {
+class PackageInfoResolverPeer {
public:
- PackageNameResolverPeer() {
- PackageNameResolver::getInstance();
- mPackageNameResolver = PackageNameResolver::sInstance;
+ PackageInfoResolverPeer() {
+ PackageInfoResolver::getInstance();
+ mPackageInfoResolver = PackageInfoResolver::sInstance;
mockWatchdogServiceHelper = new MockWatchdogServiceHelper();
- mPackageNameResolver->initWatchdogServiceHelper(mockWatchdogServiceHelper);
+ mPackageInfoResolver->initWatchdogServiceHelper(mockWatchdogServiceHelper);
}
- ~PackageNameResolverPeer() {
- PackageNameResolver::sInstance.clear();
- PackageNameResolver::sGetpwuidHandler = &getpwuid;
+ ~PackageInfoResolverPeer() {
+ PackageInfoResolver::sInstance.clear();
+ PackageInfoResolver::sGetpwuidHandler = &getpwuid;
clearMappingCache();
}
void injectCacheMapping(const std::unordered_map<uid_t, PackageInfo>& mapping) {
- mPackageNameResolver->mUidToPackageInfoMapping = mapping;
+ mPackageInfoResolver->mUidToPackageInfoMapping = mapping;
}
void setVendorPackagePrefixes(const std::unordered_set<std::string>& prefixes) {
- mPackageNameResolver->setVendorPackagePrefixes(prefixes);
+ mPackageInfoResolver->setVendorPackagePrefixes(prefixes);
}
void stubGetpwuid(const std::unordered_map<uid_t, std::string>& nativeUidToPackageNameMapping) {
updateNativeUidToPackageNameMapping(nativeUidToPackageNameMapping);
- PackageNameResolver::sGetpwuidHandler = [&](uid_t uid) -> struct passwd* {
+ PackageInfoResolver::sGetpwuidHandler = [&](uid_t uid) -> struct passwd* {
const auto& it = mNativeUidToPackageNameMapping.find(uid);
if (it == mNativeUidToPackageNameMapping.end()) {
return nullptr;
@@ -124,15 +124,15 @@
mNativeUidToPackageNameMapping.clear();
}
- sp<PackageNameResolver> mPackageNameResolver;
+ sp<PackageInfoResolver> mPackageInfoResolver;
std::unordered_map<uid_t, struct passwd> mNativeUidToPackageNameMapping;
};
} // namespace internal
-TEST(PackageNameResolverTest, TestGetPackageInfosForUidsViaGetpwuid) {
- internal::PackageNameResolverPeer peer;
- auto packageNameResolver = PackageNameResolver::getInstance();
+TEST(PackageInfoResolverTest, TestGetPackageInfosForUidsViaGetpwuid) {
+ internal::PackageInfoResolverPeer peer;
+ auto packageInfoResolver = PackageInfoResolver::getInstance();
std::unordered_map<uid_t, PackageInfo> expectedMappings{
{7700,
@@ -150,7 +150,7 @@
{{7700, "system.package.B"}, {5100, "vendor.package.A"}, {6700, "vendor.pkg"}});
EXPECT_CALL(*peer.mockWatchdogServiceHelper, getPackageInfosForUids(_, _, _)).Times(0);
- auto actualMappings = packageNameResolver->getPackageInfosForUids({7700, 5100, 6700});
+ auto actualMappings = packageInfoResolver->getPackageInfosForUids({7700, 5100, 6700});
for (const auto& it : expectedMappings) {
ASSERT_TRUE(actualMappings.find(it.first) != actualMappings.end())
@@ -161,9 +161,9 @@
}
}
-TEST(PackageNameResolverTest, TestGetPackageInfosForUidsViaWatchdogService) {
- internal::PackageNameResolverPeer peer;
- auto packageNameResolver = PackageNameResolver::getInstance();
+TEST(PackageInfoResolverTest, TestGetPackageInfosForUidsViaWatchdogService) {
+ internal::PackageInfoResolverPeer peer;
+ auto packageInfoResolver = PackageInfoResolver::getInstance();
peer.setVendorPackagePrefixes({"vendor.pkg"});
/*
* Shared UID should be resolved with car watchdog service as well to get the shared packages
@@ -197,7 +197,7 @@
getPackageInfosForUids(expectedUids, expectedPrefixes, _))
.WillOnce(DoAll(SetArgPointee<2>(injectPackageInfos), Return(binder::Status::ok())));
- auto actualMappings = packageNameResolver->getPackageInfosForUids({6100, 7700, 15100, 16700});
+ auto actualMappings = packageInfoResolver->getPackageInfosForUids({6100, 7700, 15100, 16700});
for (const auto& it : expectedMappings) {
ASSERT_TRUE(actualMappings.find(it.first) != actualMappings.end())
@@ -208,9 +208,9 @@
}
}
-TEST(PackageNameResolverTest, TestResolvesApplicationUidFromLocalCache) {
- internal::PackageNameResolverPeer peer;
- auto packageNameResolver = PackageNameResolver::getInstance();
+TEST(PackageInfoResolverTest, TestResolvesApplicationUidFromLocalCache) {
+ internal::PackageInfoResolverPeer peer;
+ auto packageInfoResolver = PackageInfoResolver::getInstance();
PackageInfo expectedPackageInfo =
constructPackageInfo("vendor.package", 1003456, UidType::NATIVE, ComponentType::SYSTEM,
ApplicationCategoryType::OTHERS);
@@ -219,7 +219,7 @@
peer.stubGetpwuid({});
EXPECT_CALL(*peer.mockWatchdogServiceHelper, getPackageInfosForUids(_, _, _)).Times(0);
- auto actualMappings = packageNameResolver->getPackageInfosForUids({1003456});
+ auto actualMappings = packageInfoResolver->getPackageInfosForUids({1003456});
ASSERT_TRUE(actualMappings.find(1003456) != actualMappings.end());
EXPECT_EQ(actualMappings.find(1003456)->second, expectedPackageInfo);
diff --git a/cpp/watchdog/server/tests/WatchdogPerfServiceTest.cpp b/cpp/watchdog/server/tests/WatchdogPerfServiceTest.cpp
index 0b25ebc..601bc35 100644
--- a/cpp/watchdog/server/tests/WatchdogPerfServiceTest.cpp
+++ b/cpp/watchdog/server/tests/WatchdogPerfServiceTest.cpp
@@ -24,7 +24,6 @@
#include "ProcPidStat.h"
#include "ProcStat.h"
#include "UidIoStats.h"
-#include "utils/PackageNameResolver.h"
#include <WatchdogProperties.sysprop.h>
#include <android-base/file.h>