2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-30 21:55:10 +00:00

Disables album art download on metered connections (e.g. 4G)

Summary: Won't typically be a problem (you're usually connected via wifi with KDE Connect anyway), but shouldn't hurt.

Test Plan: Works with the bluetooth backend on 4G (i.e. no album art is downloaded). Still downloads album art otherwise, as expected.

Reviewers: #kde_connect, nicolasfella

Reviewed By: #kde_connect, nicolasfella

Subscribers: #kde_connect

Differential Revision: https://phabricator.kde.org/D11682
This commit is contained in:
Matthijs Tijink
2018-03-25 15:47:13 +02:00
parent 64fd08f3ac
commit 7c8301a7cc

View File

@@ -25,7 +25,9 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.ConnectivityManager;
import android.os.AsyncTask;
import android.os.Build;
import android.support.v4.util.LruCache;
import android.util.Log;
@@ -61,6 +63,10 @@ public final class AlbumArtCache {
* An on-disk cache for album art bitmaps.
*/
private static DiskLruCache diskCache;
/**
* Used to check if the connection is metered
*/
private static ConnectivityManager connectivityManager;
/**
* A list of urls yet to be fetched.
@@ -100,6 +106,8 @@ public final class AlbumArtCache {
} catch (IOException e) {
Log.e("KDE/Mpris/AlbumArtCache", "Could not open the album art disk cache!", e);
}
connectivityManager = (ConnectivityManager) context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
}
/**
@@ -217,6 +225,12 @@ public final class AlbumArtCache {
Log.e("KDE/Mpris/AlbumArtCache", "The disk cache is not intialized!");
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
//Only download art on unmetered networks (wifi etc.)
if (connectivityManager.isActiveNetworkMetered()) {
return;
}
}
//Only fetch an URL if we're not fetching it already
if (fetchUrlList.contains(url) || isFetchingList.contains(url)) {