From b9a3b2d79749940d7faa3cf6e93ec2217d34095c 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 | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/org/lineageos/updater/UpdatesCheckReceiver.java b/src/org/lineageos/updater/UpdatesCheckReceiver.java index 993c3b69..ed70029b 100644 --- a/src/org/lineageos/updater/UpdatesCheckReceiver.java +++ b/src/org/lineageos/updater/UpdatesCheckReceiver.java @@ -24,6 +24,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.SystemClock; +import android.provider.Settings; import android.util.Log; import androidx.core.app.NotificationCompat; @@ -52,6 +53,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 d795a7c9..a68901be 100644 --- a/src/org/lineageos/updater/misc/Utils.java +++ b/src/org/lineageos/updater/misc/Utils.java @@ -58,6 +58,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; @@ -94,6 +95,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 { @@ -214,6 +220,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) { @@ -232,6 +240,11 @@ public class Utils { if (serverUrl.trim().isEmpty()) { 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 5785a6bc29fdaf94334703b714c8964f23f8f091 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 1e392b4c..3f990832 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -20,6 +20,8 @@ to be updated. This will be fixed later + + + -- GitLab