I created 2 apps, a client and a server app. When someone using the client app writes something on the RDB this triggers some events on the phones running the server app then when the server is done performing the operation requested by the client it deletes that from the RDB.
Each app does what it has to (client writes and server deletes entries), the problem arrives after some phone innactivity, in order to complete the write and delete operation I need to turn off and on the wifi/mobile data connection.
Below there is a code snipet that shows how the server app tries to communicate with the firebase RDB to delete the entry that was written by the client, this happens everytime a phone call ends on the server app. BTW the onReceive method does get called and I don´t think this problem is related with this code implementation because I´ve tried in many different ways to fix this problem with no success.
public class CallStateReceiver extends BroadcastReceiver {
public static String prevState = TelephonyManager.EXTRA_STATE_IDLE;
private final String LOG_TAG = "CallStateReceiver";
@Override
public void onReceive(Context context, Intent intent) {
final PendingResult pendingResult = goAsync();
Task asyncTask = new Task(pendingResult, intent, context);
asyncTask.execute();
}
private static class Task extends AsyncTask {
private final PendingResult pendingResult;
private final Intent intent;
String PREFS_NAME = "MyPrefsFile";
SharedPreferences serverInfoPrefs;
String serverName;
AudioManager audioManager;
private Task(PendingResult pendingResult, Intent intent, Context context) {
this.pendingResult = pendingResult;
this.intent = intent;
serverInfoPrefs = context. getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
}
@Override
protected void onPostExecute(Object o) {
super.onPostExecute(o);
pendingResult.finish();
}
@Override
protected Object doInBackground(Object[] objects) {
Bundle bundle = intent.getExtras();
if (bundle == null) {
return null;
}
serverName = serverInfoPrefs.getString("serverName", "Servidor1");
String state = bundle.getString(TelephonyManager.EXTRA_STATE);
if (state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_IDLE)
&& !prevState.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_IDLE)) {
FirebaseDatabase.getInstance().getReference().child("servers").child(serverName).child("current")
.child("callRequest").removeValue();
audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, 5, 0);
MyAccessibilityService.onCallAlready = false;
}
prevState = state;
return null;
}
}
}
I enabled the debug logging and this line (not sure if this is related to the issue though):
03-02 18:08:55.360 10832-10840/? W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/data/com.google.android.gsf/databases/gservices.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
And also found this solution but I don´t know how that applies to firebase