Add fetch remote provisioning with xmlrpc

This commit is contained in:
Margaux Clerc 2015-11-02 17:15:15 +01:00
parent d6c87d61a2
commit 104668cd4d
13 changed files with 1220 additions and 143 deletions

View file

@ -85,7 +85,7 @@
<Button
android:id="@+id/assistant_apply"
android:text="@string/assistant_apply"
android:text="@string/assistant_login"
android:background="@drawable/assistant_button"
style="@style/font8"
android:contentDescription="@string/content_description_validate"

View file

@ -109,7 +109,7 @@
<Button
android:id="@+id/assistant_apply"
android:text="@string/assistant_apply"
android:text="@string/assistant_login"
android:background="@drawable/assistant_button"
style="@style/font8"
android:contentDescription="@string/content_description_validate"

View file

@ -14,8 +14,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"/>
<LinearLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
@ -57,5 +57,5 @@
android:layout_centerInParent="true"
android:layout_centerVertical="true"/>
</LinearLayout>
</LinearLayout>

View file

@ -1,91 +1,113 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="@color/colorH"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:text="@string/assistant_remote_provisioning_title"
android:contentDescription="@string/content_description_welcome"
style="@style/font6"
android:textAllCaps="true"
android:paddingTop="20dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"/>
<TextView
android:text="@string/assistant_remote_provisioning_login"
style="@style/font11"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp"
android:orientation="vertical">
<TextView
android:contentDescription="@string/content_description_welcome"
android:paddingTop="40dp"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/assistant_title"/>
<TextView
android:paddingTop="10dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/setup_remote_provisioning_login_hint"
android:textColor="@android:color/black"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="40dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:gravity="center"
android:orientation="vertical">
<EditText
android:textCursorDrawable="@null"
android:id="@+id/setup_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/setup_username_hint"
android:inputType="textEmailAddress"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:background="@drawable/resizable_textfield" />
<EditText
android:textCursorDrawable="@null"
android:id="@+id/setup_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/setup_password_hint"
android:inputType="textPassword"
android:layout_marginTop="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:background="@drawable/resizable_textfield" />
<EditText
android:textCursorDrawable="@null"
android:id="@+id/setup_domain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/setup_domain_hint"
android:inputType="textEmailAddress"
android:layout_marginTop="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:background="@drawable/resizable_textfield" />
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:gravity="center"
android:orientation="vertical">
<TextView
android:text="@string/username"
style="@style/font13"
android:textAllCaps="true"
android:paddingTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/assistant_username"
android:background="@drawable/resizable_textfield"
android:textColor="@color/colorB"
android:textCursorDrawable="@null"
android:inputType="textEmailAddress"
android:layout_width="match_parent"
android:layout_height="40dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"/>
<TextView
android:text="@string/password"
style="@style/font13"
android:textAllCaps="true"
android:paddingTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/assistant_password"
android:background="@drawable/resizable_textfield"
android:textColor="@color/colorB"
android:textCursorDrawable="@null"
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="40dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"/>
<TextView
android:text="@string/domain"
style="@style/font13"
android:textAllCaps="true"
android:paddingTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/assistant_domain"
android:background="@drawable/resizable_textfield"
android:textColor="@color/colorB"
android:textCursorDrawable="@null"
android:inputType="textEmailAddress"
android:layout_width="match_parent"
android:layout_height="40dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"/>
<Button
android:id="@+id/assistant_connect"
android:text="@string/assistant_connect"
android:background="@drawable/assistant_button"
style="@style/font8"
android:contentDescription="@string/content_description_validate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_marginTop="20dp"
android:layout_centerInParent="true"
android:layout_centerVertical="true"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
</LinearLayout>
</RelativeLayout>
</LinearLayout>

View file

@ -39,6 +39,7 @@
<string name="assistant_remote_provisioning_title">Fetch remote configuration</string>
<string name="assistant_create">Create account</string>
<string name="assistant_apply">Fetch and apply</string>
<string name="assistant_login">Login</string>
<string name="assistant_ec_calibration">Echo canceller calibration in progress</string>
<string name="assistant_remote_provisioning_login">Enter your login</string>
<string name="assistant_connect">Connection</string>

View file

@ -1182,13 +1182,17 @@ public class LinphonePreferences {
}
public void contactsMigrationDone(){
getConfig().setBool("app", "contacts_migration_done",true);
getConfig().setBool("app", "contacts_migration_done", true);
}
public boolean isContactsMigrationDone(){
return getConfig().getBool("app", "contacts_migration_done",false);
}
public String getXmlRpcServerUrl() {
return getConfig().getString("app", "server_url", null);
}
public String getDebugPopupAddress(){
return getConfig().getString("app", "debug_popup_magic", null);
}

View file

@ -98,7 +98,7 @@ public class AssistantActivity extends Activity implements OnClickListener {
if(address != null && address.asString().equals(cfg.getIdentity()) ) {
if (state == RegistrationState.RegistrationOk) {
if (LinphoneManager.getLc().getDefaultProxyConfig() != null) {
//launchEchoCancellerCalibration(true);
launchEchoCancellerCalibration(true);
success();
}
} else if (state == RegistrationState.RegistrationFailed) {
@ -403,7 +403,7 @@ public class AssistantActivity extends Activity implements OnClickListener {
public void isAccountVerified(String username) {
Toast.makeText(this, getString(R.string.setup_account_validated), Toast.LENGTH_LONG).show();
LinphoneManager.getLcIfManagerNotDestroyedOrNull().refreshRegisters();
//launchEchoCancellerCalibration(true);
launchEchoCancellerCalibration(true);
}
public void isEchoCalibrationFinished() {

View file

@ -18,12 +18,10 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
import static android.content.Intent.ACTION_MAIN;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import org.linphone.LinphoneActivity;
import org.linphone.LinphoneLauncherActivity;
import org.linphone.LinphoneManager;
import org.linphone.LinphonePreferences;
@ -72,7 +70,7 @@ public class RemoteProvisioningActivity extends Activity {
}
};
}
@Override
protected void onResume() {
super.onResume();
@ -81,10 +79,10 @@ public class RemoteProvisioningActivity extends Activity {
lc.addListener(mListener);
}
LinphonePreferences.instance().setContext(this);
checkIntentForConfigUri(getIntent());
}
@Override
protected void onPause() {
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
@ -93,16 +91,21 @@ public class RemoteProvisioningActivity extends Activity {
}
super.onPause();
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
checkIntentForConfigUri(intent);
}
private void checkIntentForConfigUri(final Intent intent) {
new Thread(new Runnable() {
@Override
public void run() {
Uri openUri = intent.getData();
@ -116,7 +119,7 @@ public class RemoteProvisioningActivity extends Activity {
}
Log.d("Using config uri: " + configUriParam);
}
if (configUriParam == null) {
if (!LinphonePreferences.instance().isFirstRemoteProvisioning()) {
mHandler.post(new Runnable() {
@ -135,7 +138,7 @@ public class RemoteProvisioningActivity extends Activity {
}, 1500);
} // else we do nothing if there is no config uri parameter and if user not allowed to leave this screen
} else {
if (getResources().getBoolean(R.bool.display_confirmation_popup_after_first_configuration)
if (getResources().getBoolean(R.bool.display_confirmation_popup_after_first_configuration)
&& !LinphonePreferences.instance().isFirstRemoteProvisioning()) {
mHandler.post(new Runnable() {
@Override
@ -155,31 +158,30 @@ public class RemoteProvisioningActivity extends Activity {
}
}).start();
}
private void displayDialogConfirmation() {
new AlertDialog.Builder(RemoteProvisioningActivity.this)
.setTitle(getString(R.string.remote_provisioning_again_title))
.setMessage(getString(R.string.remote_provisioning_again_message))
.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
setRemoteProvisioningAddressAndRestart(configUriParam);
}
})
.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
goToLinphoneActivity();
}
})
.show();
.setTitle(getString(R.string.remote_provisioning_again_title))
.setMessage(getString(R.string.remote_provisioning_again_message))
.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
setRemoteProvisioningAddressAndRestart(configUriParam);
}
})
.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
goToLinphoneActivity();
}
})
.show();
}
private void setRemoteProvisioningAddressAndRestart(String configUri) {
private void setRemoteProvisioningAddressAndRestart(final String configUri) {
if (spinner != null) spinner.setVisibility(View.VISIBLE);
LinphonePreferences.instance().setContext(this); // Needed, else the next call will crash
LinphonePreferences.instance().setRemoteProvisioningUrl(configUri);
LinphonePreferences.instance().firstRemoteProvisioningSuccessful();
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
@ -187,14 +189,15 @@ public class RemoteProvisioningActivity extends Activity {
}
}, 1000);
}
private void goToLinphoneActivity() {
if (LinphoneService.isReady()) {
LinphoneService.instance().setActivityToLaunchOnIncomingReceived(LinphoneActivity.class);
LinphoneService.instance().setActivityToLaunchOnIncomingReceived(LinphoneLauncherActivity.class);
//finish(); // To prevent the user to come back to this page using back button
startActivity(new Intent().setClass(this, LinphoneActivity.class));
startActivity(new Intent().setClass(this, LinphoneLauncherActivity.class));
} else {
finish();
}
}
}

View file

@ -19,13 +19,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
import org.linphone.LinphoneActivity;
import org.linphone.LinphoneLauncherActivity;
import org.linphone.LinphoneManager;
import org.linphone.LinphonePreferences;
import org.linphone.R;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@ -57,13 +55,7 @@ public class RemoteProvisioningFragment extends Fragment implements OnClickListe
if (id == R.id.assistant_apply) {
String url = remoteProvisioningUrl.getText().toString();
LinphonePreferences.instance().setRemoteProvisioningUrl(url);
// Restart Linphone
Intent intent = new Intent();
intent.setClass(getActivity(), LinphoneLauncherActivity.class);
getActivity().finish();
LinphoneActivity.instance().quit();
startActivity(intent);
LinphoneManager.getInstance().restartLinphoneCore();
}
}
}

View file

@ -18,21 +18,31 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
import org.linphone.LinphoneActivity;
import org.linphone.LinphoneLauncherActivity;
import org.linphone.LinphoneManager;
import org.linphone.LinphonePreferences;
import org.linphone.LinphoneService;
import org.linphone.core.LinphoneCoreListenerBase;
import org.linphone.mediastream.Log;
import org.linphone.R;
import org.linphone.core.LinphoneAuthInfo;
import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCoreException;
import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.LinphoneProxyConfig;
import org.linphone.xmlrpc.XmlRpcHelper;
import org.linphone.xmlrpc.XmlRpcListenerBase;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
/**
* @author Sylvain Berfini
@ -40,24 +50,40 @@ import android.widget.ImageView;
public class RemoteProvisioningLoginActivity extends Activity implements OnClickListener {
private EditText login, password, domain;
private ImageView cancel;
private Button connect;
private LinphoneCoreListenerBase mListener;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.assistant_remote_provisioning_login);
login = (EditText) findViewById(R.id.setup_username);
password = (EditText) findViewById(R.id.setup_password);
domain = (EditText) findViewById(R.id.setup_domain);
login = (EditText) findViewById(R.id.assistant_username);
password = (EditText) findViewById(R.id.assistant_password);
domain = (EditText) findViewById(R.id.assistant_domain);
//cancel = (ImageView) findViewById(R.id.cancel);
//cancel.setOnClickListener(this);
connect = (Button) findViewById(R.id.assistant_connect);
connect.setOnClickListener(this);
cancel = (ImageView) findViewById(R.id.cancel);
cancel.setOnClickListener(this);
String defaultDomain = getIntent().getStringExtra("Domain");
if (defaultDomain != null) {
domain.setText(defaultDomain);
domain.setEnabled(false);
}
mListener = new LinphoneCoreListenerBase(){
@Override
public void configuringStatus(LinphoneCore lc, final LinphoneCore.RemoteProvisioningState state, String message) {
if (state == LinphoneCore.RemoteProvisioningState.ConfiguringSuccessful) {
//TODO
} else if (state == LinphoneCore.RemoteProvisioningState.ConfiguringFailed) {
Toast.makeText(RemoteProvisioningLoginActivity.this, R.string.remote_provisioning_failure, Toast.LENGTH_LONG).show();
}
}
};
}
private void cancelWizard(boolean bypassCheck) {
@ -70,8 +96,20 @@ public class RemoteProvisioningLoginActivity extends Activity implements OnClick
private boolean storeAccount(String username, String password, String domain) {
LinphoneCore lc = LinphoneManager.getLc();
String identity = "sip:" + username + "@" + domain;
XmlRpcHelper xmlRpcHelper = new XmlRpcHelper(null);
xmlRpcHelper.getRemoteProvisioningFilenameAsync(new XmlRpcListenerBase() {
@Override
public void onRemoteProvisioningFilenameSent(String result) {
LinphonePreferences.instance().setRemoteProvisioningUrl(result);
LinphoneManager.getInstance().restartLinphoneCore();
}
}, username.toString(), password.toString(), domain.toString());
LinphonePreferences.instance().firstLaunchSuccessful();
setResult(Activity.RESULT_OK);
finish();
/*String identity = "sip:" + username + "@" + domain;
LinphoneProxyConfig prxCfg = lc.createProxyConfig();
try {
prxCfg.setIdentity(identity);
@ -86,10 +124,28 @@ public class RemoteProvisioningLoginActivity extends Activity implements OnClick
if (LinphonePreferences.instance().getAccountCount() == 1)
lc.setDefaultProxyConfig(prxCfg);
*/
return true;
}
@Override
protected void onResume() {
super.onResume();
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
if (lc != null) {
lc.addListener(mListener);
}
}
@Override
protected void onPause() {
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
if (lc != null) {
lc.removeListener(mListener);
}
super.onPause();
}
@Override
public void onClick(View v) {
int id = v.getId();
@ -97,6 +153,9 @@ public class RemoteProvisioningLoginActivity extends Activity implements OnClick
if (id == R.id.cancel) {
cancelWizard(false);
}
if (id == R.id.assistant_connect){
storeAccount(login.getText().toString(), password.getText().toString(), domain.getText().toString());
}
}
@Override

View file

@ -0,0 +1,884 @@
package org.linphone.xmlrpc;
import java.net.MalformedURLException;
import java.net.URL;
import org.linphone.LinphonePreferences;
import org.linphone.mediastream.Log;
import de.timroes.axmlrpc.XMLRPCCallback;
import de.timroes.axmlrpc.XMLRPCClient;
import de.timroes.axmlrpc.XMLRPCException;
import de.timroes.axmlrpc.XMLRPCServerException;
public class XmlRpcHelper {
public static final String SERVER_ERROR_INVALID_ACCOUNT = "ERROR_INVALID_ACCOUNT";
public static final String SERVER_ERROR_PURCHASE_CANCELLED = "ERROR_PURCHASE_CANCELLED";
public static final String SERVER_ERROR_RECEIPT_PARSING_FAILED = "ERROR_RECEIPT_PARSING_FAILED";
public static final String SERVER_ERROR_UID_ALREADY_IN_USE = "ERROR_UID_ALREADY_IN_USE";
public static final String SERVER_ERROR_SIGNATURE_VERIFICATION_FAILED = "ERROR_SIGNATURE_VERIFICATION_FAILED";
public static final String SERVER_ERROR_ACCOUNT_ALREADY_EXISTS = "ERROR_ACCOUNT_ALREADY_EXISTS";
public static final String SERVER_ERROR_UNKNOWN_ERROR = "ERROR_UNKNOWN_ERROR";
public static final String CLIENT_ERROR_INVALID_SERVER_URL = "INVALID_SERVER_URL";
public static final String CLIENT_ERROR_SERVER_NOT_REACHABLE = "SERVER_NOT_REACHABLE";
private XMLRPCClient mXmlRpcClient;
public XmlRpcHelper(String serverUrl) {
try {
if(serverUrl != null) {
mXmlRpcClient = new XMLRPCClient(new URL(serverUrl));
} else {
mXmlRpcClient = new XMLRPCClient(new URL(LinphonePreferences.instance().getXmlRpcServerUrl()));
}
} catch (MalformedURLException e) {
Log.e(e);
}
}
public void createAccountAsync(final XmlRpcListener listener, String username, String email, String password) {
if (mXmlRpcClient != null) {
mXmlRpcClient.callAsync(new XMLRPCCallback() {
@Override
public void onServerError(long id, XMLRPCServerException error) {
Log.e(error);
listener.onError(error.toString());
}
@Override
public void onResponse(long id, Object object) {
String result = (String)object;
Log.d("createAccountAsync: " + result);
if (result.startsWith("ERROR_")) {
Log.e(result);
listener.onError(result);
return;
}
listener.onAccountCreated(result);
}
@Override
public void onError(long id, XMLRPCException error) {
Log.e(error);
listener.onError(error.toString());
}
}, "create_account", username, email, password == null ? "" : password);
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
listener.onError(CLIENT_ERROR_INVALID_SERVER_URL);
}
}
public String createAccount(String username, String email, String password) {
if (mXmlRpcClient != null) {
try {
Object object = mXmlRpcClient.call("create_account", username, email, password == null ? "" : password);
String result = (String)object;
Log.d("createAccount: " + result);
if (result.startsWith("ERROR_")) {
Log.e(result);
return null;
}
return result;
} catch (XMLRPCException e) {
Log.e(e);
}
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
}
return null;
}
public void getAccountExpireAsync(final XmlRpcListener listener, String username, String password) {
if (mXmlRpcClient != null) {
mXmlRpcClient.callAsync(new XMLRPCCallback() {
@Override
public void onServerError(long id, XMLRPCServerException error) {
Log.e(error);
listener.onError(error.toString());
}
@Override
public void onResponse(long id, Object object) {
String result = (String)object;
Log.d("getAccountExpireAsync: " + result);
if (result.startsWith("ERROR_")) {
Log.e(result);
listener.onError(result);
return;
}
listener.onAccountExpireFetched(result);
}
@Override
public void onError(long id, XMLRPCException error) {
Log.e(error);
listener.onError(error.toString());
}
}, "get_expiration_for_account", username, password);
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
listener.onError(CLIENT_ERROR_INVALID_SERVER_URL);
}
}
public String getAccountExpire(String username, String password) {
if (mXmlRpcClient != null) {
try {
Object object = mXmlRpcClient.call("get_expiration_for_account", username, password);
String result = (String)object;
Log.d("getAccountExpire: " + result);
if (result.startsWith("ERROR_")) {
Log.e(result);
return null;
}
return result;
} catch (XMLRPCException e) {
Log.e(e);
}
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
}
return null;
}
public void updateAccountExpireAsync(final XmlRpcListener listener, String username, String password, String payload, String signature) {
if (mXmlRpcClient != null) {
mXmlRpcClient.callAsync(new XMLRPCCallback() {
@Override
public void onServerError(long id, XMLRPCServerException error) {
Log.e(error);
listener.onError(error.toString());
}
@Override
public void onResponse(long id, Object object) {
String result = (String)object;
Log.d("updateAccountExpireAsync: " + result);
if (result.startsWith("ERROR_")) {
Log.e(result);
listener.onError(result);
return;
}
listener.onAccountExpireUpdated(result);
}
@Override
public void onError(long id, XMLRPCException error) {
Log.e(error);
listener.onError(error.toString());
}
}, "update_expiration_date", username, password, payload, signature);
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
listener.onError(CLIENT_ERROR_INVALID_SERVER_URL);
}
}
public String updateAccountExpire(String username, String password, String payload, String signature) {
if (mXmlRpcClient != null) {
try {
Object object = mXmlRpcClient.call("update_expiration_date", username, password, payload, signature);
String result = (String)object;
Log.d("updateAccountExpire: " + result);
if (result.startsWith("ERROR_")) {
Log.e(result);
return null;
}
return result;
} catch (XMLRPCException e) {
Log.e(e);
}
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
}
return null;
}
public void activateAccountAsync(final XmlRpcListener listener, String username, String password) {
if (mXmlRpcClient != null) {
mXmlRpcClient.callAsync(new XMLRPCCallback() {
@Override
public void onServerError(long id, XMLRPCServerException error) {
Log.e(error);
listener.onError(error.toString());
}
@Override
public void onResponse(long id, Object object) {
String result = (String)object;
Log.d("activateAccountAsync: " + result);
if (result.startsWith("ERROR_")) {
Log.e(result);
listener.onError(result);
return;
}
listener.onAccountActivated(result);
return;
}
@Override
public void onError(long id, XMLRPCException error) {
Log.e(error);
listener.onError(error.toString());
}
}, "activate_account", username, password);
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
listener.onError(CLIENT_ERROR_INVALID_SERVER_URL);
}
}
public String activateAccount(String gmailAccount, String username, String password) {
if (mXmlRpcClient != null) {
try {
Object object = mXmlRpcClient.call("activate_account", username, password);
String result = (String)object;
Log.d("activateAccount: " + result);
if (result.startsWith("ERROR_")) {
Log.e(result);
return null;
}
return result;
} catch (XMLRPCException e) {
Log.e(e);
}
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
}
return null;
}
public void isAccountActivatedAsync(final XmlRpcListener listener, String username) {
if (mXmlRpcClient != null) {
mXmlRpcClient.callAsync(new XMLRPCCallback() {
@Override
public void onServerError(long id, XMLRPCServerException error) {
Log.e(error);
listener.onError(error.toString());
}
@Override
public void onResponse(long id, Object object) {
String result = (String) object;
Log.d("isAccountActivatedAsync: " + result);
if ("OK".equals(result)) {
listener.onAccountActivatedFetched(true);
return;
} else if (!"ERROR_ACCOUNT_NOT_ACTIVATED".equals(result)) {
Log.e(result);
listener.onError(result);
}
listener.onAccountActivatedFetched(false);
}
@Override
public void onError(long id, XMLRPCException error) {
Log.e(error);
listener.onError(error.toString());
}
}, "check_account_activated", username);
}
}
public boolean isAccountActivated(String username) {
if (mXmlRpcClient != null) {
try {
Object object = mXmlRpcClient.call("check_account_activated", username);
String result = (String)object;
Log.d("isAccountActivated: " + result);
if ("OK".equals(result)) {
return true;
} else if (!"ERROR_ACCOUNT_NOT_ACTIVATED".equals(result)) {
Log.e(result);
}
} catch (XMLRPCException e) {
Log.e(e);
}
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
}
return false;
}
public void isTrialAccountAsync(final XmlRpcListener listener, String username, String password) {
if (mXmlRpcClient != null) {
mXmlRpcClient.callAsync(new XMLRPCCallback() {
@Override
public void onServerError(long id, XMLRPCServerException error) {
Log.e(error);
listener.onError(error.toString());
}
@Override
public void onResponse(long id, Object object) {
String result = (String)object;
Log.d("isTrialAccountAsync: " + result);
if (!"NOK".equals(result) && !"OK".equals(result)) {
listener.onError(result);
}
listener.onAccountFetched("OK".equals(result));
}
@Override
public void onError(long id, XMLRPCException error) {
Log.e(error);
listener.onError(error.toString());
}
}, "check_account_trial", username, password);
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
listener.onError(CLIENT_ERROR_INVALID_SERVER_URL);
}
}
public boolean isTrialAccount(String username, String password) {
if (mXmlRpcClient != null) {
try {
Object object = mXmlRpcClient.call("check_account_trial", username, password);
String result = (String)object;
Log.d("isTrialAccount: " + result);
return "OK".equals(result);
} catch (XMLRPCException e) {
Log.e(e);
}
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
}
return false;
}
public void isAccountAsync(final XmlRpcListener listener, String username) {
if (mXmlRpcClient != null) {
mXmlRpcClient.callAsync(new XMLRPCCallback() {
@Override
public void onServerError(long id, XMLRPCServerException error) {
Log.e(error);
listener.onError(error.toString());
}
@Override
public void onResponse(long id, Object object) {
String result = (String)object;
Log.d("isAccountAsync: " + result);
if ("OK".equals(result)) {
listener.onAccountFetched(true);
return;
} else if (!"ERROR_ACCOUNT_DOESNT_EXIST".equals(result)) {
Log.e(result);
listener.onError(result);
}
listener.onAccountFetched(false);
}
@Override
public void onError(long id, XMLRPCException error) {
Log.e(error);
listener.onError(error.toString());
}
}, "check_account_activated", username);
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
listener.onError(CLIENT_ERROR_INVALID_SERVER_URL);
}
}
public boolean isAccount(String username) {
if (mXmlRpcClient != null) {
try {
Object object = mXmlRpcClient.call("check_account_activated", username);
String result = (String)object;
Log.d("isAccount: " + result);
if ("OK".equals(result)) {
return true;
} else if (!"ERROR_ACCOUNT_DOESNT_EXIST".equals(result)) {
Log.e(result);
}
} catch (XMLRPCException e) {
Log.e(e);
}
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
}
return false;
}
public void changeAccountEmailAsync(final XmlRpcListener listener, String username, String password, String newEmail) {
if (mXmlRpcClient != null) {
mXmlRpcClient.callAsync(new XMLRPCCallback() {
@Override
public void onServerError(long id, XMLRPCServerException error) {
Log.e(error);
listener.onError(error.toString());
}
@Override
public void onResponse(long id, Object object) {
String result = (String)object;
Log.d("changeAccountEmailAsync: " + result);
if (result.startsWith("ERROR_")) {
Log.e(result);
listener.onError(result);
return;
}
listener.onAccountEmailChanged(result);
}
@Override
public void onError(long id, XMLRPCException error) {
Log.e(error);
listener.onError(error.toString());
}
}, "change_email", username, password, newEmail);
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
listener.onError(CLIENT_ERROR_INVALID_SERVER_URL);
}
}
public String changeAccountEmail(String username, String password, String newEmail) {
if (mXmlRpcClient != null) {
try {
Object object = mXmlRpcClient.call("change_email", username, password, newEmail);
String result = (String)object;
Log.d("changeAccountEmail: " + result);
if (result.startsWith("ERROR_")) {
Log.e(result);
return null;
}
return result;
} catch (XMLRPCException e) {
Log.e(e);
}
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
}
return null;
}
public void changeAccountPasswordAsync(final XmlRpcListener listener, String username, String oldPassword, String newPassword) {
if (mXmlRpcClient != null) {
mXmlRpcClient.callAsync(new XMLRPCCallback() {
@Override
public void onServerError(long id, XMLRPCServerException error) {
Log.e(error);
listener.onError(error.toString());
}
@Override
public void onResponse(long id, Object object) {
String result = (String)object;
Log.d("changeAccountPasswordAsync: " + result);
if (result.startsWith("ERROR_")) {
Log.e(result);
listener.onError(result);
return;
}
listener.onAccountPasswordChanged(result);
}
@Override
public void onError(long id, XMLRPCException error) {
Log.e(error);
listener.onError(error.toString());
}
}, "change_password", username, oldPassword, newPassword);
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
listener.onError(CLIENT_ERROR_INVALID_SERVER_URL);
}
}
public String changeAccountPassword(String username, String oldPassword, String newPassword) {
if (mXmlRpcClient != null) {
try {
Object object = mXmlRpcClient.call("change_password", username, oldPassword, newPassword);
String result = (String)object;
Log.d("changeAccountPassword: " + result);
if (result.startsWith("ERROR_")) {
Log.e(result);
return null;
}
return result;
} catch (XMLRPCException e) {
Log.e(e);
}
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
}
return null;
}
public void changeAccountHashPasswordAsync(final XmlRpcListener listener, String username, String oldPassword, String newPassword) {
if (mXmlRpcClient != null) {
mXmlRpcClient.callAsync(new XMLRPCCallback() {
@Override
public void onServerError(long id, XMLRPCServerException error) {
Log.e(error);
listener.onError(error.toString());
}
@Override
public void onResponse(long id, Object object) {
String result = (String)object;
Log.d("changeAccountHashPasswordAsync: " + result);
if (result.startsWith("ERROR_")) {
Log.e(result);
listener.onError(result);
return;
}
listener.onAccountPasswordChanged(result);
}
@Override
public void onError(long id, XMLRPCException error) {
Log.e(error);
listener.onError(error.toString());
}
}, "change_hash", username, oldPassword, newPassword);
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
listener.onError(CLIENT_ERROR_INVALID_SERVER_URL);
}
}
public String changeAccountHashPassword(String username, String oldPassword, String newPassword) {
if (mXmlRpcClient != null) {
try {
Object object = mXmlRpcClient.call("change_hash", username, oldPassword, newPassword);
String result = (String)object;
Log.d("changeAccountHashPassword: " + result);
if (result.startsWith("ERROR_")) {
Log.e(result);
return null;
}
return result;
} catch (XMLRPCException e) {
Log.e(e);
}
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
}
return null;
}
public void sendRecoverPasswordLinkByEmailAsync(final XmlRpcListener listener, String usernameOrEmail) {
if (mXmlRpcClient != null) {
mXmlRpcClient.callAsync(new XMLRPCCallback() {
@Override
public void onServerError(long id, XMLRPCServerException error) {
Log.e(error);
listener.onError(error.toString());
}
@Override
public void onResponse(long id, Object object) {
String result = (String)object;
Log.d("sendRecoverPasswordLinkByEmailAsync: " + result);
if (result.startsWith("ERROR_")) {
Log.e(result);
listener.onError(result);
return;
}
listener.onRecoverPasswordLinkSent(result);
}
@Override
public void onError(long id, XMLRPCException error) {
Log.e(error);
listener.onError(error.toString());
}
}, "send_reset_account_password_email", usernameOrEmail);
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
listener.onError(CLIENT_ERROR_INVALID_SERVER_URL);
}
}
public String sendRecoverPasswordLinkByEmail(String usernameOrEmail) {
if (mXmlRpcClient != null) {
try {
Object object = mXmlRpcClient.call("send_reset_account_password_email", usernameOrEmail);
String result = (String)object;
Log.d("sendRecoverPasswordLinkByEmail: " + result);
if (result.startsWith("ERROR_")) {
Log.e(result);
return null;
}
return result;
} catch (XMLRPCException e) {
Log.e(e);
}
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
}
return null;
}
public void sendActivateAccountLinkByEmailAsync(final XmlRpcListener listener, String usernameOrEmail) {
if (mXmlRpcClient != null) {
mXmlRpcClient.callAsync(new XMLRPCCallback() {
@Override
public void onServerError(long id, XMLRPCServerException error) {
Log.e(error);
listener.onError(error.toString());
}
@Override
public void onResponse(long id, Object object) {
String result = (String)object;
Log.d("sendActivateAccountLinkByEmailAsync: " + result);
if (result.startsWith("ERROR_")) {
Log.e(result);
listener.onError(result);
return;
}
listener.onActivateAccountLinkSent(result);
}
@Override
public void onError(long id, XMLRPCException error) {
Log.e(error);
listener.onError(error.toString());
}
}, "resend_activation_email", usernameOrEmail);
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
listener.onError(CLIENT_ERROR_INVALID_SERVER_URL);
}
}
public String sendActivateAccountLinkByEmail(String usernameOrEmail) {
if (mXmlRpcClient != null) {
try {
Object object = mXmlRpcClient.call("resend_activation_email", usernameOrEmail);
String result = (String)object;
Log.d("sendActivateAccountLinkByEmail: " + result);
if (result.startsWith("ERROR_")) {
Log.e(result);
return null;
}
return result;
} catch (XMLRPCException e) {
Log.e(e);
}
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
}
return null;
}
public void sendUsernameByEmailAsync(final XmlRpcListener listener, String email) {
if (mXmlRpcClient != null) {
mXmlRpcClient.callAsync(new XMLRPCCallback() {
@Override
public void onServerError(long id, XMLRPCServerException error) {
Log.e(error);
listener.onError(error.toString());
}
@Override
public void onResponse(long id, Object object) {
String result = (String)object;
Log.d("sendUsernameByEmailAsync: " + result);
if (result.startsWith("ERROR_")) {
Log.e(result);
listener.onError(result);
return;
}
listener.onUsernameSent(result);
}
@Override
public void onError(long id, XMLRPCException error) {
Log.e(error);
listener.onError(error.toString());
}
}, "recover_username_from_email", email);
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
listener.onError(CLIENT_ERROR_INVALID_SERVER_URL);
}
}
public String sendUsernameByEmail(String email) {
if (mXmlRpcClient != null) {
try {
Object object = mXmlRpcClient.call("recover_username_from_email", email);
String result = (String)object;
Log.d("sendUsernameByEmail: " + result);
if (result.startsWith("ERROR_")) {
Log.e(result);
return null;
}
return result;
} catch (XMLRPCException e) {
Log.e(e);
}
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
}
return null;
}
public void verifySignatureAsync(final XmlRpcListener listener, String payload, String signature) {
if (mXmlRpcClient != null) {
mXmlRpcClient.callAsync(new XMLRPCCallback() {
@Override
public void onServerError(long id, XMLRPCServerException error) {
Log.e(error);
listener.onError(error.toString());
}
@Override
public void onResponse(long id, Object object) {
String result = (String)object;
Log.d("verifySignatureAsync: " + result);
if (result.startsWith("ERROR_")) {
Log.e(result);
listener.onError(result);
return;
}
listener.onSignatureVerified("OK".equals(result));
}
@Override
public void onError(long id, XMLRPCException error) {
Log.e(error);
listener.onError(error.toString());
}
}, "verify_payload_signature", payload, signature);
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
listener.onError(CLIENT_ERROR_INVALID_SERVER_URL);
}
}
public boolean verifySignature(String payload, String signature) {
if (mXmlRpcClient != null) {
try {
Object object = mXmlRpcClient.call("verify_payload_signature", payload, signature);
String result = (String)object;
Log.d("verifySignature: " + result);
if (result.startsWith("ERROR_")) {
Log.e(result);
return false;
}
return "OK".equals(result);
} catch (XMLRPCException e) {
Log.e(e);
}
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
}
return false;
}
public void getRemoteProvisioningFilenameAsync(final XmlRpcListener listener,String username, String domain, String password){
if (mXmlRpcClient != null) {
mXmlRpcClient.callAsync(new XMLRPCCallback() {
@Override
public void onServerError(long id, XMLRPCServerException error) {
Log.e(error);
listener.onError(error.toString());
}
@Override
public void onResponse(long id, Object object) {
String result = (String)object;
Log.d("getRemoteProvisioningFilenameAsync: " + result);
if (result.startsWith("ERROR_")) {
Log.e(result);
listener.onError(result);
return;
}
listener.onRemoteProvisioningFilenameSent(result);
}
@Override
public void onError(long id, XMLRPCException error) {
Log.e(error);
listener.onError(error.toString());
}
}, "get_remote_provisioning_filename", username, domain, password);
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
listener.onError(CLIENT_ERROR_INVALID_SERVER_URL);
}
}
public String getRemoteProvisioningFilename(String username, String domain, String password){
if (mXmlRpcClient != null) {
try {
Object object = mXmlRpcClient.call("get_remote_provisioning_filename", username, domain, password);
String result = (String)object;
Log.d("getRemoteProvisioningFilename:: " + result);
if (result.startsWith("ERROR_")) {
Log.e(result);
return result;
}
return result;
} catch (XMLRPCException e) {
Log.e(e);
}
} else {
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
}
return null;
}
}

View file

@ -0,0 +1,19 @@
package org.linphone.xmlrpc;
public interface XmlRpcListener {
public void onError(String error);
public void onAccountCreated(String result);
public void onAccountExpireFetched(String result);
public void onAccountExpireUpdated(String result);
public void onAccountActivated(String result);
public void onAccountActivatedFetched(boolean isActivated);
public void onTrialAccountFetched(boolean isTrial);
public void onAccountFetched(boolean isExisting);
public void onAccountEmailChanged(String result);
public void onAccountPasswordChanged(String result);
public void onRecoverPasswordLinkSent(String result);
public void onActivateAccountLinkSent(String result);
public void onSignatureVerified(boolean success);
public void onUsernameSent(String result);
public void onRemoteProvisioningFilenameSent(String result);
}

View file

@ -0,0 +1,93 @@
package org.linphone.xmlrpc;
public class XmlRpcListenerBase implements XmlRpcListener {
@Override
public void onError(String error) {
// TODO Auto-generated method stub
}
@Override
public void onAccountCreated(String result) {
// TODO Auto-generated method stub
}
@Override
public void onAccountExpireFetched(String result) {
// TODO Auto-generated method stub
}
@Override
public void onAccountActivated(String result) {
// TODO Auto-generated method stub
}
@Override
public void onAccountActivatedFetched(boolean isActivated) {
// TODO Auto-generated method stub
}
@Override
public void onTrialAccountFetched(boolean isTrial) {
// TODO Auto-generated method stub
}
@Override
public void onAccountFetched(boolean isExisting) {
// TODO Auto-generated method stub
}
@Override
public void onAccountEmailChanged(String result) {
// TODO Auto-generated method stub
}
@Override
public void onAccountPasswordChanged(String result) {
// TODO Auto-generated method stub
}
@Override
public void onRecoverPasswordLinkSent(String result) {
// TODO Auto-generated method stub
}
@Override
public void onActivateAccountLinkSent(String result) {
// TODO Auto-generated method stub
}
@Override
public void onAccountExpireUpdated(String result) {
// TODO Auto-generated method stub
}
@Override
public void onSignatureVerified(boolean success) {
// TODO Auto-generated method stub
}
@Override
public void onUsernameSent(String result) {
// TODO Auto-generated method stub
}
@Override
public void onRemoteProvisioningFilenameSent(String result) {
// TODO Auto-generated method stub
}
}