Example usage for android.telephony TelephonyManager CALL_STATE_RINGING

List of usage examples for android.telephony TelephonyManager CALL_STATE_RINGING

Introduction

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

Prototype

int CALL_STATE_RINGING

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

Click Source Link

Document

Device call state: Ringing.

Usage

From source file:org.mythtv.client.ui.MainMenuFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mLocationProfile = mLocationProfileDaoHelper.findConnectedProfile(getActivity());

    adapter = new FrontendAdapter(getActivity(), R.layout.frontend_row, MainMenuFragment.GetFrontends());

    sTelManager = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
    sTelManager.listen(new PhoneStateListener() {

        /* (non-Javadoc)
         * @see android.telephony.PhoneStateListener#onCallStateChanged(int, java.lang.String)
         */// w  w  w . j  av a 2 s.  com
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {

            if (state == TelephonyManager.CALL_STATE_RINGING) {

                final Frontend fe = selectedFrontend;

                if (null == fe)
                    return;

                SendMessageTask sendMessageTask = new SendMessageTask(getActivity(), mLocationProfile);
                sendMessageTask.execute(fe.getUrl(), "Incoming Call From: " + incomingNumber);
            }

            super.onCallStateChanged(state, incomingNumber);
        }
    }, PhoneStateListener.LISTEN_CALL_STATE);
}

From source file:com.yangtsaosoftware.pebblemessenger.services.PebbleCenter.java

@Override
public void onCreate() {
    super.onCreate();
    Handler pebbleCenterHandler = new PebbleCenterHandler();
    mPebbleCenterHandler = new Messenger(pebbleCenterHandler);
    Constants.log(TAG_NAME, "Create PebbleCenter Messenger.");
    loadPref();/*from   www .j  av  a  2  s.  c  o m*/
    _contex = this;
    //   busyBegin=new Time();
    //        waitQueue=new ArrayDeque<PebbleMessage>();
    sendQueue = new ArrayDeque<PebbleDictionary>();
    bindService(new Intent(this, MessageProcessingService.class), connToMessageProcessing,
            Context.BIND_AUTO_CREATE);
    Thread prepareThread = new PrepareThread();
    prepareThread.start();
    Thread sendMsgThread = new SendMsgThread();
    sendMsgThread.start();
    isPebbleEnable = PebbleKit.isWatchConnected(_contex);
    PebbleKit.registerReceivedDataHandler(_contex, new PebbleKit.PebbleDataReceiver(Constants.PEBBLE_UUID) {
        @Override
        public void receiveData(Context context, int transactionId, PebbleDictionary data) {
            PebbleKit.sendAckToPebble(_contex, transactionId);
            //          appStatue++;
            Constants.log(TAG_NAME, "Received data form pebble");
            switch (data.getUnsignedIntegerAsLong(ID_COMMAND).intValue()) {
            case REQUEST_TRANSID_CALL_TABLE: {
                Constants.log(TAG_NAME, "Request call table.");
                clean_SendQue();
                Message msg = Message.obtain();
                msg.what = MessageProcessingService.MSG_GET_CALL_TABLE;
                try {
                    rMessageProcessingHandler.send(msg);
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
            }
                break;
            case REQUEST_TRANSID_MESSAGE_TABLE: {
                Constants.log(TAG_NAME, "Request message table.");
                clean_SendQue();
                Message msg = Message.obtain();
                msg.what = MessageProcessingService.MSG_GET_MESSAGE_TABLE;
                try {
                    rMessageProcessingHandler.send(msg);
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
            }
                break;
            case REQUEST_TRANSID_CALL: {
                clean_SendQue();
                Message msg = Message.obtain();
                msg.what = MessageProcessingService.MSG_GET_CALL;
                Bundle b = new Bundle();
                b.putString(MessageDbHandler.COL_CALL_ID, data.getString(ID_EXTRA_DATA));
                Constants.log(TAG_NAME, "Request call id:" + data.getString(ID_EXTRA_DATA));

                msg.setData(b);
                try {
                    rMessageProcessingHandler.send(msg);
                } catch (RemoteException e) {
                    e.printStackTrace();
                }

            }
                break;
            case REQUEST_TRANSID_MESSAGE:
                clean_SendQue();
                Message msg = Message.obtain();
                msg.what = MessageProcessingService.MSG_GET_MESSAGE;
                Bundle b = new Bundle();
                b.putString(MessageDbHandler.COL_MESSAGE_ID, data.getString(ID_EXTRA_DATA));
                Constants.log(TAG_NAME, "Request message id:" + data.getString(ID_EXTRA_DATA));

                msg.setData(b);
                try {
                    rMessageProcessingHandler.send(msg);
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
                break;
            case REQUEST_TRANSID_PICKUP_PHONE:
                TelephonyManager telMag = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
                Constants.log("Receivephone", "Receive phone:" + data.getString(ID_EXTRA_DATA2));
                if (telMag.getCallState() == TelephonyManager.CALL_STATE_RINGING) {
                    switch (data.getUnsignedIntegerAsLong(ID_EXTRA_DATA).intValue()) {
                    case REQUEST_EXTRA_SPEAKER_ON:
                        answerCall(true);
                        break;
                    case REQUEST_EXTRA_SPEAKER_OFF:
                        answerCall(false);
                        break;
                    }
                } else {
                    switch (data.getUnsignedIntegerAsLong(ID_EXTRA_DATA).intValue()) {
                    case REQUEST_EXTRA_SPEAKER_ON:
                        dialNumber(data.getString(ID_EXTRA_DATA2), true);
                        break;
                    case REQUEST_EXTRA_SPEAKER_OFF:
                        dialNumber(data.getString(ID_EXTRA_DATA2), false);
                        break;
                    }

                }
                //                pebbleBusy = false;
                break;
            case REQUEST_TRANSID_HANGOFF_PHONE:
                endCall();
                //                pebbleBusy=false;

                break;
            case REQUEST_TRANSID_HANGOFF_SMS1:
                Constants.log(TAG_NAME, "Request hangoff and send sms1");

                endCall();
                doSendSMSTo(data.getString(ID_EXTRA_DATA), sms1);
                //               pebbleBusy=false;

                break;
            case REQUEST_TRANSID_HANGOFF_SMS2:
                Constants.log(TAG_NAME, "Request hangoff and send sms2");

                endCall();
                doSendSMSTo(data.getString(ID_EXTRA_DATA), sms2);
                //              pebbleBusy=false;

                break;
            case REQUEST_TRANSID_CLOSE_APP:
                Constants.log(TAG_NAME, "Request close app command.");
                sendMsgThreadHandler.sendEmptyMessage(SEND_CLOSE_APP);
                //               need_delay=true;

                break;
            case REQUEST_TRANSID_NEXTPAGE:
                Constants.log(TAG_NAME, "Request send next page.");

                sendMsgThreadHandler.sendEmptyMessage(SEND_NEXT_PAGE);
                break;
            case REQUEST_TRANSID_READ_NOTIFY: {
                Constants.log(TAG_NAME, "Request  read msg");
                Message read_msg = Message.obtain();
                read_msg.what = MessageProcessingService.MSG_READ;
                Bundle bd = new Bundle();
                bd.putString(MessageDbHandler.COL_MESSAGE_ID,
                        data.getUnsignedIntegerAsLong(ID_EXTRA_DATA).toString());
                read_msg.setData(bd);
                try {
                    rMessageProcessingHandler.send(read_msg);
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
            }
                break;
            case REQUEST_TRANSID_IM_FREE:
                Constants.log(TAG_NAME, "Request pebble app is free to receive data.");

                //               need_delay = data.getUnsignedInteger(ID_EXTRA_DATA).intValue() == REQUEST_EXTRA_DELAY_ON ;
                //               clean_SendQue();
                break;
            case REQUEST_TRANSID_VERSION: {
                send_test_get_return = true;
                String result = data.getString(ID_EXTRA_DATA);
                Constants.log("PmpVersion", result);
                StringTokenizer tokens = new StringTokenizer(result, ".");

                Intent inner_intent = new Intent(SetupFragment.class.getName());
                inner_intent.putExtra(Constants.BROADCAST_VERSION,
                        new byte[] { Byte.parseByte(tokens.nextToken()), Byte.parseByte(tokens.nextToken()),
                                Byte.parseByte(tokens.nextToken()) });
                LocalBroadcastManager.getInstance(context).sendBroadcast(inner_intent);
                sendMsgThreadHandler.sendEmptyMessage(SEND_CLOSE_APP);
                break;
            }
            }
        }
    });

    PebbleKit.registerReceivedAckHandler(_contex, new PebbleKit.PebbleAckReceiver(Constants.PEBBLE_UUID) {
        @Override
        public void receiveAck(Context context, int transactionId) {
            Constants.log(TAG_NAME, "Get a receiveAck:" + String.valueOf(transactionId));
            switch (transactionId) {
            case TRANS_ID_COMMON:
                Constants.log(TAG_NAME, "Send continue...");
                //                  pebbleBusy=true;
                sendMsgThreadHandler.sendEmptyMessage(SEND_CONTINUE);
                break;
            case TRANS_ID_END:
                send_full_page = true;
                break;
            case TRANS_ID_EMPTY:
                //                 pebbleBusy=true;
                sendMsgThreadHandler.sendEmptyMessage(SEND_CONTINUE);
                break;
            case TRANS_ID_TEST: {
                break;
            }
            }
        }
    });

    PebbleKit.registerReceivedNackHandler(_contex, new PebbleKit.PebbleNackReceiver(Constants.PEBBLE_UUID) {
        @Override
        public void receiveNack(Context context, int transactionId) {
            Constants.log(TAG_NAME, "Get a receivedNack:" + String.valueOf(transactionId));
            if (PebbleKit.isWatchConnected(_contex)) {
                switch (transactionId) {
                case TRANS_ID_COMMON:
                    sendMsgThreadHandler.sendEmptyMessage(SEND_CONTINUE);
                    break;
                case TRANS_ID_END:
                    send_full_page = true;
                    break;
                case TRANS_ID_EMPTY:
                    //                   appStatue=0;
                    sendMsgThreadHandler.sendEmptyMessage(SEND_OPEN_APP);
                    break;
                case TRANS_ID_TEST: {
                    Intent inner_intent = new Intent(SetupFragment.class.getName());
                    inner_intent.putExtra(Constants.BROADCAST_VERSION, new byte[] { 0, 0, 0 });
                    LocalBroadcastManager.getInstance(context).sendBroadcast(inner_intent);
                }
                }
            } else {
                sendMsgThreadHandler.sendEmptyMessage(SEND_CLOSE_APP);
            }

        }
    });

    PebbleKit.registerPebbleConnectedReceiver(_contex, new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            isPebbleEnable = true;
        }
    });

    PebbleKit.registerPebbleDisconnectedReceiver(_contex, new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            isPebbleEnable = false;
            sendMsgThreadHandler.sendEmptyMessage(SEND_CLOSE_APP);
        }
    });

    BroadcastReceiver br = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            int command = intent.getIntExtra(Constants.BROADCAST_COMMAND, Constants.BROADCAST_PREFER_CHANGED);

            switch (command) {
            case Constants.BROADCAST_PREFER_CHANGED:
                loadPref();
                break;
            case Constants.BROADCAST_CALL_IDLE:
                if (callEnable) {
                    sendMsgThreadHandler.sendEmptyMessage(SEND_CALL_END);
                }
                break;
            case Constants.BROADCAST_CALL_HOOK:
                if (callEnable) {
                    sendMsgThreadHandler.sendEmptyMessage(SEND_CALL_HOOK);
                }
                break;
            case Constants.BROADCAST_PEBBLE_TEST:
                if (isPebbleEnable) {
                    prepareThreadHandler.sendEmptyMessage(PREPARE_TEST);
                }
                break;
            }
        }
    };
    IntentFilter intentFilter = new IntentFilter(PebbleCenter.class.getName());
    LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(br, intentFilter);
}

From source file:net.sf.asap.PlayerService.java

@Override
public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);

    registerReceiver(headsetReceiver, new IntentFilter(Intent.ACTION_HEADSET_PLUG));
    registerMediaButtonEventReceiver("registerMediaButtonEventReceiver");

    TelephonyManager telephony = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    telephony.listen(new PhoneStateListener() {
        public void onCallStateChanged(int state, String incomingNumber) {
            if (state == TelephonyManager.CALL_STATE_RINGING)
                pause();/*from w w  w.j  a  v  a2s.c om*/
        }
    }, PhoneStateListener.LISTEN_CALL_STATE);

    Uri uri = intent.getData();
    String playlistUri = intent.getStringExtra(EXTRA_PLAYLIST);
    if (playlistUri != null)
        setPlaylist(Uri.parse(playlistUri), false);
    else if ("file".equals(uri.getScheme())) {
        if (ASAPInfo.isOurFile(uri.toString()))
            setPlaylist(Util.getParent(uri), false);
        else {
            setPlaylist(uri, true);
            uri = playlist.get(0);
        }
    }
    playFile(uri, SONG_DEFAULT);
}

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

/**
 * Returns whether the device should drop this event. Caches notifications
 * if necessary./*from w  w w.j a va2 s .  c  om*/
 *
 * @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:com.aujur.ebookreader.activity.ReadingFragment.java

private void printScreenAndCallState(String calledFrom) {
    boolean isScreenOn = powerManager.isScreenOn();

    if (!isScreenOn) {
        LOG.debug(calledFrom + ": Screen is off");
    } else {//from ww w.  j  a  va2  s.  co m
        LOG.debug(calledFrom + ": Screen is on");
    }

    int phoneState = telephonyManager.getCallState();

    if (phoneState == TelephonyManager.CALL_STATE_RINGING
            || phoneState == TelephonyManager.CALL_STATE_OFFHOOK) {
        LOG.debug(calledFrom + ": Detected call activity");
    } else {
        LOG.debug(calledFrom + ": No active call.");
    }
}

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 a 2 s. 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:org.restcomm.app.qoslib.Services.LibPhoneStateListener.java

public void phoneOffHook(int iPhoneState) {
    try {//from  w  w w . j av  a  2  s  .  com
        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 {//from   w w w  .j  a v  a2 s.  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);
    }
}

From source file:com.google.android.marvin.mytalkback.TalkBackService.java

/**
 * Returns whether the device should drop this event. Caches notifications
 * if necessary.//from w ww  . 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 (!isServiceActive()) {
        return true;
    }

    // Always drop duplicate events (only applies to API < 14).
    if (AccessibilityEventUtils.eventEquals(mLastSpokenEvent, event)) {
        LogUtils.log(this, Log.VERBOSE, "Drop duplicate event");
        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)) {
        LogUtils.log(this, Log.VERBOSE, "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 (!mPowerManager.isScreenOn() && !shouldSpeakCallerId) {
        if (!mSpeakWhenScreenOff) {
            // If the user doesn't allow speech when the screen is
            // off, drop the event immediately.
            LogUtils.log(this, Log.VERBOSE, "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.
            LogUtils.log(this, Log.VERBOSE, "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 = (mRadialMenuManager.isRadialMenuShowing() && !canInterruptRadialMenu);

    // Don't speak events that cannot interrupt the radial menu, if showing
    if (silencedByRadialMenu) {
        LogUtils.log(this, Log.VERBOSE, "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)) {
        LogUtils.log(this, Log.VERBOSE, "Drop notification due to touch or phone state");
        return true;
    }

    final int touchscreenState = 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.
    final int touchscreenConfig = getResources().getConfiguration().touchscreen;
    if ((touchscreenState == Configuration.TOUCHSCREEN_NOTOUCH) && isTouchInteractionStateChange) {
        return true;
    }

    return false;
}

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

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

    try {/*from  w ww  .  j a va 2s .  c om*/
        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);
    }
}