Example usage for android.telephony TelephonyManager EXTRA_STATE_IDLE

List of usage examples for android.telephony TelephonyManager EXTRA_STATE_IDLE

Introduction

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

Prototype

String EXTRA_STATE_IDLE

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

Click Source Link

Document

Value used with #EXTRA_STATE corresponding to #CALL_STATE_IDLE .

Usage

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

@MediumTest
public void testWindowStateChanged_notFromDialer_screenOff() {
    mMatchEventType = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
    mMatchNode = null;/*from   w ww.j  a  v a 2s.  c o m*/

    simulateTelephonyState(TelephonyManager.EXTRA_STATE_IDLE);
    simulateScreenState(false);
    sendEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED, "com.example.app.ExampleClass");

    assertFalse(mMatched);
}

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

@MediumTest
public void testWindowStateChanged_notFromDialer_screenOn() {
    mMatchEventType = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
    mMatchNode = null;/*from w w w.  j  av  a 2 s  .  c  om*/

    simulateTelephonyState(TelephonyManager.EXTRA_STATE_IDLE);
    simulateScreenState(true);
    sendEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED, "com.example.app.ExampleClass");

    assertTrue(mMatched);
}

From source file:org.durka.hallmonitor.CoreReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED) || intent.getAction().equals(QUICKBOOT_POWERON)
            || intent.getAction().equals(HTC_QUICKBOOT_POWERON)) {
        Log.d(LOG_TAG + ".boot", "Boot called.");
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        if (prefs.getBoolean("pref_enabled", false)) {
            Intent mIntent = new Intent(context, CoreService.class);
            context.startService(mIntent);
        }//from   w w w  .j av  a 2  s .  co m
    }

    if (CoreStateManager.getInitialized()) {
        localContext = CoreStateManager.getContext();
        mStateManager = ((CoreApp) localContext).getStateManager();
    } else {
        return;
    }

    if (!mStateManager.getPreference().getBoolean("pref_enabled", false)) {
        return;
    }

    mStateManager.acquireCPUGlobal();

    if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {

        Log.d(LOG_TAG + ".screen", "Screen on event received.");

        if (mStateManager.getCoverClosed()) {
            Log.d(LOG_TAG + ".screen", "Cover is closed, display Default Activity.");
            mStateManager.setBlackScreenTime(0);
            Intent mIntent = new Intent(localContext, CoreService.class);
            mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_LAUNCH_ACTIVITY);
            mStateManager.sendToCoreService(mIntent);
        } else {
            // Log.d(LOG_TAG + ".screen",
            // "Cover is open, free everything.");
            // mStateManager.freeDevice();
            Log.d(LOG_TAG + ".screen", "Cover is open, send to background.");
            Intent stbDAIntent = new Intent(CoreApp.DA_ACTION_SEND_TO_BACKGROUND);
            LocalBroadcastManager.getInstance(localContext).sendBroadcastSync(stbDAIntent);
        }

    } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
        Log.d(LOG_TAG + ".screen", "Screen off event received.");
        // mStateManager.freeDevice();

    } else if (intent.getAction().equals(Intent.ACTION_POWER_CONNECTED)) {
        Intent batteryDAIntent = new Intent(CoreApp.DA_ACTION_BATTERY_REFRESH);
        LocalBroadcastManager.getInstance(localContext).sendBroadcastSync(batteryDAIntent);

        Intent mIntent = new Intent(localContext, CoreService.class);
        mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_WAKEUP_DEVICE);
        mStateManager.sendToCoreService(mIntent);

    } else if (intent.getAction().equals(Intent.ACTION_POWER_DISCONNECTED)) {
        Intent batteryDAIntent = new Intent(CoreApp.DA_ACTION_BATTERY_REFRESH);
        LocalBroadcastManager.getInstance(localContext).sendBroadcastSync(batteryDAIntent);

        Intent mIntent = new Intent(localContext, CoreService.class);
        mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_WAKEUP_DEVICE);
        mStateManager.sendToCoreService(mIntent);

    } else if (intent.getAction().equals(ALARM_ALERT_ACTION)) {

        Log.d(LOG_TAG + ".alarm", "Alarm on event received.");

        // only take action if alarm controls are enabled
        if (mStateManager.getPreference().getBoolean("pref_alarm_controls", false)) {

            Log.d(LOG_TAG + ".alarm", "Alarm controls are enabled, taking action.");
            mStateManager.setAlarmFiring(true);

            Intent mIntent = new Intent(localContext, CoreService.class);
            mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_INCOMMING_ALARM);
            mStateManager.sendToCoreService(mIntent);
        } else {
            Log.d(LOG_TAG + ".alarm", "Alarm controls are not enabled.");
        }

    } else if (intent.getAction().equals(ALARM_DONE_ACTION)) {

        Log.d(LOG_TAG + ".alarm", "Alarm done event received.");

        // only take action if alarm controls are enabled
        if (mStateManager.getPreference().getBoolean("pref_alarm_controls", false)) {
            Log.d(mStateManager.getPreference() + ".alarm", "alarm is over, cleaning up");
            mStateManager.setAlarmFiring(false);

            if (mStateManager.getCoverClosed()) {
                Intent mIntent = new Intent(localContext, CoreService.class);
                mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_LAUNCH_ACTIVITY);
                mStateManager.sendToCoreService(mIntent);
            }
        }
    } else if (intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {

        if (mStateManager.getPreference().getBoolean("pref_phone_controls", false)) {
            String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
            Log.d(LOG_TAG + ".phone", "phone state changed to " + state);
            if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                Intent mIntent;
                mStateManager.setPhoneRinging(true);
                mStateManager.setCallFrom(intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER));
                Log.d(LOG_TAG, "call from " + mStateManager.getCallFrom());
                mIntent = new Intent(localContext, CoreService.class);
                mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_INCOMMING_CALL);
                mStateManager.sendToCoreService(mIntent);
            } else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                Intent mIntent;
                mStateManager.setPhoneRinging(false);
                Log.d(LOG_TAG, "call is over, cleaning up");
                if (mStateManager.getCoverClosed()) {
                    mIntent = new Intent(localContext, CoreService.class);
                    mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_LAUNCH_ACTIVITY);
                    mStateManager.sendToCoreService(mIntent);
                }
            } else if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
            }
        } else {
            Log.d(LOG_TAG + ".phone", "phone controls are not enabled");
        }
    } else if (intent.getAction().equals(mStateManager.getActionCover())) {
        int state = intent.getIntExtra(EXTRA_LID_STATE, LID_ABSENT);
        Log.d(LOG_TAG + ".cover", "cover state changed to " + state);
        if (state == LID_CLOSED) {
            Log.d(LOG_TAG + ".cover", "Cover is close, enable Default Activity.");
            mStateManager.setCoverClosed(true);
            Intent mIntent = new Intent(localContext, CoreService.class);
            mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_LAUNCH_ACTIVITY);
            mStateManager.sendToCoreService(mIntent);
        } else if (state == LID_OPEN) {
            // Log.d(LOG_TAG + ".cover",
            // "Cover is open, stopping Default Activity.");
            mStateManager.setCoverClosed(false);
            // mStateManager.freeDevice();
            Log.d(LOG_TAG + ".screen", "Cover is open, send to background.");
            Intent stbDAIntent = new Intent(CoreApp.DA_ACTION_SEND_TO_BACKGROUND);
            LocalBroadcastManager.getInstance(localContext).sendBroadcastSync(stbDAIntent);
            Intent mIntent = new Intent(localContext, CoreService.class);
            mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_WAKEUP_DEVICE);
            mStateManager.sendToCoreService(mIntent);
        }

    } else if (intent.getAction().equals(TORCH_STATE_CHANGED)) {
        if (mStateManager.getPreference().getBoolean("pref_flash_controls", false)) {
            Log.d(LOG_TAG + ".torch", "torch state changed");
            Intent mIntent = new Intent(localContext, CoreService.class);
            mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_TORCH_STATE);
            if (intent.getIntExtra("state", 0) != 0) {
                mIntent.putExtra(CoreApp.CS_EXTRA_STATE, true);
            } else {
                mIntent.putExtra(CoreApp.CS_EXTRA_STATE, false);
            }
            mStateManager.sendToCoreService(mIntent);
        } else {
            Log.d(LOG_TAG + ".torch", "torch controls are not enabled.");
        }

    } else if (intent.getAction().equals(Intent.ACTION_HEADSET_PLUG)) {
        int state = intent.getExtras().getInt("state");
        Log.d(LOG_TAG + ".headset", "headset is " + (state == 0 ? "gone" : "here") + "!");
        Intent mIntent = new Intent(localContext, CoreService.class);
        mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_HEADSET_PLUG);
        mStateManager.sendToCoreService(mIntent);

    } else if (intent.getAction().equals("org.durka.hallmonitor.debug")) {
        Log.d(LOG_TAG + "", "received debug intent");
        // test intent to show/hide a notification
        boolean showhide = false;
        switch (intent.getIntExtra("notif", 0)) {
        case 1:
            showhide = true;
            break;
        case 2:
            showhide = false;
            break;
        }
        if (showhide) {
            Notification.Builder mBuilder = new Notification.Builder(localContext)
                    .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Hall Monitor")
                    .setContentText("Debugging is fun!");

            NotificationManager mNotificationManager = (NotificationManager) localContext
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            mNotificationManager.notify(42, mBuilder.build());
        } else {
            NotificationManager mNotificationManager = (NotificationManager) localContext
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            mNotificationManager.cancel(42);
        }
    }
    mStateManager.releaseCPUGlobal();
}

From source file:org.apache.cordova.App.java

/**
 * Listen for telephony events: RINGING, OFFHOOK and IDLE
 * Send these events to all plugins using
 *      CordovaActivity.onMessage("telephone", "ringing" | "offhook" | "idle")
 *//*  w  ww  . j  ava2  s  .  co m*/
private void initTelephonyReceiver() {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    //final CordovaInterface mycordova = this.cordova;
    this.telephonyReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {

            // If state has changed
            if ((intent != null) && intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
                if (intent.hasExtra(TelephonyManager.EXTRA_STATE)) {
                    String extraData = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
                    if (extraData.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                        LOG.i(TAG, "Telephone RINGING");
                        webView.postMessage("telephone", "ringing");
                    } else if (extraData.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
                        LOG.i(TAG, "Telephone OFFHOOK");
                        webView.postMessage("telephone", "offhook");
                    } else if (extraData.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                        LOG.i(TAG, "Telephone IDLE");
                        webView.postMessage("telephone", "idle");
                    }
                }
            }
        }
    };

    // Register the receiver
    this.cordova.getActivity().registerReceiver(this.telephonyReceiver, intentFilter);
}

From source file:org.apache.cordova.CoreAndroid.java

/**
 * Listen for telephony events: RINGING, OFFHOOK and IDLE
 * Send these events to all plugins using
 *      CordovaActivity.onMessage("telephone", "ringing" | "offhook" | "idle")
 *//*from w  ww . j  a v a 2 s .c  o m*/
private void initTelephonyReceiver() {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    //final CordovaInterface mycordova = this.cordova;
    this.telephonyReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {

            // If state has changed
            if ((intent != null) && intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
                if (intent.hasExtra(TelephonyManager.EXTRA_STATE)) {
                    String extraData = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
                    if (extraData.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                        LOG.i(TAG, "Telephone RINGING");
                        webView.getPluginManager().postMessage("telephone", "ringing");
                    } else if (extraData.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
                        LOG.i(TAG, "Telephone OFFHOOK");
                        webView.getPluginManager().postMessage("telephone", "offhook");
                    } else if (extraData.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                        LOG.i(TAG, "Telephone IDLE");
                        webView.getPluginManager().postMessage("telephone", "idle");
                    }
                }
            }
        }
    };

    // Register the receiver
    webView.getContext().registerReceiver(this.telephonyReceiver, intentFilter);
}