Skip to content

Commit

Permalink
[Refactor] Fix blocking providers when only IFW is set
Browse files Browse the repository at this point in the history
Intent Firewall (IFW) does not support blocking providers. When IFW-only mode
was enabled, it tried to apply only the IFW rules which resulted in the
providers to remain unblocked. Instead, the providers are blocked via
“disable” option.

Signed-off-by: Muntashir Al-Islam <[email protected]>
  • Loading branch information
MuntashirAkon committed Sep 30, 2023
1 parent a94eed6 commit ddd31bc
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@ public class ComponentRule extends RuleEntry {

@NonNull
@ComponentStatus
private String mComponentStatus;
private final String mComponentStatus;

public ComponentRule(@NonNull String packageName, @NonNull String name, RuleType componentType,
@NonNull @ComponentStatus String componentStatus) {
super(packageName, name, componentType);
mComponentStatus = componentStatus;
mComponentStatus = fixComponentStatus(componentStatus);
}

public ComponentRule(@NonNull String packageName, @NonNull String name, RuleType componentType,
@NonNull StringTokenizer tokenizer) throws IllegalArgumentException {
super(packageName, name, componentType);
if (tokenizer.hasMoreElements()) {
mComponentStatus = tokenizer.nextElement().toString();
mComponentStatus = fixComponentStatus(tokenizer.nextElement().toString());
} else throw new IllegalArgumentException("Invalid format: componentStatus not found");
}

Expand Down Expand Up @@ -155,8 +155,22 @@ public String getToBe() {
}
}

public void setComponentStatus(@NonNull @ComponentStatus String componentStatus) {
mComponentStatus = componentStatus;
private String fixComponentStatus(@ComponentStatus String componentStatus) {
if (type != RuleType.PROVIDER) {
return componentStatus;
}
// Providers do not support IFW
switch (componentStatus) {
case COMPONENT_BLOCKED_IFW_DISABLE:
return COMPONENT_DISABLED;
case COMPONENT_BLOCKED_IFW:
return COMPONENT_ENABLED;
case COMPONENT_TO_BE_BLOCKED_IFW:
case COMPONENT_TO_BE_BLOCKED_IFW_DISABLE:
return COMPONENT_TO_BE_DISABLED;
default:
return componentStatus;
}
}

@NonNull
Expand Down

0 comments on commit ddd31bc

Please sign in to comment.