Example usage for android.telephony TelephonyManager CALL_STATE_OFFHOOK

List of usage examples for android.telephony TelephonyManager CALL_STATE_OFFHOOK

Introduction

In this page you can find the example usage for android.telephony TelephonyManager CALL_STATE_OFFHOOK.

Prototype

int CALL_STATE_OFFHOOK

To view the source code for android.telephony TelephonyManager CALL_STATE_OFFHOOK.

Click Source Link

Document

Device call state: Off-hook.

Usage

From source file:org.restcomm.app.qoslib.Services.LibPhoneStateListener.java

public void phoneOffHook(int iPhoneState) {
    try {//from  w  ww .j  a v  a2s .c o m
        final EventObj event = owner.getEventManager().startPhoneEvent(EventType.EVT_CONNECT,
                EventType.EVT_DISCONNECT);
        if (event != null) {
            if (mPhoneState.bOffHook) {
                if (iPhoneState == TelephonyManager.CALL_STATE_OFFHOOK
                        && (event.getFlags() & EventObj.CALL_INCOMING) > 0)
                    mPhoneState.setCallConnected(true);
                //            if (iPhoneState == TelephonyManager.CALL_STATE_RINGING && (event.getFlags() & EventObj.CALL_INCOMING) == 0)
                //               setCallWaiting(true);
                return;
            }
            owner.startRadioLog(true, "call", EventType.EVT_CONNECT); // "monitoring signal strength");
            if (iPhoneState == TelephonyManager.CALL_STATE_RINGING) {
                event.setFlag(EventObj.CALL_INCOMING, true);
                mPhoneState.setCallRinging(true);
            } else {
                mPhoneState.setCallDialing(true); // in case it is an outgoing call (not sure), dialing time will start now
                mPhoneState.setCallRinging(false); // in case it is an outgoing call (not sure), dialing time will start now
            }
        }
        mPhoneState.bOffHook = true;
        mPhoneState.offhookTime = System.currentTimeMillis();

        mPhoneState.lastCallDropped = false;
        mPhoneState.lastDroppedCause = null;

        Intent intent = new Intent(IntentHandler.PHONE_CALL_CONNECT);
        owner.sendBroadcast(intent);

        // Delay for a few seconds and then check the voice network to detect if we have a VoLTE call
        owner.handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                int tech = mPhoneState.getVoiceNetworkType();
                if (tech == mPhoneState.NETWORK_NEWTYPE_LTE && event != null) {
                    event.setFlag(EventObj.CALL_VOLTE, true);
                    LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, TAG, "getRilVoiceRadioTechnology",
                            "VOLTE CALL DETECTED");
                } else if ((tech <= 0 || tech == mPhoneState.NETWORK_NEWTYPE_IWLAN) && event != null) {
                    event.setFlag(EventObj.CALL_OFFNET, true);
                    LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, TAG, "getRilVoiceRadioTechnology",
                            "WIFI CALL DETECTED?");
                }
                //boolean isInCall = IsInCall ();
            }
        }, 3500);

        // Set all ongoing events as occurring in a call
        List<EventObj> ongoingEvents = owner.getEventManager().getOngoingEvents();
        int i;
        for (i = 0; i < ongoingEvents.size(); i++) {
            ongoingEvents.get(i).setFlag(EventObj.PHONE_INUSE, true);
        }
    } catch (Exception e) {
        LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "phoneOffHook", "exception", e);
    }
}

From source file:com.sentaroh.android.TaskAutomation.TaskExecutor.java

final static private void executeBuiltinActionConditional(TaskManagerParms taskMgrParms,
        EnvironmentParms envParms, CommonUtilities util, TaskResponse taskResponse, ActionResponse ar,
        String bia, String en, String tn) {
    if (bia.equals(BUILTIN_ACTION_IF_WIFI_ON_ABORT)) {
        if (envParms.wifiIsActive)
            ar.action_resp = ActionResponse.ACTION_ABORT;
    } else if (bia.equals(BUILTIN_ACTION_IF_WIFI_CONNECTED_ABORT)) {
        if (envParms.isWifiConnected())
            ar.action_resp = ActionResponse.ACTION_ABORT;
    } else if (bia.equals(BUILTIN_ACTION_IF_WIFI_DISCONNECTED_ABORT)) {
        if (!envParms.isWifiConnected())
            ar.action_resp = ActionResponse.ACTION_ABORT;
    } else if (bia.equals(BUILTIN_ACTION_IF_WIFI_OFF_ABORT)) {
        if (!envParms.wifiIsActive)
            ar.action_resp = ActionResponse.ACTION_ABORT;
    } else if (bia.equals(BUILTIN_ACTION_IF_BLUETOOTH_ON_ABORT)) {
        if (envParms.bluetoothIsActive)
            ar.action_resp = ActionResponse.ACTION_ABORT;
    } else if (bia.equals(BUILTIN_ACTION_IF_BLUETOOTH_CONNECTED_ABORT)) {
        if (envParms.isBluetoothConnected())
            ar.action_resp = ActionResponse.ACTION_ABORT;
    } else if (bia.equals(BUILTIN_ACTION_IF_BLUETOOTH_DISCONNECTED_ABORT)) {
        if (!envParms.isBluetoothConnected())
            ar.action_resp = ActionResponse.ACTION_ABORT;
    } else if (bia.equals(BUILTIN_ACTION_IF_BLUETOOTH_OFF_ABORT)) {
        if (!envParms.bluetoothIsActive)
            ar.action_resp = ActionResponse.ACTION_ABORT;
    } else if (bia.equals(BUILTIN_ACTION_IF_SCREEN_UNLOCKED_ABORT)) {
        if (!envParms.screenIsLocked)
            ar.action_resp = ActionResponse.ACTION_ABORT;
    } else if (bia.equals(BUILTIN_ACTION_IF_SCREEN_LOCKED_ABORT)) {
        if (envParms.screenIsLocked)
            ar.action_resp = ActionResponse.ACTION_ABORT;
    } else if (bia.equals(BUILTIN_ACTION_IF_PROXIMITY_DETECTED_ABORT)) {
        if (envParms.proximitySensorAvailable) {
            if (envParms.proximitySensorValue == 0)
                ar.action_resp = ActionResponse.ACTION_ABORT;
        } else {/* w ww  .  j  av  a2 s  .  co  m*/
            ar.action_resp = ActionResponse.ACTION_ERROR;
            ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_proximity_not_available;
            return;
        }
    } else if (bia.equals(BUILTIN_ACTION_IF_PROXIMITY_UNDETECTED_ABORT)) {
        if (envParms.proximitySensorAvailable) {
            if (envParms.proximitySensorValue == 1)
                ar.action_resp = ActionResponse.ACTION_ABORT;
        } else {
            ar.action_resp = ActionResponse.ACTION_ERROR;
            ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_proximity_not_available;
            return;
        }
    } else if (bia.equals(BUILTIN_ACTION_IF_LIGHT_DETECTED_ABORT)) {
        if (envParms.lightSensorAvailable) {
            if (envParms.lightSensorValue == 1)
                ar.action_resp = ActionResponse.ACTION_ABORT;
        } else {
            ar.action_resp = ActionResponse.ACTION_ERROR;
            ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_light_not_available;
            return;
        }
    } else if (bia.equals(BUILTIN_ACTION_IF_LIGHT_UNDETECTED_ABORT)) {
        if (envParms.lightSensorAvailable) {
            if (envParms.lightSensorValue == 0)
                ar.action_resp = ActionResponse.ACTION_ABORT;
        } else {
            ar.action_resp = ActionResponse.ACTION_ERROR;
            ar.resp_msg_text = taskMgrParms.teMsgs.msgs_thread_task_exec_light_not_available;
            return;
        }
    } else if (bia.equals(BUILTIN_ACTION_IF_POWER_IS_AC_OR_CHRAGE_ABORT)) {
        if (envParms.batteryPowerSource.equals(CURRENT_POWER_SOURCE_AC))
            ar.action_resp = ActionResponse.ACTION_ABORT;
    } else if (bia.equals(BUILTIN_ACTION_IF_POWER_IS_BATTERY_ABORT)) {
        if (envParms.batteryPowerSource.equals(CURRENT_POWER_SOURCE_BATTERY))
            ar.action_resp = ActionResponse.ACTION_ABORT;
    } else if (bia.equals(BUILTIN_ACTION_IF_CALL_STATE_IDLE_ABORT)) {
        if (envParms.telephonyStatus == TelephonyManager.CALL_STATE_IDLE)
            ar.action_resp = ActionResponse.ACTION_ABORT;
    } else if (bia.equals(BUILTIN_ACTION_IF_CALL_STATE_OFF_HOOK_ABORT)) {
        if (envParms.telephonyStatus == TelephonyManager.CALL_STATE_OFFHOOK)
            ar.action_resp = ActionResponse.ACTION_ABORT;
    } else if (bia.equals(BUILTIN_ACTION_IF_CALL_STATE_RINGING_ABORT)) {
        if (envParms.telephonyStatus == TelephonyManager.CALL_STATE_RINGING)
            ar.action_resp = ActionResponse.ACTION_ABORT;
    } else if (bia.equals(BUILTIN_ACTION_IF_AIRPLANE_MODE_ON_ABORT)) {
        if (envParms.airplane_mode_on == 1)
            ar.action_resp = ActionResponse.ACTION_ABORT;
    } else if (bia.equals(BUILTIN_ACTION_IF_AIRPLANE_MODE_OFF_ABORT)) {
        if (envParms.airplane_mode_on == 0)
            ar.action_resp = ActionResponse.ACTION_ABORT;
    } else if (bia.equals(BUILTIN_ACTION_IF_MOBILE_NETWORK_CONNECTED_ABORT)) {
        if (envParms.mobileNetworkIsConnected)
            ar.action_resp = ActionResponse.ACTION_ABORT;
    } else if (bia.equals(BUILTIN_ACTION_IF_MOBILE_NETWORK_DISCONNECTED_ABORT)) {
        if (!envParms.mobileNetworkIsConnected)
            ar.action_resp = ActionResponse.ACTION_ABORT;
        //      } else if (bia.equals(BUILTIN_ACTION_IF_NETWORK_CONNECTED_ABORT)) {
        //         if (envParms.networkIsConnected) ar.action_resp=ActionResponse.ACTION_ABORT;
        //      } else if (bia.equals(BUILTIN_ACTION_IF_NETWORK_DISCONNECTED_ABORT)) {
        //         if (!envParms.networkIsConnected) ar.action_resp=ActionResponse.ACTION_ABORT;
    } else if (bia.equals(BUILTIN_ACTION_IF_ORIENTATION_LANDSCAPE_ABORT)) {
        if (envParms.isOrientationLanscape())
            ar.action_resp = ActionResponse.ACTION_ABORT;
    } else if (bia.equals(BUILTIN_ACTION_IF_ORIENTATION_PORTRAIT_ABORT)) {
        if (!envParms.isOrientationLanscape())
            ar.action_resp = ActionResponse.ACTION_ABORT;
    } else {
        ar.action_resp = ActionResponse.ACTION_ERROR;
        ar.resp_msg_text = String.format(taskMgrParms.teMsgs.msgs_thread_task_unknoww_action, bia);
    }
    if (ar.action_resp == ActionResponse.ACTION_ABORT) {
        ar.resp_msg_text = String.format(taskMgrParms.teMsgs.msgs_thread_task_exec_builtin_abort, bia);
    }
}

From source file:org.restcomm.app.qoslib.Services.LibPhoneStateListener.java

@Override
public void onCallStateChanged(int state, String incomingNumber) {
    super.onCallStateChanged(state, incomingNumber);

    try {//  w  ww .  j av  a  2 s .com
        Intent intent;

        switch (state) {
        case TelephonyManager.CALL_STATE_IDLE:
            LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, TAG, "onCallStateChanged", "IDLE");

            if (mPhoneState.bOffHook == false) {
                LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, TAG, "onCallStateChanged", "not off hook");
                return;
            }
            mPhoneState.disconnectTime = System.currentTimeMillis();
            mPhoneState.bOffHook = false;

            HashMap<String, Integer> handset = ReportManager.getHandsetCaps(owner);
            // If phone needs heuristics, check the signal for a dropped call
            int heurDelay = 9;
            if (handset.containsKey("capHeurDelay"))
                heurDelay = handset.get("capHeurDelay");
            if (DeviceInfoOld.getPlatform() == 3)
                heurDelay = 2;

            mPhoneState.bOffHook = false;
            TimerTask verifyConnectTask = new VerifyConnectTask();
            disconnectTimer.schedule(verifyConnectTask, 2000); // 1300
            TimerTask disconnectTimerTask1 = new DisconnectTimerTask(1);
            disconnectTimer.schedule(disconnectTimerTask1, heurDelay * 1000);
            intent = new Intent(IntentHandler.PHONE_CALL_DISCONNECT);
            owner.sendBroadcast(intent);
            if (disconnectLatch != null)
                disconnectLatch.countDown();

            break;
        case TelephonyManager.CALL_STATE_OFFHOOK:
            LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, TAG, "onCallStateChanged", "OFFHOOK");
            //if (owner.bOffHook)
            //   return;

            phoneOffHook(TelephonyManager.CALL_STATE_OFFHOOK);
            //intent = new Intent(MMCIntentHandlerOld.PHONE_CALL_CONNECT);
            //owner.sendBroadcast(intent);
            if (connectLatch != null)
                connectLatch.countDown();

            //TimerTask launchConnectTask = new LaunchConnectTask();
            //disconnectTimer.schedule(launchConnectTask, 2000);
            break;

        case TelephonyManager.CALL_STATE_RINGING:
            LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, TAG, "onCallStateChanged", "RINGING");
            if (mPhoneState.bOffHook)
                return;
            phoneOffHook(TelephonyManager.CALL_STATE_RINGING);
            //if (incomingNumber != null && incomingNumber.length() > 1)
            //   txtIncomingNumber = incomingNumber;

            break;
        }
    } catch (Exception e) {
        LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, TAG, "onCallStateChanged", "Exception", e);
    }
}

From source file:org.yammp.MusicPlaybackService.java

/**
 * Starts playback of a previously opened file.
 *///from   w w  w .  j a va  2s.co m
public void play() {

    CharSequence contentTitle, contentText = null;

    TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager.getCallState() == TelephonyManager.CALL_STATE_OFFHOOK)
        return;

    mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC,
            AudioManager.AUDIOFOCUS_GAIN);
    mAudioManager.registerMediaButtonEventReceiver(
            new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()));

    telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);

    if (mPlayer.isInitialized()) {
        // if we are at the end of the song, go to the next song first
        long duration = mPlayer.duration();
        if (mRepeatMode != REPEAT_CURRENT && duration > 2000 && mPlayer.position() >= duration - 2000) {
            next(true);
        }

        mPlayer.start();

        // make sure we fade in, in case a previous fadein was stopped
        // because
        // of another focus loss
        mMediaplayerHandler.removeMessages(FADEDOWN);
        mMediaplayerHandler.sendEmptyMessage(FADEUP);

        contentTitle = getTrackName();

        String artist = getArtistName();
        boolean isUnknownArtist = artist == null || MediaStore.UNKNOWN_STRING.equals(artist);

        String album = getAlbumName();
        boolean isUnknownAlbum = album == null || MediaStore.UNKNOWN_STRING.equals(album);

        if (!isUnknownArtist && !isUnknownAlbum) {
            contentText = getString(R.string.notification_artist_album, artist, album);
        } else if (isUnknownArtist && !isUnknownAlbum) {
            contentText = album;
        } else if (!isUnknownArtist && isUnknownAlbum) {
            contentText = artist;
        }

        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(INTENT_PLAYBACK_VIEWER), 0);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setOngoing(true);
        builder.setSmallIcon(R.drawable.ic_stat_playback);
        builder.setContentIntent(contentIntent);
        builder.setContentTitle(contentTitle);
        builder.setContentText(contentText);
        mNotificationManager.notify(ID_NOTIFICATION_PLAYBACK, builder.getNotification());

        if (!mIsSupposedToBePlaying) {
            mIsSupposedToBePlaying = true;
            notifyChange(BROADCAST_PLAYSTATE_CHANGED);
        }

    } else if (mPlayListLen <= 0) {
        // This is mostly so that if you press 'play' on a bluetooth headset
        // without every having played anything before, it will still play
        // something.
        setShuffleMode(SHUFFLE_NORMAL);
    }
}