Skip to content
This repository has been archived by the owner on Feb 10, 2025. It is now read-only.

Commit

Permalink
EuiccGoogle: skip Resources.getText() filtering for getApplicationLabel
Browse files Browse the repository at this point in the history
PackageManager.getApplicationLabel() calls Resources.getText(), which in EuiccGoogle replaces
strings that contain "Google" with an empty string. This replacement is done to remove a misleading
string about info being sent to Google.

During Google Fi activation, Google Fi app invokes EuiccGoogle. EuiccGoogle then checks for caller
app label and aborts activation if it's empty. Since the Google Fi app label contains "Google",
it was always replaced with an empty string before this change, which broke Google Fi activation.
  • Loading branch information
muhomorr authored and thestinger committed May 3, 2024
1 parent b7e22b1 commit 5af848e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
9 changes: 8 additions & 1 deletion core/java/android/app/ApplicationPackageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import com.android.internal.ext.EuiccGoogleHooks;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
Expand Down Expand Up @@ -2389,7 +2390,13 @@ public CharSequence getText(String packageName, @StringRes int resid,
}
try {
Resources r = getResourcesForApplication(appInfo);
text = r.getText(resid);
if (AppGlobals.getInitialPackageId() == android.ext.PackageId.G_EUICC_LPA) {
try (var s = new EuiccGoogleHooks.SuppressResourceFiltering()) {
text = r.getText(resid);
}
} else {
text = r.getText(resid);
}
putCachedString(name, text);
return text;
} catch (NameNotFoundException e) {
Expand Down
9 changes: 7 additions & 2 deletions core/java/android/content/res/Resources.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@

import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.ext.EuiccGoogleHooks;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.GrowingArrayUtils;
import com.android.internal.util.Preconditions;
Expand Down Expand Up @@ -456,8 +457,12 @@ public ConfigurationBoundResourceCache<StateListAnimator> getStateListAnimatorCa
CharSequence res = mResourcesImpl.getAssets().getResourceText(id);
if (res != null) {
if (android.app.AppGlobals.getInitialPackageId() == android.ext.PackageId.G_EUICC_LPA) {
if (res.toString().contains("Google")) {
return "";
if (!EuiccGoogleHooks.isResourceFilteringSuppressed()) {
String s = res.toString();
if (s.contains("Google")) {
Log.d("GEuiccLpa", "replaced getText() with empty string: " + s);
return "";
}
}
}
return res;
Expand Down
33 changes: 33 additions & 0 deletions core/java/com/android/internal/ext/EuiccGoogleHooks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.android.internal.ext;

public class EuiccGoogleHooks {

private static final ThreadLocal<Integer> resourceFilteringSuppressionCounter =
ThreadLocal.withInitial(() -> Integer.valueOf(0));

public static boolean isResourceFilteringSuppressed() {
return resourceFilteringSuppressionCounter.get() > 0;
}

public static class SuppressResourceFiltering implements AutoCloseable {

public SuppressResourceFiltering() {
var tl = resourceFilteringSuppressionCounter;
int newValue = tl.get() + 1;
if (newValue <= 0) {
throw new IllegalStateException();
}
tl.set(newValue);
}

@Override
public void close() {
var tl = resourceFilteringSuppressionCounter;
int newValue = tl.get() - 1;
if (newValue < 0) {
throw new IllegalStateException();
}
tl.set(newValue);
}
}
}

0 comments on commit 5af848e

Please sign in to comment.