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

Commit 42b5c0bf authored by Nihar Thakkar's avatar Nihar Thakkar
Browse files

Revert "Update apps only on unmetered networks by default."

This reverts commit 99fbeaa7
parent 99fbeaa7
Loading
Loading
Loading
Loading
+1 −9
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import java.util.concurrent.TimeUnit
class UpdatesManager(applicationContext: Context) {
    private val TAG = "UpdatesManager"
    private var automaticUpdateInterval: Int
    private var updateOnUnmeteredNetworkOnly: Boolean

    init {
        val preferences = PreferenceManager.getDefaultSharedPreferences(applicationContext)
@@ -38,18 +37,11 @@ class UpdatesManager(applicationContext: Context) {
                        applicationContext.getString(R.string.pref_update_interval_key),
                        applicationContext.getString(R.string.preference_update_interval_default))
                        .toInt()
        updateOnUnmeteredNetworkOnly =
                preferences.getBoolean(applicationContext.getString(
                        R.string.pref_update_wifi_only_key), true)
    }

    private fun getWorkerConstraints() = Constraints.Builder().apply {
        setRequiresBatteryNotLow(true)
        if (updateOnUnmeteredNetworkOnly) {
            setRequiredNetworkType(NetworkType.UNMETERED)
        } else {
        setRequiredNetworkType(NetworkType.CONNECTED)
        }
    }.build()

    private fun getPeriodicWorkRequest() = PeriodicWorkRequest.Builder(
+31 −4
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ class UpdatesWorker(context: Context, params: WorkerParameters) : Worker(context
    private val blocker = Object()
    private var notifyAvailable = true
    private var installAutomatically = true
    private var wifiOnly = false

    override fun doWork(): Result {
        Log.i(TAG, "Checking for app updates")
@@ -59,6 +60,9 @@ class UpdatesWorker(context: Context, params: WorkerParameters) : Worker(context
        installAutomatically =
                preferences.getBoolean(applicationContext.getString(
                        R.string.pref_update_install_automatically_key), true)
        wifiOnly =
                preferences.getBoolean(applicationContext.getString(
                        R.string.pref_update_wifi_only_key), false)
    }

    private fun loadOutdatedApplications(applicationManager: ApplicationManager) {
@@ -88,6 +92,16 @@ class UpdatesWorker(context: Context, params: WorkerParameters) : Worker(context
                        installAutomatically)
            }
            if (installAutomatically && canWriteStorage(applicationContext)) {
                if (wifiOnly) {
                    if (isConnectedToUnmeteredNetwork(applicationContext)) {
                        applications.forEach {
                            if (it.state == State.NOT_UPDATED) {
                                Log.i(TAG, "Updating ${it.packageName}")
                                it.buttonClicked(applicationContext, null)
                            }
                        }
                    }
                } else {
                    applications.forEach {
                        if (it.state == State.NOT_UPDATED) {
                            Log.i(TAG, "Updating ${it.packageName}")
@@ -96,6 +110,7 @@ class UpdatesWorker(context: Context, params: WorkerParameters) : Worker(context
                    }
                }
            }
        }
        synchronized(blocker) {
            blocker.notify()
        }
@@ -104,4 +119,16 @@ class UpdatesWorker(context: Context, params: WorkerParameters) : Worker(context
    private fun canWriteStorage(context: Context) = !(android.os.Build.VERSION.SDK_INT >= 23 &&
            context.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) !=
            PackageManager.PERMISSION_GRANTED)

    private fun isConnectedToUnmeteredNetwork(context: Context): Boolean {
        val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as
                ConnectivityManager
        return if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
            val network = connectivityManager.activeNetwork
            val capabilities = connectivityManager.getNetworkCapabilities(network)
            capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED)
        } else {
            Common.isNetworkAvailable(context)
        }
    }
}
+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="true"
            android:defaultValue="false"
            android:key="@string/pref_update_wifi_only_key"
            android:summary="@string/preference_update_wifi_only_description"
            android:title="@string/preference_update_wifi_only_title" />