Skip to content
Snippets Groups Projects
Commit 42c14b04 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

jni/aidl: add and use setAccountActive API

When netowrk connectivity is lost, accounts are
desactivated and enabled back when connectivity is
restored.

Tuleap: #9
Change-Id: I2548e106ab1c350e8ebc9f7684e854a749e1e170
parent a416c743
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,8 @@ interface ISipService { ...@@ -23,6 +23,8 @@ interface ISipService {
Map getAccountTemplate(in String accountType); Map getAccountTemplate(in String accountType);
void registerAllAccounts(); void registerAllAccounts();
void setAccountDetails(in String accountId, in Map accountDetails); void setAccountDetails(in String accountId, in Map accountDetails);
void setAccountActive(in String accountId, in boolean active);
void setAccountsActive(in boolean active);
List getCredentials(in String accountID); List getCredentials(in String accountID);
void setCredentials(in String accountID, in List creds); void setCredentials(in String accountID, in List creds);
void setAudioPlugin(in String callID); void setAudioPlugin(in String callID);
......
...@@ -78,7 +78,8 @@ import cx.ring.model.TextMessage; ...@@ -78,7 +78,8 @@ import cx.ring.model.TextMessage;
import cx.ring.model.account.Account; import cx.ring.model.account.Account;
public class LocalService extends Service { public class LocalService extends Service
{
static final String TAG = LocalService.class.getSimpleName(); static final String TAG = LocalService.class.getSimpleName();
static public final String ACTION_CONF_UPDATE = BuildConfig.APPLICATION_ID + ".action.CONF_UPDATE"; static public final String ACTION_CONF_UPDATE = BuildConfig.APPLICATION_ID + ".action.CONF_UPDATE";
static public final String ACTION_ACCOUNT_UPDATE = BuildConfig.APPLICATION_ID + ".action.ACCOUNT_UPDATE"; static public final String ACTION_ACCOUNT_UPDATE = BuildConfig.APPLICATION_ID + ".action.ACCOUNT_UPDATE";
...@@ -109,6 +110,9 @@ public class LocalService extends Service { ...@@ -109,6 +110,9 @@ public class LocalService extends Service {
private LruCache<Long, Bitmap> mMemoryCache = null; private LruCache<Long, Bitmap> mMemoryCache = null;
private final ExecutorService mPool = Executors.newCachedThreadPool(); private final ExecutorService mPool = Executors.newCachedThreadPool();
private boolean isWifiConn = false;
private boolean isMobileConn = false;
public ContactsLoader.Result getSortedContacts() { public ContactsLoader.Result getSortedContacts() {
Log.w(TAG, "getSortedContacts " + lastContactLoaderResult.contacts.size() + " contacts, " + lastContactLoaderResult.starred.size() + " starred."); Log.w(TAG, "getSortedContacts " + lastContactLoaderResult.contacts.size() + " contacts, " + lastContactLoaderResult.starred.size() + " starred.");
return lastContactLoaderResult; return lastContactLoaderResult;
...@@ -126,6 +130,13 @@ public class LocalService extends Service { ...@@ -126,6 +130,13 @@ public class LocalService extends Service {
return systemContactCache; return systemContactCache;
} }
public boolean isConnected() {
return isWifiConn || isMobileConn;
}
public boolean isWifiConnected() {
return isWifiConn;
}
public interface Callbacks { public interface Callbacks {
ISipService getRemoteService(); ISipService getRemoteService();
LocalService getService(); LocalService getService();
...@@ -160,6 +171,12 @@ public class LocalService extends Service { ...@@ -160,6 +171,12 @@ public class LocalService extends Service {
Intent intent = new Intent(this, SipService.class); Intent intent = new Intent(this, SipService.class);
startService(intent); startService(intent);
bindService(intent, mConnection, BIND_AUTO_CREATE | BIND_IMPORTANT | BIND_ABOVE_CLIENT); bindService(intent, mConnection, BIND_AUTO_CREATE | BIND_IMPORTANT | BIND_ABOVE_CLIENT);
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
isWifiConn = ni != null && ni.isConnected();
ni = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
isMobileConn = ni != null && ni.isConnected();
} }
@Override @Override
...@@ -184,11 +201,11 @@ public class LocalService extends Service { ...@@ -184,11 +201,11 @@ public class LocalService extends Service {
private final Loader.OnLoadCompleteListener<ArrayList<Account>> onAccountsLoaded = new Loader.OnLoadCompleteListener<ArrayList<Account>>() { private final Loader.OnLoadCompleteListener<ArrayList<Account>> onAccountsLoaded = new Loader.OnLoadCompleteListener<ArrayList<Account>>() {
@Override @Override
public void onLoadComplete(Loader<ArrayList<Account>> loader, ArrayList<Account> data) { public void onLoadComplete(Loader<ArrayList<Account>> loader, ArrayList<Account> data) {
Log.w(TAG, "AccountsLoader Loader.OnLoadCompleteListener"); Log.w(TAG, "AccountsLoader Loader.OnLoadCompleteListener " + data.size());
all_accounts = data; all_accounts = data;
accounts = all_accounts.subList(0,data.size()-1); accounts = all_accounts.subList(0,data.size()-1);
ip2ip_account = all_accounts.subList(data.size()-1,data.size()); ip2ip_account = all_accounts.subList(data.size()-1,data.size());
sendBroadcast(new Intent(ACTION_ACCOUNT_UPDATE)); updateConnectivityState();
} }
}; };
private final Loader.OnLoadCompleteListener<ContactsLoader.Result> onSystemContactsLoaded = new Loader.OnLoadCompleteListener<ContactsLoader.Result>() { private final Loader.OnLoadCompleteListener<ContactsLoader.Result> onSystemContactsLoaded = new Loader.OnLoadCompleteListener<ContactsLoader.Result>() {
...@@ -201,7 +218,7 @@ public class LocalService extends Service { ...@@ -201,7 +218,7 @@ public class LocalService extends Service {
for (CallContact c : data.contacts) for (CallContact c : data.contacts)
systemContactCache.put(c.getId(), c); systemContactCache.put(c.getId(), c);
sendBroadcast(new Intent(ACTION_ACCOUNT_UPDATE)); sendBroadcast(new Intent(ACTION_CONF_UPDATE));
} }
}; };
...@@ -830,15 +847,35 @@ public class LocalService extends Service { ...@@ -830,15 +847,35 @@ public class LocalService extends Service {
} }
} }
private void updateConnectivityState() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
Log.w(TAG, "ActiveNetworkInfo (Wifi): " + (ni == null ? "null" : ni.toString()));
isWifiConn = ni != null && ni.isConnected();
ni = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
Log.w(TAG, "ActiveNetworkInfo (mobile): " + (ni == null ? "null" : ni.toString()));
isMobileConn = ni != null && ni.isConnected();
try {
getRemoteService().setAccountsActive(isWifiConn);
} catch (RemoteException e) {
e.printStackTrace();
}
// if account list loaded
if (!ip2ip_account.isEmpty())
sendBroadcast(new Intent(ACTION_ACCOUNT_UPDATE));
}
private final BroadcastReceiver receiver = new BroadcastReceiver() { private final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
switch(intent.getAction()) { switch(intent.getAction()) {
case ConnectivityManager.CONNECTIVITY_ACTION: case ConnectivityManager.CONNECTIVITY_ACTION:
Log.w(TAG, "ConnectivityManager.CONNECTIVITY_ACTION " + " " + intent.getStringExtra(ConnectivityManager.EXTRA_EXTRA_INFO) + " " + intent.getStringExtra(ConnectivityManager.EXTRA_EXTRA_INFO)); Log.w(TAG, "ConnectivityManager.CONNECTIVITY_ACTION " + " " + intent.getStringExtra(ConnectivityManager.EXTRA_EXTRA_INFO) + " " + intent.getStringExtra(ConnectivityManager.EXTRA_EXTRA_INFO));
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); updateConnectivityState();
NetworkInfo ni = cm.getActiveNetworkInfo();
Log.w(TAG, "ActiveNetworkInfo: " + (ni == null ? "null" : ni.toString()));
break; break;
case ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED: case ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED:
Log.w(TAG, "Received " + intent.getAction() + " " + intent.getStringExtra("Account") + " " + intent.getStringExtra("State") + " " + intent.getIntExtra("code", 0)); Log.w(TAG, "Received " + intent.getAction() + " " + intent.getStringExtra("Account") + " " + intent.getStringExtra("State") + " " + intent.getIntExtra("code", 0));
......
...@@ -660,6 +660,30 @@ public class SipService extends Service { ...@@ -660,6 +660,30 @@ public class SipService extends Service {
}); });
} }
@Override
public void setAccountActive(final String accountId, final boolean active) {
getExecutor().execute(new SipRunnable() {
@Override
protected void doRun() throws SameThreadException {
Log.i(TAG, "SipService.setAccountActive() thread running... " + accountId + " -> " + active);
Ringservice.setAccountActive(accountId, active);
}
});
}
@Override
public void setAccountsActive(final boolean active) {
getExecutor().execute(new SipRunnable() {
@Override
protected void doRun() throws SameThreadException {
Log.i(TAG, "SipService.setAccountsActive() thread running... " + active);
StringVect list = Ringservice.getAccountList();
for (int i=0, n=list.size(); i<n; i++)
Ringservice.setAccountActive(list.get(i), active);
}
});
}
@Override @Override
public Map<String, String> getVolatileAccountDetails(final String accountId) { public Map<String, String> getVolatileAccountDetails(final String accountId) {
return getExecutor().executeAndReturn(new SipRunnableWithReturn<Map<String, String>>() { return getExecutor().executeAndReturn(new SipRunnableWithReturn<Map<String, String>>() {
......
...@@ -61,6 +61,7 @@ namespace DRing { ...@@ -61,6 +61,7 @@ namespace DRing {
std::map<std::string, std::string> getAccountDetails(const std::string& accountID); std::map<std::string, std::string> getAccountDetails(const std::string& accountID);
std::map<std::string, std::string> getVolatileAccountDetails(const std::string& accountID); std::map<std::string, std::string> getVolatileAccountDetails(const std::string& accountID);
void setAccountDetails(const std::string& accountID, const std::map<std::string, std::string>& details); void setAccountDetails(const std::string& accountID, const std::map<std::string, std::string>& details);
void setAccountActive(const std::string& accountID, bool active);
std::map<std::string, std::string> getAccountTemplate(const std::string& accountType); std::map<std::string, std::string> getAccountTemplate(const std::string& accountType);
std::string addAccount(const std::map<std::string, std::string>& details); std::string addAccount(const std::map<std::string, std::string>& details);
void removeAccount(const std::string& accountID); void removeAccount(const std::string& accountID);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment