Skip to content

Commit

Permalink
config-parser: add support for "force_ComponentEnabledSettings" section
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitrii <bankersenator@gmail.com>
  • Loading branch information
muhomorr authored and shutter-cat committed Aug 3, 2023
1 parent 84cede7 commit 826dc94
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/app/grapheneos/gmscompat/GmsCompatConfigParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ private void parse(ArrayList<String> lines, GmsCompatConfig res) {
final int SECTION_FORCE_DEFAULT_FLAGS = 3;
final int SECTION_SPOOF_SELF_PERMISSION_CHECKS = 4;
final int SECTION_GmsServiceBroker_SELF_PERMISSION_BYPASS = 5;
final int SECTION_force_ComponentEnabledSettings = 6;

final long selfVersionCode = App.ctx().getApplicationInfo().longVersionCode;

Expand Down Expand Up @@ -175,6 +176,9 @@ private void parse(ArrayList<String> lines, GmsCompatConfig res) {
case "GmsServiceBroker_self_permission_bypass":
section2Type = SECTION_GmsServiceBroker_SELF_PERMISSION_BYPASS;
break;
case "force_ComponentEnabledSettings":
section2Type = SECTION_force_ComponentEnabledSettings;
break;
default:
invalidLine(line);
return;
Expand Down Expand Up @@ -203,6 +207,7 @@ private void parse(ArrayList<String> lines, GmsCompatConfig res) {
long targetGmsCompatVersion = 0L;
ArrayList<String> forceDefaultFlags = null;
ArrayList<String> spoofSelfPermissionChecks = null;
ArrayMap<String, Integer> forceCes = null;

if (section2Type == SECTION_FLAGS) {
String ns = sectionL1;
Expand Down Expand Up @@ -231,6 +236,10 @@ private void parse(ArrayList<String> lines, GmsCompatConfig res) {
} else if (section2Type == SECTION_GmsServiceBroker_SELF_PERMISSION_BYPASS) {
targetGmsCompatVersion = Long.parseLong(sectionL1);
res.gmsServiceBrokerPermissionBypasses.clear();
} else if (section2Type == SECTION_force_ComponentEnabledSettings) {
String packageName = sectionL1;
forceCes = new ArrayMap<>();
res.forceComponentEnabledSettingsMap.put(packageName, forceCes);
}

sectionL0Loop:
Expand Down Expand Up @@ -308,6 +317,26 @@ private void parse(ArrayList<String> lines, GmsCompatConfig res) {
String[] permissions = lineParser.next().split(",");
res.gmsServiceBrokerPermissionBypasses.put(serviceId, new ArraySet<>(permissions));
}
} else if (section2Type == SECTION_force_ComponentEnabledSettings) {
String modeStr = lineParser.next();
int mode;
switch (modeStr) {
case "disable":
mode = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
break;
case "enable":
mode = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
break;
case "default":
mode = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
break;
default:
Log.d(TAG, "unknown component enabled setting " + modeStr);
invalidLine(line);
continue;
}
String className = lineParser.next();
forceCes.put(className, Integer.valueOf(mode));
}
}
}
Expand Down

0 comments on commit 826dc94

Please sign in to comment.