Search in sources :

Example 1 with ConnectivityHelper

use of com.voipgrid.vialer.util.ConnectivityHelper in project vialer-android by VoIPGRID.

the class LoginFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    Activity activity = getActivity();
    mConnectivityHelper = new ConnectivityHelper((ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE), (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE));
    mEmailEdittext = (EditText) view.findViewById(R.id.emailTextDialog);
    mEmailEdittext.addTextChangedListener(this);
    mPasswordEdittext = (EditText) view.findViewById(R.id.passwordTextDialog);
    mPasswordEdittext.addTextChangedListener(this);
    mPasswordEdittext.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            // forgot password and initiates a login.
            return actionId == EditorInfo.IME_ACTION_DONE && mLoginButton.performClick();
        }
    });
    mLoginButton = (Button) view.findViewById(R.id.button_login);
    mLoginButton.setOnClickListener(this);
    mForgotPasswordButton = (Button) view.findViewById(R.id.button_forgot_password);
    mForgotPasswordButton.setOnClickListener(this);
    mInfoButton = (Button) view.findViewById(R.id.button_info);
    mInfoButton.setOnClickListener(this);
}
Also used : KeyEvent(android.view.KeyEvent) ConnectivityHelper(com.voipgrid.vialer.util.ConnectivityHelper) TelephonyManager(android.telephony.TelephonyManager) ConnectivityManager(android.net.ConnectivityManager) WebActivity(com.voipgrid.vialer.WebActivity) Activity(android.app.Activity) TextView(android.widget.TextView)

Example 2 with ConnectivityHelper

use of com.voipgrid.vialer.util.ConnectivityHelper in project vialer-android by VoIPGRID.

the class FcmMessagingService method onMessageReceived.

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);
    mRemoteLogger.d("onMessageReceived");
    Map<String, String> data = remoteMessage.getData();
    String requestType = data.get(MESSAGE_TYPE);
    LogHelper.using(mRemoteLogger).logMiddlewareMessageReceived(remoteMessage, requestType);
    if (requestType == null) {
        mRemoteLogger.e("No requestType");
        return;
    }
    if (requestType.equals(CALL_REQUEST_TYPE)) {
        AnalyticsHelper analyticsHelper = new AnalyticsHelper(((AnalyticsApplication) getApplication()).getDefaultTracker());
        ConnectivityHelper connectivityHelper = ConnectivityHelper.get(this);
        mRemoteLogger.d("SipService Active: " + SipService.sipServiceActive);
        mRemoteLogger.d("CurrentConnection: " + connectivityHelper.getConnectionTypeString());
        mRemoteLogger.d("Payload: " + data.toString());
        boolean connectionSufficient = connectivityHelper.hasNetworkConnection() && connectivityHelper.hasFastData();
        // just return and don't reply to the middleware for now.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
            boolean isDeviceIdleMode = powerManager.isDeviceIdleMode();
            mRemoteLogger.d("is device in idle mode: " + isDeviceIdleMode);
            if (isDeviceIdleMode && !connectionSufficient) {
                mRemoteLogger.e("Device in idle mode and connection insufficient. For now do nothing wait for next middleware push.");
                return;
            }
        }
        if (!connectionSufficient) {
            mRemoteLogger.e("Connection is insufficient. For now do nothing and wait for next middleware push");
            return;
        }
        // fast enough to support VoIP call.
        if (!SipService.sipServiceActive) {
            String number = data.get(PHONE_NUMBER);
            // Is the current number suppressed.
            if (number != null && (number.equalsIgnoreCase(SUPPRESSED) || number.toLowerCase().contains("xxxx"))) {
                number = getString(R.string.supressed_number);
            }
            String callerId = data.get(CALLER_ID) != null ? data.get(CALLER_ID) : "";
            String responseUrl = data.get(RESPONSE_URL) != null ? data.get(RESPONSE_URL) : "";
            String requestToken = data.get(REQUEST_TOKEN) != null ? data.get(REQUEST_TOKEN) : "";
            String messageStartTime = data.get(MESSAGE_START_TIME) != null ? data.get(MESSAGE_START_TIME) : "";
            mRemoteLogger.d("Payload processed, calling startService method");
            // First start the SIP service with an incoming call.
            startSipService(number, callerId, responseUrl, requestToken, messageStartTime);
        } else {
            mRemoteLogger.d("Reject due to lack of connection");
            // Inform the middleware the incoming call is received but the app can not handle
            // the sip call because there is no LTE or Wifi connection available at this
            // point.
            String analyticsLabel = connectivityHelper.getAnalyticsLabel();
            analyticsHelper.sendEvent(getString(R.string.analytics_event_category_middleware), getString(R.string.analytics_event_action_middleware_rejected), analyticsLabel);
            replyServer(data.get(RESPONSE_URL) != null ? data.get(RESPONSE_URL) : "", data.get(REQUEST_TOKEN) != null ? data.get(REQUEST_TOKEN) : "", data.get(MESSAGE_START_TIME) != null ? data.get(MESSAGE_START_TIME) : "", false);
        }
    } else if (requestType.equals(MESSAGE_REQUEST_TYPE)) {
        mRemoteLogger.d("Code not implemented");
    // TODO implement this message.
    }
}
Also used : PowerManager(android.os.PowerManager) ConnectivityHelper(com.voipgrid.vialer.util.ConnectivityHelper) AnalyticsHelper(com.voipgrid.vialer.analytics.AnalyticsHelper)

Example 3 with ConnectivityHelper

use of com.voipgrid.vialer.util.ConnectivityHelper in project vialer-android by VoIPGRID.

the class DeviceInformation method getConnectionType.

public String getConnectionType() {
    ConnectivityHelper connectivityHelper = ConnectivityHelper.get(mContext);
    if (connectivityHelper.getConnectionType() == ConnectivityHelper.Connection.WIFI || connectivityHelper.getConnectionType() == ConnectivityHelper.Connection.NO_CONNECTION) {
        return connectivityHelper.getConnectionTypeString();
    } else {
        TelephonyManager manager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
        String carrierName = manager.getNetworkOperatorName();
        return connectivityHelper.getConnectionTypeString() + " (" + carrierName + ")";
    }
}
Also used : ConnectivityHelper(com.voipgrid.vialer.util.ConnectivityHelper) TelephonyManager(android.telephony.TelephonyManager)

Example 4 with ConnectivityHelper

use of com.voipgrid.vialer.util.ConnectivityHelper in project vialer-android by VoIPGRID.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle startBundle = getIntent().getExtras();
    if (startBundle != null) {
        boolean onBoot = startBundle.getBoolean("OnBoot");
        if (onBoot) {
            finish();
            return;
        }
    }
    JsonStorage jsonStorage = new JsonStorage(this);
    ConnectivityHelper connectivityHelper = ConnectivityHelper.get(this);
    Boolean hasSystemUser = jsonStorage.has(SystemUser.class);
    SystemUser systemUser = (SystemUser) jsonStorage.get(SystemUser.class);
    // on boarding part where the mobile number needs to be configured.
    if (!hasSystemUser) {
        // Start on boarding flow.
        startActivity(new Intent(this, SetupActivity.class));
        finish();
        return;
    } else if (UpdateHelper.requiresUpdate(this)) {
        Intent intent = new Intent(this, UpdateActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        finish();
        return;
    } else if (systemUser.getMobileNumber() == null) {
        Intent intent = new Intent(this, SetupActivity.class);
        Bundle bundle = new Bundle();
        bundle.putInt("fragment", R.id.fragment_account);
        bundle.putString("activity", AccountFragment.class.getSimpleName());
        intent.putExtras(bundle);
        startActivity(intent);
        finish();
        return;
    } else if (connectivityHelper.hasNetworkConnection()) {
        // Update SystemUser and PhoneAccount on background thread.
        new PhoneAccountHelper(this).executeUpdatePhoneAccountTask();
    }
    if (SyncUtils.requiresFullContactSync(this)) {
        SyncUtils.requestContactSync(this);
    } else {
        startContactObserverService();
    }
    SyncUtils.setPeriodicSync(this);
    setContentView(R.layout.activity_main);
    // Set the Toolbar to use as ActionBar.
    setActionBar(R.id.action_bar);
    setNavigationDrawer(R.id.drawer_layout);
    // Set tabs.
    setupTabs();
    FloatingActionButton openDialerFab = findViewById(R.id.floating_action_button);
    openDialerFab.setOnClickListener(this);
    requestCounter = 0;
    mReachabilityReceiver = new ReachabilityReceiver(this);
}
Also used : ConnectivityHelper(com.voipgrid.vialer.util.ConnectivityHelper) Bundle(android.os.Bundle) UpdateActivity(com.voipgrid.vialer.util.UpdateActivity) Intent(android.content.Intent) ReachabilityReceiver(com.voipgrid.vialer.reachability.ReachabilityReceiver) SetupActivity(com.voipgrid.vialer.onboarding.SetupActivity) PhoneAccountHelper(com.voipgrid.vialer.util.PhoneAccountHelper) SystemUser(com.voipgrid.vialer.api.models.SystemUser) FloatingActionButton(android.support.design.widget.FloatingActionButton) JsonStorage(com.voipgrid.vialer.util.JsonStorage) AccountFragment(com.voipgrid.vialer.onboarding.AccountFragment)

Example 5 with ConnectivityHelper

use of com.voipgrid.vialer.util.ConnectivityHelper in project vialer-android by VoIPGRID.

the class NavigationDrawerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mConnectivityHelper = new ConnectivityHelper((ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE), (TelephonyManager) getSystemService(TELEPHONY_SERVICE));
    mJsonStorage = new JsonStorage(this);
    mSystemUser = (SystemUser) mJsonStorage.get(SystemUser.class);
    if (mSystemUser != null && !TextUtils.isEmpty(getPassword())) {
        mApi = ServiceGenerator.createService(this, Api.class, getString(R.string.api_url), getEmail(), getPassword());
        // Preload availability.
        Call<VoipGridResponse<UserDestination>> call = mApi.getUserDestination();
        call.enqueue(this);
    }
}
Also used : VoipGridResponse(com.voipgrid.vialer.api.models.VoipGridResponse) ConnectivityHelper(com.voipgrid.vialer.util.ConnectivityHelper) TelephonyManager(android.telephony.TelephonyManager) ConnectivityManager(android.net.ConnectivityManager) Api(com.voipgrid.vialer.api.Api) JsonStorage(com.voipgrid.vialer.util.JsonStorage)

Aggregations

ConnectivityHelper (com.voipgrid.vialer.util.ConnectivityHelper)5 TelephonyManager (android.telephony.TelephonyManager)3 ConnectivityManager (android.net.ConnectivityManager)2 JsonStorage (com.voipgrid.vialer.util.JsonStorage)2 Activity (android.app.Activity)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 PowerManager (android.os.PowerManager)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 KeyEvent (android.view.KeyEvent)1 TextView (android.widget.TextView)1 WebActivity (com.voipgrid.vialer.WebActivity)1 AnalyticsHelper (com.voipgrid.vialer.analytics.AnalyticsHelper)1 Api (com.voipgrid.vialer.api.Api)1 SystemUser (com.voipgrid.vialer.api.models.SystemUser)1 VoipGridResponse (com.voipgrid.vialer.api.models.VoipGridResponse)1 AccountFragment (com.voipgrid.vialer.onboarding.AccountFragment)1 SetupActivity (com.voipgrid.vialer.onboarding.SetupActivity)1 ReachabilityReceiver (com.voipgrid.vialer.reachability.ReachabilityReceiver)1 PhoneAccountHelper (com.voipgrid.vialer.util.PhoneAccountHelper)1