mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 01:40:07 +01:00
Improve and streamline Application#onCreate.
This commit is contained in:
committed by
Alan Evans
parent
c27300c19d
commit
cdd7b2deb9
@@ -8,6 +8,7 @@ import android.telephony.TelephonyManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.signal.core.util.concurrent.SignalExecutors;
|
||||
import org.thoughtcrime.securesms.jobmanager.ConstraintObserver;
|
||||
|
||||
public class CellServiceConstraintObserver implements ConstraintObserver {
|
||||
@@ -17,11 +18,15 @@ public class CellServiceConstraintObserver implements ConstraintObserver {
|
||||
private volatile Notifier notifier;
|
||||
private volatile ServiceState lastKnownState;
|
||||
|
||||
private static CellServiceConstraintObserver instance;
|
||||
private static volatile CellServiceConstraintObserver instance;
|
||||
|
||||
public static synchronized CellServiceConstraintObserver getInstance(@NonNull Application application) {
|
||||
public static CellServiceConstraintObserver getInstance(@NonNull Application application) {
|
||||
if (instance == null) {
|
||||
instance = new CellServiceConstraintObserver(application);
|
||||
synchronized (CellServiceConstraintObserver.class) {
|
||||
if (instance == null) {
|
||||
instance = new CellServiceConstraintObserver(application);
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
@@ -30,7 +35,9 @@ public class CellServiceConstraintObserver implements ConstraintObserver {
|
||||
TelephonyManager telephonyManager = (TelephonyManager) application.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
ServiceStateListener serviceStateListener = new ServiceStateListener();
|
||||
|
||||
telephonyManager.listen(serviceStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
|
||||
SignalExecutors.BOUNDED.execute(() -> {
|
||||
telephonyManager.listen(serviceStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,18 +13,10 @@ public class DecryptionsDrainedConstraintObserver implements ConstraintObserver
|
||||
|
||||
private static final String REASON = DecryptionsDrainedConstraintObserver.class.getSimpleName();
|
||||
|
||||
private volatile Notifier notifier;
|
||||
|
||||
public DecryptionsDrainedConstraintObserver() {
|
||||
ApplicationDependencies.getIncomingMessageObserver().addDecryptionDrainedListener(() -> {
|
||||
if (notifier != null) {
|
||||
notifier.onConstraintMet(REASON);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(@NonNull Notifier notifier) {
|
||||
this.notifier = notifier;
|
||||
ApplicationDependencies.getIncomingMessageObserver().addDecryptionDrainedListener(() -> {
|
||||
notifier.onConstraintMet(REASON);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user