Example usage for android.telephony TelephonyManager CALL_STATE_IDLE

List of usage examples for android.telephony TelephonyManager CALL_STATE_IDLE

Introduction

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

Prototype

int CALL_STATE_IDLE

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

Click Source Link

Document

Device call state: No activity.

Usage

From source file:com.googlecode.mindbell.accessors.ContextAccessor.java

public boolean isPhoneOffHook() {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return telephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE;
}

From source file:com.android.screenspeak.eventprocessor.AccessibilityEventProcessor.java

/**
 * Returns whether the device should drop this event. Caches notifications
 * if necessary./*from  w ww .j  av a  2s .  com*/
 *
 * @param event The current event.
 * @return {@code true} if the event should be dropped.
 */
private boolean shouldDropEvent(AccessibilityEvent event) {
    // Always drop null events.
    if (event == null) {
        return true;
    }

    // Always drop events if the service is suspended.
    if (!ScreenSpeakService.isServiceActive()) {
        return true;
    }

    // If touch exploration is enabled, drop automatically generated events
    // that are sent immediately after a window state change... unless we
    // decide to keep the event.
    if (AccessibilityManagerCompat.isTouchExplorationEnabled(mAccessibilityManager)
            && ((event.getEventType() & AUTOMATIC_AFTER_STATE_CHANGE) != 0)
            && ((event.getEventTime() - mLastWindowStateChanged) < DELAY_AUTO_AFTER_STATE)
            && !shouldKeepAutomaticEvent(event)) {
        if (LogUtils.LOG_LEVEL <= Log.VERBOSE) {
            Log.v(LOGTAG, "Drop event after window state change");
        }
        return true;
    }

    // Real notification events always have parcelable data.
    final boolean isNotification = (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED)
            && (event.getParcelableData() != null);

    final boolean isPhoneActive = (mCallStateMonitor != null)
            && (mCallStateMonitor.getCurrentCallState() != TelephonyManager.CALL_STATE_IDLE);
    final boolean shouldSpeakCallerId = (mSpeakCallerId && (mCallStateMonitor != null)
            && (mCallStateMonitor.getCurrentCallState() == TelephonyManager.CALL_STATE_RINGING));

    if (mRingerModeAndScreenMonitor != null && !mRingerModeAndScreenMonitor.isScreenOn()
            && !shouldSpeakCallerId) {
        if (!mSpeakWhenScreenOff) {
            // If the user doesn't allow speech when the screen is
            // off, drop the event immediately.
            if (LogUtils.LOG_LEVEL <= Log.VERBOSE) {
                Log.v(LOGTAG, "Drop event due to screen state and user pref");
            }
            return true;
        } else if (!isNotification) {
            // If the user allows speech when the screen is off, drop
            // all non-notification events.
            if (LogUtils.LOG_LEVEL <= Log.VERBOSE) {
                Log.v(LOGTAG, "Drop non-notification event due to screen state");
            }
            return true;
        }
    }

    final boolean canInterruptRadialMenu = AccessibilityEventUtils.eventMatchesAnyType(event,
            MASK_EVENT_TYPES_INTERRUPT_RADIAL_MENU);
    final boolean silencedByRadialMenu = (mService.getMenuManager().isMenuShowing() && !canInterruptRadialMenu);

    // Don't speak events that cannot interrupt the radial menu, if showing
    if (silencedByRadialMenu) {
        if (LogUtils.LOG_LEVEL <= Log.VERBOSE) {
            Log.v(LOGTAG, "Drop event due to radial menu state");
        }
        return true;
    }

    // Don't speak notification events if the user is touch exploring or a phone call is active.
    if (isNotification && (mIsUserTouchExploring || isPhoneActive)) {
        if (LogUtils.LOG_LEVEL <= Log.VERBOSE) {
            Log.v(LOGTAG, "Drop notification due to touch or phone state");
        }
        return true;
    }

    final int touchscreenState = mService.getResources().getConfiguration().touchscreen;
    final boolean isTouchInteractionStateChange = AccessibilityEventUtils.eventMatchesAnyType(event,
            MASK_EVENT_TYPES_TOUCH_STATE_CHANGES);

    // Drop all events related to touch interaction state on devices that don't support touch.
    return (touchscreenState == Configuration.TOUCHSCREEN_NOTOUCH) && isTouchInteractionStateChange;
}

From source file:org.chirpradio.mobile.PlaybackService.java

private void setupTelephonyHooks() {
    TelephonyManager telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);

    phoneStateListener = new PhoneStateListener() {

        @Override//from www  .j a va  2  s  .c  om
        public void onCallStateChanged(int state, String incomingNumber) {
            switch (state) {
            case TelephonyManager.CALL_STATE_OFFHOOK:
            case TelephonyManager.CALL_STATE_RINGING:
                if (isPlaying) {
                    Debug.log(this, "call began, stopping...");
                    stop();
                    isInCall = true;
                }
                break;
            case TelephonyManager.CALL_STATE_IDLE:
                if (isInCall) {
                    isInCall = false;
                    Debug.log(this, "call ended; resuming...");
                    start();
                }
                break;
            }
        }
    };

    telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}

From source file:se.erichansander.retrotimer.TimerKlaxon.java

private void play(boolean ring, boolean vibrate) {
    TinyTracelog.trace("5");

    // stop() checks to see if we are already playing.
    stop();//from ww  w .ja  va  2 s.co m

    if (ring) {
        TinyTracelog.trace("5.1");
        mMediaPlayer = new MediaPlayer();
        mMediaPlayer.setOnErrorListener(new OnErrorListener() {
            public boolean onError(MediaPlayer mp, int what, int extra) {
                TinyTracelog.trace("5.1.e1");
                stop();
                return true;
            }
        });

        try {
            /*
             * Check if we are in a call. If we are, use the in-call alarm
             * resource at a low volume to not disrupt the call.
             */
            if (mTelephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE) {
                TinyTracelog.trace("5.1.1");
                mMediaPlayer.setVolume(IN_CALL_VOLUME, IN_CALL_VOLUME);
                setDataSourceFromResource(getResources(), mMediaPlayer, R.raw.in_call_alarm);
            } else {
                TinyTracelog.trace("5.1.2");
                setDataSourceFromResource(getResources(), mMediaPlayer, R.raw.classic_alarm);
            }
        } catch (Exception ex) {
            // Failed to set data source. Not much we can do to save
            // the situation though...
            TinyTracelog.trace("5.1.e2");
        }

        try {
            final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
            // do not play alarms if stream volume is 0
            int volume = audioManager.getStreamVolume(AudioManager.STREAM_ALARM);
            TinyTracelog.trace("5.1.3 " + volume);
            if (volume != 0) {
                mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
                mMediaPlayer.setLooping(true);
                mMediaPlayer.prepare();
                if (mAudioFocusHelper != null) {
                    mAudioFocusHelper.requestFocus();
                }
                mMediaPlayer.start();
            }
        } catch (Exception ex) {
            // Failed to play ring tone. Not much we can do to save
            // the situation though...
            TinyTracelog.trace("5.1.e3");
        }
    }

    /* Start the vibrator after everything is ok with the media player */
    if (vibrate) {
        TinyTracelog.trace("5.2");
        mVibrator.vibrate(sVibratePattern, 0);
    } else {
        mVibrator.cancel();
    }

    mPlaying = true;
}

From source file:com.mindprotectionkit.freephone.RedPhoneService.java

private boolean isBusy() {
    TelephonyManager telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    return ((currentCallManager != null && state != RedPhone.STATE_IDLE)
            || telephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE);
}

From source file:com.android.talkback.eventprocessor.AccessibilityEventProcessor.java

/**
 * Returns whether the device should drop this event. Caches notifications
 * if necessary.//from www  .  ja v  a  2  s .c o m
 *
 * @param event The current event.
 * @return {@code true} if the event should be dropped.
 */
private boolean shouldDropEvent(AccessibilityEvent event) {
    // Always drop null events.
    if (event == null) {
        return true;
    }

    // Always drop events if the service is suspended.
    if (!TalkBackService.isServiceActive()) {
        return true;
    }

    // If touch exploration is enabled, drop automatically generated events
    // that are sent immediately after a window state change... unless we
    // decide to keep the event.
    if (AccessibilityManagerCompat.isTouchExplorationEnabled(mAccessibilityManager)
            && ((event.getEventType() & AUTOMATIC_AFTER_STATE_CHANGE) != 0)
            && ((event.getEventTime() - mLastWindowStateChanged) < DELAY_AUTO_AFTER_STATE)
            && !shouldKeepAutomaticEvent(event)) {
        if (LogUtils.LOG_LEVEL <= Log.VERBOSE) {
            Log.v(LOGTAG, "Drop event after window state change");
        }
        return true;
    }

    // Some view-selected events are spurious if sent immediately after a focused event.
    if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED && !shouldKeepViewSelectedEvent(event)) {
        if (LogUtils.LOG_LEVEL <= Log.VERBOSE) {
            Log.v(LOGTAG, "Drop selected event after focused event");
        }
        return true;
    }

    // Real notification events always have parcelable data.
    final boolean isNotification = (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED)
            && (event.getParcelableData() != null);

    final boolean isPhoneActive = (mCallStateMonitor != null)
            && (mCallStateMonitor.getCurrentCallState() != TelephonyManager.CALL_STATE_IDLE);
    final boolean isPhoneRinging = (mCallStateMonitor != null)
            && (mCallStateMonitor.getCurrentCallState() == TelephonyManager.CALL_STATE_RINGING);

    // Sometimes the dialer's window-state-changed event gets sent right before the
    // TelephonyManager transitions to CALL_STATE_RINGING, so we need to check isDialerEvent().
    final boolean shouldSpeakCallerId = isPhoneRinging || isDialerEvent(event);

    if (mRingerModeAndScreenMonitor != null && !mRingerModeAndScreenMonitor.isScreenOn()
            && !shouldSpeakCallerId) {
        if (!mSpeakWhenScreenOff) {
            // If the user doesn't allow speech when the screen is
            // off, drop the event immediately.
            if (LogUtils.LOG_LEVEL <= Log.VERBOSE) {
                Log.v(LOGTAG, "Drop event due to screen state and user pref");
            }
            return true;
        } else if (!isNotification) {
            // If the user allows speech when the screen is off, drop
            // all non-notification events.
            if (LogUtils.LOG_LEVEL <= Log.VERBOSE) {
                Log.v(LOGTAG, "Drop non-notification event due to screen state");
            }
            return true;
        }
    }

    final boolean canInterruptRadialMenu = AccessibilityEventUtils.eventMatchesAnyType(event,
            MASK_EVENT_TYPES_INTERRUPT_RADIAL_MENU);
    final boolean silencedByRadialMenu = (mService.getMenuManager().isMenuShowing() && !canInterruptRadialMenu);

    // Don't speak events that cannot interrupt the radial menu, if showing
    if (silencedByRadialMenu) {
        if (LogUtils.LOG_LEVEL <= Log.VERBOSE) {
            Log.v(LOGTAG, "Drop event due to radial menu state");
        }
        return true;
    }

    // Don't speak notification events if the user is touch exploring or a phone call is active.
    if (isNotification && (mIsUserTouchExploring || isPhoneActive)) {
        if (LogUtils.LOG_LEVEL <= Log.VERBOSE) {
            Log.v(LOGTAG, "Drop notification due to touch or phone state");
        }
        return true;
    }

    final int touchscreenState = mService.getResources().getConfiguration().touchscreen;
    final boolean isTouchInteractionStateChange = AccessibilityEventUtils.eventMatchesAnyType(event,
            MASK_EVENT_TYPES_TOUCH_STATE_CHANGES);

    // Drop all events related to touch interaction state on devices that don't support touch.
    return (touchscreenState == Configuration.TOUCHSCREEN_NOTOUCH) && isTouchInteractionStateChange;
}

From source file:ro.ciubex.keepscreenlock.MainApplication.java

/**
 * Get last phone state.//w  w  w.ja v  a2 s. c o  m
 * @return The last phone state.
  */
public int getLastPhoneState() {
    return mSharedPreferences.getInt(KEY_LAST_PHONE_STATE, TelephonyManager.CALL_STATE_IDLE);
}

From source file:leoisasmendi.android.com.suricatepodcast.services.MediaPlayerService.java

private void callStateListener() {
    // Get the telephony manager
    telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    //Starting listening for PhoneState changes
    phoneStateListener = new PhoneStateListener() {
        @Override//from  w  w  w.  ja v  a2s  . c  o m
        public void onCallStateChanged(int state, String incomingNumber) {
            switch (state) {
            //if at least one call exists or the phone is ringing
            //pause the MediaPlayer
            case TelephonyManager.CALL_STATE_OFFHOOK:
            case TelephonyManager.CALL_STATE_RINGING:
                if (mediaPlayer != null) {
                    pauseMedia();
                    ongoingCall = true;
                }
                break;
            case TelephonyManager.CALL_STATE_IDLE:
                // Phone idle. Start playing.
                if (mediaPlayer != null) {
                    if (ongoingCall) {
                        ongoingCall = false;
                        resumeMedia();
                    }
                }
                break;
            }
        }
    };
    // Register the listener with the telephony manager
    // Listen for changes to the device call state.
    telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}

From source file:edu.polyu.screamalert.SoundProcessing.java

private static void callPhone() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Exchanger.thisContext);
    String phoneNumber = prefs.getString("phoneNumber", null);
    Boolean enableCall = prefs.getBoolean("enableCall", false);
    if (phoneNumber != null && enableCall) {
        if (phoneNumber.trim().length() > 0) { // Avoid empty string or white spaces in the preference field
            TelephonyManager phoneMgr = (TelephonyManager) thisContext
                    .getSystemService(Context.TELEPHONY_SERVICE);
            if (phoneMgr.getCallState() == TelephonyManager.CALL_STATE_IDLE
                    && phoneMgr.getSimState() != TelephonyManager.SIM_STATE_ABSENT) {
                Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                callIntent.setData(Uri.parse("tel:" + phoneNumber));
                Exchanger.thisContext.startActivity(callIntent);
            }/* w  ww .  j  a v  a  2s.co m*/
        }
    }
}

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 {/*from w  w  w . ja  v  a 2s  . c  o  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);
    }
}