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

Commit 36276377 authored by Nihar Thakkar's avatar Nihar Thakkar
Browse files

Update apps only on unmetered networks by default.

parent 0da29fcd
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -31,7 +31,11 @@ import foundation.e.apps.R
import foundation.e.apps.utils.Constants

class UpdatesNotifier {
    private fun getNotification(context: Context, numberOfApps: Int, installAutomatically: Boolean):
    private fun getNotification(context: Context,
                                numberOfApps: Int,
                                installAutomatically: Boolean,
                                unmeteredNetworkOnly: Boolean,
                                isConnectedToUnmeteredNetwork: Boolean):
            Notification {
        val notificationBuilder =
                NotificationCompat.Builder(context, Constants.UPDATES_NOTIFICATION_CHANNEL_ID)
@@ -51,6 +55,10 @@ class UpdatesNotifier {
        if (installAutomatically) {
            notificationBuilder.setContentText(context.getString(R.string.updates_notification_text,
                    Constants.AUTOMATICALLY_INSTALL_UPDATES))
            if (unmeteredNetworkOnly && !isConnectedToUnmeteredNetwork) {
                notificationBuilder.setSubText(context
                        .getString(R.string.updates_notification_unmetered_network_warning))
            }
        } else {
            notificationBuilder.setContentText(context.getString(R.string.updates_notification_text,
                    Constants.MANUALLY_INSTALL_UPDATES))
@@ -82,11 +90,19 @@ class UpdatesNotifier {
        }
    }

    fun showNotification(context: Context, numberOfApps: Int, installAutomatically: Boolean) {
    fun showNotification(context: Context,
                         numberOfApps: Int,
                         installAutomatically: Boolean,
                         unmeteredNetworkOnly: Boolean,
                         isConnectedToUnmeteredNetwork: Boolean) {
        with(NotificationManagerCompat.from(context)) {
            createNotificationChannel(context)
            notify(Constants.UPDATES_NOTIFICATION_ID,
                    getNotification(context, numberOfApps, installAutomatically))
                    getNotification(context,
                            numberOfApps,
                            installAutomatically,
                            unmeteredNetworkOnly,
                            isConnectedToUnmeteredNetwork))
        }
    }
}
+6 −3
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ class UpdatesWorker(context: Context, params: WorkerParameters) : Worker(context
                        R.string.pref_update_install_automatically_key), true)
        wifiOnly =
                preferences.getBoolean(applicationContext.getString(
                        R.string.pref_update_wifi_only_key), false)
                        R.string.pref_update_wifi_only_key), true)
    }

    private fun loadOutdatedApplications(applicationManager: ApplicationManager) {
@@ -85,15 +85,18 @@ class UpdatesWorker(context: Context, params: WorkerParameters) : Worker(context
                }
                it.close()
            }
            val isConnectedToUnmeteredNetwork = isConnectedToUnmeteredNetwork(applicationContext)
            if (notifyAvailable) {
                UpdatesNotifier().showNotification(
                        applicationContext,
                        applications.size,
                        installAutomatically)
                        installAutomatically,
                        wifiOnly,
                        isConnectedToUnmeteredNetwork)
            }
            if (installAutomatically && canWriteStorage(applicationContext)) {
                if (wifiOnly) {
                    if (isConnectedToUnmeteredNetwork(applicationContext)) {
                    if (isConnectedToUnmeteredNetwork) {
                        applications.forEach {
                            if (it.state == State.NOT_UPDATED) {
                                Log.i(TAG, "Updating ${it.packageName}")
+1 −0
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@
        <item quantity="other">%1$d app updates are available</item>
    </plurals>
    <string name="updates_notification_text">App updates %1$s be installed automatically</string>
    <string name="updates_notification_unmetered_network_warning">Waiting for un-metered network</string>

    <!-- Settings Fragment -->
    <string name="preference_updates_title">Updates</string>
+1 −1
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@
            android:title="@string/preference_update_install_automatically_title" />

        <CheckBoxPreference
            android:defaultValue="false"
            android:defaultValue="true"
            android:key="@string/pref_update_wifi_only_key"
            android:summary="@string/preference_update_wifi_only_description"
            android:title="@string/preference_update_wifi_only_title" />
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ buildscript {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.0'
        classpath 'com.android.tools.build:gradle:3.4.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong