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

Commit c6910ff7 authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

Merge branch '1923-r-auto_resume' into 'v1-r'

Updater: resume update on network failure

See merge request !180
parents d7a9a067 71a759a1
Loading
Loading
Loading
Loading

Android.bp

0 → 100644
+34 −0
Original line number Diff line number Diff line
android_app {
    name: "Updater",

    srcs: [
           "src/**/*.java",
           "src/**/*.kt",
    ],
    resource_dirs: ["res"],

    static_libs: [
        "com.google.android.material_material",
        "androidx.core_core",
        "androidx.core_core-ktx",
        "androidx.appcompat_appcompat",
        "androidx.cardview_cardview",
        "androidx.preference_preference",
        "androidx.recyclerview_recyclerview",
    ],

    platform_apis: true,
    privileged: true,
    certificate: "platform",
    optimize: {
        proguard_flags_files: ["proguard.flags"],
    },

    required: ["privapp_whitelist_org.lineageos.updater.xml"],
}

prebuilt_etc {
    name: "privapp_whitelist_org.lineageos.updater.xml",
    src: "privapp_whitelist_org.lineageos.updater.xml",
    sub_dir: "permissions",
}
+0 −38
Original line number Diff line number Diff line
LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_USE_AAPT2 := true

LOCAL_STATIC_ANDROID_LIBRARIES := \
    com.google.android.material_material \
    androidx.core_core \
    androidx.appcompat_appcompat \
    androidx.cardview_cardview \
    androidx.preference_preference \
    androidx.recyclerview_recyclerview \

LOCAL_RESOURCE_DIR := \
    $(LOCAL_PATH)/res

LOCAL_PACKAGE_NAME := Updater
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_PRIVILEGED_MODULE := true
LOCAL_CERTIFICATE := platform
LOCAL_PROGUARD_FLAG_FILES := proguard.flags

LOCAL_REQUIRED_MODULES := privapp_whitelist_org.lineageos.updater.xml

include $(BUILD_PACKAGE)

include $(CLEAR_VARS)
LOCAL_MODULE := privapp_whitelist_org.lineageos.updater.xml
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/permissions
LOCAL_SRC_FILES := $(LOCAL_MODULE)
include $(BUILD_PREBUILT)


include $(CLEAR_VARS)
LOCAL_MODULE := UpdaterStudio
LOCAL_MODULE_CLASS := FAKE
+4 −1
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ buildscript {

    dependencies {
        classpath 'com.android.tools.build:gradle:7.1.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"
    }
}

@@ -19,6 +20,7 @@ def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

apply plugin: 'com.android.application'
apply plugin: 'org.jetbrains.kotlin.android'

android {
    compileSdkVersion 30
@@ -58,9 +60,10 @@ android {
dependencies {
    compileOnly fileTree(dir: 'system_libs/', include: ['*.jar'])

    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.core:core-ktx:1.9.0'
    implementation 'androidx.preference:preference:1.1.0'
    implementation 'androidx.recyclerview:recyclerview:1.2.1'
    implementation 'com.google.android.material:material:1.4.0'
}
+17 −8
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import androidx.core.app.NotificationCompat;
import androidx.preference.PreferenceManager;

import org.json.JSONException;
import org.lineageos.updater.controller.UpdaterService;
import org.lineageos.updater.download.DownloadClient;
import org.lineageos.updater.misc.Constants;
import org.lineageos.updater.misc.JsonValidator;
@@ -54,6 +55,10 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(final Context context, Intent intent) {
        final SharedPreferences preferences =
                PreferenceManager.getDefaultSharedPreferences(context);
        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 eLicenseID = Settings.Secure.getString(context.getContentResolver(),
@@ -67,6 +72,10 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
            }

            Utils.cleanupDownloadsDir(context);

            // Reset resume or update check failed on reboot
            editor.putBoolean(Constants.AUTO_UPDATE_CHECK_FAILED, false).apply();
            editor.putString(Constants.RESUME_DOWNLOAD_ID, "").apply();
        }

        final File json = Utils.getCachedUpdateList(context);
@@ -74,9 +83,6 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
            Log.i(TAG, "Removing cached json file due validation failure");
        }

        final SharedPreferences preferences =
                PreferenceManager.getDefaultSharedPreferences(context);

        if (!Utils.isUpdateCheckEnabled(context)) {
            return;
        }
@@ -87,9 +93,14 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
        }

        if (!Utils.isNetworkAvailable(context)) {
            Log.d(TAG, "Network not available, scheduling new check");
            scheduleUpdatesCheck(context);
            if (!UpdaterService.isNetworkCallBackActive()) {
                editor.putBoolean(Constants.AUTO_UPDATE_CHECK_FAILED, true).apply();
                UpdaterService.setupNetworkCallback(true);
            }
            return;
        } else if (UpdaterService.isNetworkCallBackActive()) {
            editor.putBoolean(Constants.AUTO_UPDATE_CHECK_FAILED, false).apply();
            UpdaterService.setupNetworkCallback(false);
        }

        final File jsonNew = new File(json.getAbsolutePath() + UUID.randomUUID());
@@ -120,9 +131,7 @@ public class UpdatesCheckReceiver extends BroadcastReceiver {
                    //noinspection ResultOfMethodCallIgnored
                    jsonNew.renameTo(json);
                    long currentMillis = System.currentTimeMillis();
                    preferences.edit()
                            .putLong(Constants.PREF_LAST_UPDATE_CHECK, currentMillis)
                            .apply();
                    editor.putLong(Constants.PREF_LAST_UPDATE_CHECK, currentMillis).apply();
                    // In case we set a one-shot check because of a previous failure
                    cancelUpdatesCheck(context);
                } catch (IOException | JSONException e) {
+1 −1
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ public class UpdaterController {
    private int mActiveDownloads = 0;
    private final Set<String> mVerifyingUpdates = new HashSet<>();

    protected static synchronized UpdaterController getInstance(Context context) {
    public static synchronized UpdaterController getInstance(Context context) {
        if (sUpdaterController == null) {
            sUpdaterController = new UpdaterController(context);
        }
Loading