Added exception reporting for tag writing failures.

This commit is contained in:
Jan Christian Grünhage 2017-03-28 17:50:21 +02:00
parent bd7cd4d8ef
commit 3374b3f8d0
Signed by: jcgruenhage
GPG key ID: 321A67D9EE8BC3E1
3 changed files with 164 additions and 148 deletions

View file

@ -7,6 +7,11 @@ import android.net.Uri;
import android.os.PowerManager;
import android.util.Log;
import com.mpatric.mp3agic.InvalidDataException;
import com.mpatric.mp3agic.NotSupportedException;
import com.mpatric.mp3agic.UnsupportedTagException;
import java.io.IOException;
import java.util.List;
import ly.count.android.sdk.Countly;
@ -35,8 +40,7 @@ public class ExportAllService extends IntentService {
Log.i(TAG, "Intent sent!");
}
public ExportAllService()
{
public ExportAllService() {
super("AutoGPME-ExportService");
}
@ -90,19 +94,14 @@ public class ExportAllService extends IntentService {
*/
Log.i(TAG, "Automatic export failed, because the URI is invalid.");
} else throw e;
}
finally
{
if ( CPULock.isHeld())
{
CPULock.release();
} catch (Exception e) {
Countly.sharedInstance().logException(e);
e.printStackTrace();
}
}
}
}
}
if ( CPULock.isHeld())
{
if (CPULock.isHeld()) {
CPULock.release();
}
}

View file

@ -30,6 +30,12 @@ import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import com.mpatric.mp3agic.InvalidDataException;
import com.mpatric.mp3agic.NotSupportedException;
import com.mpatric.mp3agic.UnsupportedTagException;
import java.io.IOException;
import de.arcus.framework.logger.Logger;
import ly.count.android.sdk.Countly;
import re.jcg.playmusicexporter.R;
@ -201,12 +207,17 @@ public class ExportService extends IntentService {
updateNotification();
// Exports the song
try {
if (playMusicManager.exportMusicTrack(mTrackCurrent, uri, path, PlayMusicExporterPreferences.getFileOverwritePreference())) {
Countly.sharedInstance().recordEvent("Exported Song", 1);
} else {
// Export failed
mTracksFailed ++;
}
} catch (Exception e) {
Countly.sharedInstance().logException(e);
e.printStackTrace();
}
} else {
// Export failed
mTracksFailed ++;

View file

@ -44,7 +44,10 @@ import com.mpatric.mp3agic.ID3v2;
import com.mpatric.mp3agic.ID3v22Tag;
import com.mpatric.mp3agic.ID3v23Tag;
import com.mpatric.mp3agic.ID3v24Tag;
import com.mpatric.mp3agic.InvalidDataException;
import com.mpatric.mp3agic.Mp3File;
import com.mpatric.mp3agic.NotSupportedException;
import com.mpatric.mp3agic.UnsupportedTagException;
import java.io.ByteArrayOutputStream;
import java.io.File;
@ -138,6 +141,7 @@ public class PlayMusicManager {
/**
* The database will be copied to a temp folder to access from the app
*
* @return Gets the temp path to the database
*/
private String getTempDatabasePath() {
@ -297,6 +301,7 @@ public class PlayMusicManager {
/**
* Creates a new PlayMusic manager
*
* @param context App context
*/
public PlayMusicManager(Context context) {
@ -307,6 +312,7 @@ public class PlayMusicManager {
/**
* Loads all needed information and opens the database
*
* @throws PlayMusicNotFoundException PlayMusic is not installed
* @throws NoSuperUserException No super user permissions
* @throws CouldNotOpenDatabaseException Could not open the database
@ -345,6 +351,7 @@ public class PlayMusicManager {
/**
* Copies the database to a temp directory and opens it
*
* @throws NoSuperUserException No super user permissions
* @throws de.arcus.playmusiclib.exceptions.CouldNotOpenDatabaseException Could not open the database
*/
@ -370,6 +377,7 @@ public class PlayMusicManager {
/**
* Reloads the database from PlayMusic
*
* @throws NoSuperUserException No super user permissions
* @throws CouldNotOpenDatabaseException Could not open the database
*/
@ -403,6 +411,7 @@ public class PlayMusicManager {
/**
* Gets the path to the music track
*
* @param localCopyPath The local copy path
* @return The path to the music file
*/
@ -437,6 +446,7 @@ public class PlayMusicManager {
/**
* Gets the full path to the artwork
*
* @param artworkPath The artwork path
* @return The full path to the artwork
*/
@ -469,12 +479,13 @@ public class PlayMusicManager {
/**
* Exports a track to the sd card
*
* @param musicTrack The music track you want to export
* @param dest The destination path
* @param forceOverwrite Forces overwrite of the destination file
* @return Returns whether the export was successful
*/
public boolean exportMusicTrack(MusicTrack musicTrack, String dest, boolean forceOverwrite ) {
public boolean exportMusicTrack(MusicTrack musicTrack, String dest, boolean forceOverwrite) throws InvalidDataException, IOException, UnsupportedTagException, NotSupportedException {
// Creates the destination directory
File directory = new File(dest).getParentFile();
@ -487,12 +498,13 @@ public class PlayMusicManager {
/**
* Exports a track to the sd card
*
* @param musicTrack The music track you want to export
* @param uri The document tree
* @param forceOverwrite Forces overwrite of the destination file
* @return Returns whether the export was successful
*/
public boolean exportMusicTrack(MusicTrack musicTrack, Uri uri, String path, boolean forceOverwrite) {
public boolean exportMusicTrack(MusicTrack musicTrack, Uri uri, String path, boolean forceOverwrite) throws InvalidDataException, IOException, UnsupportedTagException, NotSupportedException {
// Check for null
if (musicTrack == null) return false;
@ -504,8 +516,7 @@ public class PlayMusicManager {
String uniqueID = UUID.randomUUID().toString();
if ( forceOverwrite || !isAlreadyThere(uri, path) )
{
if (forceOverwrite || !isAlreadyThere(uri, path)) {
String fileTmp = getTempPath() + uniqueID + "_tmp.mp3";
@ -530,7 +541,6 @@ public class PlayMusicManager {
}
String dest;
Uri copyUri = null;
if (uri.toString().startsWith("file://")) {
@ -669,6 +679,7 @@ public class PlayMusicManager {
/**
* Checks if the destination file already exists
*
* @param pUri the source file
* @param pPath The destination
* return true if the file already exists
@ -699,13 +710,13 @@ public class PlayMusicManager {
/**
* Copies the music file to a new path and adds the mp3 meta data
*
* @param musicTrack Track information
* @param src The source mp3 file
* @param dest The destination path
* return Return if the operation was successful
*/
private boolean trackWriteID3(MusicTrack musicTrack, String src, String dest) {
try {
private boolean trackWriteID3(MusicTrack musicTrack, String src, String dest) throws InvalidDataException, IOException, UnsupportedTagException, NotSupportedException {
// Opens the mp3
Mp3File mp3File = new Mp3File(src);
@ -802,16 +813,11 @@ public class PlayMusicManager {
// Done
return true;
} catch (Exception e) {
Logger.getInstance().logError("TrackWriteId3", e.toString());
}
// Failed
return false;
}
/**
* Encrypts a track and save it to a new path
*
* @param musicTrack The music track
* @param src The source mp3 file
* @param dest The destination path