Example usage for android.content Intent ACTION_USER_PRESENT

List of usage examples for android.content Intent ACTION_USER_PRESENT

Introduction

In this page you can find the example usage for android.content Intent ACTION_USER_PRESENT.

Prototype

String ACTION_USER_PRESENT

To view the source code for android.content Intent ACTION_USER_PRESENT.

Click Source Link

Document

Broadcast Action: Sent when the user is present after device wakes up (e.g when the keyguard is gone).

Usage

From source file:net.kidlogger.kidlogger.KLService.java

public void setupLogging() {
    // Set up GPS / Network logging      
    if (Settings.loggingGps(this)) {
        startGpsUpdates();/*from  ww  w.java 2  s .  co m*/
        gpsOn = true;
    }

    // Set up WiFi logging
    if (Settings.loggingWifi(this)) {
        wifiReceiver = new WifiReceiver(this);
        registerReceiver(wifiReceiver, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION));
        wifiOn = true;
    }

    // Set up SMS logging
    if (Settings.loggingSms(this)) {
        smsObserver = new SmsObserver(this, handlering);
        IntentFilter smsFilter = new IntentFilter(SMS_RECEIVED);
        registerReceiver(smsObserver.inSms, smsFilter);
        smsOn = true;
    }

    // Set up Calls logging
    if (Settings.loggingCalls(this)) {
        IntentFilter callsFilter = new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED);

        callsReceiver = new CallsReceiver(this);
        registerReceiver(callsReceiver, callsFilter);
        callOn = true;
    }

    // Set up Idle logging
    IntentFilter idleFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
    idleFilter.addAction(Intent.ACTION_USER_PRESENT);

    idleReceiver = new IdleReceiver(this);
    registerReceiver(idleReceiver, idleFilter);
    idleOn = true;
    /*if(Settings.loggingIdle(this)){
       IntentFilter idleFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
       idleFilter.addAction(Intent.ACTION_USER_PRESENT);
               
       idleReceiver = new IdleReceiver(this);
       registerReceiver(idleReceiver, idleFilter);
       idleOn = true;
    }*/

    // Set up URL logging
    if (Settings.loggingUrl(this)) {
        urlObserver = new HistoryObserver(this, handlering);
        urlOn = true;
    }

    // Set up USB logging
    if (Settings.loggingUsb(this)) {
        IntentFilter usbFilter = new IntentFilter(Intent.ACTION_UMS_CONNECTED);
        usbFilter.addAction(Intent.ACTION_UMS_DISCONNECTED);

        usbReceiver = new UsbReceiver(this);
        registerReceiver(usbReceiver, usbFilter);
        usbOn = true;
    }

    // Set up Tasks logging
    if (logTask) {
        // Check if a new Application was started
        taskScan = new Runnable() {
            public void run() {
                new Thread(new Runnable() {
                    public void run() {
                        doScanTask();
                    }
                }).start();
                if (userPresent) {
                    handleTask.postDelayed(this, SCAN_TASK_TIME);
                    scanningTask = true;
                } else {
                    scanningTask = false;
                }
            }
        };
        handleTask.postDelayed(taskScan, SCAN_TASK_TIME);
        taskOn = true;
    }

    // Set up Clipboard logging
    if (logClip) {
        // Scan clipboard content, only first 30 characters
        clipboardScan = new Runnable() {
            public void run() {
                new Thread(new Runnable() {
                    public void run() {
                        doScanClipboard();
                    }
                }).start();
                if (userPresent) {
                    handleClipb.postDelayed(this, SCAN_CLIP_TIME);
                    scanningClip = true;
                } else {
                    scanningClip = false;
                }
            }
        };
        handleClipb.postDelayed(clipboardScan, SCAN_CLIP_TIME);
        clipOn = true;
    }

    // Set up Power logging
    if (Settings.loggingPower(this)) {
        IntentFilter powerFilter = new IntentFilter(Intent.ACTION_SHUTDOWN);

        powerReceiver = new ShutdownReceiver(this);
        registerReceiver(powerReceiver, powerFilter);
        powerOn = true;
    }

    // Set up Memory Card logging
    if (Settings.loggingMedia(this)) {
        IntentFilter mediaFilter = new IntentFilter(Intent.ACTION_MEDIA_REMOVED);
        mediaFilter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL);
        mediaFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
        mediaFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
        mediaFilter.addAction(Intent.ACTION_MEDIA_SHARED);
        mediaFilter.addDataScheme("file");

        mediaReceiver = new MediaReceiver(this);
        registerReceiver(mediaReceiver, mediaFilter);

        mediaOn = true;
    }

    // Set up GSM logging
    if (Settings.loggingGsm(this)) {
        gsmObserver = new GsmObserver(this);
        telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        telManager.listen(gsmObserver,
                PhoneStateListener.LISTEN_SERVICE_STATE | PhoneStateListener.LISTEN_CELL_LOCATION);
        gsmOn = true;
    }

    // Set up Airplane mode receiver
    if (Settings.loggingAir(this)) {
        IntentFilter airFilter = new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);

        airReceiver = new AirplaneReceiver(this);
        registerReceiver(airReceiver, airFilter);
        airOn = true;
    }

    // Set up Photos logging
    if (Settings.loggingPhotos(this)) {
        photoObserver = new PhotoObserver(this, this, handlering);
        photoOn = true;
    }

    // Set up SliceMultimediaFile
    if (Settings.uploadPhotos(this) || Settings.uploadRecords(this)) {
        mediaSlicer = new SliceMultimediaFile(this);
    }

    // Set up ConnectivityReceiver
    mConReceiver = new ConnectivityReceiver(this);
    registerReceiver(mConReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));

    // Ser up CallIntentReceiver
    //outCallReceiver = new CallIntentReceiver();
    //registerReceiver(outCallReceiver, new IntentFilter(KLService.OUTGOING_CALL));
}

From source file:org.sipdroid.sipua.ui.Receiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String intentAction = intent.getAction();
    if (!Sipdroid.on(context))
        return;/* w  w  w . j  a v a 2  s.co m*/
    if (!Sipdroid.release)
        Log.i("SipUA:", intentAction);
    if (mContext == null)
        mContext = context;
    if (intentAction.equals(Intent.ACTION_BOOT_COMPLETED)) {
        on_vpn(false);
        engine(context).register();
    } else if (intentAction.equals(ConnectivityManager.CONNECTIVITY_ACTION)
            || intentAction.equals(ACTION_EXTERNAL_APPLICATIONS_AVAILABLE)
            || intentAction.equals(ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)
            || intentAction.equals(Intent.ACTION_PACKAGE_REPLACED)) {
        engine(context).register();
    } else if (intentAction.equals(ACTION_VPN_CONNECTIVITY) && intent.hasExtra("connection_state")) {
        String state = intent.getSerializableExtra("connection_state").toString();
        if (state != null && on_vpn() != state.equals("CONNECTED")) {
            on_vpn(state.equals("CONNECTED"));
            for (SipProvider sip_provider : engine(context).sip_providers)
                if (sip_provider != null)
                    sip_provider.haltConnections();
            engine(context).register();
        }
    } else if (intentAction.equals(ACTION_DATA_STATE_CHANGED)) {
        engine(context).registerMore();
    } else if (intentAction.equals(ACTION_PHONE_STATE_CHANGED)
            && !intent.getBooleanExtra(context.getString(R.string.app_name), false)) {
        stopRingtone();
        pstn_state = intent.getStringExtra("state");
        pstn_time = SystemClock.elapsedRealtime();
        if (pstn_state.equals("IDLE") && call_state != UserAgent.UA_STATE_IDLE)
            broadcastCallStateChanged(null, null);
        if (!pstn_state.equals("IDLE") && call_state == UserAgent.UA_STATE_INCALL)
            mHandler.sendEmptyMessageDelayed(MSG_HOLD, 5000);
        else if (!pstn_state.equals("IDLE") && (call_state == UserAgent.UA_STATE_INCOMING_CALL
                || call_state == UserAgent.UA_STATE_OUTGOING_CALL))
            mHandler.sendEmptyMessageDelayed(MSG_HANGUP, 5000);
        else if (pstn_state.equals("IDLE")) {
            mHandler.removeMessages(MSG_HOLD);
            mHandler.removeMessages(MSG_HANGUP);
            if (call_state == UserAgent.UA_STATE_HOLD)
                mHandler.sendEmptyMessageDelayed(MSG_HOLD, 1000);
        }
    } else if (intentAction.equals(ACTION_DOCK_EVENT)) {
        docked = intent.getIntExtra(EXTRA_DOCK_STATE, -1) & 7;
        if (call_state == UserAgent.UA_STATE_INCALL)
            engine(mContext).speaker(speakermode());
    } else if (intentAction.equals(ACTION_SCO_AUDIO_STATE_CHANGED)) {
        bluetooth = intent.getIntExtra(EXTRA_SCO_AUDIO_STATE, -1);
        progress();
        RtpStreamSender.changed = true;
    } else if (intentAction.equals(Intent.ACTION_HEADSET_PLUG)) {
        headset = intent.getIntExtra("state", -1);
        if (call_state == UserAgent.UA_STATE_INCALL)
            engine(mContext).speaker(speakermode());
    } else if (intentAction.equals(Intent.ACTION_SCREEN_ON)) {
        if (!PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean(
                org.sipdroid.sipua.ui.Settings.PREF_OWNWIFI, org.sipdroid.sipua.ui.Settings.DEFAULT_OWNWIFI))
            alarm(0, OwnWifi.class);
    } else if (intentAction.equals(Intent.ACTION_USER_PRESENT)) {
        mHandler.sendEmptyMessageDelayed(MSG_ENABLE, 3000);
    } else if (intentAction.equals(Intent.ACTION_SCREEN_OFF)) {
        if (PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean(
                org.sipdroid.sipua.ui.Settings.PREF_OWNWIFI, org.sipdroid.sipua.ui.Settings.DEFAULT_OWNWIFI)) {
            WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
            WifiInfo wi = wm.getConnectionInfo();
            if (wm.getWifiState() != WifiManager.WIFI_STATE_ENABLED || wi == null
                    || wi.getSupplicantState() != SupplicantState.COMPLETED || wi.getIpAddress() == 0)
                alarm(2 * 60, OwnWifi.class);
            else
                alarm(15 * 60, OwnWifi.class);
        }
        if (SipdroidEngine.pwl != null)
            for (PowerManager.WakeLock pwl : SipdroidEngine.pwl)
                if (pwl != null && pwl.isHeld()) {
                    pwl.release();
                    pwl.acquire();
                }
    } else if (intentAction.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
        if (PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean(
                org.sipdroid.sipua.ui.Settings.PREF_SELECTWIFI,
                org.sipdroid.sipua.ui.Settings.DEFAULT_SELECTWIFI))
            mHandler.sendEmptyMessageDelayed(MSG_SCAN, 3000);
    } else if (intentAction.equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
        if (SystemClock.uptimeMillis() > lastscan + 45000
                && PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean(
                        org.sipdroid.sipua.ui.Settings.PREF_SELECTWIFI,
                        org.sipdroid.sipua.ui.Settings.DEFAULT_SELECTWIFI)) {
            WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
            WifiInfo wi = wm.getConnectionInfo();
            String activeSSID = null;
            if (wi != null)
                activeSSID = wi.getSSID();
            if (activeSSID != null && (activeSSID.length() == 0 || activeSSID.equals("0x")))
                activeSSID = null;
            List<ScanResult> mScanResults = wm.getScanResults();
            List<WifiConfiguration> configurations = wm.getConfiguredNetworks();
            if (configurations != null) {
                WifiConfiguration bestconfig = null, maxconfig = null, activeconfig = null;
                for (final WifiConfiguration config : configurations) {
                    if (maxconfig == null || config.priority > maxconfig.priority) {
                        maxconfig = config;
                    }
                    if (config.SSID != null
                            && (config.SSID.equals("\"" + activeSSID + "\"") || config.SSID.equals(activeSSID)))
                        activeconfig = config;
                }
                ScanResult bestscan = null, activescan = null;
                if (mScanResults != null)
                    for (final ScanResult scan : mScanResults) {
                        for (final WifiConfiguration config : configurations) {
                            if (config.SSID != null && config.SSID.equals("\"" + scan.SSID + "\"")) {
                                if (bestscan == null || scan.level > bestscan.level) {
                                    bestscan = scan;
                                    bestconfig = config;
                                }
                                if (config == activeconfig)
                                    activescan = scan;
                            }
                        }
                    }
                if (activescan != null)
                    System.out.println("debug wifi asu(active)" + asu(activescan));
                if (bestconfig != null && (activeconfig == null || bestconfig.priority != activeconfig.priority)
                        && asu(bestscan) > asu(activescan) * 1.5 &&
                        /* (activeSSID == null || activescan != null) && */ asu(bestscan) > 22) {
                    if (!Sipdroid.release)
                        Log.i("SipUA:", "changing to " + bestconfig.SSID);
                    if (activeSSID == null || !activeSSID.equals(bestscan.SSID))
                        wm.disconnect();
                    bestconfig.priority = maxconfig.priority + 1;
                    wm.updateNetwork(bestconfig);
                    wm.enableNetwork(bestconfig.networkId, true);
                    wm.saveConfiguration();
                    if (activeSSID == null || !activeSSID.equals(bestscan.SSID))
                        wm.reconnect();
                    lastscan = SystemClock.uptimeMillis();
                } else if (activescan != null && asu(activescan) < 15) {
                    wm.disconnect();
                    wm.disableNetwork(activeconfig.networkId);
                    wm.saveConfiguration();
                }
            }
        }
    }
}

From source file:com.android.leanlauncher.LauncherTransitionable.java

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();

    // Listen for broadcasts related to user-presence
    final IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_USER_PRESENT);
    // For handling managed profiles
    filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
    filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
    registerReceiver(mReceiver, filter);
    FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
    setupTransparentSystemBarsForLmp();// w  w  w  . ja va  2  s.  c o m
    mAttached = true;
    mVisible = true;
}

From source file:com.intel.xdk.device.Device.java

private void registerScreenStatusReceiver() {

    if (screenStatusReceiver == null) {
        //Listener to the screen unlock event.

        screenStatusReceiver = new BroadcastReceiver() {

            @Override/* w w  w.jav a 2  s  .  co m*/
            public void onReceive(Context context, Intent intent) {
                if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
                    Log.d("screen_on", "Screen is on.");
                } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
                    Log.d("screen_lock", "Screen is off");
                    String js = "javascript: var e = document.createEvent('Events');e.initEvent('intel.xdk.device.pause');e.success=true;document.dispatchEvent(e);";
                    injectJS(js);
                } else if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {
                    Log.d("user_present", "User is present.");
                    String js = "javascript: var e = document.createEvent('Events');e.initEvent('intel.xdk.device.continue');e.success=true;document.dispatchEvent(e);";
                    injectJS(js);
                }

            }

        };
    }
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_USER_PRESENT);
    activity.registerReceiver(screenStatusReceiver, filter);
}

From source file:com.android.launcher2.Launcher.java

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();

    // Listen for broadcasts related to user-presence
    final IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_USER_PRESENT);
    registerReceiver(mReceiver, filter);

    mAttached = true;/*w w  w  .ja v a 2  s .  c o m*/
    mVisible = true;
}

From source file:com.android.soma.Launcher.java

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();

    // Listen for broadcasts related to user-presence
    final IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_USER_PRESENT);
    registerReceiver(mReceiver, filter);
    FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
    mAttached = true;//from w  w  w  . j av a2  s  . co  m
    mVisible = true;
}

From source file:xyz.klinker.blur.launcher3.Launcher.java

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();

    // Listen for broadcasts related to user-presence
    final IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_USER_PRESENT);
    // For handling managed profiles
    if (ENABLE_DEBUG_INTENTS) {
        filter.addAction(DebugIntents.DELETE_DATABASE);
        filter.addAction(DebugIntents.MIGRATE_DATABASE);
    }/*from w  ww. jav a  2 s.  c  o  m*/
    registerReceiver(mReceiver, filter);
    FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
    mAttached = true;
    mVisible = true;

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onAttachedToWindow();
    }
}

From source file:com.klinker.android.launcher.launcher3.Launcher.java

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();

    // Listen for broadcasts related to user-presence
    final IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_USER_PRESENT);
    // For handling managed profiles
    if (ENABLE_DEBUG_INTENTS) {
        filter.addAction(DebugIntents.DELETE_DATABASE);
        filter.addAction(DebugIntents.MIGRATE_DATABASE);
    }/*w ww .j  ava  2 s .  c o m*/
    registerReceiver(mReceiver, filter);
    FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
    setupTransparentSystemBarsForLmp();
    mAttached = true;
    mVisible = true;
}

From source file:g7.bluesky.launcher3.Launcher.java

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();

    // Listen for broadcasts related to user-presence
    final IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_USER_PRESENT);
    // For handling managed profiles
    filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
    filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
    if (ENABLE_DEBUG_INTENTS) {
        filter.addAction(DebugIntents.DELETE_DATABASE);
        filter.addAction(DebugIntents.MIGRATE_DATABASE);
    }/* w ww.j av a  2s  . c om*/
    registerReceiver(mReceiver, filter);
    FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
    setupTransparentSystemBarsForLmp();
    mAttached = true;
    mVisible = true;
}

From source file:com.android.launcher3.Launcher.java

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();

    // Listen for broadcasts related to user-presence
    final IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_USER_PRESENT);
    registerReceiver(mReceiver, filter);
    FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
    mAttached = true;// w  w  w .j  a v  a  2s.c o  m
    mVisible = true;

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onAttachedToWindow();
    }
}