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

Commit f3494ca9 authored by Mohit Mali's avatar Mohit Mali Committed by Nishith Khanna
Browse files

Updater: Check in Settings if the device has to fetch updates from the staging OTA server



Change-Id: Ice445b0ae4086dfbea91b3a34b7f13c3553282d0
Signed-off-by: default avataralthafvly <althafvly@gmail.com>
parent 0b1cf97a
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017-2025 The LineageOS Project
 * Copyright (C) 2025 e Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -22,11 +23,14 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.Uri;
import android.os.SystemProperties;
import android.os.storage.StorageManager;
import android.provider.Settings;
import android.util.Log;
import android.widget.Toast;

@@ -57,6 +61,7 @@ import java.util.regex.Pattern;
public class Utils {

    private static final String TAG = "Utils";
    private static final String CONTENT_URI_PATH = "content://custom.setting.Provider.OTA_SERVER/cte";

    private Utils() {
    }
@@ -170,6 +175,11 @@ public class Utils {
        String type = SystemProperties.get(Constants.PROP_RELEASE_TYPE).toLowerCase(Locale.ROOT);

        String serverUrl = SystemProperties.get(Constants.PROP_UPDATER_URI);
        if (retrieveStatus(context) != null && retrieveStatus(context).equals("true")
                && isDevModeOn(context)) {
            serverUrl = context.getString(R.string.ota_staging_server_url);
        }

        if (serverUrl.trim().isEmpty()) {
            serverUrl = context.getString(R.string.updater_server_url);
        }
@@ -179,6 +189,30 @@ public class Utils {
                .replace("{incr}", incrementalVersion);
    }

    /* get the status from database that ota option is on or off */
    public static String retrieveStatus(Context context) {
        try (Cursor cursor = context.getContentResolver().query(
                Uri.parse(CONTENT_URI_PATH),
                new String[]{"Status"},
                "id=?",
                new String[]{"1"},
                null
        )) {
            if (cursor != null && cursor.moveToFirst()) {
                int index = cursor.getColumnIndex("Status");
                if (index != -1) {
                    String status = cursor.getString(index);
                    Log.d(TAG, "Status retrieved: " + status);
                    return status;
                }
                Log.w(TAG, "Column 'Status' not found.");
            }
        } catch (Exception e) {
            Log.e(TAG, "Error retrieving status", e);
        }
        return null;
    }

    public static String getUpgradeBlockedURL(Context context) {
        String device = SystemProperties.get(Constants.PROP_NEXT_DEVICE,
                SystemProperties.get(Constants.PROP_DEVICE));
@@ -377,6 +411,11 @@ public class Utils {
        return isAB;
    }

    public static boolean isDevModeOn(Context context) {
        return Settings.Global.getInt(context.getContentResolver(),
                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED , 0) == 1;
    }

    public static boolean hasTouchscreen(Context context) {
        return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN);
    }
+1 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
          {incr} - Incremental version
    -->
    <string name="updater_server_url" translatable="false">https://ota.ecloud.global/api/v1/{device}/{type}/{incr}</string>
    <string name="ota_staging_server_url" translatable="false"> https://test.ota.ecloud.global/api/v1/{device}/{type}/{incr}</string>

    <string name="verification_failed_notification">Verification failed</string>
    <string name="verifying_download_notification">Verifying update</string>