From af9d788c74742b60c5888a436d557c629859a3ad Mon Sep 17 00:00:00 2001 From: althafvly Date: Wed, 12 Jul 2023 11:11:40 +0530 Subject: [PATCH 1/2] Updater: Generate license ID for ota requests Change-Id: I4ed9c9565d9bf1071b22be1a2ab357f5d988739a --- src/org/lineageos/updater/UpdatesCheckReceiver.java | 9 +++++++++ src/org/lineageos/updater/misc/Utils.java | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/org/lineageos/updater/UpdatesCheckReceiver.java b/src/org/lineageos/updater/UpdatesCheckReceiver.java index d16e9c5b..28fa7f32 100644 --- a/src/org/lineageos/updater/UpdatesCheckReceiver.java +++ b/src/org/lineageos/updater/UpdatesCheckReceiver.java @@ -27,6 +27,7 @@ import android.net.ConnectivityManager; import android.net.NetworkCapabilities; import android.net.NetworkRequest; import android.os.SystemClock; +import android.provider.Settings; import android.util.Log; import androidx.core.app.NotificationCompat; @@ -66,6 +67,14 @@ public class UpdatesCheckReceiver extends BroadcastReceiver { @Override public void onReceive(final Context context, Intent intent) { if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { + // Check if the current value is empty or null and set license id. + String eLicenseID = Settings.Secure.getString(context.getContentResolver(), + Settings.Secure.E_LICENSE_ID); + if (eLicenseID == null || eLicenseID.isEmpty()) { + Settings.Secure.putString(context.getContentResolver(), + Settings.Secure.E_LICENSE_ID, Utils.generateRandomID()); + } + Utils.cleanupDownloadsDir(context); } diff --git a/src/org/lineageos/updater/misc/Utils.java b/src/org/lineageos/updater/misc/Utils.java index 18eef0d8..77782ff3 100644 --- a/src/org/lineageos/updater/misc/Utils.java +++ b/src/org/lineageos/updater/misc/Utils.java @@ -68,6 +68,7 @@ import java.util.ArrayList; import java.util.Enumeration; import java.util.List; import java.util.Locale; +import java.util.UUID; import java.util.regex.Pattern; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -103,6 +104,11 @@ public class Utils { return new File(context.getCacheDir(), "updates.json"); } + public static String generateRandomID() { + String uuid = UUID.randomUUID().toString().replace("-", ""); + return "anon" + uuid; + } + // This should really return an UpdateBaseInfo object, but currently this only // used to initialize UpdateInfo objects private static UpdateInfo parseJsonUpdate(JSONObject object) throws JSONException { @@ -233,6 +239,8 @@ public class Utils { String device = SystemProperties.get(Constants.PROP_NEXT_DEVICE, SystemProperties.get(Constants.PROP_DEVICE)); String type = SystemProperties.get(Constants.PROP_RELEASE_TYPE).toLowerCase(Locale.ROOT); + String eLicenseID = Settings.Secure.getString(context.getContentResolver(), + Settings.Secure.E_LICENSE_ID); String serverUrl = ""; if (retrieveStatus(context) != null) { @@ -252,6 +260,10 @@ public class Utils { serverUrl = context.getString(R.string.updater_server_url); } + if (eLicenseID != null && !eLicenseID.isEmpty()) { + serverUrl += "?license_id=" + eLicenseID; + } + return serverUrl.replace("{device}", device) .replace("{type}", type) .replace("{incr}", incrementalVersion); -- GitLab From 840789edb29c90e00b1add0c52e2dcaeeb7c52b4 Mon Sep 17 00:00:00 2001 From: althafvly Date: Thu, 13 Jul 2023 10:34:01 +0530 Subject: [PATCH 2/2] Updater: add missing permissions Change-Id: I9d1e6f02a2445609a4e08d50e0102e900fc9a5ef --- AndroidManifest.xml | 2 ++ privapp_whitelist_org.lineageos.updater.xml | 1 + 2 files changed, 3 insertions(+) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index da8cdb8b..a723d380 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -12,6 +12,8 @@ + + + -- GitLab