From 849cc61bd9186d490ddfb4c61e115a546acc2f0d Mon Sep 17 00:00:00 2001 From: Austin Hogan Date: Sun, 15 Sep 2019 10:59:53 -0400 Subject: [PATCH 1/2] Oversight On Android 8.0+ service management - 1.6.7 (2019-9-15) codename: jingus * Fixed non-foreground service crash Bug * Show user permissions each update * Active App Notification changes after track switch --- app/build.gradle | 6 +++--- app/src/main/assets/changelog.txt | 5 +++++ .../com/adam/aslfms/EditUserCredentials.java | 3 ++- .../java/com/adam/aslfms/OptionsActivity.java | 2 ++ .../com/adam/aslfms/PermissionsActivity.java | 21 +++++++++++++++---- .../com/adam/aslfms/SettingsActivity.java | 20 ++++++++---------- .../com/adam/aslfms/UserCredActivity.java | 9 ++++---- .../adam/aslfms/UserCredsListActivity.java | 9 ++++---- .../receiver/AbstractPlayStatusReceiver.java | 2 +- .../service/ControllerReceiverService.java | 1 - .../aslfms/service/ScrobblingService.java | 8 +++---- .../main/java/com/adam/aslfms/util/Util.java | 16 +++++++++----- 12 files changed, 64 insertions(+), 38 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 84896ab9..f779313f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,8 +6,8 @@ android { applicationId "com.adam.aslfms" minSdkVersion 14 targetSdkVersion 26 - versionCode = 57 - versionName = "1.6.6" + versionCode = 58 + versionName = "1.6.7" testApplicationId "com.adam.aslfms.test" testInstrumentationRunner "android.test.InstrumentationTestRunner" @@ -39,6 +39,6 @@ dependencies { implementation 'com.android.support:appcompat-v7:26.1.0' implementation 'com.android.support:support-compat:26.1.0' implementation 'com.android.support:design:26.1.0' - //compile 'info.guardianproject.netcipher:netcipher:1.2' + //compile 'info.guardianproject.netcipher:netcipher:1.2' // would have been used to create secure ssl cipher for older android devices connecting through cloud flare for Libre.fm implementation 'com.android.support.constraint:constraint-layout:1.1.3' } diff --git a/app/src/main/assets/changelog.txt b/app/src/main/assets/changelog.txt index c2161bf9..81c6eef7 100644 --- a/app/src/main/assets/changelog.txt +++ b/app/src/main/assets/changelog.txt @@ -2,6 +2,11 @@ Visit, https://github.com/simple-last-fm-scrobbler/sls For more details. +- 1.6.7 (2019-9-15) codename: jingus + * Fixed non-foreground service crash Bug + * Show user permissions each update + * Active App Notification changes after track switch + - 1.6.6 (2019-9-14) codename: ingus * Better Service Management * Listener warning notification for Android 8.0+ diff --git a/app/src/main/java/com/adam/aslfms/EditUserCredentials.java b/app/src/main/java/com/adam/aslfms/EditUserCredentials.java index b875d827..31295d55 100644 --- a/app/src/main/java/com/adam/aslfms/EditUserCredentials.java +++ b/app/src/main/java/com/adam/aslfms/EditUserCredentials.java @@ -37,6 +37,7 @@ import com.adam.aslfms.service.ScrobblingService; import com.adam.aslfms.util.AppSettings; import com.adam.aslfms.util.MD5; +import com.adam.aslfms.util.Util; /** * @author tgwizard @@ -165,7 +166,7 @@ protected void onDialogClosed(boolean positiveResult) { settings.setSecureSocketListenbrainz(mNetApp, mListenBrainzSecureSocket.isChecked()); } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && settings.isActiveAppEnabled(Util.checkPower(getContext()))) { getContext().startForegroundService(service); } else { getContext().startService(service); diff --git a/app/src/main/java/com/adam/aslfms/OptionsActivity.java b/app/src/main/java/com/adam/aslfms/OptionsActivity.java index ced30831..7a85059e 100644 --- a/app/src/main/java/com/adam/aslfms/OptionsActivity.java +++ b/app/src/main/java/com/adam/aslfms/OptionsActivity.java @@ -245,7 +245,9 @@ public void create() { public boolean onClick(Preference pref) { if (pref == active_app) { settings.setActiveAppEnabled(power, active_app.isChecked()); + settings.setTempExitAppEnabled(Util.checkPower(ctx), true); Util.runServices(pref.getContext()); + settings.setTempExitAppEnabled(Util.checkPower(ctx), false); } else if (pref == scrobble) { settings.setScrobblingEnabled(power, scrobble.isChecked()); return true; diff --git a/app/src/main/java/com/adam/aslfms/PermissionsActivity.java b/app/src/main/java/com/adam/aslfms/PermissionsActivity.java index 7daf204e..c3ca0388 100644 --- a/app/src/main/java/com/adam/aslfms/PermissionsActivity.java +++ b/app/src/main/java/com/adam/aslfms/PermissionsActivity.java @@ -91,7 +91,7 @@ protected void onCreate(Bundle savedInstanceState) { settings = new AppSettings(this); setTheme(settings.getAppTheme()); - + settings.setKeyBypassNewPermissions(2); checkCurrrentPermissions(); } @@ -166,7 +166,11 @@ public void checkCurrrentPermissions(){ public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: - settings.setKeyBypassNewPermissions(1); + settings.setKeyBypassNewPermissions(1); // user has bypassed permissions is True + int v = Util.getAppVersionCode(ctx , getPackageName()); + if (settings.getWhatsNewViewedVersion() < v) { + resetVersionCode(v); + } Intent intent = new Intent(ctx, SettingsActivity.class); ctx.startActivity(intent); Util.runServices(ctx); @@ -186,9 +190,13 @@ public void onClick(DialogInterface dialog, int which) { .setNegativeButton(R.string.no, dialogClickListener).show(); } }); - continueBtn.setOnClickListener((View v) -> { + continueBtn.setOnClickListener((View view) -> { if(allPermsCheck()){ - settings.setKeyBypassNewPermissions(0); + settings.setKeyBypassNewPermissions(0); // user has bypassed permissions is false + int v = Util.getAppVersionCode(this, getPackageName()); + if (settings.getWhatsNewViewedVersion() < v) { + resetVersionCode(v); + } Intent intent = new Intent(ctx, SettingsActivity.class); ctx.startActivity(intent); Util.runServices(ctx); @@ -218,4 +226,9 @@ private boolean allPermsCheck() { && Util.checkExternalPermission(this) && Util.checkBatteryOptimizationsPermission(this); } + + private void resetVersionCode(int v){ + new WhatsNewDialog(this).show(); + settings.setWhatsNewViewedVersion(v); + } } diff --git a/app/src/main/java/com/adam/aslfms/SettingsActivity.java b/app/src/main/java/com/adam/aslfms/SettingsActivity.java index f3bd5af9..f894804a 100644 --- a/app/src/main/java/com/adam/aslfms/SettingsActivity.java +++ b/app/src/main/java/com/adam/aslfms/SettingsActivity.java @@ -120,16 +120,13 @@ protected void onCreate(Bundle savedInstanceState) { // TODO: VERIFY EVERYTHING BELOW IS SAFE int v = Util.getAppVersionCode(this, getPackageName()); if (settings.getWhatsNewViewedVersion() < v){ - Intent i = new Intent(this, PermissionsActivity.class); - startActivity(i); - } - - if (settings.getWhatsNewViewedVersion() < v && settings.getKeyBypassNewPermissions() != 2) { - new WhatsNewDialog(this).show(); - settings.setWhatsNewViewedVersion(v); + settings.setKeyBypassNewPermissions(2); mDb.rebuildDataBaseOnce(); // keep as not all users have the newest database. } - Util.runServices(this); // Scrobbler, Controller + if (settings.getKeyBypassNewPermissions() == 2){ + startActivity(new Intent(this, PermissionsActivity.class)); + } + Util.runServices(this); } @Override @@ -153,6 +150,10 @@ protected void onResume() { registerReceiver(onStatusChange, ifs); update(); Util.runServices(this); + if(settings.getKeyBypassNewPermissions() == 2){ + Intent i = new Intent(this, PermissionsActivity.class); + startActivity(i); + } } @Override @@ -160,10 +161,7 @@ protected void onResume() { public boolean onPreferenceTreeClick(PreferenceScreen prefScreen, Preference pref) { if (pref == mScrobbleAllNow) { - checkNetwork(); - - int numInCache = mDb.queryNumberOfTracks(); Util.scrobbleAllIfPossible(this, numInCache); return true; diff --git a/app/src/main/java/com/adam/aslfms/UserCredActivity.java b/app/src/main/java/com/adam/aslfms/UserCredActivity.java index af52f6ab..d96dfc02 100644 --- a/app/src/main/java/com/adam/aslfms/UserCredActivity.java +++ b/app/src/main/java/com/adam/aslfms/UserCredActivity.java @@ -36,6 +36,7 @@ import android.util.Log; import android.view.MenuItem; +import com.adam.aslfms.service.ControllerReceiverService; import com.adam.aslfms.service.NetApp; import com.adam.aslfms.service.ScrobblingService; import com.adam.aslfms.util.AppSettings; @@ -117,9 +118,9 @@ public boolean onPreferenceTreeClick(PreferenceScreen prefScreen, Util.confirmDialog(this, getString(R.string.confirm_clear_creds).replaceAll( "%1", mNetApp.getName()), R.string.clear_creds, - android.R.string.cancel, (dialog, which) -> sendClearCreds()); + android.R.string.cancel, (dialog, which) -> sendClearCreds(pref.getContext())); } else { - sendClearCreds(); + sendClearCreds(pref.getContext()); } update(); @@ -142,11 +143,11 @@ public boolean onPreferenceTreeClick(PreferenceScreen prefScreen, return super.onPreferenceTreeClick(prefScreen, pref); } - private void sendClearCreds() { + private void sendClearCreds(Context ctx) { Intent service = new Intent(this, ScrobblingService.class); service.setAction(ScrobblingService.ACTION_CLEARCREDS); service.putExtra("netapp", mNetApp.getIntentExtraValue()); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && settings.isActiveAppEnabled(Util.checkPower(ctx))) { this.startForegroundService(service); } else { this.startService(service); diff --git a/app/src/main/java/com/adam/aslfms/UserCredsListActivity.java b/app/src/main/java/com/adam/aslfms/UserCredsListActivity.java index dec1c35b..9aee27dc 100644 --- a/app/src/main/java/com/adam/aslfms/UserCredsListActivity.java +++ b/app/src/main/java/com/adam/aslfms/UserCredsListActivity.java @@ -122,9 +122,9 @@ public boolean onPreferenceTreeClick(PreferenceScreen prefScreen, Util.confirmDialog(this, getString(R.string.confirm_clear_all_creds), R.string.clear_creds, android.R.string.cancel, - (dialog, which) -> sendClearCreds()); + (dialog, which) -> sendClearCreds(pref.getContext())); } else { - sendClearCreds(); + sendClearCreds(pref.getContext()); } return true; @@ -153,11 +153,12 @@ public boolean onOptionsItemSelected(MenuItem item) { return super.onOptionsItemSelected(item); } - private void sendClearCreds() { + private void sendClearCreds(Context ctx) { Intent service = new Intent(this, ScrobblingService.class); service.setAction(ScrobblingService.ACTION_CLEARCREDS); service.putExtra("clearall", true); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + AppSettings appSettings = new AppSettings(ctx); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && appSettings.isActiveAppEnabled(Util.checkPower(ctx))) { startForegroundService(service); } else { startService(service); diff --git a/app/src/main/java/com/adam/aslfms/receiver/AbstractPlayStatusReceiver.java b/app/src/main/java/com/adam/aslfms/receiver/AbstractPlayStatusReceiver.java index 9ab5b70c..373ab674 100644 --- a/app/src/main/java/com/adam/aslfms/receiver/AbstractPlayStatusReceiver.java +++ b/app/src/main/java/com/adam/aslfms/receiver/AbstractPlayStatusReceiver.java @@ -126,7 +126,7 @@ public final void onReceive(Context context, Intent intent) { InternalTrackTransmitter.appendTrack(mTrack); // start/call the Scrobbling Service - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && settings.isActiveAppEnabled(Util.checkPower(context))) { context.startForegroundService(mService); } else { context.startService(mService); diff --git a/app/src/main/java/com/adam/aslfms/service/ControllerReceiverService.java b/app/src/main/java/com/adam/aslfms/service/ControllerReceiverService.java index 22dcb4e6..649e0971 100644 --- a/app/src/main/java/com/adam/aslfms/service/ControllerReceiverService.java +++ b/app/src/main/java/com/adam/aslfms/service/ControllerReceiverService.java @@ -66,7 +66,6 @@ public void onCreate() { Log.d(TAG,"created"); settings = new AppSettings(this); - this.startForeground(NotificationCreator.FOREGROUND_ID, NotificationCreator.prepareNotification(extras, this)); init(extras); if (!settings.isActiveAppEnabled(Util.checkPower(this))) { this.stopForeground(true); diff --git a/app/src/main/java/com/adam/aslfms/service/ScrobblingService.java b/app/src/main/java/com/adam/aslfms/service/ScrobblingService.java index 18567246..9996915b 100644 --- a/app/src/main/java/com/adam/aslfms/service/ScrobblingService.java +++ b/app/src/main/java/com/adam/aslfms/service/ScrobblingService.java @@ -124,7 +124,7 @@ private void handleCommand(Intent i, int startId) { Intent ii = new Intent(this, ControllerReceiverService.class); ii.putExtras(bundleTrack()); Log.d(TAG, "(re)starting controllerreceiver"); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && settings.isActiveAppEnabled(Util.checkPower(this))) { this.startForegroundService(ii); } else { this.startService(ii); @@ -491,10 +491,10 @@ private Bundle bundleTrack(){ } private void foreGroundService(){ - if (!settings.isActiveAppEnabled(Util.checkPower(mCtx))) { - this.stopForeground(true); - } else { + if (settings.isActiveAppEnabled(Util.checkPower(mCtx))) { this.startForeground(NotificationCreator.FOREGROUND_ID, NotificationCreator.prepareNotification(bundleTrack(), mCtx)); + } else { + this.stopForeground(true); } } } \ No newline at end of file diff --git a/app/src/main/java/com/adam/aslfms/util/Util.java b/app/src/main/java/com/adam/aslfms/util/Util.java index 22636a59..19335bf2 100644 --- a/app/src/main/java/com/adam/aslfms/util/Util.java +++ b/app/src/main/java/com/adam/aslfms/util/Util.java @@ -221,10 +221,12 @@ public static void warningDialog(Context ctx, String msg) { public static void scrobbleIfPossible(Context ctx, NetApp napp, int numInCache) { if (numInCache > 0) { + Intent intent = new Intent(ctx, ScrobblingService.class); intent.setAction(ScrobblingService.ACTION_JUSTSCROBBLE); intent.putExtra("netapp", napp.getIntentExtraValue()); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + AppSettings appSettings = new AppSettings(ctx); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && appSettings.isActiveAppEnabled(Util.checkPower(ctx))) { ctx.startForegroundService(intent); } else { ctx.startService(intent); @@ -240,7 +242,8 @@ public static void scrobbleAllIfPossible(Context ctx, int numInCache) { Intent service = new Intent(ctx, ScrobblingService.class); service.setAction(ScrobblingService.ACTION_JUSTSCROBBLE); service.putExtra("scrobbleall", true); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + AppSettings appSettings = new AppSettings(ctx); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && appSettings.isActiveAppEnabled(Util.checkPower(ctx))) { ctx.startForegroundService(service); } else { ctx.startService(service); @@ -256,7 +259,8 @@ public static void heartIfPossible(Context ctx) { try { Intent service = new Intent(ctx, ScrobblingService.class); service.setAction(ScrobblingService.ACTION_HEART); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + AppSettings appSettings = new AppSettings(ctx); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && appSettings.isActiveAppEnabled(Util.checkPower(ctx))) { ctx.startForegroundService(service); } else { ctx.startService(service); @@ -272,7 +276,8 @@ public static void copyIfPossible(Context ctx) { try { Intent service = new Intent(ctx, ScrobblingService.class); service.setAction(ScrobblingService.ACTION_COPY); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + AppSettings appSettings = new AppSettings(ctx); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && appSettings.isActiveAppEnabled(Util.checkPower(ctx))) { ctx.startForegroundService(service); } else { ctx.startService(service); @@ -613,7 +618,8 @@ public static void runServices(Context context) { Log.d(TAG, "(re)starting scrobbleservice"); Intent i = new Intent(context, ScrobblingService.class); i.setAction(ScrobblingService.ACTION_START_SCROBBLER_SERVICE); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + AppSettings appSettings = new AppSettings(context); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && appSettings.isActiveAppEnabled(Util.checkPower(context))) { context.startForegroundService(i); } else { context.startService(i); From bfbd2ad12f2ee853954b4fb701772ae8f89180a0 Mon Sep 17 00:00:00 2001 From: Austin Hogan Date: Sun, 15 Sep 2019 11:01:22 -0400 Subject: [PATCH 2/2] Changelog changelog --- app/src/main/assets/changelog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/assets/changelog.txt b/app/src/main/assets/changelog.txt index 81c6eef7..91b5e327 100644 --- a/app/src/main/assets/changelog.txt +++ b/app/src/main/assets/changelog.txt @@ -5,7 +5,7 @@ For more details. - 1.6.7 (2019-9-15) codename: jingus * Fixed non-foreground service crash Bug * Show user permissions each update - * Active App Notification changes after track switch + * Option Active App Notification status changes after track switch - 1.6.6 (2019-9-14) codename: ingus * Better Service Management