diff --git a/AndroidManifest.xml b/AndroidManifest.xml index da8cdb8b9e33a6827a206c19a7af35256195fe59..a723d3808c39ad642736d9258ac468a0184b5895 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -12,6 +12,8 @@ + + + diff --git a/src/org/lineageos/updater/UpdatesCheckReceiver.java b/src/org/lineageos/updater/UpdatesCheckReceiver.java index d16e9c5b0131fc3ea39d91318b04294d67823aec..28fa7f32f12be4a500a4a232f3b0438ce4c8e6fc 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 18eef0d891b8954afb9c32e02d9ffe2ef52e0513..77782ff3bfc722ceb3fbf88285ae3dcb1d198711 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);