Search in sources :

Example 11 with RemoteLogger

use of com.voipgrid.vialer.logging.RemoteLogger 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();
}
Also used : AnalyticsApplication(com.voipgrid.vialer.analytics.AnalyticsApplication) Intent(android.content.Intent) RemoteLogger(com.voipgrid.vialer.logging.RemoteLogger) ProximitySensorHelper(com.voipgrid.vialer.util.ProximitySensorHelper) AnalyticsHelper(com.voipgrid.vialer.analytics.AnalyticsHelper)

Example 12 with RemoteLogger

use of com.voipgrid.vialer.logging.RemoteLogger in project vialer-android by VoIPGRID.

the class SyncUtils method requestContactSync.

/**
 * Function to initiate a contact sync. The only function that should be used to initiate
 * a contact sync.
 *
 * @param context
 */
public static void requestContactSync(Context context) {
    new RemoteLogger(SyncUtils.class).d(TAG + " requestContactSync");
    // job we can't really ask the user for permission.
    if (!ContactsPermission.hasPermission(context)) {
        // TODO VIALA-349 Delete sync account.
        return;
    }
    // No need to request sync when a full sync is in progress.
    if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SyncConstants.FULL_SYNC_INPROGRESS, false)) {
        return;
    }
    Account account = checkSyncAccount(context);
    ContentResolver.requestSync(account, ContactsContract.AUTHORITY, new Bundle());
}
Also used : Account(android.accounts.Account) Bundle(android.os.Bundle) RemoteLogger(com.voipgrid.vialer.logging.RemoteLogger)

Example 13 with RemoteLogger

use of com.voipgrid.vialer.logging.RemoteLogger in project vialer-android by VoIPGRID.

the class MiddlewareHelper method registerAtMiddleware.

/**
 * Register token at the middleware.
 *
 * @param context Context
 */
public static void registerAtMiddleware(Context context) {
    RemoteLogger remoteLogger = new RemoteLogger(MiddlewareHelper.class).enableConsoleLogging();
    String refreshedToken = FirebaseInstanceId.getInstance().getToken();
    remoteLogger.d("New refresh token: " + refreshedToken);
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    String currentToken = preferences.getString(CURRENT_TOKEN, "");
    remoteLogger.d("Current token: " + currentToken);
    // If token changed or we are not registered with the middleware register.
    if (refreshedToken != null) {
        register(context, refreshedToken);
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) RemoteLogger(com.voipgrid.vialer.logging.RemoteLogger)

Example 14 with RemoteLogger

use of com.voipgrid.vialer.logging.RemoteLogger 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);
    }
}
Also used : AccountHelper(com.voipgrid.vialer.util.AccountHelper) SharedPreferences(android.content.SharedPreferences) ResponseBody(okhttp3.ResponseBody) PhoneAccount(com.voipgrid.vialer.api.models.PhoneAccount) Registration(com.voipgrid.vialer.api.Registration) RemoteLogger(com.voipgrid.vialer.logging.RemoteLogger) SharedPreferences(android.content.SharedPreferences) Preferences(com.voipgrid.vialer.Preferences) JsonStorage(com.voipgrid.vialer.util.JsonStorage)

Example 15 with RemoteLogger

use of com.voipgrid.vialer.logging.RemoteLogger in project vialer-android by VoIPGRID.

the class ServiceGenerator method getHttpClient.

/**
 * Function to create the HttpClient to be used by retrofit for API calls.
 * @param context
 * @param username
 * @param password
 * @return
 */
private static OkHttpClient getHttpClient(final Context context, final String username, final String password) {
    httpClient.addInterceptor(new Interceptor() {

        @Override
        public Response intercept(Chain chain) throws IOException {
            Request original = chain.request();
            Request.Builder requestBuilder = original.newBuilder();
            if (username != null && password != null) {
                requestBuilder.header("Authorization", Credentials.basic(username, password));
            }
            requestBuilder.header("User-Agent", getUserAgentHeader(context));
            if (ConnectivityHelper.get(context).hasNetworkConnection()) {
                // read from cache for 1 minute
                int maxAge = 60;
                requestBuilder.header("Cache-Control", "public, max-age=" + maxAge);
            } else {
                // tolerate 4-weeks stale
                int maxStale = 60 * 60 * 24 * 28;
                requestBuilder.header("Cache-Control", "public, only-if-cached, max-stale=" + maxStale);
            }
            Request request = requestBuilder.build();
            Response response = chain.proceed(request);
            // Check if we get a 401 and are not in the onboarding.
            if (response.code() == 401 && !context.getClass().getSimpleName().equals(SetupActivity.class.getSimpleName())) {
                new RemoteLogger(ServiceGenerator.class).w("Logged out on 401 API response");
                // Clear logged in values.
                new JsonStorage(context).clear();
                new AccountHelper(context).clearCredentials();
                if (context instanceof Activity) {
                    // Start onboarding.
                    Intent intent = new Intent(context, SetupActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    context.startActivity(intent);
                    ((Activity) context).finish();
                }
            }
            return response;
        }
    });
    httpClient.cache(getCache(context));
    return httpClient.build();
}
Also used : AccountHelper(com.voipgrid.vialer.util.AccountHelper) GsonBuilder(com.google.gson.GsonBuilder) Request(okhttp3.Request) SetupActivity(com.voipgrid.vialer.onboarding.SetupActivity) Activity(android.app.Activity) Intent(android.content.Intent) IOException(java.io.IOException) Response(okhttp3.Response) SetupActivity(com.voipgrid.vialer.onboarding.SetupActivity) RemoteLogger(com.voipgrid.vialer.logging.RemoteLogger) JsonStorage(com.voipgrid.vialer.util.JsonStorage) Interceptor(okhttp3.Interceptor)

Aggregations

RemoteLogger (com.voipgrid.vialer.logging.RemoteLogger)17 JsonStorage (com.voipgrid.vialer.util.JsonStorage)5 Bundle (android.os.Bundle)4 Preferences (com.voipgrid.vialer.Preferences)4 Intent (android.content.Intent)3 Account (android.accounts.Account)2 SharedPreferences (android.content.SharedPreferences)2 AnalyticsApplication (com.voipgrid.vialer.analytics.AnalyticsApplication)2 AnalyticsHelper (com.voipgrid.vialer.analytics.AnalyticsHelper)2 PhoneAccount (com.voipgrid.vialer.api.models.PhoneAccount)2 SystemUser (com.voipgrid.vialer.api.models.SystemUser)2 SetupActivity (com.voipgrid.vialer.onboarding.SetupActivity)2 AccountHelper (com.voipgrid.vialer.util.AccountHelper)2 Activity (android.app.Activity)1 Fragment (android.app.Fragment)1 IntentFilter (android.content.IntentFilter)1 MatrixCursor (android.database.MatrixCursor)1 Handler (android.os.Handler)1 MediaSessionCompat (android.support.v4.media.session.MediaSessionCompat)1 PlaybackStateCompat (android.support.v4.media.session.PlaybackStateCompat)1