Fix flaky test BinderTest#NetworkSetProtectAllowDeny
It is caused by conflicted uid which has already been used by system.
Use maximum reserved appId for applications to avoid conflict with
existing. Also clear uid permission before querying.
error log:
05-24 22:19:37.561 1287 1577 I WifiService: startScan uid=10114
05-24 22:19:41.632 755 4865 I netd : networkSetProtectAllow(10114) <0.09ms>
05-24 22:19:41.632 755 4865 I netd : networkCanProtect(10114) -> {"true"} <0.12ms>
05-24 22:19:41.633 755 4865 I netd : networkSetProtectDeny(10114) <0.09ms>
05-24 22:19:41.633 1728 1728 I Finsky : [2] pke.a(46): Running job: 1-1337
05-24 22:19:41.633 755 4865 I netd : networkCanProtect(10114) -> {"true"} <0.13ms>
Bug: 133818065
Test: cd system/netd && atest
Change-Id: I557a7d75c519209a3bb020514f596fe5df84490f
diff --git a/tests/binder_test.cpp b/tests/binder_test.cpp
index cb915d3..8dc9e2b 100644
--- a/tests/binder_test.cpp
+++ b/tests/binder_test.cpp
@@ -1994,16 +1994,20 @@
}
TEST_F(BinderTest, NetworkSetProtectAllowDeny) {
- const int testUid = randomUid();
- binder::Status status = mNetd->networkSetProtectAllow(testUid);
+ binder::Status status = mNetd->networkSetProtectAllow(TEST_UID1);
EXPECT_TRUE(status.isOk()) << status.exceptionMessage();
bool ret = false;
- status = mNetd->networkCanProtect(testUid, &ret);
+ status = mNetd->networkCanProtect(TEST_UID1, &ret);
EXPECT_TRUE(ret);
- status = mNetd->networkSetProtectDeny(testUid);
+ status = mNetd->networkSetProtectDeny(TEST_UID1);
EXPECT_TRUE(status.isOk()) << status.exceptionMessage();
- status = mNetd->networkCanProtect(testUid, &ret);
+
+ // Clear uid permission before calling networkCanProtect to ensure
+ // the call won't be affected by uid permission.
+ EXPECT_TRUE(mNetd->networkClearPermissionForUser({TEST_UID1}).isOk());
+
+ status = mNetd->networkCanProtect(TEST_UID1, &ret);
EXPECT_FALSE(ret);
}