Fixes for #30 and #25, as well as some other little things:

- Disabled JACK Toolchain, moved to native Java 8 support instead.
 - Updated gradle plugin from 2.3 to 2.4-alpha6
 - Removed the paragraph about bithub from the README
 - Rephrased some things about why 5.0 is minimum
 - Made analytics opt-in on first launch
 - Extracted strings from the intro
 - Added [LeakCanary](https://github.com/square/leakcanary)
This commit is contained in:
Jan Christian Grünhage 2017-04-22 15:40:29 +02:00
parent 1861adfd22
commit 204829ac5b
Signed by: jcgruenhage
GPG Key ID: 321A67D9EE8BC3E1
15 changed files with 179 additions and 73 deletions

View File

@ -19,8 +19,9 @@ There is also a nice library you can simply use in your projects.
**This app and the included library will require root access to your device!
If your device is not rooted you can neither use this app nor the library.**
This app uses API Level 21, which has been introduced by Android Lollipop. If you use KitKat
or lower, this app will not work.
This app uses multiple features introduced in API Level 21 (Android 5.0 Lollipop), the JobScheduler
and the the folder selection of the storage access framework.
If you use KitKat or lower, this app will not work.
### Credits
@ -57,8 +58,6 @@ If you are unable to do that, but you still want to support this project, you co
I will distribute bitcoins send to me to others helping on the project too, so that other people contributing also have a piece of the cake.
I might later set up [BitHub](https://github.com/WhisperSystems/BitHub) for this purpose later (if there are a lot of donations to distribute), but this project is a little small for that, and BitHub works based on the commit count only, which I would like to modify before setting that up.
### Copyright
Copyright (c) 2016 Jan Christian Grünhage. See LICENSE.txt for details.

View File

@ -27,7 +27,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:2.4.0-alpha6'
}
}

View File

@ -1,9 +1,5 @@
package de.arcus.framework.superuser;
/**
* Created by jcgruenhage on 1/18/17.
*/
public interface SuperUserPermissionRequestListener {
void superUserGranted(boolean granted);
}

View File

@ -22,6 +22,8 @@
package de.arcus.framework.utils;
import android.os.Environment;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@ -42,10 +44,12 @@ public class FileTools {
/**
* Private constructor
*/
private FileTools() {}
private FileTools() {
}
/**
* Creates a directory if it not exists
*
* @param dir Directory path
* @return Returns true if the directory was created or already exists
*/
@ -75,6 +79,7 @@ public class FileTools {
/**
* Checks if the directory exists
*
* @param dir Path of the file
* @return Return whether the directory exists
*/
@ -87,6 +92,7 @@ public class FileTools {
/**
* Creates an empty file
*
* @param file File path
* @return Returns true if the file was successfully created
*/
@ -98,7 +104,7 @@ public class FileTools {
return (new File(file)).createNewFile();
} catch (IOException e) {
// Failed
Logger.getInstance().logError("FileCreate", "Could not create file: " + e.getMessage());
Logger.getInstance().logError("FileCreate", "Could not create file: " + e.getMessage());
return false;
}
@ -106,7 +112,8 @@ public class FileTools {
/**
* Moves a file
* @param src Soruce path
*
* @param src Soruce path
* @param dest Destination path
* @return Return whether the moving was successful
*/
@ -122,7 +129,8 @@ public class FileTools {
/**
* Copies a stream
* @param inputStream Source stream
*
* @param inputStream Source stream
* @param outputStream Destination stream
* @return Return whether the stream was copied successful
*/
@ -155,7 +163,8 @@ public class FileTools {
/**
* Copies a file
* @param src Source path
*
* @param src Source path
* @param dest Destination path
* @return Return whether the file was copied successful
*/
@ -195,6 +204,7 @@ public class FileTools {
/**
* Deletes a file
*
* @param file Path of the file
* @return Returns whether the deleting was successful
*/
@ -205,6 +215,7 @@ public class FileTools {
/**
* Checks if the file exists
*
* @param file Path of the file
* @return Return whether the file exists
*/
@ -217,6 +228,7 @@ public class FileTools {
/**
* Checks whether the file or directory is a link
*
* @param path Path of the file / directory
* @return Returns whether the file or directory is a link
*/
@ -235,6 +247,7 @@ public class FileTools {
/**
* Gets the root canonical file of a symbolic link
*
* @param path The path
* @return The root file
*/
@ -244,6 +257,7 @@ public class FileTools {
/**
* Gets the root canonical file of a symbolic link
*
* @param file The file
* @return The root file
*/
@ -269,19 +283,20 @@ public class FileTools {
/**
* Gets all storages; eg. all sdcards
*
* @return List of all storages
*/
public static String[] getStorages() {
List<String> storages = new ArrayList<>();
// Hard coded mount points
final String[] mountPointBlacklist = new String[] { "/mnt/tmp", "/mnt/factory", "/mnt/obb", "/mnt/asec", "/mnt/secure", "/mnt/media_rw", "/mnt/shell", "/storage/emulated" };
final String[] mountPointDirectories = new String[] { "/mnt", "/storage" };
final String[] mountPoints = new String[] { "/sdcard", "/external_sd" };
final String[] mountPointBlacklist = new String[]{"/mnt/tmp", "/mnt/factory", "/mnt/obb", "/mnt/asec", "/mnt/secure", "/mnt/media_rw", "/mnt/shell", "/storage/emulated"};
final String[] mountPointDirectories = new String[]{"/mnt", "/storage"};
final String[] mountPoints = new String[]{Environment.getExternalStorageDirectory().getAbsolutePath(), "/external_sd"};
// Adds all mount point directories
for(String mountPointDirectory : mountPointDirectories) {
for (String mountPointDirectory : mountPointDirectories) {
// Checks all subdirectories
File dir = getRootCanonicalFile(mountPointDirectory);
if (dir.exists() && dir.isDirectory()) {
@ -301,7 +316,7 @@ public class FileTools {
}
// Adds all direct mount points
for(String mountPoint : mountPoints) {
for (String mountPoint : mountPoints) {
File file = getRootCanonicalFile(mountPoint);
if (file.isDirectory() && file.canRead()) {
if (!storages.contains(file.getAbsolutePath()))

View File

@ -35,9 +35,6 @@ android {
versionName '0.9.6.0'
vectorDrawables.useSupportLibrary = true
jackOptions {
enabled true
}
buildConfigField "java.util.Date", "BUILD_TIME", "new java.util.Date(" + System.currentTimeMillis() + "L)"
}
buildTypes {
@ -62,4 +59,7 @@ dependencies {
compile 'com.android.support:support-vector-drawable:25.3.1'
compile 'com.github.paolorotolo:appintro:4.1.0'
compile 'ly.count.android:sdk:16.12.2'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
}

View File

@ -33,7 +33,8 @@
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:name=".PlayMusicExporter">
<activity
android:name=".activities.MusicContainerListActivity"
android:label="@string/app_name">

View File

@ -0,0 +1,24 @@
package re.jcg.playmusicexporter;
import android.app.Application;
import com.squareup.leakcanary.LeakCanary;
/**
* Android Application.
* Normally, we would not need to extend this, but it is required for
* the leak detection library we use.
* See {@link LeakCanary}
*/
public class PlayMusicExporter extends Application {
@Override public void onCreate() {
super.onCreate();
if (LeakCanary.isInAnalyzerProcess(this)) {
// This process is dedicated to LeakCanary for heap analysis.
// You should not init your app in this process.
return;
}
LeakCanary.install(this);
}
}

View File

@ -1,9 +1,9 @@
package re.jcg.playmusicexporter.activities;
import android.Manifest;
import android.app.Dialog;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
@ -29,49 +29,41 @@ public class Intro extends AppIntro {
Fragment warning;
Fragment storage;
Fragment superuser;
Fragment error;
Fragment finish;
private void initFragments() {
int color = ContextCompat.getColor(this, R.color.application_main);
welcome = AppIntroFragment.newInstance(
"Welcome!",
"This is the Play Music Exporter. It can export songs from Play Music " +
"and save them as MP3 files where you want them to be.",
getString(R.string.intro_welcome_title),
getString(R.string.intro_welcome_description),
R.drawable.ic_launcher_transparent,
Color.parseColor("#ef6c00"));
color);
warning = AppIntroFragment.newInstance(
"Warning!",
"You are responsible for what you do with this app. Depending on where you live " +
"it might be illegal to use this app. We discourage piracy of music " +
"and other intellectual property. Sharing music you exported with " +
"this tool might be a very bad idea, Google could put an invisible " +
"watermark on the music, so that people can trace the MP3s back to " +
"the owner of the Google account that was used.",
getString(R.string.intro_warning_title),
getString(R.string.intro_warning_description),
R.drawable.ic_warning_white,
Color.parseColor("#ef6c00"));
color);
storage = AppIntroFragment.newInstance(
"We need access to your storage.",
"We need to access the external storage, " +
"for copying the Play Music database to a folder," +
"where we have the right to work with it. " +
"We also need access to the external storage," +
"to finish up the MP3s, from encrypted without ID3 tags," +
"to decrypted with ID3 tags, before we save them to your export path.",
getString(R.string.intro_storage_title),
getString(R.string.intro_storage_description),
R.drawable.ic_folder_white,
Color.parseColor("#ef6c00"));
color);
superuser = AppIntroFragment.newInstance(
"We need root access.",
"Some of the files we need to access are in the private folders of Play Music. " +
"Android prevents apps from accessing the private folders " +
"of other apps, but luckily, you can circumvent this protection " +
"with root access. Without root access this app can't do anything.",
getString(R.string.intro_superuser_title),
getString(R.string.intro_superuser_description),
R.drawable.ic_superuser,
Color.parseColor("#ef6c00"));
color);
error = AppIntroFragment.newInstance(
getString(R.string.intro_error_title),
getString(R.string.intro_error_description),
R.drawable.ic_error_white,
color);
finish = AppIntroFragment.newInstance(
"Tutorial finished!",
"One note: Should you revoke any of these permission, the tutorial will be " +
"shown again on the next launch.",
getString(R.string.intro_finish_title),
getString(R.string.intro_finish_description),
R.drawable.ic_launcher_transparent,
Color.parseColor("#ef6c00"));
color);
}
@Override
@ -87,6 +79,7 @@ public class Intro extends AppIntro {
addSlide(warning);
addSlide(storage);
addSlide(superuser);
addSlide(error);
addSlide(finish);
pager.setPagingEnabled(true);
@ -100,7 +93,7 @@ public class Intro extends AppIntro {
promptAcceptWarning();
} else if (storage.equals(oldFragment) && superuser.equals(newFragment)) {
requestStoragePermission();
} else if (superuser.equals(oldFragment) && finish.equals(newFragment)) {
} else if (superuser.equals(oldFragment) && error.equals(newFragment)) {
SuperUser.askForPermissionInBackground(granted -> {
if (!granted) {
AlertDialog.Builder builder =
@ -113,9 +106,30 @@ public class Intro extends AppIntro {
builder.show();
}
});
} else if (error.equals(oldFragment) && finish.equals(newFragment)) {
promptEnableErrorReporting();
}
}
private void promptEnableErrorReporting() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
Dialog.OnClickListener enable = (dialog, which) -> {
PlayMusicExporterPreferences.setReportStats(true);
dialog.dismiss();
};
Dialog.OnClickListener disable = (dialog, which) -> {
PlayMusicExporterPreferences.setReportStats(false);
dialog.dismiss();
};
builder.setTitle(R.string.error_alert_dialog_title);
builder.setMessage(R.string.error_alert_dialog_message);
builder.setCancelable(false);
builder.setNegativeButton(R.string.no, disable);
builder.setNeutralButton(R.string.whatever, enable);
builder.setPositiveButton(R.string.yes, enable);
builder.show();
}
private void requestStoragePermission() {
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
@ -151,12 +165,12 @@ public class Intro extends AppIntro {
private void promptAcceptWarning() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Understood?");
builder.setMessage("Have you read and understood this?");
builder.setTitle(R.string.warning_alert_dialog_title);
builder.setMessage(R.string.warning_alert_dialog_message);
builder.setCancelable(false);
builder.setNegativeButton("No", ((dialog, which)
builder.setNegativeButton(getString(R.string.no), ((dialog, which)
-> pager.setCurrentItem(pager.getCurrentItem() - 1)));
builder.setPositiveButton("Yes", (((dialog, which) -> dialog.dismiss())));
builder.setPositiveButton(getString(R.string.no), (((dialog, which) -> dialog.dismiss())));
builder.show();
}

View File

@ -108,17 +108,15 @@ public class MusicContainerListActivity extends AppCompatActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Countly.sharedInstance().init(this, getString(R.string.countly_url), getString(R.string.countly_token), null, DeviceId.Type.OPEN_UDID);
Countly.sharedInstance().enableCrashReporting();
PlayMusicExporterPreferences.init(this);
if (!PlayMusicExporterPreferences.getSetupDone()) {
startActivity(new Intent(this, Intro.class));
finish();
} else {
if (PlayMusicExporterPreferences.getReportStats()) {
Countly.sharedInstance().init(this, getString(R.string.countly_url), getString(R.string.countly_token), null, DeviceId.Type.OPEN_UDID);
Countly.sharedInstance().enableCrashReporting();
}
setContentView(R.layout.activity_track_list);
@ -379,12 +377,14 @@ public class MusicContainerListActivity extends AppCompatActivity
@Override
public void onStart() {
super.onStart();
Countly.sharedInstance().onStart(this);
if (PlayMusicExporterPreferences.getReportStats())
Countly.sharedInstance().onStart(this);
}
@Override
public void onStop() {
Countly.sharedInstance().onStop();
if (PlayMusicExporterPreferences.getReportStats())
Countly.sharedInstance().onStop();
super.onStop();
}
}

View File

@ -75,7 +75,8 @@ public class ExportAllService extends IntentService {
try {
if (lPlayMusicManager.exportMusicTrack(lTrack, lUri, lPath, PlayMusicExporterPreferences.getFileOverwritePreference())) {
Log.i(TAG, "Exported Music Track: " + getStringForTrack(lTrack));
Countly.sharedInstance().recordEvent("Exported Song", 1);
if (PlayMusicExporterPreferences.getReportStats())
Countly.sharedInstance().recordEvent("Exported Song", 1);
} else {
Log.i(TAG, "Failed to export Music Track: " + getStringForTrack(lTrack));
}
@ -90,7 +91,8 @@ public class ExportAllService extends IntentService {
Log.i(TAG, "Automatic export failed, because the URI is invalid.");
} else throw e;
} catch (Exception e) {
Countly.sharedInstance().logException(e);
if (PlayMusicExporterPreferences.getReportStats())
Countly.sharedInstance().logException(e);
e.printStackTrace();
}
}

View File

@ -203,13 +203,15 @@ public class ExportService extends IntentService {
// Exports the song
try {
if (playMusicManager.exportMusicTrack(mTrackCurrent, uri, path, PlayMusicExporterPreferences.getFileOverwritePreference())) {
Countly.sharedInstance().recordEvent("Exported Song", 1);
if (PlayMusicExporterPreferences.getReportStats())
Countly.sharedInstance().recordEvent("Exported Song", 1);
} else {
// Export failed
mTracksFailed ++;
}
} catch (Exception e) {
Countly.sharedInstance().logException(e);
if (PlayMusicExporterPreferences.getReportStats())
Countly.sharedInstance().logException(e);
e.printStackTrace();
}
} else {

View File

@ -7,6 +7,7 @@ import android.net.Uri;
import android.os.Environment;
import android.preference.PreferenceManager;
import re.jcg.playmusicexporter.BuildConfig;
import re.jcg.playmusicexporter.fragments.NavigationDrawerFragment;
public class PlayMusicExporterPreferences {
@ -49,6 +50,9 @@ public class PlayMusicExporterPreferences {
public static final String SETUP_DONE = "preference_setup_done";
public static final boolean SETUP_DONE_DEFAULT = false;
public static final String REPORT_STATS = "preference_report_stats";
public static final boolean REPORT_STATS_DEFAULT = true;
private PlayMusicExporterPreferences() {
}
@ -175,4 +179,13 @@ public class PlayMusicExporterPreferences {
public static void setAlbumArtSize(int size) {
preferences.edit().putString(EXPORT_ALBUM_ART_SIZE, "" + size).apply();
}
public static boolean getReportStats() {
//Never report stats in debug builds
return preferences.getBoolean(REPORT_STATS, REPORT_STATS_DEFAULT) && !BuildConfig.DEBUG;
}
public static void setReportStats(boolean reportStats) {
preferences.edit().putBoolean(REPORT_STATS, reportStats).apply();
}
}

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="240dp"
android:height="240dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-2h2v2zM13,13h-2L11,7h2v6z"/>
</vector>

View File

@ -122,7 +122,7 @@
<string name="settings_open_old_homepage_url" translatable="false"><![CDATA[http://www.david-schulte.de/]]></string>
<string name="settings_open_homepage_title" translatable="false">Website</string>
<string name="settings_open_homepage_url" translatable="false"><![CDATA[https://jcg.re/]]></string>
<string name="settings_open_homepage_url" translatable="false"><![CDATA[https://github.com/jcgruenhage/PlayMusicExporter]]></string>
<string name="settings_mp3agic_title" translatable="false">Mp3agic ID3 Libary</string>
<string name="settings_mp3agic_summery" translatable="false">Michael Patricios &#169; 2006&#8211;2013</string>
@ -149,4 +149,26 @@
<string name="action_refesh">Refresh</string>
<string name="database_reloaded">Music Database Reloaded</string>
<string name="debug_test_crash_handler">Test Crash Handler</string>
<string name="settings_donation_title">Support me</string>
<string name="settings_donation_summery">Donate to the current developer via Bitcoin. This requires that you have installed a bitcoin wallet on your phone. For donations from a computer, see the homepage.</string>
<string name="settings_donation_url"><![CDATA[bitcoin:1NdzpDWPQ53xWT5fraGPZX5F9XrKiPBXjp]]></string>
<string name="intro_welcome_title">Welcome!</string>
<string name="intro_welcome_description">This is the Play Music Exporter. It can export songs from Play Music and save them as MP3 files where you want them to be.</string>
<string name="intro_warning_title">Warning!</string>
<string name="intro_warning_description">You are responsible for what you do with this app. Depending on where you live it might be illegal to use this app. We discourage piracy of music and other intellectual property. Sharing music you exported with this tool might be a very bad idea, Google could put an invisible watermark on the music, so that people can trace the MP3s back to the owner of the Google account that was used.</string>
<string name="intro_storage_title">We need access to your storage.</string>
<string name="intro_storage_description">We need to access the external storage, for copying the Play Music database to a folder, where we have the right to work with it. We also need access to the external storage, to finish up the MP3s, from encrypted without ID3 tags, to decrypted with ID3 tags, before we save them to your export path.</string>
<string name="intro_superuser_description">Some of the files we need to access are in the private folders of Play Music. Android prevents apps from accessing the private folders of other apps, but luckily, you can circumvent this protection with root access. Without root access this app can\'t do anything.</string>
<string name="intro_superuser_title">We need root access.</string>
<string name="intro_error_description">No single piece of software is perfect. To get this closer though, we have added automated error reporting to this app. If you would like to help make this app better, let us enable that. If you don\'t enable this and something does not work, you are on your own, since we can\'t help you without having the logs this provides us with. The data collected by this does not include anything that could be used to identify you. (You will be prompted to either accept or deny that when you go to the next slide)</string>
<string name="intro_error_title">Anonymous error reporting.</string>
<string name="intro_finish_description">One note: Should you revoke any of these permission, the tutorial will be shown again on the next launch.</string>
<string name="intro_finish_title">Introduction finished!</string>
<string name="error_alert_dialog_title">Anonymous error reporting?</string>
<string name="error_alert_dialog_message">In order to make this app better, please enable automatic crash reporting. You wont ever get any help, if you disable this, since we can\'t fix bugs without the logs provided by this. The data collected by this does not include anything that could be used to identify you.</string>
<string name="no">No</string>
<string name="yes">Yes</string>
<string name="whatever">I don\'t care, just let me use the app!</string>
<string name="warning_alert_dialog_title">Understood?</string>
<string name="warning_alert_dialog_message">Have you read and understood this?</string>
</resources>

View File

@ -12,7 +12,7 @@
</Preference>
</PreferenceCategory>
<!-- About David Schulte -->
<!-- About this project -->
<PreferenceCategory android:title="@string/settings_category_about_me">
<!-- Homepage -->
<Preference
@ -22,6 +22,15 @@
android:action="android.intent.action.VIEW"
android:data="@string/settings_open_homepage_url" />
</Preference>
<!-- Donation -->
<Preference
android:summary="@string/settings_donation_summery"
android:title="@string/settings_donation_title">
<intent
android:action="android.intent.action.VIEW"
android:data="@string/settings_donation_url" />
</Preference>
</PreferenceCategory>
<!-- About David Schulte -->