use of com.voipgrid.vialer.Preferences 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);
}
}
use of com.voipgrid.vialer.Preferences in project vialer-android by VoIPGRID.
the class ReachabilityBarView method initLayout.
private void initLayout() {
mReachabilityBarView = (RelativeLayout) LayoutInflater.from(mContext).inflate(R.layout.view_reachability_bar, this);
mReachabilityBarTextView = (TextView) mReachabilityBarView.findViewById(R.id.reachability_bar_text_view);
mReachabilityInfoImageView = (ImageView) mReachabilityBarView.findViewById(R.id.reachability_bar_drawable_info_icon);
mReachabilityInfoImageView.setOnClickListener(this);
if (!isInEditMode()) {
mConnectivityHelper = ConnectivityHelper.get(mContext);
mPreferences = new Preferences(mContext);
} else {
mReachabilityBarTextView.setText(R.string.dialer_warning_voip_disabled);
}
ReachabilityReceiver.setInterfaceCallback(this);
}
use of com.voipgrid.vialer.Preferences in project vialer-android by VoIPGRID.
the class SipService method onCreate.
@Override
public void onCreate() {
super.onCreate();
mHandler = new Handler();
mToneGenerator = new ToneGenerator(AudioManager.STREAM_VOICE_CALL, SipConstants.RINGING_VOLUME);
mSipBroadcaster = new SipBroadcaster(this);
mPreferences = new Preferences(this);
mRemoteLogger = new RemoteLogger(SipService.class).enableConsoleLogging();
mNativeCallManager = new NativeCallManager((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE));
mRemoteLogger.d("onCreate");
IntentFilter filter = new IntentFilter();
filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
registerReceiver(phoneStateReceiver, filter);
// Create runnable to check if the SipService is still in use.
mCheckServiceHandler = new Handler();
mCheckServiceRunnable = new Runnable() {
@Override
public void run() {
// Check if the service is being used after 10 seconds and shutdown the service
// if required.
checkServiceBeingUsed();
mCheckServiceHandler.postDelayed(this, mCheckServiceUsedTimer);
}
};
mCheckServiceHandler.postDelayed(mCheckServiceRunnable, mCheckServiceUsedTimer);
PhoneAccount phoneAccount = new JsonStorage<PhoneAccount>(this).get(PhoneAccount.class);
if (phoneAccount != null) {
// Try to load PJSIP library.
mSipConfig = new SipConfig(this, phoneAccount);
try {
mSipConfig.initLibrary();
} catch (SipConfig.LibraryInitFailedException e) {
stopSelf();
}
} else {
// User has no sip account so destroy the service.
mRemoteLogger.w("No sip account when trying to create service");
stopSelf();
}
}
Aggregations