diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 693ded466f7ea65cccca3433ecaec319495fecca..06296f0f36baf0255ee2da281e8ca32a188f7d75 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -11,6 +11,8 @@ + + + diff --git a/src/org/lineageos/updater/UpdatesCheckReceiver.java b/src/org/lineageos/updater/UpdatesCheckReceiver.java index b74798f1d02d1b9a9513646570d34df2ee74d9cd..8e47f07fdd4b9fbd2c847dea8e0a1e2650b3136a 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 4e7b20f209fd84ac9b9bbe83c38070c0ffe4b366..99102edaea617f7f5ef3671ba647172f4758a90b 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);