use of com.voipgrid.vialer.util.AccountHelper in project vialer-android by VoIPGRID.
the class NavigationDrawerActivity method performLogout.
/**
* Perform logout; Remove the stored SystemUser and PhoneAccount and show the login view
*/
private void performLogout() {
if (mConnectivityHelper.hasNetworkConnection()) {
MiddlewareHelper.unregister(this);
// Delete our account information.
mJsonStorage.clear();
new AccountHelper(this).clearCredentials();
// Mark ourselves as unregistered.
PreferenceManager.getDefaultSharedPreferences(this).edit().putInt(REGISTRATION_STATUS, STATUS_UNREGISTERED).apply();
// Start a new session.
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
} else {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setTitle(getText(R.string.cannot_logout_error_title));
alertDialogBuilder.setMessage(getText(R.string.cannot_logout_error_text)).setCancelable(false).setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
}
use of com.voipgrid.vialer.util.AccountHelper in project vialer-android by VoIPGRID.
the class WebActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookie();
if (getIntent().getStringExtra(PAGE).equals(getString(R.string.web_password_change))) {
AccountHelper accountHelper = new AccountHelper(this);
accountHelper.clearCredentials();
}
finish();
return true;
}
use of com.voipgrid.vialer.util.AccountHelper in project vialer-android by VoIPGRID.
the class WebActivityHelper method startWebActivity.
/**
* Start a new WebActivity to display the page.
* @param title
* @param page
*/
public void startWebActivity(String title, String page, String gaTitle) {
AccountHelper accountHelper = new AccountHelper(mContext);
Intent intent = new Intent(mContext, WebActivity.class);
intent.putExtra(WebActivity.PAGE, page);
intent.putExtra(WebActivity.TITLE, title);
intent.putExtra(WebActivity.USERNAME, accountHelper.getEmail());
intent.putExtra(WebActivity.PASSWORD, accountHelper.getPassword());
if (gaTitle != null) {
intent.putExtra(WebActivity.GA_TITLE, gaTitle);
}
mContext.startActivity(intent);
}
use of com.voipgrid.vialer.util.AccountHelper in project vialer-android by VoIPGRID.
the class MiddlewareHelper method register.
public static void register(final Context context, String token) {
Preferences sipPreferences = new Preferences(context);
Tracker analyticsTracker = ((AnalyticsApplication) context.getApplicationContext()).getDefaultTracker();
final AnalyticsHelper analyticsHelper = new AnalyticsHelper(analyticsTracker);
if (!sipPreferences.canUseSip()) {
return;
}
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
final SharedPreferences.Editor editor = preferences.edit();
editor.putLong(LAST_REGISTRATION, System.currentTimeMillis());
JsonStorage jsonStorage = new JsonStorage(context);
AccountHelper accountHelper = new AccountHelper(context);
if (!jsonStorage.has(PhoneAccount.class)) {
return;
}
Registration api = ServiceGenerator.createService(context, Registration.class, getBaseApiUrl(context), accountHelper.getEmail(), accountHelper.getPassword());
String sipUserId = ((PhoneAccount) jsonStorage.get(PhoneAccount.class)).getAccountId();
String fullName = ((SystemUser) jsonStorage.get(SystemUser.class)).getFullName();
String appName = context.getPackageName();
Call<ResponseBody> call = api.register(fullName, token, sipUserId, Build.VERSION.CODENAME, Build.VERSION.RELEASE, appName);
editor.putString(CURRENT_TOKEN, token);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
if (response.isSuccessful()) {
setRegistrationStatus(context, STATUS_REGISTERED);
} else {
setRegistrationStatus(context, STATUS_FAILED);
analyticsHelper.sendException(context.getString(R.string.analytics_event_description_registration_failed));
}
editor.apply();
}
@Override
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
t.printStackTrace();
setRegistrationStatus(context, STATUS_FAILED);
}
});
}
use of com.voipgrid.vialer.util.AccountHelper in project vialer-android by VoIPGRID.
the class MiddlewareHelper method unregister.
/**
* Function to synchronously unregister at the middleware if a phone account and
* token are present.
* @param context
*/
public static void unregister(final Context context) {
final RemoteLogger remoteLogger = new RemoteLogger(MiddlewareHelper.class).enableConsoleLogging();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
String token = preferences.getString(CURRENT_TOKEN, "");
// Check if we have a phone account and a push token.
if (new Preferences(context).hasPhoneAccount() && !token.equals("")) {
JsonStorage jsonStorage = new JsonStorage(context);
AccountHelper accountHelper = new AccountHelper(context);
Registration api = ServiceGenerator.createService(context, Registration.class, getBaseApiUrl(context), accountHelper.getEmail(), accountHelper.getPassword());
String sipUserId = ((PhoneAccount) jsonStorage.get(PhoneAccount.class)).getAccountId();
String appName = context.getPackageName();
Call<ResponseBody> call = api.unregister(token, sipUserId, appName);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
if (response.isSuccessful()) {
remoteLogger.d("unregister successful");
setRegistrationStatus(context, STATUS_UNREGISTERED);
} else {
remoteLogger.d("unregister failed");
setRegistrationStatus(context, STATUS_FAILED);
}
}
@Override
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
remoteLogger.d("unregister failed");
setRegistrationStatus(context, STATUS_FAILED);
}
});
} else {
remoteLogger.d("No token or phone account so unregister");
setRegistrationStatus(context, STATUS_FAILED);
}
}
Aggregations