From a46c94a3450c3f7caa87ad4067d8d089a70588fd 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 b74798f1..8e47f07f 100644 --- a/src/org/lineageos/updater/UpdatesCheckReceiver.java +++ b/src/org/lineageos/updater/UpdatesCheckReceiver.java @@ -25,6 +25,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; @@ -53,6 +54,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 4e7b20f2..99102eda 100644 --- a/src/org/lineageos/updater/misc/Utils.java +++ b/src/org/lineageos/updater/misc/Utils.java @@ -61,6 +61,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; @@ -97,6 +98,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 { @@ -225,6 +231,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) { @@ -243,6 +251,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 181eb4b15e928f6f3f1e58d53819af17954a84c9 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 693ded46..06296f0f 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -11,6 +11,8 @@ + + + -- GitLab