Skip to content
This repository has been archived by the owner on May 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #531 from a93h/master
Browse files Browse the repository at this point in the history
Oversight On Android 8.0+ service management
  • Loading branch information
Austin H authored Sep 15, 2019
2 parents 46894d7 + bfbd2ad commit bc3fa68
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 38 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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'
}
5 changes: 5 additions & 0 deletions app/src/main/assets/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
* Option Active App Notification status changes after track switch

- 1.6.6 (2019-9-14) codename: ingus
* Better Service Management
* Listener warning notification for Android 8.0+
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/adam/aslfms/EditUserCredentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/adam/aslfms/OptionsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 17 additions & 4 deletions app/src/main/java/com/adam/aslfms/PermissionsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected void onCreate(Bundle savedInstanceState) {

settings = new AppSettings(this);
setTheme(settings.getAppTheme());

settings.setKeyBypassNewPermissions(2);
checkCurrrentPermissions();
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}
20 changes: 9 additions & 11 deletions app/src/main/java/com/adam/aslfms/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -153,17 +150,18 @@ protected void onResume() {
registerReceiver(onStatusChange, ifs);
update();
Util.runServices(this);
if(settings.getKeyBypassNewPermissions() == 2){
Intent i = new Intent(this, PermissionsActivity.class);
startActivity(i);
}
}

@Override
@SuppressWarnings("deprecation")
public boolean onPreferenceTreeClick(PreferenceScreen prefScreen,
Preference pref) {
if (pref == mScrobbleAllNow) {

checkNetwork();


int numInCache = mDb.queryNumberOfTracks();
Util.scrobbleAllIfPossible(this, numInCache);
return true;
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/java/com/adam/aslfms/UserCredActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/java/com/adam/aslfms/UserCredsListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
}
16 changes: 11 additions & 5 deletions app/src/main/java/com/adam/aslfms/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit bc3fa68

Please sign in to comment.