Example usage for android.bluetooth BluetoothDevice ACTION_ACL_DISCONNECTED

List of usage examples for android.bluetooth BluetoothDevice ACTION_ACL_DISCONNECTED

Introduction

In this page you can find the example usage for android.bluetooth BluetoothDevice ACTION_ACL_DISCONNECTED.

Prototype

String ACTION_ACL_DISCONNECTED

To view the source code for android.bluetooth BluetoothDevice ACTION_ACL_DISCONNECTED.

Click Source Link

Document

Broadcast Action: Indicates a low level (ACL) disconnection from a remote device.

Usage

From source file:org.restcomm.app.qoslib.Services.Intents.IntentHandler.java

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    Bundle intentExtras = intent.getExtras();

    if (owner == null)
        return;/* w ww.  j av a 2 s.  co m*/
    owner.getWebSocketManager().sendIntentToWebSocket(action, intentExtras);

    //capture the "battery changed" event
    if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
        int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
        int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100);
        DeviceInfoOld.battery = level * 100 / scale;
        int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
        boolean bCharging = plugged == BatteryManager.BATTERY_PLUGGED_AC
                || plugged == BatteryManager.BATTERY_PLUGGED_USB;
        owner.setBatteryCharging(bCharging);
        dataMonitorStats.setBattery(bCharging, DeviceInfoOld.battery);
    } else if (action.equals(Intent.ACTION_POWER_CONNECTED)) {
        owner.setBatteryCharging(true);
        dataMonitorStats.setBattery(true, null);
    } else if (action.equals(Intent.ACTION_POWER_DISCONNECTED)) {
        owner.setBatteryCharging(false);
        dataMonitorStats.setBattery(false, null);
    } else if (action.equals(Intent.ACTION_VIEW)) {
        //this is supposed to trigger the update event
        //owner.triggerUpdateEvent(false, false);
    } else if (action.equals(CommonIntentActionsOld.ACTION_START_UI)) {
        String packagename = intent.getStringExtra("packagename");
        String mypackagename = context.getPackageName();
        PreferenceManager.getDefaultSharedPreferences(context).edit()
                .putString(PreferenceKeys.Miscellaneous.YEILDED_SERVICE, packagename).commit();
        // If the UI started on a different MMC app UI, then we stop this service until this UI is launched
        if (!packagename.equals(mypackagename)) // This will exit the service when safe, and won't restart it because it will be yeilded
            owner.restartSelf();
    } else if (action.equals(UPDATE_ACTION)) {
        owner.getEventManager().triggerUpdateEvent(false, false);
    } else if (action.equals(COLDRESET_ACTION)) {
        //this is supposed to trigger the update event
        owner.getGpsManager().coldStart("triggered by user");
    } else if (action.equals(EMAIL_CSV)) {
        //this is supposed to trigger the update event
        owner.requestCsvEmail();
    } else if (action.equals(SPEED_TEST)) {
        //this is supposed to trigger a speed test
        int trigger = intent.getIntExtra(CommonIntentBundleKeysOld.EXTRA_SPEED_TRIGGER, 0);
        //owner.triggerSMSTest(trigger);
        owner.getEventManager().queueActiveTest(EventType.MAN_SPEEDTEST, trigger);
    } else if (action.equals(RUN_WEBSOCKET)) {
        //this is supposed to trigger a speed test
        boolean bStart = intent.getBooleanExtra(EXTRA_START_WEBSOCKET, true);
        owner.getWebSocketManager().runWebSocket(bStart);
        //owner.triggerSpeedTest(trigger);
    } else if (action.equals(ACTIVE_TEST)) {
        //this is supposed to trigger a speed test
        int evType = intent.getIntExtra(CommonIntentBundleKeysOld.EXTRA_TEST_TYPE, 0);
        EventType eventType = EventType.get(evType);
        int trigger = intent.getIntExtra(CommonIntentBundleKeysOld.EXTRA_SPEED_TRIGGER, 0);
        owner.getEventManager().queueActiveTest(eventType, trigger);
    } else if (action.equals(SMS_TEST)) {
        //this is supposed to trigger a speed test
        int trigger = intent.getIntExtra(CommonIntentBundleKeysOld.EXTRA_SPEED_TRIGGER, 0);
        //owner.triggerSMSTest(trigger);
        owner.getEventManager().queueActiveTest(EventType.SMS_TEST, trigger);
    } else if (action.contains(SMS_DELIVERED)) {
        //add delivery time to connection history

        int identifier = intent.getIntExtra("identifier", 0); //in case we need to search connection list to find which SMS
        long deliveryTime = 0;

        switch (getResultCode()) {
        case Activity.RESULT_OK:
            deliveryTime = System.currentTimeMillis();
            break;
        case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
            deliveryTime = -1;
            break;
        case SmsManager.RESULT_ERROR_NO_SERVICE:
            deliveryTime = -1;
            break;
        case SmsManager.RESULT_ERROR_NULL_PDU:
            deliveryTime = -1;
            break;
        case SmsManager.RESULT_ERROR_RADIO_OFF:
            deliveryTime = -1;
            break;
        }

        owner.getEventManager().handleSMSDeliverNotification(identifier, deliveryTime);
    } else if (action.equals(LATENCY_TEST)) {
        int trigger = intent.getIntExtra(CommonIntentBundleKeysOld.EXTRA_SPEED_TRIGGER, 0);
        owner.getEventManager().queueActiveTest(EventType.LATENCY_TEST, trigger);
        //owner.runLatencyTest(false);
    } else if (action.equals(ACTION_STOP_SPEEDTEST)) {
        owner.getEventManager().killSpeedTest();
    } else if (action.equals(ACTION_STOP_VIDEOTEST)) {
        int testType = intent.getIntExtra(CommonIntentBundleKeysOld.EXTRA_TEST_TYPE, 0);
        owner.getEventManager().killActiveTest(testType);
    } else if (action.equals(ROAMING_ON)) {
        dataMonitorStats.setRoaming(true);
    } else if (action.equals(ROAMING_OFF)) {
        dataMonitorStats.setRoaming(false);
    } else if (action.equals("android.intent.action.ANY_DATA_STATE")) {
        String apn = intentExtras.getString("apn");
        String state = intentExtras.getString("state");
        String apnType = intentExtras.getString("apnType");
        String extras = apnType + "" + state;
        if (state.equals("CONNECTED") && !apnType.equals("default"))
            extras = extras + "!";
        if (apnType != null && apnType.equals("default") && apn != null) {
            SharedPreferences securePref = MainService.getSecurePreferences(context);
            securePref.edit().putString(PreferenceKeys.Miscellaneous.KEY_APN, apn).commit();
        }

    } else if (action.equals("android.intent.action.DATA_CONNECTION_CONNECTED_TO_PROVISIONING_APN")) {
        String apn = intentExtras.getString("apn");
        String apnType = intentExtras.getString("apnType");
        String extras = apn + "," + apnType;
    } else if (action.equals("android.intent.action.ACTION_DATA_CONNECTION_FAILED")) {
        String phoneName = intentExtras.getString("phoneName");
        String reason = intentExtras.getString("reason");
        String extras = phoneName + "," + reason;
    } else if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
        if (owner.getUsageLimits().getDormantMode() > 0)
            return;
        // wifi state change may trigger the event queue to be sent
        //MMCLogger.logToFile(MMCLogger.Level.DEBUG, "MMCIntentHandlerOld", "NETWORK_STATE_CHANGED_ACTION", "");
        owner.wifiStateChange((NetworkInfo) intentExtras.getParcelable(WifiManager.EXTRA_NETWORK_INFO));
        owner.trackAccessPoints(0);
        dataMonitorStats.setWifi(PhoneState.isNetworkWifi(owner));
    } else if (action.equals(WIMAX_STATE_CHANGE)) {
        owner.trackAccessPoints(0);
    } else if (action.equals(BluetoothDevice.ACTION_ACL_CONNECTED)) {
        //         BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        //         BluetoothClass bclass = device.getBluetoothClass();
        //         int major = bclass.getMajorDeviceClass();
        //         if (major == 1024)
        //            owner.setBTHeadsetState(1);
        //         owner.trackAccessPoints();
    } else if (action.equals(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED)) {
        owner.trackAccessPoints(0);
    } else if (action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) {
        //         BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        //         BluetoothClass bclass = device.getBluetoothClass();
        //         int major = bclass.getMajorDeviceClass();
        //         if (major == 1024)
        //            owner.setBTHeadsetState(0);
        //         owner.trackAccessPoints();
    } else if (action.equals(Intent.ACTION_HEADSET_PLUG)) {
        try {
            int state = intent.getIntExtra("state", -1);
            owner.setHeadsetState(state);
        } catch (Exception e) {
            LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "onReceive",
                    "error receiving Intent.ACTION_HEADSET_PLUG: " + e);
        }
    } else if (action.equals(Intent.ACTION_HEADSET_PLUG)) {
        int state = intent.getIntExtra("state", -1);
        owner.setHeadsetState(state);
    } else if (action.equals(CommonIntentActionsOld.ACTION_START_VOICETEST)) {
        //this is supposed to trigger a speed test
        int trigger = intent.getIntExtra(CommonIntentBundleKeysOld.EXTRA_VQ_TRIGGER, 0);
        owner.getVQManager().runTest(trigger);
    } else if (action.equals(CommonIntentActionsOld.ACTION_TEST_VQ_DEVICE)) {
        owner.getVQManager().runTest(10);
    } else if (action.equals(CommonIntentActionsOld.ACTION_STOP_VOICETEST)) {
        owner.getVQManager().killTest();
    } else if (action.equals(RESTART_MMC_SERVICE)) {
        owner.restartNextIdle();

    } else if (action.equals(STOP_TRACKING_ACTION)) {
        owner.getEventManager().stopTracking();
    } else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
        try {
            dataMonitorStats.setScreen(false);
            SignalEx mmcSignal = new SignalEx();
            owner.getPhoneStateListener().processNewMMCSignal(mmcSignal);
            if (owner.getTravelDetector() != null) {
                owner.getPhoneState().screenChanged(false);
                owner.getEventManager().screenChanged(false);
            }
        } catch (Exception e) {
            LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "onReceive",
                    "received action SCREEN_OFF, calling MainService.processNewMMCSignal()", e);
        }
    } else if (action.equals(Intent.ACTION_SCREEN_ON)) {
        dataMonitorStats.setScreen(true);
        if (owner.getTravelDetector() != null) {
            owner.getPhoneState().screenChanged(true);
            owner.getEventManager().screenChanged(true);
        }
    } else if (action.equals(ACTION_ALARM_MINUTE)) {
        // CPU wakes very briefly only in order to spur cellid updates
        owner.getTravelDetector().triggerTravelCheck();
        QosAPI.checkHostApp(context);
    } else if (action.equals(ACTION_TRACKING_5MINUTE)) {
        owner.getTrackingManager().runTracking();
    } else if (action.equals(ACTION_TRACKING_1MINUTE)) {
        LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, TAG, "onReceive", "ACTION_TRACKING_1MINUTE");
        owner.getTrackingManager().runTrackingTests();
    } else if (action.equals(ACTION_ALARM_3HOUR)) {
        dataMonitorStats.prepareAllStatistics();
        owner.getEventManager().triggerUpdateEvent(true, false);
        //         Calendar cal = Calendar.getInstance(); 
        //          int hour = cal.get (Calendar.HOUR_OF_DAY); 
        //         //If 12pm to 3 am
        //          if(((hour >= 0 && hour <= 3) || hour == 24) && owner.isNetworkWifi()) {
        //            //See if transit info needs to be downloaded
        //             
        //             //Don't allow the app to shut down until the work is done, keep the CPU running
        //             MMCLogger.logToFile(MMCLogger.Level.DEBUG, TAG, "onReceive", "ACTION_ALARM_3HOUR, wakelock turned on and checking transit "
        //                   + "info uptodate at 24-hour: " + hour);
        //             wakeLock.acquire();
        //             
        //             downloadAreasIfOutOfDate();
        //          }
    }
    //      else if(action.equals(ACTION_TRANSIT_DL_DONE)) {
    //         //Allow CPU to move on
    //         if(wakeLock != null) {
    //            wakeLock.release(); 
    //            MMCLogger.logToFile(MMCLogger.Level.DEBUG, TAG, "onReceive", "received action ACTION_TRANSIT_DONE, wakelock turned off");
    //         }
    //      }
    //      else if(action.equals(ACTION_TRANSIT_DL_START)) {
    //         //Don't allow the app to shut down until the work is done, keep the CPU running
    //          MMCLogger.logToFile(MMCLogger.Level.DEBUG, TAG, "onReceive", "ACTION_TRANSIT_DL_START, wakelock turned on and downloading transit if was requested");
    //          wakeLock.acquire();
    //          
    //          downloadAreasIfOutOfDate();
    //      }
    else if (action.equals(ACTION_ALARM_SCANAPPS)) {
        int intervalDM = PreferenceManager.getDefaultSharedPreferences(owner)
                .getInt(PreferenceKeys.Miscellaneous.MANAGE_DATAMONITOR, 0);
        // run datamonitor if enabled
        if (intervalDM > 0) {
            dataMonitorStats.scanApps();
            dataMonitorStats.getRunningAppsString(false); // for debug
        }

        // Also using this timer for GCM heartbeats (its a 5 minute heartbeat to tell Google Cloud Messaging to check the socket more often for more reliable push messages)
        // 2 independent timers might wake up device twice as often, doubling the battery impact, so I'm forcing it to use one for both cases
        //         boolean useHeartbeat = PreferenceManager.getDefaultSharedPreferences(owner).getBoolean("KEY_GCM_HEARTBEAT", false);
        //         if (useHeartbeat) {
        //            GcmKeepAlive gcm = new GcmKeepAlive(owner);
        //            gcm.broadcastIntents();
        //         }
    } else if (action.equals(ACTION_ALARM_15MINUTE)) {

        int intervalDM = PreferenceManager.getDefaultSharedPreferences(owner)
                .getInt(PreferenceKeys.Miscellaneous.MANAGE_DATAMONITOR, 0);
        // run datamonitor if enabled
        if (intervalDM > 0) {
            boolean firstBucketDone = PreferenceManager.getDefaultSharedPreferences(owner)
                    .getBoolean(PreferenceKeys.Miscellaneous.FIRST_BUCKET, false);
            if (!firstBucketDone) { //if false, first bucket needs to be done
                dataMonitorStats.firstBucket();
                dataMonitorStats.monitor();
                PreferenceManager.getDefaultSharedPreferences(owner).edit()
                        .putBoolean(PreferenceKeys.Miscellaneous.FIRST_BUCKET, true).commit();
                LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, "MMCIntentHandlerOld", "onReceive",
                        "First bucket at: " + System.currentTimeMillis() / 1000);
            } else {
                dataMonitorStats.monitor();
                //MMCLogger.logToFile(MMCLogger.Level.DEBUG, "MMCIntentHandlerOld", "onReceive", "15 min bucket at: " + System.currentTimeMillis()/1000);
            }
        }
        // regardless, still make sure GPS is idle unless needed
        owner.getGpsManager().safeguardGps();
    } else if (action.equals(GPS_STATE_ON)) {
        dataMonitorStats.setGps(true);
    } else if (action.equals(GPS_STATE_OFF)) {
        dataMonitorStats.setGps(false);
    } else if (action.equals(PHONE_CALL_CONNECT)) {
        dataMonitorStats.setPhone(true);
    } else if (action.equals(PHONE_CALL_DISCONNECT)) {
        dataMonitorStats.setPhone(false);
    } else if (action.equals(HANDOFF)) {
        dataMonitorStats.handoff();
    } else if (action.equals(MANUAL_TRANSIT_START)) {
        long lat = intent.getIntExtra("latitude", 0);
        long lon = intent.getIntExtra("longitude", 0);
        Location location = new Location("");
        location.setLatitude(lat / 1000000.0);
        location.setLongitude(lon / 1000000.0);
        location.setAccuracy(-3);

        //         PreferenceManager.getDefaultSharedPreferences(owner).edit().putString(
        //                PreferenceKeys.Miscellaneous.SURVEY_COMMAND,).commit();
        PreferenceManager.getDefaultSharedPreferences(owner).edit()
                .putString("transitEvent", String.valueOf(lat) + "," + String.valueOf(lon)).commit();
        reportManager.manualTransitEvent = owner.getEventManager().triggerSingletonEvent(EventType.MAN_TRANSIT);
        reportManager.manualTransitEvent.setLocation(location, 0);
        owner.getTravelDetector().setTravelling(false);
    } else if (action.equals(MANUAL_TRANSIT_END)) {
        if (reportManager.manualTransitEvent == null)
            return;
        String accelData = intent.getStringExtra("accelerometer");
        int stationFrom = intent.getIntExtra("stationFrom", 0);
        int stationTo = intent.getIntExtra("stationTo", 0);
        int duration = intent.getIntExtra("duration", 0);
        int corrected = intent.getIntExtra("corrected", 0);
        if (corrected != 0) {
            Location location = reportManager.manualTransitEvent.getLocation();
            location.setAccuracy(-4);
        }

        reportManager.manualTransitEvent.setAppData(accelData); //TODO want this to really be in appdata?
        reportManager.manualTransitEvent.setLookupid1(stationFrom);
        reportManager.manualTransitEvent.setLookupid2(stationTo);
        reportManager.manualTransitEvent.setDuration(duration);
        owner.getEventManager().unstageAndUploadEvent(reportManager.manualTransitEvent, null);
        reportManager.manualTransitEvent = null;
    } else if (action.equals(MANUAL_TRANSIT_CANCEL)) {
        if (reportManager.manualTransitEvent != null) {
            owner.getEventManager().unstageEvent(reportManager.manualTransitEvent);
            ReportManager reportManager = ReportManager.getInstance(owner);
            reportManager.getDBProvider().delete(TablesEnum.LOCATIONS.getContentUri(),
                    "timestamp > ? And accuracy = 3",
                    new String[] { String.valueOf(reportManager.manualTransitEvent.getEventTimestamp()) });
            reportManager.manualTransitEvent = null;
        }
    } else if (action.equals(MANUAL_PLOTTING_START)) {
        int floor = intent.getIntExtra("floor", 0);
        //         int type = intent.getIntExtra("type", -1);  //1(indoor) or 2(outdoor)
        int topFloor = intent.getIntExtra("top", -1);
        int lat = intent.getIntExtra("latitude", -1);
        int lng = intent.getIntExtra("longitude", -1);
        long osm_id = intent.getLongExtra("osm_id", 0);
        String poly = intent.getStringExtra("poly");

        reportManager.manualPlottingEvent = owner.getEventManager()
                .triggerSingletonEvent(EventType.MAN_PLOTTING);
        reportManager.manualPlottingEvent.setEventIndex(floor);
        reportManager.manualPlottingEvent.setDuration(topFloor);
        reportManager.manualPlottingEvent.setBuildingID(osm_id);
        reportManager.manualPlottingEvent.setAppData(poly);
        Location location = new Location("");
        location.setLatitude(lat / 1000000.0);
        location.setLongitude(lng / 1000000.0);
        location.setAccuracy(-1);
        reportManager.updateEventField(reportManager.manualPlottingEvent.getLocalID(), "latitude",
                Double.toString(location.getLatitude()));
        reportManager.updateEventField(reportManager.manualPlottingEvent.getLocalID(), "longitude",
                Double.toString(location.getLongitude()));

        reportManager.manualPlottingEvent.setLocation(location, 0);
        presetEventId(reportManager.manualPlottingEvent); // reserve an EventID for this manual sampling event, to be used for Share links

        owner.getTravelDetector().setTravelling(false);
    } else if (action.equals(MANUAL_PLOTTING_END)) {
        LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, TAG, "onReceive", "MANUAL_PLOTTING_END");
        //         owner.getEventManager().unstageEvent(manulaPlottingEvent); //does not upload
        if (reportManager.manualPlottingEvent != null)
            owner.getEventManager().unstageAndUploadEvent(reportManager.manualPlottingEvent, null);
        //After the event was submitted, reset it so we don't restore an old event in ManualMapping
        reportManager.manualPlottingEvent = null;
    } else if (action.equals(MANUAL_PLOTTING_CANCEL)) {
        if (reportManager.manualPlottingEvent != null) {
            reportManager.getDBProvider().delete(TablesEnum.LOCATIONS.getContentUri(),
                    "timestamp > ? And accuracy < 0",
                    new String[] { String.valueOf(reportManager.manualPlottingEvent.getEventTimestamp()) });
            reportManager.manualPlottingEvent = null;

        }
    }
    //      else if(intent.getAction().equals(MMS_RECEIVED)) {
    //         LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, TAG, "onReceived MMS_RECEIVED", intentExtras.toString());
    //      }
    //      else if(intent.getAction().equals(MMS_SENT)) {
    //         LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, TAG, "onReceived MMS_SENT", intentExtras.toString());
    //      }
    //      else if(intent.getAction().equals(SMS_REJECTED)) {
    //         LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, TAG, "onReceived SMS_REJECTED", intentExtras.toString());
    //      }
    else if (intent.getAction().equals(SMS_RECEIVED)) {
        SmsMessage[] msgs = null;
        //         String msg_from;
        if (intentExtras == null)
            return;

        Object[] pdus = (Object[]) intentExtras.get("pdus");
        msgs = new SmsMessage[pdus.length];
        String[] msgBody = new String[msgs.length];
        for (int i = 0; i < msgs.length; i++) {
            msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
            //            msg_from = msgs[i].getOriginatingAddress();
            String msg = msgs[i].getMessageBody().trim();
            if (msg.length() > 10) {
                msg = msg.substring(1, msg.length() - 1);
                msg = "{" + msg + "}";
            }

            msgBody[i] = msg;

        }
        handleCommands(msgBody, true, 0);
    } else if (action.equals(VIEWING_SIGNAL)) {
        owner.setEnggQueryTime();
    } else if (intent.getAction().equals(SURVEY)) {
        if (intentExtras == null)
            return;

        int surveyid = intentExtras.getInt(SURVEY_EXTRA);
        postSurvey(surveyid);
    } else if (intent.getAction().equals(GCM_MESSAGE)) {
        if (intentExtras == null)
            return;
        try {
            String msg = intentExtras.getString(GCM_MESSAGE_EXTRA);
            long starttime = intentExtras.getLong("GCM_STARTTIME_EXTRA");
            EventResponse eventResponse = gson.fromJson(msg, EventResponse.class);
            eventResponse.init();
            eventResponse.setStartTime(starttime);
            eventResponse.handleEventResponse(owner, true);
        } catch (Exception e) {
            LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "onReceived GCM_MESSAGE", "exception", e);
        }
    } else if (intent.getAction().equals(COMMAND)) {
        if (intentExtras == null)
            return;

        String commands = intentExtras.getString(COMMAND_EXTRA);
        if (commands == null)
            return;
        long starttime = intent.getLongExtra("STARTTIME_EXTRA", 0);
        String[] msgs = null;
        try {
            JSONArray cmds = new JSONArray(commands);
            msgs = new String[cmds.length()];
            for (int j = 0; j < cmds.length(); j++)
                msgs[j] = cmds.getJSONObject(j).toString();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            //e.printStackTrace();
        }
        //commands = commands.replace("[", "");
        //commands = commands.replace("]", "");
        //String msgs[] = commands.split("/");
        handleCommands(msgs, false, starttime);
    }

    else if (intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
        int val = 0;
        val = intent.getIntExtra("android.telecom.extra.CALL_DISCONNECT_CAUSE", -1);
        String msg = intent.getStringExtra("android.telecom.extra.CALL_DISCONNECT_CAUSE");
        String msg2 = intent.getStringExtra("android.telecom.extra.CALL_DISCONNECT_MESSAGE");
        //MMCLogger.logToFile(MMCLogger.Level.ERROR, TAG, "String CALL_DISCONNECT_CAUSE", msg);
        //MMCLogger.logToFile(MMCLogger.Level.ERROR, TAG, "Int CALL_DISCONNECT_CAUSE", ""+val);
    } else if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
        String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        //if (phoneNumber != null)
        //    MMCLogger.logToFile(MMCLogger.Level.ERROR, TAG, "NEW_OUTGOING_CALL", phoneNumber);
    }

    else if (intent.getAction().equals("android.intent.action.PRECISE_CALL_STATE")) {
        int val = 0;
        //val = intent.getIntExtra("android.telecom.extra.CALL_DISCONNECT_CAUSE", -1);
        int state_ringing = intent.getIntExtra("ringing_state", -1);
        int state_foreground = intent.getIntExtra("foreground_state", -1);
        int state_background = intent.getIntExtra("background_state", -1);

        int disconnect_cause = intent.getIntExtra("disconnect_cause", -1);
        int precise_disconnect_cause = intent.getIntExtra("precise_disconnect_cause", -1);
        PreciseCallCodes precisecall = new PreciseCallCodes(state_ringing, state_foreground, state_background,
                disconnect_cause, precise_disconnect_cause);
        LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "PRECISE_CALL_STATE", precisecall.toString());
        owner.getPhoneStateListener().onPreciseCallState(precisecall);
    } else if (intent.getAction().equals("android.intent.action.PRECISE_DATA_CONNECTION_STATE_CHANGED")) {
        int val = 0;
        //val = intent.getIntExtra("android.telecom.extra.CALL_DISCONNECT_CAUSE", -1);
        int state = intent.getIntExtra("state", -1);
        int networkType = intent.getIntExtra("networkType", -1);
        String reason = intent.getStringExtra("reason");
        String failCause = intent.getStringExtra("failCause");
        String apnType = intent.getStringExtra("apnType");
        String apn = intent.getStringExtra("apn");
        Object linkProperties = intent.getParcelableExtra("linkProperties");
        if (!apnType.equals("default"))
            return;
        //         if (failCause != null && failCause.length() > 0)
        //         {
        //            String msg = String.format("state:%d,netType:%d,apnType:%s,reason:%s\r\nfailCause:%s", state,networkType,apnType,reason,failCause);
        //            MMCLogger.logToFile(MMCLogger.Level.ERROR, TAG, "PRECISE_DATA_CONNECTION_STATE_CHANGED", msg);
        //            if (linkProperties != null)
        //            {
        //               msg = String.format("PRECISE_DATA_CONNECTION_STATE_CHANGED  linkProperties:%s", linkProperties.toString());
        //               MMCLogger.logToFile(MMCLogger.Level.ERROR, TAG, "PRECISE_DATA_CONNECTION_STATE_CHANGED", msg);
        //            }
        //         }
        //         else if (reason != null && reason.length() > 0)
        //         {
        //            String msg = String.format("state:%d,netType:%d,apnType:%s,reason:%s\r\nfailCause:%s", state,networkType,apnType,reason,failCause);
        //            MMCLogger.logToFile(MMCLogger.Level.ERROR, TAG, "PRECISE_DATA_CONNECTION_STATE_CHANGED", msg);
        //            if (linkProperties != null)
        //            {
        //               msg = String.format("PRECISE_DATA_CONNECTION_STATE_CHANGED  linkProperties:%s", linkProperties.toString());
        //               MMCLogger.logToFile(MMCLogger.Level.ERROR, TAG, "PRECISE_DATA_CONNECTION_STATE_CHANGED", msg);
        //            }
        //         }
    } else if (intent.getAction().equals("org.restcomm.android.CONNECT_FAILED")
            || intent.getAction().equals("org.restcomm.android.CALL_STATE")
            || intent.getAction().equals("org.restcomm.android.DISCONNECT_ERROR")) {
        owner.getPhoneStateListener().getRestCommManager().handleIntent(owner, intent);
    } else if (intent.getAction().equals(ACTION_RADIOLOG_DISCONNECT)) {
        String time = intent.getStringExtra(EXTRA_RADIOLOG_TIME);
        String cause = intent.getStringExtra(EXTRA_RADIOLOG_DISC_CAUSE);
        owner.getPhoneStateListener().onDisconnect(time, cause);
    } else if (intent.getAction().equals(ACTION_RADIOLOG_CONNECT)) {
        String time = intent.getStringExtra(EXTRA_RADIOLOG_TIME);
        String state = intent.getStringExtra(EXTRA_RADIOLOG_CONN_STATE);
        owner.getPhoneStateListener().onConnect(time, state);
    } else if (intent.getAction().equals(ACTION_RADIOLOG_NEIGHBORS)) {
        String time = intent.getStringExtra(EXTRA_RADIOLOG_TIME);
        String neighbors = intent.getStringExtra(EXTRA_RADIOLOG_NEIGHBORS);
        //owner.onConnect(time, state);
    } else if (intent.getAction().equals(ACTION_RADIOLOG_SERVICEMODE)) {
        String time = intent.getStringExtra(EXTRA_RADIOLOG_TIME);
        String jsonstr = intent.getStringExtra(EXTRA_RADIOLOG_SVC_JSON);
        JSONObject json = null;
        try {
            json = new JSONObject(jsonstr);
        } catch (Exception e) {
        }
        String values = intent.getStringExtra(EXTRA_RADIOLOG_SVC_TEXT);
        String name = intent.getStringExtra(EXTRA_RADIOLOG_SVC_NAME);
        owner.getPhoneStateListener().onServiceMode(time, json, values, name);
    } else if (intent.getAction().equals(ACTION_RADIOLOG_SERVICEMENU)) {
        String time = intent.getStringExtra(EXTRA_RADIOLOG_TIME);
        String values = intent.getStringExtra(EXTRA_RADIOLOG_SVC_TEXT);
        String name = intent.getStringExtra(EXTRA_RADIOLOG_SVC_NAME);
        owner.getPhoneStateListener().onServiceMenu(time, values, name);
    } else if (intent.getAction().equals(ACTION_MMCSYS_VERSION)) {
        Integer version = intent.getIntExtra(EXTRA_MMCSYS_VERSION, 0);
        owner.onSvcModeVersion(version);
    } else if (intent.getAction().equals(ACTION_RADIOLOG_ERROR)) {
        String error = intent.getStringExtra(EXTRA_RADIOLOG_ERROR);
        String details = intent.getStringExtra(EXTRA_RADIOLOG_ERROR_DETAIL);
        LoggerUtil.logToFile(LoggerUtil.Level.ERROR, "RilReader", error, details);
        //owner.onConnect(time, state);
    }

}

From source file:ibme.sleepap.recording.SignalsRecorder.java

/**
 * Called when the activity is first created. onStart() is called
 * immediately afterwards.//from   ww  w.j av  a2 s .  c  o  m
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.signals_recorder);
    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    // Log both handled and unhandled issues.
    if (sharedPreferences.getBoolean(Constants.PREF_WRITE_LOG, Constants.DEFAULT_WRITE_LOG)) {
        String bugDirPath = Environment.getExternalStorageDirectory().toString() + "/"
                + getString(R.string.app_name) + "/" + Constants.FILENAME_LOG_DIRECTORY;
        File bugDir = new File(bugDirPath);
        if (!bugDir.exists()) {
            bugDir.mkdirs();
        }
        String handledFileName = bugDirPath + "/logcat" + System.currentTimeMillis() + ".trace";
        String unhandledFileName = bugDirPath + "/unhandled" + System.currentTimeMillis() + ".trace";
        // Log any warning or higher, and write it to handledFileName.
        String[] cmd = new String[] { "logcat", "-f", handledFileName, "*:W" };
        try {
            Runtime.getRuntime().exec(cmd);
        } catch (IOException e1) {
            Log.e(Constants.CODE_APP_TAG, "Error creating bug files", e1);
        }
        Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(unhandledFileName));
    }

    bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    extras = getIntent().getBundleExtra(Constants.EXTRA_RECORDING_SETTINGS);
    actigraphyEnabled = extras.getBoolean(Constants.EXTRA_COLLECT_ACTIGRAPHY, false);
    audioEnabled = extras.getBoolean(Constants.EXTRA_COLLECT_AUDIO, false);
    ppgEnabled = extras.getBoolean(Constants.EXTRA_COLLECT_PPG, false);
    dateTimeString = DateFormat.format(Constants.PARAM_DATE_FORMAT, System.currentTimeMillis()).toString();
    sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    magnetometer = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    String appDirPath = Environment.getExternalStorageDirectory().toString() + "/"
            + getString(R.string.app_name);
    filesDirPath = appDirPath + "/" + dateTimeString + "/";
    lastAccelerometerRecordedTime = 0;
    lastPositionChangeTime = System.currentTimeMillis();
    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Constants.CODE_APP_TAG);
    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    actigraphyQueue = new LinkedList<Double>();
    positionDisplay = (TextView) findViewById(R.id.position);
    recordingSign = (ImageView) findViewById(R.id.recordingSign);

    for (int i = 0; i < 5; ++i) {
        totalPositionTime[i] = 0;
    }

    // Battery check receiver.
    registerReceiver(this.batteryLevelReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

    // Button to stop the recording.
    Button stopButton = (Button) findViewById(R.id.buttonStop);
    stopButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View viewNext) {
            stopRecording();
        }
    });

    // Button to reconnect the bluetooth.
    reconnectButton = (Button) findViewById(R.id.reconnectButton);
    reconnectButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View viewNext) {
            String macAddress = sharedPreferences.getString(Constants.PREF_MAC_ADDRESS,
                    Constants.DEFAULT_MAC_ADDRESS);
            noninManager = null;
            noninManager = new NoninManager(getApplicationContext(), bluetoothAdapter, macAddress,
                    new PpgHandler(SignalsRecorder.this));
            noninManager.start();
            reconnectButton.setEnabled(false);
            reconnectButton.setClickable(false);
        }
    });

    // Create a folder for the recordings, and delete any extra recordings.
    File dir = new File(filesDirPath);
    if (!dir.exists()) {
        dir.mkdirs();
        File appDir = new File(appDirPath);

        // Create a list of recordings in the app directory. These
        // are named by the date on which they were formed and so can be in
        // date order (earliest first).
        String[] recordingDirs = appDir.list();
        Arrays.sort(recordingDirs);

        // How many more recordings do we have in the app directory than are
        // specified in the settings? Should account for questionnaires
        // file,
        // which must exist for the user to have gotten to this stage
        // (checklist).

        int numberRecordings = 0;
        for (String folderOrFileName : recordingDirs) {
            if (!folderOrFileName.equals(Constants.FILENAME_QUESTIONNAIRE)
                    && !folderOrFileName.equals(Constants.FILENAME_LOG_DIRECTORY)
                    && !folderOrFileName.equals(Constants.FILENAME_FEEDBACK_DIRECTORY)) {
                numberRecordings++;
            }
        }

        int extraFiles = numberRecordings - Integer.parseInt(sharedPreferences
                .getString(Constants.PREF_NUMBER_RECORDINGS, Constants.DEFAULT_NUMBER_RECORDINGS));

        if (extraFiles > 0) {
            // Too many recordings. Delete the earliest n, where n is the
            // number of extra files.
            boolean success;
            int nDeleted = 0;
            for (String candidateFolderName : recordingDirs) {
                if (nDeleted >= extraFiles) {
                    // We've deleted enough already.
                    break;
                }
                if (candidateFolderName.equals(Constants.FILENAME_QUESTIONNAIRE)
                        || candidateFolderName.equals(Constants.FILENAME_LOG_DIRECTORY)
                        || candidateFolderName.equals(Constants.FILENAME_FEEDBACK_DIRECTORY)) {
                    // Don't delete questionnaire file or log/feedback
                    // directory.
                    continue;
                }
                // See if the path is a directory, and skip it if it isn't.
                File candidateFolder = new File(appDir, candidateFolderName);
                if (!candidateFolder.isDirectory()) {
                    continue;
                }
                // If we've got to this stage, the file is the earliest
                // recording and should be deleted. Delete files in
                // recording first.
                success = Utils.deleteDirectory(candidateFolder);
                if (success) {
                    nDeleted++;
                }
            }
        }
    }

    // Copy latest questionnaire File
    try {
        File latestQuestionnaireFile = new File(appDirPath, Constants.FILENAME_QUESTIONNAIRE);
        InputStream in = new FileInputStream(latestQuestionnaireFile);
        OutputStream out = new FileOutputStream(new File(filesDirPath, Constants.FILENAME_QUESTIONNAIRE));
        // Copy the bits from instream to outstream
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        in.close();
        out.close();
    } catch (FileNotFoundException e) {
        Log.e(Constants.CODE_APP_TAG, "FileNotFoundException copying Questionnaire file.");
    } catch (IOException e) {
        Log.e(Constants.CODE_APP_TAG, "IOException copying Questionnaire file.");
    }

    // Create txt files.
    orientationFile = new File(filesDirPath, Constants.FILENAME_ORIENTATION);
    accelerationFile = new File(filesDirPath, Constants.FILENAME_ACCELERATION_RAW);
    actigraphyFile = new File(filesDirPath, Constants.FILENAME_ACCELERATION_PROCESSED);
    audioProcessedFile = new File(filesDirPath, Constants.FILENAME_AUDIO_PROCESSED);
    bodyPositionFile = new File(filesDirPath, Constants.FILENAME_POSITION);
    ppgFile = new File(filesDirPath, Constants.FILENAME_PPG);
    spo2File = new File(filesDirPath, Constants.FILENAME_SPO2);
    audioRawFile = new File(filesDirPath, Constants.FILENAME_AUDIO_RAW);

    /** Recording starts here. */
    // Log start time so recording can begin in 30 minutes.
    startTime = Calendar.getInstance(Locale.getDefault());
    finishRecordingFlag = false;
    recordingStartDelayMs = Constants.CONST_MILLIS_IN_MINUTE * Integer.parseInt(sharedPreferences
            .getString(Constants.PREF_RECORDING_START_DELAY, Constants.DEFAULT_RECORDING_START_DELAY));
    recordingDurationMs = Constants.CONST_MILLIS_IN_MINUTE * Integer.parseInt(sharedPreferences
            .getString(Constants.PREF_RECORDING_DURATION, Constants.DEFAULT_RECORDING_DURATION));
    if (recordingStartDelayMs > 0) {
        startRecordingFlag = false;
        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
        dialogBuilder.setTitle(getString(R.string.delayAlertTitle))
                .setMessage(getString(R.string.delayAlertMessage1) + " "
                        + sharedPreferences.getString(Constants.PREF_RECORDING_START_DELAY,
                                Constants.DEFAULT_RECORDING_START_DELAY)
                        + " " + getString(R.string.delayAlertMessage2))
                .setPositiveButton(getString(R.string.ok), null);
        delayAlertDialog = dialogBuilder.create();
        delayAlertDialog.show();
    } else {
        startRecordingFlag = true;
        // Notify user
        Intent notificationIntent = new Intent(SignalsRecorder.this, SignalsRecorder.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
        if (sharedPreferences.getBoolean(Constants.PREF_NOTIFICATIONS, Constants.DEFAULT_NOTIFICATIONS)) {
            NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext())
                    .setSmallIcon(R.drawable.notification_icon)
                    .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.deviceaccessmic))
                    .setContentTitle("SleepAp").setContentText(getString(R.string.startedRecordingNotification))
                    .setAutoCancel(false).setOngoing(true).setContentIntent(pendingIntent);
            notificationManager.notify(Constants.CODE_APP_NOTIFICATION_ID, builder.build());
            recordingSign.setVisibility(View.VISIBLE);
        }
    }

    // Start audio recording.
    if (audioEnabled) {
        extAudioRecorder = new ExtAudioRecorder(this);
        extAudioRecorder.setOutputFile(audioRawFile);
        extAudioRecorder.setShouldWrite(startRecordingFlag);
        extAudioRecorder.setAudioProcessedFile(audioProcessedFile);
        extAudioRecorder.prepare();
        extAudioRecorder.start();
    }

    // Start PPG recording.
    if (ppgEnabled && bluetoothAdapter != null) {
        String macAddress = sharedPreferences.getString(Constants.PREF_MAC_ADDRESS,
                Constants.DEFAULT_MAC_ADDRESS);
        noninManager = new NoninManager(this, bluetoothAdapter, macAddress,
                new PpgHandler(SignalsRecorder.this));
        noninManager.start();
    }

    // Start actigraphy recording.
    if (actigraphyEnabled) {
        sensorManager.registerListener(this, accelerometer, 1000000
                / (Constants.PARAM_SAMPLERATE_ACCELEROMETER * Constants.PARAM_UPSAMPLERATE_ACCELEROMETER));
        sensorManager.registerListener(this, magnetometer, 1000000 / Constants.PARAM_SAMPLERATE_ACCELEROMETER);
    }
    wakeLock.acquire();

    // Set up listener so that if Bluetooth connection is lost we set give
    // the user an option to reconnect.
    if (ppgEnabled) {
        IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED);
        filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED);
        filter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
        filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);

        registerReceiver(bluetoothDisconnectReceiver, filter);
    }

    // Start graphs update.
    graphUpdateTask = new UserInterfaceUpdater();
    graphUpdateTask.execute();
}

From source file:com.handpoint.headstart.client.ui.MainActivity.java

private void registerBroadcastReceivers() {
    IntentFilter btServiceFilter = new IntentFilter();
    btServiceFilter.addAction(BROADCAST_CONNECTION_STATE_CHANGE);
    btServiceFilter.addAction(BROADCAST_ERROR);
    btServiceFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
    registerReceiver(mBtServiceReceiver, btServiceFilter);
}

From source file:org.restcomm.app.qoslib.Services.Intents.IntentHandler.java

public IntentFilter declareIntentFilters() {
    IntentFilter intentFilter = new IntentFilter(IntentHandler.UPDATE_ACTION);
    intentFilter.addAction(IntentHandler.START_TRACKING_ACTION);
    intentFilter.addAction(IntentHandler.TRACK_REMOTE);
    intentFilter.addAction(IntentHandler.STOP_TRACKING_ACTION);
    intentFilter.addAction(IntentHandler.SPEED_TEST);
    intentFilter.addAction(IntentHandler.RUN_WEBSOCKET);
    intentFilter.addAction(CommonIntentActionsOld.ACTION_START_UI);

    intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_UPDATE);
    intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_LOCATION_UPDATE);
    intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_CELL_UPDATE);
    intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_GPS_STATUS_UPDATE);
    intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_SIGNAL_STRENGTH_UPDATE);
    intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_EVENT_UPDATE);
    intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_NEIGHBOR_UPDATE);
    intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_NETWORK_UPDATE);
    //intentFilter.addAction(CommonIntentBundleKeysOld.ACTION_RX_TX);

    intentFilter.addAction(IntentHandler.ACTION_SPEEDTEST_RESULT);
    intentFilter.addAction(IntentHandler.ACTION_SPEEDTEST_ERROR);
    intentFilter.addAction(IntentHandler.ACTION_SPEEDTEST_COMPLETE);
    intentFilter.addAction(IntentHandler.ACTION_SPEEDTEST_CANCELLED);

    intentFilter.addAction(IntentHandler.ACTION_WEBTEST_RESULT);
    intentFilter.addAction(IntentHandler.ACTION_WEBTEST_ERROR);
    intentFilter.addAction(IntentHandler.ACTION_WEBTEST_COMPLETE);
    intentFilter.addAction(IntentHandler.ACTION_WEBTEST_CANCELLED);

    //do not add filter if sms test permissions aren't all allowed
    if (PreferenceKeys.getSMSPermissionsAllowed(owner, true))
        intentFilter.addAction(IntentHandler.SMS_TEST);

    intentFilter.addAction(IntentHandler.SMS_DELIVERED);
    intentFilter.addAction(IntentHandler.LATENCY_TEST);
    intentFilter.addAction(IntentHandler.ACTION_STOP_SPEEDTEST);
    intentFilter.addAction(IntentHandler.RESTART_MMC_SERVICE);
    intentFilter.addAction(IntentHandler.COLDRESET_ACTION);
    intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
    intentFilter.addAction(Intent.ACTION_POWER_CONNECTED);
    intentFilter.addAction(Intent.ACTION_POWER_DISCONNECTED);
    intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
    intentFilter.addAction(Intent.ACTION_SCREEN_ON);
    intentFilter.addAction(IntentHandler.COMMAND);
    intentFilter.addAction(IntentHandler.SURVEY);
    //intentFilter.addAction(Intent.ACTION_VIEW);
    //intentFilter.addAction("android.intent.PHONE_STATE");
    intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
    intentFilter.addAction(IntentHandler.ACTION_ALARM_MINUTE);
    intentFilter.addAction(IntentHandler.ACTION_TRACKING_5MINUTE);
    intentFilter.addAction(IntentHandler.ACTION_TRACKING_1MINUTE);
    intentFilter.addAction(IntentHandler.ACTION_ALARM_3HOUR);
    intentFilter.addAction(IntentHandler.ACTION_ALARM_15MINUTE);
    intentFilter.addAction(IntentHandler.ACTION_ALARM_SCANAPPS);
    intentFilter.addAction(IntentHandler.EMAIL_CSV);
    intentFilter.addAction(IntentHandler.GPS_STATE_OFF);
    intentFilter.addAction(IntentHandler.GPS_STATE_ON);
    intentFilter.addAction(IntentHandler.PHONE_CALL_CONNECT);
    intentFilter.addAction(IntentHandler.PHONE_CALL_DISCONNECT);
    intentFilter.addAction(IntentHandler.HANDOFF);
    //intentFilter.addAction(IntentHandler.SMS_SENT);
    intentFilter.addAction(IntentHandler.SMS_RECEIVED);
    intentFilter.addAction(Intent.ACTION_SEND);
    intentFilter.addAction(IntentHandler.MANUAL_PLOTTING_START);
    intentFilter.addAction(IntentHandler.MANUAL_PLOTTING_END);
    intentFilter.addAction(IntentHandler.MANUAL_PLOTTING_CANCEL);
    intentFilter.addAction(IntentHandler.MANUAL_TRANSIT_START);
    intentFilter.addAction(IntentHandler.MANUAL_TRANSIT_END);
    intentFilter.addAction(IntentHandler.MANUAL_TRANSIT_CANCEL);
    intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
    intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED);
    intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);

    intentFilter.addAction(Intent.ACTION_HEADSET_PLUG);
    intentFilter.addAction(IntentHandler.ROAMING_ON);
    intentFilter.addAction(IntentHandler.ROAMING_OFF);

    intentFilter.addAction(IntentHandler.VIEWING_SIGNAL);
    intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    intentFilter.addAction("android.intent.action.PRECISE_CALL_STATE");
    intentFilter.addAction("android.intent.action.PRECISE_DATA_CONNECTION_STATE_CHANGED");
    intentFilter.addAction("android.intent.action.PHONE_STATE");
    intentFilter.addAction("android.intent.action.NEW_OUTGOING_CALL");

    intentFilter.addAction("android.intent.action.DATA_CONNECTION_CONNECTED_TO_PROVISIONING_APN");
    intentFilter.addAction("android.intent.action.ANY_DATA_STATE");
    intentFilter.addAction("android.intent.action.ACTION_DATA_CONNECTION_FAILED");

    intentFilter.addAction(CommonIntentActionsOld.ACTION_BLUETOOTH_ENDDOWNLOAD);
    intentFilter.addAction(CommonIntentActionsOld.ACTION_START_VOICETEST);
    intentFilter.addAction(CommonIntentActionsOld.ACTION_STOP_VOICETEST);
    intentFilter.addAction(CommonIntentActionsOld.ACTION_TEST_VQ_DEVICE);

    intentFilter.addAction(IntentHandler.ACTIVE_TEST);
    intentFilter.addAction(IntentHandler.ACTION_STOP_VIDEOTEST);
    intentFilter.addAction(IntentHandler.GCM_MESSAGE);

    intentFilter.addAction("org.restcomm.android.CONNECT_FAILED");
    intentFilter.addAction("org.restcomm.android.CALL_STATE");
    intentFilter.addAction("org.restcomm.android.DISCONNECT_ERROR");

    intentFilter.addAction(IntentHandler.ACTION_RADIOLOG_DISCONNECT);
    intentFilter.addAction(IntentHandler.ACTION_RADIOLOG_CONNECT);
    intentFilter.addAction(IntentHandler.ACTION_RADIOLOG_NEIGHBORS);
    intentFilter.addAction(IntentHandler.ACTION_RADIOLOG_SERVICEMODE);
    intentFilter.addAction(IntentHandler.ACTION_RADIOLOG_SERVICEMENU);
    intentFilter.addAction(IntentHandler.ACTION_MMCSYS_VERSION);

    //intentFilter.addAction(Intent.ACTION_APP_ERROR);
    int raisePriority = owner.getPackageManager().checkPermission("android.permission.RAISED_THREAD_PRIORITY",
            owner.getPackageName());//  w  w w  . ja va  2s.  c o  m
    // With permission to raise priority for SMS messages
    if (raisePriority == 0)
        intentFilter.setPriority(9999999);

    return intentFilter;
}