3
0
Fork 0

PropImitationHooks: Run google-java-format with AOSP style

Change-Id: Ic3bf8e75eee14dfa5bf8c806688bfbbfbabd17e4
This commit is contained in:
ralph950412 2024-11-17 17:51:05 +00:00
parent 81d019fafe
commit 86e2a36c0a
1 changed files with 84 additions and 65 deletions

View File

@ -25,8 +25,8 @@ import android.app.TaskStackListener;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Build;
import android.os.Binder; import android.os.Binder;
import android.os.Build;
import android.os.Process; import android.os.Process;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
@ -50,13 +50,16 @@ public class PropImitationHooks {
private static final String PACKAGE_GPHOTOS = "com.google.android.apps.photos"; private static final String PACKAGE_GPHOTOS = "com.google.android.apps.photos";
private static final String PACKAGE_SETUPWIZARD = "com.google.android.setupwizard"; private static final String PACKAGE_SETUPWIZARD = "com.google.android.setupwizard";
private static final String PACKAGE_SUBSCRIPTION_RED = "com.google.android.apps.subscriptions.red"; private static final String PACKAGE_SUBSCRIPTION_RED =
"com.google.android.apps.subscriptions.red";
private static final String PACKAGE_VELVET = "com.google.android.googlequicksearchbox"; private static final String PACKAGE_VELVET = "com.google.android.googlequicksearchbox";
private static final ComponentName GMS_ADD_ACCOUNT_ACTIVITY = ComponentName.unflattenFromString( private static final ComponentName GMS_ADD_ACCOUNT_ACTIVITY =
ComponentName.unflattenFromString(
"com.google.android.gms/.auth.uiflows.minutemaid.MinuteMaidActivity"); "com.google.android.gms/.auth.uiflows.minutemaid.MinuteMaidActivity");
private static final Map<String, String> sPixelNineProps = Map.of( private static final Map<String, String> sPixelNineProps =
Map.of(
"PRODUCT", "komodo", "PRODUCT", "komodo",
"DEVICE", "komodo", "DEVICE", "komodo",
"HARDWARE", "komodo", "HARDWARE", "komodo",
@ -64,10 +67,11 @@ public class PropImitationHooks {
"BRAND", "google", "BRAND", "google",
"MODEL", "Pixel 9 Pro XL", "MODEL", "Pixel 9 Pro XL",
"ID", "AP4A.241205.013", "ID", "AP4A.241205.013",
"FINGERPRINT", "google/komodo/komodo:15/AP4A.241205.013/12621605:user/release-keys" "FINGERPRINT",
); "google/komodo/komodo:15/AP4A.241205.013/12621605:user/release-keys");
private static final Map<String, String> sPixelTabletProps = Map.of( private static final Map<String, String> sPixelTabletProps =
Map.of(
"PRODUCT", "tangorpro", "PRODUCT", "tangorpro",
"DEVICE", "tangorpro", "DEVICE", "tangorpro",
"HARDWARE", "tangorpro", "HARDWARE", "tangorpro",
@ -75,10 +79,11 @@ public class PropImitationHooks {
"BRAND", "google", "BRAND", "google",
"MODEL", "Pixel Tablet", "MODEL", "Pixel Tablet",
"ID", "AP4A.241205.013", "ID", "AP4A.241205.013",
"FINGERPRINT", "google/tangorpro/tangorpro:15/AP4A.241205.013/12621605:user/release-keys" "FINGERPRINT",
); "google/tangorpro/tangorpro:15/AP4A.241205.013/12621605:user/release-keys");
private static final Set<String> sPixelFeatures = Set.of( private static final Set<String> sPixelFeatures =
Set.of(
"PIXEL_2017_EXPERIENCE", "PIXEL_2017_EXPERIENCE",
"PIXEL_2017_PRELOAD", "PIXEL_2017_PRELOAD",
"PIXEL_2018_EXPERIENCE", "PIXEL_2018_EXPERIENCE",
@ -90,18 +95,17 @@ public class PropImitationHooks {
"PIXEL_2020_EXPERIENCE", "PIXEL_2020_EXPERIENCE",
"PIXEL_2020_MIDYEAR_EXPERIENCE", "PIXEL_2020_MIDYEAR_EXPERIENCE",
"PIXEL_2021_MIDYEAR_EXPERIENCE", "PIXEL_2021_MIDYEAR_EXPERIENCE",
"PIXEL_EXPERIENCE" "PIXEL_EXPERIENCE");
);
private static final Set<String> sTensorFeatures = Set.of( private static final Set<String> sTensorFeatures =
Set.of(
"PIXEL_2021_EXPERIENCE", "PIXEL_2021_EXPERIENCE",
"PIXEL_2022_EXPERIENCE", "PIXEL_2022_EXPERIENCE",
"PIXEL_2022_MIDYEAR_EXPERIENCE", "PIXEL_2022_MIDYEAR_EXPERIENCE",
"PIXEL_2023_EXPERIENCE", "PIXEL_2023_EXPERIENCE",
"PIXEL_2023_MIDYEAR_EXPERIENCE", "PIXEL_2023_MIDYEAR_EXPERIENCE",
"PIXEL_2024_EXPERIENCE", "PIXEL_2024_EXPERIENCE",
"PIXEL_2024_MIDYEAR_EXPERIENCE" "PIXEL_2024_MIDYEAR_EXPERIENCE");
);
private static volatile String[] sCertifiedProps; private static volatile String[] sCertifiedProps;
private static volatile String sStockFp; private static volatile String sStockFp;
@ -154,14 +158,19 @@ public class PropImitationHooks {
dlog("Spoofing Pixel Tablet for: " + packageName + " process: " + processName); dlog("Spoofing Pixel Tablet for: " + packageName + " process: " + processName);
setProps(sPixelTabletProps); setProps(sPixelTabletProps);
} else { } else {
dlog("Spoofing Pixel 9 Pro XL for: " + packageName + " process: " + processName); dlog(
"Spoofing Pixel 9 Pro XL for: "
+ packageName
+ " process: "
+ processName);
setProps(sPixelNineProps); setProps(sPixelNineProps);
} }
return; return;
case PACKAGE_ARCORE: case PACKAGE_ARCORE:
if (!sStockFp.isEmpty()) { if (!sStockFp.isEmpty()) {
dlog("Setting stock fingerprint for: " + packageName); dlog("Setting stock fingerprint for: " + packageName);
setPropValue("FINGERPRINT", sStockFp);; setPropValue("FINGERPRINT", sStockFp);
;
} }
return; return;
} }
@ -195,13 +204,19 @@ public class PropImitationHooks {
return; return;
} }
final boolean was = isGmsAddAccountActivityOnTop(); final boolean was = isGmsAddAccountActivityOnTop();
final TaskStackListener taskStackListener = new TaskStackListener() { final TaskStackListener taskStackListener =
new TaskStackListener() {
@Override @Override
public void onTaskStackChanged() { public void onTaskStackChanged() {
final boolean is = isGmsAddAccountActivityOnTop(); final boolean is = isGmsAddAccountActivityOnTop();
if (is ^ was) { if (is ^ was) {
dlog("GmsAddAccountActivityOnTop is:" + is + " was:" + was + dlog(
", killing myself!"); // process will restart automatically later "GmsAddAccountActivityOnTop is:"
+ is
+ " was:"
+ was
+ ", killing myself!"); // process will restart
// automatically later
Process.killProcess(Process.myPid()); Process.killProcess(Process.myPid());
} }
} }
@ -235,7 +250,8 @@ public class PropImitationHooks {
try { try {
final ActivityTaskManager.RootTaskInfo focusedTask = final ActivityTaskManager.RootTaskInfo focusedTask =
ActivityTaskManager.getService().getFocusedRootTaskInfo(); ActivityTaskManager.getService().getFocusedRootTaskInfo();
return focusedTask != null && focusedTask.topActivity != null return focusedTask != null
&& focusedTask.topActivity != null
&& focusedTask.topActivity.equals(GMS_ADD_ACCOUNT_ACTIVITY); && focusedTask.topActivity.equals(GMS_ADD_ACCOUNT_ACTIVITY);
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Unable to get top activity!", e); Log.e(TAG, "Unable to get top activity!", e);
@ -258,7 +274,8 @@ public class PropImitationHooks {
} }
private static boolean isCallerSafetyNet() { private static boolean isCallerSafetyNet() {
return sIsGms && Arrays.stream(Thread.currentThread().getStackTrace()) return sIsGms
&& Arrays.stream(Thread.currentThread().getStackTrace())
.anyMatch(elem -> elem.getClassName().contains("DroidGuard")); .anyMatch(elem -> elem.getClassName().contains("DroidGuard"));
} }
@ -271,7 +288,9 @@ public class PropImitationHooks {
} }
public static boolean hasSystemFeature(String name, boolean has) { public static boolean hasSystemFeature(String name, boolean has) {
if (sIsPhotos && !sIsPixelDevice && has if (sIsPhotos
&& !sIsPixelDevice
&& has
&& (sPixelFeatures.stream().anyMatch(name::contains) && (sPixelFeatures.stream().anyMatch(name::contains)
|| sTensorFeatures.stream().anyMatch(name::contains))) { || sTensorFeatures.stream().anyMatch(name::contains))) {
dlog("Blocked system feature " + name + " for Google Photos"); dlog("Blocked system feature " + name + " for Google Photos");