mirror of
https://github.com/playmusicexporter/playmusicexporter
synced 2024-05-15 13:46:42 +00:00
Trying to prevent deep sleeping during big exports. (export would totally stall, and then resume when device was woken up). Not really what was wanted. Testing this out....
This commit is contained in:
parent
6529c82896
commit
b503cfb966
|
@ -25,6 +25,7 @@
|
|||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
|
|
|
@ -22,8 +22,10 @@
|
|||
|
||||
package re.jcg.playmusicexporter.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.PowerManager;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.TextUtils;
|
||||
|
@ -63,6 +65,7 @@ public class MusicTrackListFragment extends Fragment {
|
|||
*/
|
||||
public static final String ARG_MUSIC_TRACK_LIST_ID = "music_track_list_id";
|
||||
public static final String ARG_MUSIC_TRACK_LIST_TYPE = "music_track_list_type";
|
||||
private PowerManager.WakeLock m_CPULock;
|
||||
|
||||
/**
|
||||
* The track list
|
||||
|
@ -138,6 +141,8 @@ public class MusicTrackListFragment extends Fragment {
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
PowerManager powerManager = (PowerManager)this.getContext().getSystemService(Context.POWER_SERVICE);
|
||||
m_CPULock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ExportAllService");
|
||||
if (getArguments().containsKey(ARG_MUSIC_TRACK_LIST_ID)
|
||||
&& getArguments().containsKey(ARG_MUSIC_TRACK_LIST_TYPE)) {
|
||||
|
||||
|
@ -213,12 +218,19 @@ public class MusicTrackListFragment extends Fragment {
|
|||
mFloatingButtonExport = (FloatingActionButton) rootView.findViewById(R.id.floating_button_export);
|
||||
mFloatingButtonExport.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
public void onClick(View v)
|
||||
{
|
||||
m_CPULock.acquire();
|
||||
// Export all selected tracks
|
||||
for (SelectedTrack selectedTrack : SelectedTrackList.getInstance().getSelectedItems()) {
|
||||
selectedTrack.export(getActivity());
|
||||
}
|
||||
|
||||
if ( m_CPULock.isHeld())
|
||||
{
|
||||
m_CPULock.release();
|
||||
}
|
||||
|
||||
// Clear the selection
|
||||
SelectedTrackList.getInstance().clear(true);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.app.IntentService;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.PowerManager;
|
||||
import android.support.v4.provider.DocumentFile;
|
||||
import android.util.Log;
|
||||
|
||||
|
@ -24,6 +25,7 @@ public class ExportAllService extends IntentService {
|
|||
public static final String TAG = "AutoGPME_ExportService";
|
||||
public static final String ACTION_EXPORT = "re.jcg.playmusicexporter.action.EXPORT";
|
||||
public static final String ACTION_SET_EXPORT_JOB = "re.jcg.playmusicexporter.action.SET_EXPORT_JOB";
|
||||
private PowerManager.WakeLock m_CPULock;
|
||||
|
||||
public static void startExport(Context pContext) {
|
||||
Intent lIntent = new Intent(pContext, ExportAllService.class);
|
||||
|
@ -32,8 +34,11 @@ public class ExportAllService extends IntentService {
|
|||
Log.i(TAG, "Intent sent!");
|
||||
}
|
||||
|
||||
public ExportAllService() {
|
||||
public ExportAllService()
|
||||
{
|
||||
super("AutoGPME-ExportService");
|
||||
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
|
||||
m_CPULock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ExportAllService");
|
||||
}
|
||||
|
||||
protected void onHandleIntent(Intent intent) {
|
||||
|
@ -62,6 +67,7 @@ public class ExportAllService extends IntentService {
|
|||
Log.i(TAG, lUri.toString());
|
||||
AlbumDataSource lAlbumDataSource = new AlbumDataSource(lPlayMusicManager);
|
||||
lAlbumDataSource.setOfflineOnly(true);
|
||||
m_CPULock.acquire();
|
||||
List<Album> lAlba = lAlbumDataSource.getAll();
|
||||
for (Album lAlbum : lAlba) {
|
||||
for (MusicTrack lTrack : lAlbum.getMusicTrackList()) {
|
||||
|
@ -84,9 +90,20 @@ public class ExportAllService extends IntentService {
|
|||
Log.i(TAG, "Automatic export failed, because the URI is invalid.");
|
||||
} else throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if ( m_CPULock.isHeld())
|
||||
{
|
||||
m_CPULock.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( m_CPULock.isHeld())
|
||||
{
|
||||
m_CPULock.release();
|
||||
}
|
||||
}
|
||||
|
||||
private String getStringForTrack(MusicTrack pTrack) {
|
||||
|
|
Loading…
Reference in a new issue