Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
platform_packages_modules_Connectivity
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LMODroid
platform_packages_modules_Connectivity
Commits
18520551
Commit
18520551
authored
1 year ago
by
Motomu Utsumi
Committed by
Gerrit Code Review
1 year ago
Browse files
Options
Downloads
Plain Diff
Merge "Cleanup existing firewall rule on myUid before the test" into main
parents
8cfccc9d
4d8c70c0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java
+20
-10
20 additions, 10 deletions
.../cts/net/src/android/net/cts/ConnectivityManagerTest.java
with
20 additions
and
10 deletions
tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java
+
20
−
10
View file @
18520551
...
@@ -47,6 +47,7 @@ import static android.net.ConnectivityManager.FIREWALL_CHAIN_POWERSAVE;
...
@@ -47,6 +47,7 @@ import static android.net.ConnectivityManager.FIREWALL_CHAIN_POWERSAVE;
import
static
android
.
net
.
ConnectivityManager
.
FIREWALL_CHAIN_RESTRICTED
;
import
static
android
.
net
.
ConnectivityManager
.
FIREWALL_CHAIN_RESTRICTED
;
import
static
android
.
net
.
ConnectivityManager
.
FIREWALL_CHAIN_STANDBY
;
import
static
android
.
net
.
ConnectivityManager
.
FIREWALL_CHAIN_STANDBY
;
import
static
android
.
net
.
ConnectivityManager
.
FIREWALL_RULE_ALLOW
;
import
static
android
.
net
.
ConnectivityManager
.
FIREWALL_RULE_ALLOW
;
import
static
android
.
net
.
ConnectivityManager
.
FIREWALL_RULE_DEFAULT
;
import
static
android
.
net
.
ConnectivityManager
.
FIREWALL_RULE_DENY
;
import
static
android
.
net
.
ConnectivityManager
.
FIREWALL_RULE_DENY
;
import
static
android
.
net
.
ConnectivityManager
.
PROFILE_NETWORK_PREFERENCE_ENTERPRISE
;
import
static
android
.
net
.
ConnectivityManager
.
PROFILE_NETWORK_PREFERENCE_ENTERPRISE
;
import
static
android
.
net
.
ConnectivityManager
.
TYPE_BLUETOOTH
;
import
static
android
.
net
.
ConnectivityManager
.
TYPE_BLUETOOTH
;
...
@@ -3591,6 +3592,15 @@ public class ConnectivityManagerTest {
...
@@ -3591,6 +3592,15 @@ public class ConnectivityManagerTest {
}
}
}
}
private
void
setUidFirewallRule
(
final
int
chain
,
final
int
uid
,
final
int
rule
)
{
try
{
mCm
.
setUidFirewallRule
(
chain
,
uid
,
rule
);
}
catch
(
IllegalStateException
ignored
)
{
// Removing match causes an exception when the rule entry for the uid does
// not exist. But this is fine and can be ignored.
}
}
private
static
final
boolean
EXPECT_OPEN
=
false
;
private
static
final
boolean
EXPECT_OPEN
=
false
;
private
static
final
boolean
EXPECT_CLOSE
=
true
;
private
static
final
boolean
EXPECT_CLOSE
=
true
;
...
@@ -3599,6 +3609,8 @@ public class ConnectivityManagerTest {
...
@@ -3599,6 +3609,8 @@ public class ConnectivityManagerTest {
runWithShellPermissionIdentity
(()
->
{
runWithShellPermissionIdentity
(()
->
{
// Firewall chain status will be restored after the test.
// Firewall chain status will be restored after the test.
final
boolean
wasChainEnabled
=
mCm
.
getFirewallChainEnabled
(
chain
);
final
boolean
wasChainEnabled
=
mCm
.
getFirewallChainEnabled
(
chain
);
final
int
myUid
=
Process
.
myUid
();
final
int
previousMyUidFirewallRule
=
mCm
.
getUidFirewallRule
(
chain
,
myUid
);
final
int
previousUidFirewallRule
=
mCm
.
getUidFirewallRule
(
chain
,
targetUid
);
final
int
previousUidFirewallRule
=
mCm
.
getUidFirewallRule
(
chain
,
targetUid
);
final
Socket
socket
=
new
Socket
(
TEST_HOST
,
HTTP_PORT
);
final
Socket
socket
=
new
Socket
(
TEST_HOST
,
HTTP_PORT
);
socket
.
setSoTimeout
(
NETWORK_REQUEST_TIMEOUT_MS
);
socket
.
setSoTimeout
(
NETWORK_REQUEST_TIMEOUT_MS
);
...
@@ -3606,12 +3618,12 @@ public class ConnectivityManagerTest {
...
@@ -3606,12 +3618,12 @@ public class ConnectivityManagerTest {
mCm
.
setFirewallChainEnabled
(
chain
,
false
/* enable */
);
mCm
.
setFirewallChainEnabled
(
chain
,
false
/* enable */
);
assertSocketOpen
(
socket
);
assertSocketOpen
(
socket
);
try
{
setUidFirewallRule
(
chain
,
targetUid
,
rule
);
mCm
.
setUidFirewallRule
(
chain
,
targetUid
,
rule
);
if
(
targetUid
!=
myUid
)
{
}
catch
(
IllegalStateException
ignored
)
{
// If this test does not set rule on myUid, remove existing rule on myUid
// Removing match causes an exception when the rule entry for the uid does
setUidFirewallRule
(
chain
,
myUid
,
FIREWALL_RULE_DEFAULT
);
// not exist. But this is fine and can be ignored.
}
}
mCm
.
setFirewallChainEnabled
(
chain
,
true
/* enable */
);
mCm
.
setFirewallChainEnabled
(
chain
,
true
/* enable */
);
if
(
expectClose
)
{
if
(
expectClose
)
{
...
@@ -3624,11 +3636,9 @@ public class ConnectivityManagerTest {
...
@@ -3624,11 +3636,9 @@ public class ConnectivityManagerTest {
mCm
.
setFirewallChainEnabled
(
chain
,
wasChainEnabled
);
mCm
.
setFirewallChainEnabled
(
chain
,
wasChainEnabled
);
},
/* cleanup */
()
->
{
},
/* cleanup */
()
->
{
// Restore the uid firewall rule status
// Restore the uid firewall rule status
try
{
setUidFirewallRule
(
chain
,
targetUid
,
previousUidFirewallRule
);
mCm
.
setUidFirewallRule
(
chain
,
targetUid
,
previousUidFirewallRule
);
if
(
targetUid
!=
myUid
)
{
}
catch
(
IllegalStateException
ignored
)
{
setUidFirewallRule
(
chain
,
myUid
,
previousMyUidFirewallRule
);
// Removing match causes an exception when the rule entry for the uid does
// not exist. But this is fine and can be ignored.
}
}
},
/* cleanup */
()
->
{
},
/* cleanup */
()
->
{
socket
.
close
();
socket
.
close
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment