use of com.voipgrid.vialer.analytics.AnalyticsHelper in project vialer-android by VoIPGRID.
the class CallActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mRemoteLogger = new RemoteLogger(CallActivity.class).enableConsoleLogging();
mRemoteLogger.d("onCreate");
// Check if we have permission to use the microphone. If not, request it.
if (!MicrophonePermission.hasPermission(this)) {
MicrophonePermission.askForPermission(this);
}
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
setContentView(R.layout.activity_call);
// Fetch a broadcast manager for communication.
mBroadcastManager = LocalBroadcastManager.getInstance(this);
mNotificationHelper = NotificationHelper.getInstance(this);
// Set the AnalyticsHelper.
mAnalyticsHelper = new AnalyticsHelper(((AnalyticsApplication) getApplication()).getDefaultTracker());
mMediaManager = MediaManager.init(this, this, this);
mProximityHelper = new ProximitySensorHelper(this, this, findViewById(R.id.screen_off));
// Fetch a broadcast manager for communication to the sip service
mBroadcastManager = LocalBroadcastManager.getInstance(this);
mStateView = (TextView) findViewById(R.id.state_text_view);
mCallDurationView = (TextView) findViewById(R.id.duration_text_view);
mConnected = false;
onCallStatesUpdateButtons(SERVICE_STOPPED);
Intent intent = getIntent();
// Get the intent to see if it's an outgoing or an incoming call.
mType = intent.getType();
if (mType.equals(TYPE_INCOMING_CALL) || mType.equals(TYPE_OUTGOING_CALL)) {
// Update the textView with a number URI.
mPhoneNumberToDisplay = intent.getStringExtra(PHONE_NUMBER);
mCallerIdToDisplay = intent.getStringExtra(CONTACT_NAME);
displayCallInfo();
mIsIncomingCall = mType.equals(TYPE_INCOMING_CALL);
Boolean openedFromNotification = intent.getBooleanExtra(NotificationHelper.TAG, false);
if (openedFromNotification && !mIsIncomingCall) {
mNotificationId = mNotificationHelper.displayCallProgressNotification(getCallerInfo(), getString(R.string.callnotification_active_call), TYPE_CONNECTED_CALL, mCallerIdToDisplay, mPhoneNumberToDisplay, NotificationHelper.mCallNotifyId);
toggleCallStateButtonVisibility(TYPE_CONNECTED_CALL);
// Keep timer running for as long as possible.
mCallHandler.postDelayed(mCallDurationRunnable, 1000);
mCallDurationView.setVisibility(View.VISIBLE);
} else {
toggleCallStateButtonVisibility(mType);
if (mIsIncomingCall) {
mRemoteLogger.d("inComingCall");
mNotificationHelper.removeAllNotifications();
mNotificationId = mNotificationHelper.displayCallProgressNotification(getCallerInfo(), getString(R.string.callnotification_incoming_call), mType, mCallerIdToDisplay, mPhoneNumberToDisplay, NotificationHelper.mCallNotifyId);
// Ringing event.
mAnalyticsHelper.sendEvent(getString(R.string.analytics_event_category_call), getString(R.string.analytics_event_action_inbound), getString(R.string.analytics_event_label_ringing));
if (!ReadExternalStoragePermission.hasPermission(this)) {
ReadExternalStoragePermission.askForPermission(this);
}
mIncomingCallIsRinging = true;
mMediaManager.startIncomingCallRinger();
} else {
mRemoteLogger.d("outgoingCall");
mNotificationId = mNotificationHelper.displayCallProgressNotification(getCallerInfo(), getString(R.string.callnotification_dialing), mType, mCallerIdToDisplay, mPhoneNumberToDisplay, NotificationHelper.mCallNotifyId);
}
}
mMediaManager.callStarted();
}
mProximityHelper.startSensor();
}
use of com.voipgrid.vialer.analytics.AnalyticsHelper in project vialer-android by VoIPGRID.
the class CallRecordFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* set the AnalyticsHelper */
mAnalyticsHelper = new AnalyticsHelper(((AnalyticsApplication) getActivity().getApplication()).getDefaultTracker());
mConnectivityHelper = ConnectivityHelper.get(getActivity());
mJsonStorage = new JsonStorage(getActivity());
mFilter = getArguments().getString(ARG_FILTER);
}
use of com.voipgrid.vialer.analytics.AnalyticsHelper 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.analytics.AnalyticsHelper in project vialer-android by VoIPGRID.
the class SipCall method sendMos.
private void sendMos() {
if (getCallDuration() > 10) {
float mos = this.calculateMos();
new AnalyticsHelper(((AnalyticsApplication) mSipService.getApplication()).getDefaultTracker()).sendEvent(mSipService.getString(R.string.analytics_event_category_metrics), mSipService.getString(R.string.analytics_event_action_callmetrics), mSipService.getString(R.string.analytics_event_label_mos, getCodec(), getConnectionType()), (int) (100 * (long) mos));
mRemoteLogger.e("MOS for CONNECTION: " + ConnectivityHelper.get(mSipService).getConnectionTypeString() + " with value: " + mos);
}
}
use of com.voipgrid.vialer.analytics.AnalyticsHelper in project vialer-android by VoIPGRID.
the class SipConfig method respondToMiddleware.
/**
* Response to the middleware on a incoming call to notify asterisk we are ready to accept
* calls.
*/
private void respondToMiddleware() {
Intent incomingCallDetails = mSipService.getIncomingCallDetails();
if (incomingCallDetails == null) {
mRemoteLogger.w("Trying to respond to middleware with no details");
return;
}
String url = incomingCallDetails.getStringExtra(SipConstants.EXTRA_RESPONSE_URL);
String messageStartTime = incomingCallDetails.getStringExtra(FcmMessagingService.MESSAGE_START_TIME);
String token = incomingCallDetails.getStringExtra(SipConstants.EXTRA_REQUEST_TOKEN);
// Set responded as soon as possible to avoid duplicate requests due to multiple
// onAccountRegistered calls in a row.
mHasRespondedToMiddleware = true;
AnalyticsHelper analyticsHelper = new AnalyticsHelper(((AnalyticsApplication) mSipService.getApplication()).getDefaultTracker());
Registration registrationApi = ServiceGenerator.createService(mSipService, Registration.class, url);
String analyticsLabel = ConnectivityHelper.get(mSipService).getAnalyticsLabel();
// Accepted event.
analyticsHelper.sendEvent(mSipService.getString(R.string.analytics_event_category_middleware), mSipService.getString(R.string.analytics_event_action_middleware_accepted), analyticsLabel);
// To ms.
long startTime = (long) (Double.parseDouble(messageStartTime) * 1000);
long startUpTime = System.currentTimeMillis() - startTime;
// Response timing.
analyticsHelper.sendTiming(mSipService.getString(R.string.analytics_event_category_middleware), mSipService.getString(R.string.analytics_event_name_call_response), startUpTime);
retrofit2.Call<ResponseBody> call = registrationApi.reply(token, true, messageStartTime);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(@NonNull retrofit2.Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
if (!response.isSuccessful()) {
mRemoteLogger.w("Unsuccessful response to middleware: " + Integer.toString(response.code()));
mSipService.stopSelf();
}
}
@Override
public void onFailure(@NonNull retrofit2.Call<ResponseBody> call, @NonNull Throwable t) {
mRemoteLogger.w("Failed sending response to middleware");
mSipService.stopSelf();
}
});
}
Aggregations