Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fae59f18 authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊 Committed by Nishith Khanna
Browse files

Updater: Generate anon id for ota requests

parent 9119c42d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -21,5 +21,6 @@
        <permission name="android.permission.REBOOT"/>
        <permission name="android.permission.RECOVERY"/>
        <permission name="android.permission.START_ACTIVITIES_FROM_BACKGROUND"/>
        <permission name="android.permission.WRITE_SECURE_SETTINGS"/>
    </privapp-permissions>
</permissions>
+2 −0
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@
    <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
    <uses-permission android:name="android.permission.START_ACTIVITIES_FROM_BACKGROUND" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />

    <application
        android:allowBackup="false"
+9 −0
Original line number Diff line number Diff line
@@ -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;
@@ -57,6 +58,14 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
        SharedPreferences.Editor editor = preferences.edit();

        if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
            // Check if the current value is empty or null and set anon hash.
            String anonHash = Settings.Secure.getString(context.getContentResolver(),
                    Constants.OTA_ANON_HASH);
            if (anonHash == null || anonHash.isEmpty()) {
                Settings.Secure.putString(context.getContentResolver(),
                        Constants.OTA_ANON_HASH, Utils.generateRandomID());
            }

            Utils.cleanupDownloadsDir(context);

            // Reset resume or update check failed on reboot
+1 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ public final class Constants {
    public static final String AB_PAYLOAD_BIN_PATH = "payload.bin";
    public static final String AB_PAYLOAD_PROPERTIES_PATH = "payload_properties.txt";

    public static final String OTA_ANON_HASH = "ota_anon_hash";
    public static final String RESUME_DOWNLOAD_ID = "resume_download_id";
    public static final String AUTO_UPDATE_CHECK_FAILED = "auto_update_check_failed";

+12 −0
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.regex.Matcher;
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 {
@@ -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 anonHash = Settings.Secure.getString(context.getContentResolver(),
                Constants.OTA_ANON_HASH);

        String serverUrl = SystemProperties.get(Constants.PROP_UPDATER_URI);
        if (retrieveStatus(context) != null && retrieveStatus(context).equals("true")
@@ -244,6 +252,10 @@ public class Utils {
            serverUrl = context.getString(R.string.updater_server_url);
        }

        if (anonHash != null && !anonHash.isEmpty()) {
            serverUrl += "?ota_anon_hash=" + anonHash;
        }

        return serverUrl.replace("{device}", device)
                .replace("{type}", type)
                .replace("{incr}", incrementalVersion);