mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-15 08:29:24 +00:00
Debug: monitor audio mode
This commit is contained in:
parent
855cf39d2a
commit
75d2a96b46
2 changed files with 71 additions and 6 deletions
|
@ -31,6 +31,7 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.media.AudioManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.LinkProperties;
|
||||
import android.net.Network;
|
||||
|
@ -47,9 +48,12 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.RequiresApi;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.lifecycle.MediatorLiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.sun.mail.iap.Argument;
|
||||
|
@ -676,6 +680,38 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
|
||||
final TwoStateOwner cowner = new TwoStateOwner(this, "liveUnseenNotify");
|
||||
|
||||
if (BuildConfig.DEBUG &&
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
// Widgets will be disabled too
|
||||
AudioManager am = Helper.getSystemService(this, AudioManager.class);
|
||||
|
||||
AudioManager.OnModeChangedListener listener = new AudioManager.OnModeChangedListener() {
|
||||
@Override
|
||||
public void onModeChanged(int mode) {
|
||||
boolean inCall = MediaPlayerHelper.isInCall(mode);
|
||||
boolean notify_suppress_in_call = prefs.getBoolean("notify_suppress_in_call", false);
|
||||
Log.i("Owner inCall=" + inCall + " suppress=" + notify_suppress_in_call);
|
||||
cowner.setEnabled(!notify_suppress_in_call || !inCall);
|
||||
}
|
||||
};
|
||||
listener.onModeChanged(am.getMode()); // Init
|
||||
|
||||
getLifecycle().addObserver(new LifecycleObserver() {
|
||||
private boolean registered = false;
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_ANY)
|
||||
public void onStateChanged() {
|
||||
if (ServiceSynchronize.this.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
|
||||
am.addOnModeChangedListener(executor, listener);
|
||||
registered = true;
|
||||
} else if (registered) {
|
||||
am.removeOnModeChangedListener(listener);
|
||||
registered = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
db.folder().liveSynchronizing().observe(this, new Observer<List<TupleFolderSync>>() {
|
||||
private List<Long> lastAccounts = new ArrayList<>();
|
||||
private List<Long> lastFolders = new ArrayList<>();
|
||||
|
|
|
@ -37,6 +37,8 @@ import java.util.Objects;
|
|||
|
||||
public class TwoStateOwner implements LifecycleOwner {
|
||||
private String name;
|
||||
private boolean enabled = true;
|
||||
private Boolean start = null;
|
||||
private boolean owned = true;
|
||||
private Object condition;
|
||||
private LifecycleRegistry registry;
|
||||
|
@ -77,6 +79,27 @@ public class TwoStateOwner implements LifecycleOwner {
|
|||
});
|
||||
}
|
||||
|
||||
void setEnabled(boolean value) {
|
||||
Log.i("Owner enable=" + value + " state=" + registry.getCurrentState().name());
|
||||
if (enabled && !value) {
|
||||
boolean started = registry.getCurrentState().isAtLeast(Lifecycle.State.STARTED);
|
||||
stop();
|
||||
start = (started ? true : null);
|
||||
Log.i("Owner stopped start=" + start);
|
||||
}
|
||||
|
||||
enabled = value;
|
||||
|
||||
if (enabled && start != null) {
|
||||
Log.i("Owner restore start=" + start);
|
||||
if (start)
|
||||
start();
|
||||
else
|
||||
stop();
|
||||
start = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void create() {
|
||||
if (owned) {
|
||||
// Initialize
|
||||
|
@ -99,15 +122,21 @@ public class TwoStateOwner implements LifecycleOwner {
|
|||
}
|
||||
|
||||
void start() {
|
||||
Lifecycle.State state = registry.getCurrentState();
|
||||
if (!state.equals(Lifecycle.State.STARTED) && !state.equals(Lifecycle.State.DESTROYED))
|
||||
setState(Lifecycle.State.STARTED);
|
||||
if (enabled) {
|
||||
Lifecycle.State state = registry.getCurrentState();
|
||||
if (!state.equals(Lifecycle.State.STARTED) && !state.equals(Lifecycle.State.DESTROYED))
|
||||
setState(Lifecycle.State.STARTED);
|
||||
} else
|
||||
start = true;
|
||||
}
|
||||
|
||||
void stop() {
|
||||
Lifecycle.State state = registry.getCurrentState();
|
||||
if (!state.equals(Lifecycle.State.CREATED) && !state.equals(Lifecycle.State.DESTROYED))
|
||||
setState(Lifecycle.State.CREATED);
|
||||
if (enabled) {
|
||||
Lifecycle.State state = registry.getCurrentState();
|
||||
if (!state.equals(Lifecycle.State.CREATED) && !state.equals(Lifecycle.State.DESTROYED))
|
||||
setState(Lifecycle.State.CREATED);
|
||||
} else
|
||||
start = false;
|
||||
}
|
||||
|
||||
void restart() {
|
||||
|
|
Loading…
Add table
Reference in a new issue