diff --git a/framework/build.gradle b/framework/build.gradle index fa5dad6..8d078a4 100644 --- a/framework/build.gradle +++ b/framework/build.gradle @@ -27,7 +27,7 @@ android { buildToolsVersion "25.0.2" defaultConfig { - minSdkVersion 9 + minSdkVersion 11 targetSdkVersion 25 versionCode 1 versionName "1.0" diff --git a/framework/framework.iml b/framework/framework.iml index 61fb842..9a58259 100644 --- a/framework/framework.iml +++ b/framework/framework.iml @@ -63,13 +63,6 @@ - - - - - - - @@ -77,6 +70,13 @@ + + + + + + + diff --git a/framework/src/main/java/de/arcus/framework/superuser/SuperUser.java b/framework/src/main/java/de/arcus/framework/superuser/SuperUser.java index 92df8e7..3976165 100644 --- a/framework/src/main/java/de/arcus/framework/superuser/SuperUser.java +++ b/framework/src/main/java/de/arcus/framework/superuser/SuperUser.java @@ -22,6 +22,8 @@ package de.arcus.framework.superuser; +import android.os.AsyncTask; + import java.io.IOException; import de.arcus.framework.logger.Logger; @@ -130,4 +132,20 @@ public class SuperUser { sessionStop(); return false; } + + public static void askForPermissionInBackground(final SuperUserPermissionRequestListener listener) { + new AsyncTask() { + boolean hasPermissions; + @Override + protected Void doInBackground(Void... params) { + hasPermissions = askForPermissions(); + return null; + } + + @Override + protected void onPostExecute(Void result) { + listener.superUserGranted(hasPermissions); + } + }.execute(); + } } diff --git a/framework/src/main/java/de/arcus/framework/superuser/SuperUserPermissionRequestListener.java b/framework/src/main/java/de/arcus/framework/superuser/SuperUserPermissionRequestListener.java new file mode 100644 index 0000000..a70534a --- /dev/null +++ b/framework/src/main/java/de/arcus/framework/superuser/SuperUserPermissionRequestListener.java @@ -0,0 +1,9 @@ +package de.arcus.framework.superuser; + +/** + * Created by jcgruenhage on 1/18/17. + */ + +public interface SuperUserPermissionRequestListener { + void superUserGranted(boolean granted); +} diff --git a/gradle.properties b/gradle.properties index 38ba071..30f3946 100644 --- a/gradle.properties +++ b/gradle.properties @@ -32,7 +32,7 @@ # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. # Default value: -Xmx10248m -XX:MaxPermSize=256m -# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit diff --git a/playmusicexporter/playmusicexporter.iml b/playmusicexporter/playmusicexporter.iml index beffcb2..168f989 100644 --- a/playmusicexporter/playmusicexporter.iml +++ b/playmusicexporter/playmusicexporter.iml @@ -62,13 +62,6 @@ - - - - - - - @@ -76,6 +69,13 @@ + + + + + + + diff --git a/playmusicexporter/src/main/java/re/jcg/playmusicexporter/activities/Intro.java b/playmusicexporter/src/main/java/re/jcg/playmusicexporter/activities/Intro.java index 91a7a3c..3676a14 100644 --- a/playmusicexporter/src/main/java/re/jcg/playmusicexporter/activities/Intro.java +++ b/playmusicexporter/src/main/java/re/jcg/playmusicexporter/activities/Intro.java @@ -2,11 +2,15 @@ package re.jcg.playmusicexporter.activities; import android.Manifest; import android.content.Intent; +import android.content.pm.PackageManager; import android.graphics.Color; +import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; import android.support.annotation.Nullable; +import android.support.v4.app.ActivityCompat; import android.support.v4.app.Fragment; +import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; import android.util.Log; @@ -21,10 +25,10 @@ import re.jcg.playmusicexporter.settings.PlayMusicExporterPreferences; public class Intro extends AppIntro { private static final String TAG = "PME_Intro"; + private static final int PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 1; Fragment welcome; Fragment warning; Fragment storage; - Fragment internet; Fragment superuser; Fragment finish; @@ -55,19 +59,6 @@ public class Intro extends AppIntro { "to decrypted with ID3 tags, before we save them to your export path.", R.drawable.ic_folder_white, Color.parseColor("#ef6c00")); - - //Internet Access is granted automatically, asking for it is automatically granted, - //which is unacceptable in my opinion, but why should Google care. - internet = AppIntroFragment.newInstance( - "We might need internet access.", - "It happens that we can not find the cover of a song locally. " + - "In these cases, we can, if you grant us permission to use the internet, " + - "download the cover from online. " + - "If you don't grant us permission to use the internet, " + - "we can still export songs, but the cover will be " + - "missing on some songs.", - R.drawable.ic_cloud_download_white, - Color.parseColor("#ef6c00")); superuser = AppIntroFragment.newInstance( "We need root access.", "Some of the files we need to access are in the private folders of Play Music. " + @@ -99,8 +90,6 @@ public class Intro extends AppIntro { addSlide(superuser); addSlide(finish); - askForPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 3); - pager.setPagingEnabled(true); } @@ -110,8 +99,54 @@ public class Intro extends AppIntro { logSlideChanged(oldFragment, newFragment); if (warning.equals(oldFragment) && storage.equals(newFragment)) { promptAcceptWarning(); + } else if (storage.equals(oldFragment) && superuser.equals(newFragment)) { + requestStoragePermission(); } else if (superuser.equals(oldFragment) && finish.equals(newFragment)) { - SuperUser.askForPermissions(); + SuperUser.askForPermissionInBackground(granted -> { + if (!granted) { + AlertDialog.Builder builder = + new AlertDialog.Builder(this); + builder.setTitle(R.string.dialog_superuser_access_denied_title); + builder.setMessage(R.string.dialog_superuser_access_denied); + builder.setCancelable(false); + builder.setPositiveButton(R.string.text_okay, (dialog, which) + -> pager.setCurrentItem(pager.getCurrentItem() - 1)); + builder.show(); + } + }); + } + } + + private void requestStoragePermission() { + if (ContextCompat.checkSelfPermission(this, + Manifest.permission.WRITE_EXTERNAL_STORAGE) + != PackageManager.PERMISSION_GRANTED) { + + ActivityCompat.requestPermissions(this, + new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, + PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE); + } + } + + @Override + public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { + switch (requestCode) { + case PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE: { + // If request is cancelled, the result arrays are empty. + if (!(grantResults.length > 0 + && grantResults[0] == PackageManager.PERMISSION_GRANTED)) { + // Shows a warning and close the app + AlertDialog.Builder builder = + new AlertDialog.Builder(this); + builder.setTitle(R.string.dialog_storage_access_denied_title); + builder.setMessage(R.string.dialog_storage_access_denied); + builder.setCancelable(false); + builder.setPositiveButton(R.string.text_okay, (dialog, which) + -> pager.setCurrentItem(pager.getCurrentItem() - 1)); + builder.show(); + + } + } } } diff --git a/playmusicexporter/src/main/res/values/strings.xml b/playmusicexporter/src/main/res/values/strings.xml index 9984a2b..f402eef 100644 --- a/playmusicexporter/src/main/res/values/strings.xml +++ b/playmusicexporter/src/main/res/values/strings.xml @@ -50,7 +50,11 @@ %1$s was exported successfully! Storage access denied - The PlayMusicExporter always needs to write to the external storage. This is part of the Marshmallow fix.\n\nPlease restart the app and grant the permission. + The PlayMusicExporter does not work without write access to the external storage. You can not use this app without granting it write access. + + Superuser access denied + The PlayMusicExporter does not work without superuser access. You can not use this app without granting it superuser access. + You can only export offline tracks. Try to download the album offline in Play Music. diff --git a/playmusiclib/build.gradle b/playmusiclib/build.gradle index e5b0aad..521b9e9 100644 --- a/playmusiclib/build.gradle +++ b/playmusiclib/build.gradle @@ -27,7 +27,7 @@ android { buildToolsVersion "25.0.2" defaultConfig { - minSdkVersion 9 + minSdkVersion 11 targetSdkVersion 25 versionCode 1 versionName "1.0" diff --git a/playmusiclib/playmusiclib.iml b/playmusiclib/playmusiclib.iml index cfa6777..2e0bdfb 100644 --- a/playmusiclib/playmusiclib.iml +++ b/playmusiclib/playmusiclib.iml @@ -63,13 +63,6 @@ - - - - - - - @@ -77,6 +70,13 @@ + + + + + + +