diff --git a/README.md b/README.md index 2aeec84..b2252cf 100644 --- a/README.md +++ b/README.md @@ -33,10 +33,15 @@ You decide which apps are affected: only the apps you tick in LSPosed see spoofe - **New identity on every app start** (optional): each launch of a target app gets fresh random identifiers. Configuration (hide lists, keyboard id, proxy) is never re-rolled. - **Coherent identities**: the SIM operator decides the timezone, region and GPS position too, so a - randomised device does not claim a German carrier while sitting in Tokyo. + randomised device does not claim a German carrier while sitting in Tokyo. The device model brings + its real codename, board, SoC and build fingerprint with it, so nothing contradicts the model. +- **Hidden apps stay hidden** from direct lookups, not just from package listings: a hidden package + reports itself as not installed to `getPackageInfo` and friends, which is what detection actually + asks. The module conceals its own package the same way. - **Privacy switches**: hide an active VPN, hide developer options and ADB, report Google Play as the installer, block private LAN scans, hide nearby Wi-Fi scan results, add realistic sensor noise. - **Per-profile proxy**: route app traffic through an HTTP or SOCKS proxy, leaving loopback and LAN direct. +- **Update notifications** (optional): tells you when a newer release is published. - **Master switch** to turn spoofing off without losing your values. - **Export / import** your values as a JSON file. - **Long-press a value to copy it.** @@ -53,6 +58,10 @@ You decide which apps are affected: only the apps you tick in LSPosed see spoofe | | Advertising ID | `AdvertisingIdClient.Info.getId` (Google Play services library) | | | MediaDrm ID | `MediaDrm.getPropertyByteArray("deviceUniqueId")` | | Device model | Brand, manufacturer, model | `Build.BRAND`, `Build.MANUFACTURER`, `Build.MODEL` | +| | Codename, product, board, hardware | `Build.DEVICE`, `PRODUCT`, `BOARD`, `HARDWARE`, and the matching `ro.product.*` / `ro.board.platform` / `ro.hardware` properties | +| | Bootloader, build id, incremental | `Build.BOOTLOADER`, `Build.ID`, `Build.VERSION.INCREMENTAL` and their `ro.*` properties | +| | Security patch | `Build.VERSION.SECURITY_PATCH`, `ro.build.version.security_patch` | +| | Build fingerprint | `Build.FINGERPRINT` and every `ro.*.build.fingerprint` | | Wi-Fi & Bluetooth | MAC address | `WifiInfo.getMacAddress`, `NetworkInterface.getHardwareAddress` (`wlan0`) | | | BSSID | `WifiInfo.getBSSID` | | | SSID | `WifiInfo.getSSID` | @@ -68,7 +77,7 @@ You decide which apps are affected: only the apps you tick in LSPosed see spoofe | | Latitude, longitude | `Location.getLatitude`, `getLongitude`, `LocationManager.getLastKnownLocation` | | Keyboard & IME | Default keyboard | `Settings.Secure` `default_input_method` | | | Hidden keyboards | `InputMethodManager.getInputMethodList`, `getEnabledInputMethodList` | -| System privacy | Hidden apps | `PackageManager.getInstalledPackages`, `getInstalledApplications` | +| System privacy | Hidden apps | `PackageManager.getInstalledPackages`, `getInstalledApplications`, `getPackageInfo`, `getApplicationInfo`, `getPackageUid`, `getPackageGids`, `getLaunchIntentForPackage`, `queryIntent*`, `resolve*`, `getPackagesForUid` | | Proxy & accounts | Virtual Gmail accounts | `AccountManager.getAccounts`, `getAccountsByType` | | | Proxy host, port, type | `ProxySelector.getDefault` | @@ -172,16 +181,20 @@ app/src/main/java/com/hidemydevice/app/ 3. For every identifier that has a value, `Hook` replaces the matching framework methods so they return that value. Identifiers without a value get no hook at all. 4. The app detects that it's active by asking LSPosed for a world-readable preference file (and by a self-hook on `MainActivity.isModuleActive`). +## Network access + +The app asks GitHub once a day whether a newer release exists, and that is the only network request +the project makes. It sends no query, no body and no identifying header, and the hooks themselves +never touch the network. Turn off **Check for new versions** and nothing is sent at all. + ## Known limitations These are good places to start contributing: -- **Hiding an app only filters lists.** `getInstalledPackages` and `getInstalledApplications` are - filtered, but a direct `getPackageInfo("com.example")` still answers truthfully, and most detectors - ask by name rather than enumerating. -- **Device profile isn't fully consistent.** Brand, manufacturer and model are spoofed, but - `Build.FINGERPRINT`, `DEVICE`, `PRODUCT` and the `ro.product.*` properties are not, which - contradicts them. The IMEI's TAC (model prefix) is random rather than matching the chosen model. +- **The IMEI's TAC** (the model prefix) is random rather than matching the chosen device. +- **The OS version is not spoofed.** `Build.VERSION.RELEASE` and `SDK_INT` stay real, and the build + fingerprint is composed around them, so a spoofed build id can still imply a different release + than the one actually running. - **Region is only spoofed for `Locale.getDefault`.** An app reading `getResources().getConfiguration().getLocales()` still sees the real country. - **Every scoped app sees the same identity**, so apps can still correlate with each other. @@ -201,8 +214,7 @@ These are good places to start contributing: Ideas we'd love help with: -- [ ] **Hide apps from direct lookups** (`getPackageInfo`, `getApplicationInfo`, `queryIntentActivities`) -- [ ] **Consistent device profiles** (fingerprint, device, product, `ro.product.*` and IMEI TAC matching the model) +- [ ] **IMEI TAC matching the chosen model** (the rest of the device profile is now consistent) - [ ] **Stable per-app randomisation** (seeded per app, consistent across processes) - [ ] **Spoof region for `Configuration.getLocales()`**, not just `Locale.getDefault` - [ ] **Pin a value** so "Random all" leaves it alone diff --git a/app/build.gradle b/app/build.gradle index a3791b5..6c46c66 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,8 +12,8 @@ android { minSdk = 27 // 34 keeps the classic (non edge-to-edge) window layout targetSdk = 34 - versionCode = 2 - versionName = '1.1.0' + versionCode = 3 + versionName = '1.2.0' } // Release signing comes from environment variables (set by the GitHub workflow from repository diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c4e4655..cb76d9c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,12 @@ + + + + + open(GITHUB_URL)); findViewById(R.id.source).setOnClickListener(v -> open(SOURCE_URL)); findViewById(R.id.issues).setOnClickListener(v -> open(SOURCE_URL + "/issues")); + + findViewById(R.id.app_appguard).setOnClickListener(v -> open(APPGUARD_URL)); + findViewById(R.id.app_adb_controller).setOnClickListener(v -> open(ADB_CONTROLLER_URL)); + findViewById(R.id.app_avd_kernelsu).setOnClickListener(v -> open(AVD_KERNELSU_URL)); + findViewById(R.id.all_projects).setOnClickListener(v -> open(GITHUB_URL + "?tab=repositories")); } private String versionName() { diff --git a/app/src/main/java/com/hidemydevice/app/Field.java b/app/src/main/java/com/hidemydevice/app/Field.java index 26be150..9ce32f3 100644 --- a/app/src/main/java/com/hidemydevice/app/Field.java +++ b/app/src/main/java/com/hidemydevice/app/Field.java @@ -20,6 +20,18 @@ enum Field { BRAND(Category.MODEL, "brand", "Device Brand", "Up to 32 characters", ".{1,32}", Field.TEXT), MANUFACTURER(Category.MODEL, "manufacturer", "Device Manufacturer", "Up to 32 characters", ".{1,32}", Field.TEXT), MODEL(Category.MODEL, "model", "Device Model", "Up to 32 characters", ".{1,32}", Field.TEXT), + // A spoofed model that leaves these at the real values contradicts itself: anything comparing + // MODEL against FINGERPRINT or ro.product.* sees an emulator wearing a phone's name. + DEVICE(Category.MODEL, "device", "Device Codename", "e.g. panther", Field.BUILD_TOKEN, Field.TEXT), + PRODUCT(Category.MODEL, "product", "Product Name", "e.g. panther", Field.BUILD_TOKEN, Field.TEXT), + BOARD(Category.MODEL, "board", "Board", "e.g. panther", Field.BUILD_TOKEN, Field.TEXT), + HARDWARE(Category.MODEL, "hardware", "Hardware", "e.g. panther or qcom", Field.BUILD_TOKEN, Field.TEXT), + BOOTLOADER(Category.MODEL, "bootloader", "Bootloader", "Up to 32 characters", "[A-Za-z0-9_.:+-]{1,32}", Field.TEXT), + BUILD_ID(Category.MODEL, "build_id", "Build ID", "e.g. AP2A.240905.003", "[A-Za-z0-9._-]{1,32}", Field.TEXT), + BUILD_INCREMENTAL(Category.MODEL, "build_incremental", "Build Incremental", "e.g. 12231197", "[A-Za-z0-9._-]{1,48}", Field.TEXT), + SECURITY_PATCH(Category.MODEL, "security_patch", "Security Patch", "YYYY-MM-DD", "\\d{4}-\\d{2}-\\d{2}", Field.TEXT), + FINGERPRINT(Category.MODEL, "fingerprint", "Build Fingerprint", "brand/product/device:release/id/incremental:type/tags", + "[A-Za-z0-9._/:+-]{10,160}", Field.TEXT), WIFI_MAC(Category.NETWORK, "wifi_mac", "MAC Address", "aa:bb:cc:dd:ee:ff", Field.MAC, Field.TEXT), BSSID(Category.NETWORK, "bssid", "MAC BSSID", "aa:bb:cc:dd:ee:ff", Field.MAC, Field.TEXT), @@ -61,6 +73,7 @@ enum Field { private static final int COORDINATE = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED; private static final String MAC = "([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}"; + private static final String BUILD_TOKEN = "[A-Za-z0-9_+.-]{1,32}"; private static final boolean CONFIG = false; final Category category; diff --git a/app/src/main/java/com/hidemydevice/app/Hook.java b/app/src/main/java/com/hidemydevice/app/Hook.java index 0e50c49..3444260 100644 --- a/app/src/main/java/com/hidemydevice/app/Hook.java +++ b/app/src/main/java/com/hidemydevice/app/Hook.java @@ -4,7 +4,11 @@ import android.accounts.AccountManager; import android.bluetooth.BluetoothAdapter; import android.content.pm.ApplicationInfo; +import android.content.pm.ComponentInfo; import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.content.pm.ProviderInfo; +import android.content.pm.ResolveInfo; import android.location.Location; import android.location.LocationManager; import android.media.MediaDrm; @@ -36,6 +40,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.EnumMap; +import java.util.HashMap; import java.util.Enumeration; import java.util.LinkedHashSet; import java.util.List; @@ -173,26 +178,109 @@ private static void hookBuild(Map v) { setBuildField("BRAND", v.get(Field.BRAND)); setBuildField("MANUFACTURER", v.get(Field.MANUFACTURER)); setBuildField("MODEL", v.get(Field.MODEL)); + setBuildField("DEVICE", v.get(Field.DEVICE)); + setBuildField("PRODUCT", v.get(Field.PRODUCT)); + setBuildField("BOARD", v.get(Field.BOARD)); + setBuildField("HARDWARE", v.get(Field.HARDWARE)); + setBuildField("BOOTLOADER", v.get(Field.BOOTLOADER)); + setBuildField("ID", v.get(Field.BUILD_ID)); + setBuildField("FINGERPRINT", v.get(Field.FINGERPRINT)); + setVersionField("INCREMENTAL", v.get(Field.BUILD_INCREMENTAL)); + setVersionField("SECURITY_PATCH", v.get(Field.SECURITY_PATCH)); String serial = v.get(Field.HARDWARE_ID); - if (serial == null) { + if (serial != null) { + setBuildField("SERIAL", serial); + constant(Build.class, "getSerial", serial); + } + hookSystemProperties(v, serial); + } + + /** + * The {@code ro.*} properties behind the {@link Build} fields. Setting the Java constants alone + * is not enough: plenty of detection reads the properties directly, and an app that finds + * {@code ro.product.model} disagreeing with {@code Build.MODEL} has learnt more than if neither + * had been touched. + * + *

Partition-qualified aliases ({@code ro.product.vendor.model}, {@code .system.}, + * {@code .odm.}, {@code .vendor_dlkm.} and friends) are matched by suffix so a new partition + * prefix on a future release does not quietly leak the real value. + */ + private static void hookSystemProperties(Map v, String serial) { + Map exact = new HashMap<>(); + Map productSuffix = new HashMap<>(); + + put(productSuffix, "brand", v.get(Field.BRAND)); + put(productSuffix, "manufacturer", v.get(Field.MANUFACTURER)); + put(productSuffix, "model", v.get(Field.MODEL)); + put(productSuffix, "device", v.get(Field.DEVICE)); + put(productSuffix, "name", v.get(Field.PRODUCT)); + put(productSuffix, "board", v.get(Field.BOARD)); + + put(exact, "ro.product.board", v.get(Field.BOARD)); + put(exact, "ro.board.platform", v.get(Field.BOARD)); + put(exact, "ro.hardware", v.get(Field.HARDWARE)); + put(exact, "ro.boot.hardware", v.get(Field.HARDWARE)); + put(exact, "ro.bootloader", v.get(Field.BOOTLOADER)); + put(exact, "ro.boot.bootloader", v.get(Field.BOOTLOADER)); + put(exact, "ro.build.id", v.get(Field.BUILD_ID)); + put(exact, "ro.build.display.id", v.get(Field.BUILD_ID)); + put(exact, "ro.build.version.incremental", v.get(Field.BUILD_INCREMENTAL)); + put(exact, "ro.build.version.security_patch", v.get(Field.SECURITY_PATCH)); + put(exact, "ro.vendor.build.security_patch", v.get(Field.SECURITY_PATCH)); + put(exact, "ro.serialno", serial); + put(exact, "ro.boot.serialno", serial); + + String fingerprint = v.get(Field.FINGERPRINT); + if (fingerprint != null) { + for (String key : new String[]{"ro.build.fingerprint", "ro.vendor.build.fingerprint", + "ro.system.build.fingerprint", "ro.odm.build.fingerprint", + "ro.product.build.fingerprint", "ro.bootimage.build.fingerprint"}) { + exact.put(key, fingerprint); + } + } + if (exact.isEmpty() && productSuffix.isEmpty()) { return; } - setBuildField("SERIAL", serial); - constant(Build.class, "getSerial", serial); - try { - Class systemProperties = XposedHelpers.findClass("android.os.SystemProperties", null); - hookAll(systemProperties, "get", new XC_MethodHook() { - @Override - protected void beforeHookedMethod(MethodHookParam param) { - Object key = param.args.length > 0 ? param.args[0] : null; - if ("ro.serialno".equals(key) || "ro.boot.serialno".equals(key)) { - param.setResult(serial); - } + + Class systemProperties = + XposedHelpers.findClassIfExists("android.os.SystemProperties", null); + if (systemProperties == null) { + XposedBridge.log(TAG + "no android.os.SystemProperties"); + return; + } + hookAll(systemProperties, "get", new XC_MethodHook() { + @Override + protected void beforeHookedMethod(MethodHookParam param) { + if (param.args.length == 0 || !(param.args[0] instanceof String)) { + return; } - }); + String key = (String) param.args[0]; + String value = exact.get(key); + if (value == null && key.startsWith("ro.product.")) { + value = productSuffix.get(key.substring(key.lastIndexOf('.') + 1)); + } + if (value != null) { + param.setResult(value); + } + } + }); + } + + private static void put(Map target, String key, String value) { + if (value != null) { + target.put(key, value); + } + } + + private static void setVersionField(String name, String value) { + if (value == null) { + return; + } + try { + XposedHelpers.setStaticObjectField(Build.VERSION.class, name, value); } catch (Throwable t) { - XposedBridge.log(TAG + t); + XposedBridge.log(TAG + "Build.VERSION." + name + ": " + t); } } @@ -594,15 +682,93 @@ protected void beforeHookedMethod(MethodHookParam param) { private static void hookHiddenApps(Map v) { Set hidden = csv(v.get(Field.HIDDEN_APPS)); - if (hidden.isEmpty()) { - return; - } + // The module conceals itself whether or not a hide list was configured. A tool whose job is + // concealment should not be the one package every scoped app can still enumerate. + hidden.add(Prefs.PACKAGE); + Class pm = XposedHelpers.findClassIfExists(PACKAGE_MANAGER_CLASS, null); if (pm == null) { XposedBridge.log(TAG + "no " + PACKAGE_MANAGER_CLASS); return; } + // Filtering the two list APIs is not enough on its own. Detection almost never enumerates; + // it asks for the package it already suspects, so the by-name lookups have to fail the same + // way they would for a package that genuinely is not installed. + XC_MethodHook notInstalled = new XC_MethodHook() { + @Override + protected void beforeHookedMethod(MethodHookParam param) { + if (param.args.length > 0 && param.args[0] instanceof String + && hidden.contains(param.args[0])) { + param.setThrowable( + new PackageManager.NameNotFoundException((String) param.args[0])); + } + } + }; + // Only methods that declare NameNotFoundException; throwing it from one that does not + // would surface as an UndeclaredThrowableException and be louder than the real answer. + hookAll(pm, "getPackageInfo", notInstalled); + hookAll(pm, "getPackageInfoAsUser", notInstalled); + hookAll(pm, "getApplicationInfo", notInstalled); + hookAll(pm, "getApplicationInfoAsUser", notInstalled); + hookAll(pm, "getPackageUid", notInstalled); + hookAll(pm, "getPackageUidAsUser", notInstalled); + hookAll(pm, "getPackageGids", notInstalled); + + XC_MethodHook noIntent = new XC_MethodHook() { + @Override + protected void beforeHookedMethod(MethodHookParam param) { + if (param.args.length > 0 && param.args[0] instanceof String + && hidden.contains(param.args[0])) { + param.setResult(null); + } + } + }; + hookAll(pm, "getLaunchIntentForPackage", noIntent); + hookAll(pm, "getLeanbackLaunchIntentForPackage", noIntent); + + // An app that resolves an intent can discover a package without ever naming it. + XC_MethodHook filterResolveInfo = new XC_MethodHook() { + @Override + @SuppressWarnings("unchecked") + protected void afterHookedMethod(MethodHookParam param) { + Object result = param.getResult(); + if (result instanceof List) { + List kept = new ArrayList<>(); + for (Object info : (List) result) { + if (!hidden.contains(resolvedPackage(info))) { + kept.add(info); + } + } + param.setResult(kept); + } else if (result != null && hidden.contains(resolvedPackage(result))) { + param.setResult(null); + } + } + }; + for (String name : new String[]{"queryIntentActivities", "queryIntentActivityOptions", + "queryIntentServices", "queryBroadcastReceivers", "queryContentProviders", + "resolveActivity", "resolveService", "resolveContentProvider"}) { + hookAll(pm, name, filterResolveInfo); + } + + hookAll(pm, "getPackagesForUid", new XC_MethodHook() { + @Override + protected void afterHookedMethod(MethodHookParam param) { + String[] packages = (String[]) param.getResult(); + if (packages == null) { + return; + } + List kept = new ArrayList<>(); + for (String name : packages) { + if (!hidden.contains(name)) { + kept.add(name); + } + } + param.setResult(kept.isEmpty() ? null : kept.toArray(new String[0])); + } + }); + hookAll(pm, "getInstalledPackages", new XC_MethodHook() { @Override @SuppressWarnings("unchecked") @@ -724,6 +890,30 @@ private static boolean isLocal(URI uri) { return host.startsWith("10.") || host.startsWith("192.168.") || host.endsWith(".local"); } + /** + * The package behind a {@link ResolveInfo}, {@link ProviderInfo} or the raw component info the + * query APIs hand back, or null when it carries none. + */ + private static String resolvedPackage(Object info) { + if (info instanceof ResolveInfo) { + ResolveInfo resolve = (ResolveInfo) info; + if (resolve.activityInfo != null) { + return resolve.activityInfo.packageName; + } + if (resolve.serviceInfo != null) { + return resolve.serviceInfo.packageName; + } + if (resolve.providerInfo != null) { + return resolve.providerInfo.packageName; + } + } else if (info instanceof ProviderInfo) { + return ((ProviderInfo) info).packageName; + } else if (info instanceof ComponentInfo) { + return ((ComponentInfo) info).packageName; + } + return null; + } + /** The trimmed, non-empty entries of a comma-separated preference value. */ private static Set csv(String value) { Set entries = new LinkedHashSet<>(); diff --git a/app/src/main/java/com/hidemydevice/app/MainActivity.java b/app/src/main/java/com/hidemydevice/app/MainActivity.java index d73d5f1..4d92706 100644 --- a/app/src/main/java/com/hidemydevice/app/MainActivity.java +++ b/app/src/main/java/com/hidemydevice/app/MainActivity.java @@ -1,10 +1,12 @@ package com.hidemydevice.app; +import android.content.ActivityNotFoundException; import android.content.ClipData; import android.content.ClipboardManager; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.PackageManager; import android.content.res.ColorStateList; import android.net.Uri; import android.os.Build; @@ -75,6 +77,7 @@ private static final class Toggle { new Toggle(R.id.spoof_wifi_scans, Prefs.SPOOF_WIFI_SCANS, false), new Toggle(R.id.realistic_sensors, Prefs.REALISTIC_SENSORS, false), new Toggle(R.id.proxy_enabled, Prefs.PROXY_ENABLED, false), + new Toggle(R.id.check_updates, Prefs.CHECK_UPDATES, true), }; private final Map valueViews = new EnumMap<>(Field.class); @@ -94,6 +97,10 @@ private static final class Toggle { new ActivityResultContracts.CreateDocument("application/json"), this::exportTo); private final ActivityResultLauncher importLauncher = registerForActivityResult( new ActivityResultContracts.OpenDocument(), this::importFrom); + private final ActivityResultLauncher notificationPermissionLauncher = + registerForActivityResult(new ActivityResultContracts.RequestPermission(), granted -> { + // Nothing to do either way: the snackbar covers the refusal. + }); /** Replaced by {@link Hook} to return true when the framework has loaded the module. */ public static boolean isModuleActive() { @@ -171,6 +178,41 @@ protected void onCreate(Bundle savedInstanceState) { } return true; }); + + requestNotificationPermission(); + UpdateChecker.checkInBackground(this, prefs, false, this::offerUpdate); + } + + /** + * Android 13 and later will not show the update notification without this. Asked for once; a + * refusal is final as far as this app is concerned, and the in-app snackbar still works. + */ + private void requestNotificationPermission() { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU + || !prefs.getBoolean(Prefs.CHECK_UPDATES, true)) { + return; + } + if (checkSelfPermission(android.Manifest.permission.POST_NOTIFICATIONS) + != PackageManager.PERMISSION_GRANTED) { + notificationPermissionLauncher.launch(android.Manifest.permission.POST_NOTIFICATIONS); + } + } + + private void offerUpdate(UpdateChecker.Update update) { + if (isFinishing() || isDestroyed()) { + return; + } + Snackbar.make(fab, getString(R.string.update_available_snackbar, update.versionName), + Snackbar.LENGTH_LONG) + .setAnchorView(fab) + .setAction(R.string.update_action, v -> { + try { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(update.url))); + } catch (ActivityNotFoundException e) { + show(getString(R.string.no_browser)); + } + }) + .show(); } // ------------------------------------------------------------------ profiles diff --git a/app/src/main/java/com/hidemydevice/app/Prefs.java b/app/src/main/java/com/hidemydevice/app/Prefs.java index c69b339..022c72f 100644 --- a/app/src/main/java/com/hidemydevice/app/Prefs.java +++ b/app/src/main/java/com/hidemydevice/app/Prefs.java @@ -13,6 +13,14 @@ final class Prefs { /** boolean, default false: replace every set value with a fresh random one per app start. */ static final String RANDOM_EACH_LAUNCH = "random_each_launch"; + /** + * boolean, default true: ask GitHub once a day whether a newer release exists. The only network + * access the project makes; see {@link UpdateChecker}. + */ + static final String CHECK_UPDATES = "check_updates"; + /** long: when the last update check ran, so opening the app does not mean a request. */ + static final String LAST_UPDATE_CHECK = "last_update_check"; + // Profiles static final String ACTIVE_PROFILE_ID = "active_profile_id"; static final String PROFILES_DATA = "profiles_data"; diff --git a/app/src/main/java/com/hidemydevice/app/Randomizer.java b/app/src/main/java/com/hidemydevice/app/Randomizer.java index b953851..a9d1420 100644 --- a/app/src/main/java/com/hidemydevice/app/Randomizer.java +++ b/app/src/main/java/com/hidemydevice/app/Randomizer.java @@ -1,5 +1,7 @@ package com.hidemydevice.app; +import android.os.Build; + import java.security.SecureRandom; import java.util.EnumMap; import java.util.Locale; @@ -33,19 +35,26 @@ final class Randomizer { {"50501", "Telstra", "au", "61", "Australia/Sydney", "-33.8688", "151.2093"}, }; - /** Build.BRAND, Build.MANUFACTURER, Build.MODEL. */ + /** + * One real handset per row: brand, manufacturer, model, device codename, product, board, + * hardware, build id, build incremental, security patch. + * + *

The codename and board are what give the spoof away when they are left alone. A device + * calling itself a Pixel 7 while reporting {@code board=goldfish_x86_64} has told the app both + * that it is lying and that it is an emulator, so these move together with the model. + */ private static final String[][] DEVICES = { - {"google", "Google", "Pixel 7"}, - {"google", "Google", "Pixel 6a"}, - {"google", "Google", "Pixel 8 Pro"}, - {"samsung", "samsung", "SM-S918B"}, - {"samsung", "samsung", "SM-A546B"}, - {"samsung", "samsung", "SM-G991B"}, - {"OnePlus", "OnePlus", "CPH2449"}, - {"Xiaomi", "Xiaomi", "2201123G"}, - {"Redmi", "Xiaomi", "23021RAAEG"}, - {"motorola", "motorola", "moto g84 5G"}, - {"Nokia", "HMD Global", "Nokia G42 5G"}, + {"google", "Google", "Pixel 7", "panther", "panther", "panther", "panther", "AP2A.240905.003", "12231197", "2024-09-05"}, + {"google", "Google", "Pixel 6a", "bluejay", "bluejay", "bluejay", "bluejay", "AP2A.240905.003", "12231197", "2024-09-05"}, + {"google", "Google", "Pixel 8 Pro", "husky", "husky", "husky", "husky", "AP2A.240905.003", "12231197", "2024-09-05"}, + {"samsung", "samsung", "SM-S918B", "dm3q", "dm3qxxx", "kalama", "qcom", "UP1A.231005.007", "S918BXXU5CXD1", "2024-08-01"}, + {"samsung", "samsung", "SM-A546B", "a54x", "a54xnaxx", "s5e8835", "s5e8835", "UP1A.231005.007", "A546BXXU5CXD2", "2024-08-01"}, + {"samsung", "samsung", "SM-G991B", "o1s", "o1sxxx", "exynos2100", "exynos2100", "UP1A.231005.007", "G991BXXS9DXD1", "2024-07-01"}, + {"OnePlus", "OnePlus", "CPH2449", "OP594DL1", "CPH2449", "kalama", "qcom", "UKQ1.230924.001", "CPH2449_14.0.0.700", "2024-08-05"}, + {"Xiaomi", "Xiaomi", "2201123G", "cupid", "cupid", "taro", "qcom", "UKQ1.230804.001", "V816.0.3.0.ULCMIXM", "2024-07-01"}, + {"Redmi", "Xiaomi", "23021RAAEG", "sapphire", "sapphire_global", "holi", "qcom", "UKQ1.230804.001", "V816.0.5.0.UMRMIXM", "2024-07-01"}, + {"motorola", "motorola", "moto g84 5G", "bangkk", "bangkk_retail", "holi", "qcom", "U1TDS34.82-12-7", "7bc27", "2024-06-01"}, + {"Nokia", "HMD Global", "Nokia G42 5G", "RHO_sprout", "RHO_00WW", "holi", "qcom", "U1TOS34.37-10-2", "2f1a9", "2024-05-05"}, }; private static final String[] SSID_PREFIXES = { @@ -74,6 +83,15 @@ static Map linked(Field field, String operatorCode) { case BRAND: case MANUFACTURER: case MODEL: + case DEVICE: + case PRODUCT: + case BOARD: + case HARDWARE: + case BOOTLOADER: + case BUILD_ID: + case BUILD_INCREMENTAL: + case SECURITY_PATCH: + case FINGERPRINT: putDevice(values, pick(DEVICES)); break; case TIMEZONE: @@ -134,6 +152,26 @@ private static void putDevice(Map values, String[] device) { values.put(Field.BRAND, device[0]); values.put(Field.MANUFACTURER, device[1]); values.put(Field.MODEL, device[2]); + values.put(Field.DEVICE, device[3]); + values.put(Field.PRODUCT, device[4]); + values.put(Field.BOARD, device[5]); + values.put(Field.HARDWARE, device[6]); + values.put(Field.BUILD_ID, device[7]); + values.put(Field.BUILD_INCREMENTAL, device[8]); + values.put(Field.SECURITY_PATCH, device[9]); + values.put(Field.BOOTLOADER, "unknown"); + values.put(Field.FINGERPRINT, fingerprint(device)); + } + + /** + * The canonical {@code brand/product/device:release/id/incremental:type/tags} form. + * + *

The release comes from the running device rather than the table: the OS version is not + * spoofed, so claiming one here would contradict {@code Build.VERSION.RELEASE} and SDK_INT. + */ + private static String fingerprint(String[] device) { + return device[0] + "/" + device[4] + "/" + device[3] + ":" + Build.VERSION.RELEASE + + "/" + device[7] + "/" + device[8] + ":user/release-keys"; } private static String single(Field field, String operatorCode) { diff --git a/app/src/main/java/com/hidemydevice/app/UpdateChecker.java b/app/src/main/java/com/hidemydevice/app/UpdateChecker.java new file mode 100644 index 0000000..0da6578 --- /dev/null +++ b/app/src/main/java/com/hidemydevice/app/UpdateChecker.java @@ -0,0 +1,211 @@ +package com.hidemydevice.app; + +import android.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.net.Uri; +import android.os.Build; +import android.os.Handler; +import android.os.Looper; +import android.util.Log; + +import androidx.core.app.NotificationManagerCompat; + +import org.json.JSONObject; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.concurrent.TimeUnit; + +/** + * Asks GitHub whether a newer release exists and, if so, offers it. + * + *

This is the only part of the module that touches the network, and it only ever talks to the + * project's own releases endpoint. Nothing about the device, the spoofed values or the configured + * apps is sent: the request carries no query, no body and no identifying header. It can be turned + * off entirely with {@link Prefs#CHECK_UPDATES}, and it is skipped unless a day has passed since + * the last attempt, so opening the app repeatedly does not mean repeated requests. + */ +final class UpdateChecker { + private static final String TAG = "HideMyDevice"; + private static final String RELEASES_API = + "https://api.github.com/repos/imkamaran/HideMyDevice/releases/latest"; + private static final String CHANNEL_ID = "updates"; + private static final int NOTIFICATION_ID = 1; + private static final long INTERVAL_MS = TimeUnit.DAYS.toMillis(1); + private static final int TIMEOUT_MS = 10_000; + + /** A release newer than the installed build. */ + static final class Update { + final long versionCode; + final String versionName; + final String url; + + Update(long versionCode, String versionName, String url) { + this.versionCode = versionCode; + this.versionName = versionName; + this.url = url; + } + } + + interface Callback { + void onUpdate(Update update); + } + + private UpdateChecker() { + } + + /** + * Checks in the background and calls {@code callback} on the main thread only when there is a + * newer release. Does nothing when the check is switched off or ran recently. + * + * @param force ignore the once-a-day limit, for a check the user asked for themselves + */ + static void checkInBackground(Context context, SharedPreferences prefs, boolean force, + Callback callback) { + if (!force && !isDue(prefs)) { + return; + } + Context app = context.getApplicationContext(); + new Thread(() -> { + try { + Update update = fetch(app); + prefs.edit().putLong(Prefs.LAST_UPDATE_CHECK, System.currentTimeMillis()).apply(); + if (update == null) { + return; + } + notify(app, update); + new Handler(Looper.getMainLooper()).post(() -> callback.onUpdate(update)); + } catch (Throwable t) { + // Offline, rate limited, GitHub down: all unremarkable, and none of it is worth + // interrupting the user over. + Log.i(TAG, "update check failed: " + t); + } + }, "update-check").start(); + } + + private static boolean isDue(SharedPreferences prefs) { + if (!prefs.getBoolean(Prefs.CHECK_UPDATES, true)) { + return false; + } + long last = prefs.getLong(Prefs.LAST_UPDATE_CHECK, 0L); + return System.currentTimeMillis() - last >= INTERVAL_MS; + } + + private static Update fetch(Context context) throws Exception { + HttpURLConnection connection = (HttpURLConnection) new URL(RELEASES_API).openConnection(); + String body; + try { + connection.setConnectTimeout(TIMEOUT_MS); + connection.setReadTimeout(TIMEOUT_MS); + connection.setRequestProperty("Accept", "application/vnd.github+json"); + // GitHub rejects requests without one. The app's own name identifies the client and + // nothing else; it must never carry the user's name or address. + connection.setRequestProperty("User-Agent", "HideMyDevice"); + if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { + return null; + } + try (InputStream in = connection.getInputStream()) { + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + byte[] buffer = new byte[4096]; + for (int n; (n = in.read(buffer)) > 0; ) { + bytes.write(buffer, 0, n); + } + body = bytes.toString(StandardCharsets.UTF_8.name()); + } + } finally { + connection.disconnect(); + } + + JSONObject json = new JSONObject(body); + if (json.optBoolean("draft") || json.optBoolean("prerelease")) { + return null; + } + String tag = json.optString("tag_name", ""); + long latest = versionCodeOf(tag); + if (latest <= installedVersionCode(context)) { + return null; + } + String url = json.optString("html_url", AboutActivity.SOURCE_URL + "/releases/latest"); + return new Update(latest, versionNameOf(tag, json.optString("name", "")), url); + } + + /** Releases are tagged {@code -}, e.g. {@code 2-1.1.0}. */ + private static long versionCodeOf(String tag) { + int dash = tag.indexOf('-'); + if (dash <= 0) { + return -1L; + } + try { + return Long.parseLong(tag.substring(0, dash)); + } catch (NumberFormatException e) { + return -1L; + } + } + + private static String versionNameOf(String tag, String fallback) { + int dash = tag.indexOf('-'); + if (dash >= 0 && dash + 1 < tag.length()) { + return tag.substring(dash + 1); + } + return fallback.isEmpty() ? tag : fallback; + } + + static long installedVersionCode(Context context) { + try { + PackageInfo info = + context.getPackageManager().getPackageInfo(context.getPackageName(), 0); + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.P + ? info.getLongVersionCode() + : legacyVersionCode(info); + } catch (PackageManager.NameNotFoundException e) { + return Long.MAX_VALUE; + } + } + + @SuppressWarnings("deprecation") + private static long legacyVersionCode(PackageInfo info) { + return info.versionCode; + } + + private static void notify(Context context, Update update) { + NotificationManagerCompat manager = NotificationManagerCompat.from(context); + if (!manager.areNotificationsEnabled()) { + return; + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + NotificationChannel channel = new NotificationChannel(CHANNEL_ID, + context.getString(R.string.update_channel), NotificationManager.IMPORTANCE_LOW); + channel.setDescription(context.getString(R.string.update_channel_description)); + manager.createNotificationChannel(channel); + } + + int flags = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE; + PendingIntent open = PendingIntent.getActivity(context, 0, + new Intent(Intent.ACTION_VIEW, Uri.parse(update.url)), flags); + + Notification notification = new androidx.core.app.NotificationCompat.Builder(context, CHANNEL_ID) + .setSmallIcon(R.drawable.ic_info) + .setContentTitle(context.getString(R.string.update_available_title, update.versionName)) + .setContentText(context.getString(R.string.update_available_text)) + .setPriority(androidx.core.app.NotificationCompat.PRIORITY_LOW) + .setAutoCancel(true) + .setContentIntent(open) + .build(); + try { + manager.notify(NOTIFICATION_ID, notification); + } catch (SecurityException e) { + // POST_NOTIFICATIONS withdrawn between the check above and here. + Log.i(TAG, "notification not permitted: " + e); + } + } +} diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml index 7a5d76a..c28aa2c 100644 --- a/app/src/main/res/layout/activity_about.xml +++ b/app/src/main/res/layout/activity_about.xml @@ -115,6 +115,165 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index ba81ede..31874dd 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -267,6 +267,19 @@ android:minHeight="52dp" android:text="@string/proxy_enabled" android:textAppearance="?attr/textAppearanceBodyLarge" /> + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cd631f9..28f55bb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -69,4 +69,23 @@ Hide nearby Wi-Fi scan results Add realistic sensor noise Send app traffic through the proxy below + + + More from the developer + AppGuard + Per-app privacy controls for rooted Android: hide or fake location, Wi-Fi, SIM, device IDs, contacts, clipboard and sensors. + ADB Controller + Control and manage Android devices from your phone over Wi-Fi or USB OTG: apps, files, quick settings, diagnostics and root tools. + AVD KernelSU MultiSU + KernelSU, KernelSU-Next and FinaSU images for Android Studio emulators (x86_64). + All projects on GitHub + + + Check for new versions + Updates + Tells you when a newer version of Hide My Device is available. + Hide My Device %1$s is available + Tap to open the release page. + Version %1$s is available + View