mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-02 23:25: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:
@@ -25,7 +25,9 @@ import android.content.pm.PackageInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Build;
|
||||||
import android.support.v4.util.LruCache;
|
import android.support.v4.util.LruCache;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -61,6 +63,10 @@ public final class AlbumArtCache {
|
|||||||
* An on-disk cache for album art bitmaps.
|
* An on-disk cache for album art bitmaps.
|
||||||
*/
|
*/
|
||||||
private static DiskLruCache diskCache;
|
private static DiskLruCache diskCache;
|
||||||
|
/**
|
||||||
|
* Used to check if the connection is metered
|
||||||
|
*/
|
||||||
|
private static ConnectivityManager connectivityManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of urls yet to be fetched.
|
* A list of urls yet to be fetched.
|
||||||
@@ -100,6 +106,8 @@ public final class AlbumArtCache {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e("KDE/Mpris/AlbumArtCache", "Could not open the album art disk cache!", 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!");
|
Log.e("KDE/Mpris/AlbumArtCache", "The disk cache is not intialized!");
|
||||||
return;
|
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
|
//Only fetch an URL if we're not fetching it already
|
||||||
if (fetchUrlList.contains(url) || isFetchingList.contains(url)) {
|
if (fetchUrlList.contains(url) || isFetchingList.contains(url)) {
|
||||||
|
Reference in New Issue
Block a user