mirror of
https://github.com/TeamVanced/VancedMicroG
synced 2025-02-21 23:21:08 +01:00
Directly start/stop GCM service if setting is changed in UI
This commit is contained in:
parent
170d5e4524
commit
d99fa7e86f
@ -49,7 +49,7 @@ public class GcmPrefs implements SharedPreferences.OnSharedPreferenceChangeListe
|
||||
|
||||
private SharedPreferences defaultPreferences;
|
||||
|
||||
public GcmPrefs(Context context) {
|
||||
private GcmPrefs(Context context) {
|
||||
if (context != null) {
|
||||
defaultPreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
defaultPreferences.registerOnSharedPreferenceChangeListener(this);
|
||||
|
@ -170,8 +170,15 @@ public class McsService extends Service implements Handler.Callback {
|
||||
}
|
||||
}
|
||||
|
||||
public static void stop(Context context) {
|
||||
context.stopService(new Intent(context, McsService.class));
|
||||
closeAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
alarmManager.cancel(heartbeatIntent);
|
||||
closeAll();
|
||||
database.close();
|
||||
super.onDestroy();
|
||||
}
|
||||
@ -571,7 +578,7 @@ public class McsService extends Service implements Handler.Callback {
|
||||
}
|
||||
}
|
||||
|
||||
private void tryClose(Closeable closeable) {
|
||||
private static void tryClose(Closeable closeable) {
|
||||
if (closeable != null) {
|
||||
try {
|
||||
closeable.close();
|
||||
@ -580,7 +587,7 @@ public class McsService extends Service implements Handler.Callback {
|
||||
}
|
||||
}
|
||||
|
||||
private void closeAll() {
|
||||
private static void closeAll() {
|
||||
tryClose(inputStream);
|
||||
tryClose(outputStream);
|
||||
if (sslSocket != null) {
|
||||
|
@ -38,6 +38,7 @@ import com.google.android.gms.R;
|
||||
|
||||
import org.microg.gms.gcm.GcmDatabase;
|
||||
import org.microg.gms.gcm.GcmPrefs;
|
||||
import org.microg.gms.gcm.McsConstants;
|
||||
import org.microg.gms.gcm.McsService;
|
||||
import org.microg.tools.ui.AbstractSettingsActivity;
|
||||
import org.microg.tools.ui.DimmableIconPreference;
|
||||
@ -140,6 +141,12 @@ public class GcmFragment extends ResourceSettingsFragment implements SwitchBar.O
|
||||
public void onSwitchChanged(SwitchCompat switchView, boolean isChecked) {
|
||||
if (switchView == switchCompat) {
|
||||
getPreferenceManager().getSharedPreferences().edit().putBoolean(GcmPrefs.PREF_ENABLE_GCM, isChecked).apply();
|
||||
if (!isChecked) {
|
||||
McsService.stop(getContext());
|
||||
} else {
|
||||
getContext().startService(new Intent(McsConstants.ACTION_CONNECT, null, getContext(), McsService.class));
|
||||
}
|
||||
updateContent();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user