~cmiller/ubuntuone-android-music/npe-in-artist-context

« back to all changes in this revision

Viewing changes to src/net/sourceforge/subsonic/androidapp/util/CacheCleaner.java

  • Committer: Chad Miller
  • Date: 2011-08-17 02:42:19 UTC
  • mfrom: (506.1.22 goog-analytics)
  • Revision ID: chad.miller@canonical.com-20110817024219-84i2hfzs1mkfbxtu
Merge new demo mode with trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
import net.sourceforge.subsonic.androidapp.service.DownloadFile;
15
15
import net.sourceforge.subsonic.androidapp.service.DownloadService;
16
16
 
 
17
import net.sourceforge.subsonic.u1m.androidapp.Analytics;
 
18
import com.google.android.apps.analytics.GoogleAnalyticsTracker;
 
19
 
17
20
import net.sourceforge.subsonic.u1m.R;
18
21
 
19
22
/**
27
30
    private final Context context;
28
31
    private final DownloadService downloadService;
29
32
    private final Handler notificationChannel;
 
33
    private GoogleAnalyticsTracker tracker;
 
34
    private long lastTrackerEvent = 0L;
30
35
 
31
36
    public CacheCleaner(Context context, DownloadService downloadService, Handler notificationChannel) {
32
37
        this.context = context;
33
38
        this.downloadService = downloadService;
34
39
        this.notificationChannel = notificationChannel;
 
40
 
 
41
        this.tracker = GoogleAnalyticsTracker.getInstance();
 
42
        this.tracker.start(Analytics.ACCOUNT, 60, context);
35
43
    }
36
44
 
37
45
    public void clean() {
53
61
        } catch (RuntimeException x) {
54
62
            Log.e(TAG, "Error in cache cleaning.", x);
55
63
            throw x;
 
64
        } finally {
 
65
            long now = System.currentTimeMillis();
 
66
            if ((now - (1000 * 60 * 10)) > this.lastTrackerEvent) {
 
67
                try {
 
68
                    this.tracker.trackEvent("System", TAG,  "StorageFreeMB", (int) FileUtil.getFilesystemAvailableMB());
 
69
                    this.lastTrackerEvent = now;
 
70
                } catch (java.io.IOException ex) {
 
71
                }
 
72
            }
56
73
        }
57
74
    }
58
75