Example usage for android.content Context KEYGUARD_SERVICE

List of usage examples for android.content Context KEYGUARD_SERVICE

Introduction

In this page you can find the example usage for android.content Context KEYGUARD_SERVICE.

Prototype

String KEYGUARD_SERVICE

To view the source code for android.content Context KEYGUARD_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.app.KeyguardManager for controlling keyguard.

Usage

From source file:mobisocial.musubi.ui.MusubiBaseActivity.java

/**
 * onStart Called when the activity is becoming visible to the user.
 * Followed by onResume() if the activity comes to the foreground, or
 * onStop() if it becomes hidden./*from   w  ww. jav a  2 s . c  om*/
 */

protected void onStart() {
    super.onStart();

    remoteControlRegistrar.registerRemoteControl();
    KeyguardManager kg = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
    if (!kg.inKeyguardRestrictedInputMode()) {
        new PresenceAwareNotify(this).cancelAll();
    }
}

From source file:com.nick.scalpel.core.AutoFoundWirer.java

private void wireFromContext(Context context, AutoFound.Type type, int idRes, Resources.Theme theme,
        Field field, Object forWho) {
    Resources resources = context.getResources();
    switch (type) {
    case STRING://from  w  ww  .j av  a2s .c  o  m
        setField(field, forWho, resources.getString(idRes));
        break;
    case COLOR:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            setField(field, forWho, resources.getColor(idRes, theme));
        } else {
            //noinspection deprecation
            setField(field, forWho, resources.getColor(idRes));
        }
        break;
    case INTEGER:
        setField(field, forWho, resources.getInteger(idRes));
        break;
    case BOOL:
        setField(field, forWho, resources.getBoolean(idRes));
        break;
    case STRING_ARRAY:
        setField(field, forWho, resources.getStringArray(idRes));
        break;
    case INT_ARRAY:
        setField(field, forWho, resources.getIntArray(idRes));
        break;
    case PM:
        setField(field, forWho, context.getSystemService(Context.POWER_SERVICE));
        break;
    case ACCOUNT:
        setField(field, forWho, context.getSystemService(Context.ACCOUNT_SERVICE));
        break;
    case ALARM:
        setField(field, forWho, context.getSystemService(Context.ALARM_SERVICE));
        break;
    case AM:
        setField(field, forWho, context.getSystemService(Context.ACTIVITY_SERVICE));
        break;
    case WM:
        setField(field, forWho, context.getSystemService(Context.WINDOW_SERVICE));
        break;
    case NM:
        setField(field, forWho, context.getSystemService(Context.NOTIFICATION_SERVICE));
        break;
    case TM:
        setField(field, forWho, context.getSystemService(Context.TELEPHONY_SERVICE));
        break;
    case TCM:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setField(field, forWho, context.getSystemService(Context.TELECOM_SERVICE));
        }
        break;
    case SP:
        setField(field, forWho, PreferenceManager.getDefaultSharedPreferences(context));
        break;
    case PKM:
        setField(field, forWho, context.getPackageManager());
        break;
    case HANDLE:
        setField(field, forWho, new Handler(Looper.getMainLooper()));
        break;
    case ASM:
        setField(field, forWho, context.getSystemService(Context.ACCESSIBILITY_SERVICE));
        break;
    case CAP:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setField(field, forWho, context.getSystemService(Context.CAPTIONING_SERVICE));
        }
        break;
    case KGD:
        setField(field, forWho, context.getSystemService(Context.KEYGUARD_SERVICE));
        break;
    case LOCATION:
        setField(field, forWho, context.getSystemService(Context.LOCATION_SERVICE));
        break;
    case SEARCH:
        setField(field, forWho, context.getSystemService(Context.SEARCH_SERVICE));
        break;
    case SENSOR:
        setField(field, forWho, context.getSystemService(Context.SENSOR_SERVICE));
        break;
    case STORAGE:
        setField(field, forWho, context.getSystemService(Context.STORAGE_SERVICE));
        break;
    case WALLPAPER:
        setField(field, forWho, context.getSystemService(Context.WALLPAPER_SERVICE));
        break;
    case VIBRATOR:
        setField(field, forWho, context.getSystemService(Context.VIBRATOR_SERVICE));
        break;
    case CONNECT:
        setField(field, forWho, context.getSystemService(Context.CONNECTIVITY_SERVICE));
        break;
    case NETWORK_STATUS:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            setField(field, forWho, context.getSystemService(Context.NETWORK_STATS_SERVICE));
        }
        break;
    case WIFI:
        setField(field, forWho, context.getSystemService(Context.WIFI_SERVICE));
        break;
    case AUDIO:
        setField(field, forWho, context.getSystemService(Context.AUDIO_SERVICE));
        break;
    case FP:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            setField(field, forWho, context.getSystemService(Context.FINGERPRINT_SERVICE));
        }
        break;
    case MEDIA_ROUTER:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            setField(field, forWho, context.getSystemService(Context.MEDIA_ROUTER_SERVICE));
        }
        break;
    case SUB:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            setField(field, forWho, context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE));
        }
        break;
    case IME:
        setField(field, forWho, context.getSystemService(Context.INPUT_METHOD_SERVICE));
        break;
    case CLIP_BOARD:
        setField(field, forWho, context.getSystemService(Context.CLIPBOARD_SERVICE));
        break;
    case APP_WIDGET:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setField(field, forWho, context.getSystemService(Context.APPWIDGET_SERVICE));
        }
        break;
    case DEVICE_POLICY:
        setField(field, forWho, context.getSystemService(Context.DEVICE_POLICY_SERVICE));
        break;
    case DOWNLOAD:
        setField(field, forWho, context.getSystemService(Context.DOWNLOAD_SERVICE));
        break;
    case BATTERY:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setField(field, forWho, context.getSystemService(Context.BATTERY_SERVICE));
        }
        break;
    case NFC:
        setField(field, forWho, context.getSystemService(Context.NFC_SERVICE));
        break;
    case DISPLAY:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            setField(field, forWho, context.getSystemService(Context.DISPLAY_SERVICE));
        }
        break;
    case USER:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            setField(field, forWho, context.getSystemService(Context.USER_SERVICE));
        }
        break;
    case APP_OPS:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setField(field, forWho, context.getSystemService(Context.APP_OPS_SERVICE));
        }
        break;
    case BITMAP:
        setField(field, forWho, BitmapFactory.decodeResource(resources, idRes, null));
        break;
    }
}

From source file:com.amaze.carbonfilemanager.fragments.preference_fragments.Preffrag.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    utilsProvider = (UtilitiesProviderInterface) getActivity();

    PreferenceUtils.reset();//from   w  w w.j ava  2s  . c  o m
    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences);

    sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());

    for (String PREFERENCE_KEY : PREFERENCE_KEYS) {
        findPreference(PREFERENCE_KEY).setOnPreferenceClickListener(this);
    }

    gplus = (CheckBox) findPreference("plus_pic");

    if (BuildConfig.IS_VERSION_FDROID)
        gplus.setEnabled(false);

    // crypt master password
    final EditTextPreference masterPasswordPreference = (EditTextPreference) findPreference(
            PREFERENCE_CRYPT_MASTER_PASSWORD);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
        // encryption feature not available
        masterPasswordPreference.setEnabled(false);
    }

    if (sharedPref.getBoolean(PREFERENCE_CRYPT_FINGERPRINT, false)) {
        masterPasswordPreference.setEnabled(false);
    }

    CheckBox checkBoxFingerprint = (CheckBox) findPreference(PREFERENCE_CRYPT_FINGERPRINT);

    try {

        // finger print sensor
        final FingerprintManager fingerprintManager = (FingerprintManager) getActivity()
                .getSystemService(Context.FINGERPRINT_SERVICE);

        final KeyguardManager keyguardManager = (KeyguardManager) getActivity()
                .getSystemService(Context.KEYGUARD_SERVICE);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && fingerprintManager.isHardwareDetected()) {

            checkBoxFingerprint.setEnabled(true);
        }

        checkBoxFingerprint.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {

                if (ActivityCompat.checkSelfPermission(getActivity(),
                        Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
                    Toast.makeText(getActivity(),
                            getResources().getString(R.string.crypt_fingerprint_no_permission),
                            Toast.LENGTH_LONG).show();
                    return false;
                } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
                        && !fingerprintManager.hasEnrolledFingerprints()) {
                    Toast.makeText(getActivity(),
                            getResources().getString(R.string.crypt_fingerprint_not_enrolled),
                            Toast.LENGTH_LONG).show();
                    return false;
                } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
                        && !keyguardManager.isKeyguardSecure()) {
                    Toast.makeText(getActivity(),
                            getResources().getString(R.string.crypt_fingerprint_no_security), Toast.LENGTH_LONG)
                            .show();
                    return false;
                }

                masterPasswordPreference.setEnabled(false);
                return true;
            }
        });
    } catch (NoClassDefFoundError error) {
        error.printStackTrace();

        // fingerprint manager class not defined in the framework
        checkBoxFingerprint.setEnabled(false);
    }

    // Hide root preference
    Preference mRootMode = findPreference("rootmode");
    PreferenceCategory mMisc = (PreferenceCategory) findPreference("misc");
    mMisc.removePreference(mRootMode);

}

From source file:eu.musesproject.client.contextmonitoring.sensors.DeviceProtectionSensor.java

public boolean isPasswordProtected() {
    KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);

    return keyguardManager.isKeyguardSecure();
}

From source file:com.android.mms.quickmessage.QuickMessagePopup.java

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

    // Initialise the message list and other variables
    mContext = this;
    mMessageList = new ArrayList<QuickMessage>();
    mDefaultContactImage = getResources().getDrawable(R.drawable.ic_contact_picture);
    mNumTemplates = getTemplatesCount();
    mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);

    // Get the preferences
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
    mFullTimestamp = prefs.getBoolean(MessagingPreferenceActivity.FULL_TIMESTAMP, false);
    mCloseClosesAll = prefs.getBoolean(MessagingPreferenceActivity.QM_CLOSE_ALL_ENABLED, false);
    mWakeAndUnlock = prefs.getBoolean(MessagingPreferenceActivity.QM_LOCKSCREEN_ENABLED, false);
    mDarkTheme = prefs.getBoolean(MessagingPreferenceActivity.QM_DARK_THEME_ENABLED, false);
    mUnicodeStripping = prefs.getInt(MessagingPreferenceActivity.UNICODE_STRIPPING_VALUE,
            MessagingPreferenceActivity.UNICODE_STRIPPING_LEAVE_INTACT);
    mInputMethod = Integer.parseInt(prefs.getString(MessagingPreferenceActivity.INPUT_TYPE,
            Integer.toString(InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE)));

    mDarkTheme = mContext.getResources()
            .getConfiguration().uiThemeMode == Configuration.UI_THEME_MODE_HOLO_DARK;

    // Set the window features and layout
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.dialog_quickmessage);

    // Turn on the Options Menu
    invalidateOptionsMenu();//  ww  w .ja  va  2 s  . c  o  m

    // Load the views and Parse the intent to show the QuickMessage
    setupViews();
    parseIntent(getIntent().getExtras(), false);

    setFinishOnTouchOutside(false);
}

From source file:org.interactiverobotics.headset_launcher.LauncherService.java

/**
 *    ?.//from   w  w  w .ja  v  a  2 s .  c o m
 *
 */
@SuppressWarnings("deprecation")
private void unlockScreen() {

    final KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);

    mKeyguardLock = keyguardManager.newKeyguardLock("HeadsetLauncherLock");

    mKeyguardLock.disableKeyguard();

    final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);

    mWakeLock = powerManager.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "HeadsetLauncherWakeLock");

    mWakeLock.acquire();

    // ?  ?  ?

    mTimeoutHandler.postDelayed(mTimeoutRunnable, Constants.NOTIFICATION_TIMEOUT * 1000);
}

From source file:com.linroid.pushapp.service.DownloadService.java

/**
 * ?/*  w  ww. ja  va 2s  .c o  m*/
 * @param pack 
 */
private void onDownloadComplete(Pack pack) {
    Timber.d("%s ?,?:%s", pack.getAppName(), pack.getPath());
    int toastResId = R.string.toast_download_complete;
    if (autoInstall.getValue()) {
        startActivity(IntentUtil.installApk(pack.getPath()));
        if (AndroidUtil.isAccessibilitySettingsOn(this, ApkAutoInstallService.class.getCanonicalName())) {
            PowerManager powermanager = ((PowerManager) getSystemService(Context.POWER_SERVICE));
            PowerManager.WakeLock wakeLock = powermanager.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK
                    | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP),
                    "Install Worker, FULL WAKE LOCK");
            wakeLock.acquire();
            wakeLock.release();
            KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
            //                if(keyguardManager.isDeviceLocked()) {
            final KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("unLock");
            keyguardLock.disableKeyguard();
            //                }
            ApkAutoInstallService.addInstallPackage(pack);
            toastResId = R.string.toast_start_install;
        } else {
            toastResId = R.string.toast_download_complete;
        }
    }
    Toast.makeText(this, getString(toastResId, pack.getAppName()), Toast.LENGTH_SHORT).show();

}

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

public static void onState(int state, String caller) {
    if (ccCall == null) {
        ccCall = new Call();
        ccConn = new Connection();
        ccCall.setConn(ccConn);/*from   w ww .  ja v  a  2  s .c  o m*/
        ccConn.setCall(ccCall);
    }
    if (call_state != state) {
        if (state != UserAgent.UA_STATE_IDLE)
            call_end_reason = -1;
        call_state = state;
        switch (call_state) {
        case UserAgent.UA_STATE_INCOMING_CALL:
            enable_wifi(true);
            RtpStreamReceiver.good = RtpStreamReceiver.lost = RtpStreamReceiver.loss = RtpStreamReceiver.late = 0;
            RtpStreamReceiver.speakermode = speakermode();
            bluetooth = -1;
            String text = caller.toString();
            if (text.indexOf("<sip:") >= 0 && text.indexOf("@") >= 0)
                text = text.substring(text.indexOf("<sip:") + 5, text.indexOf("@"));
            String text2 = caller.toString();
            if (text2.indexOf("\"") >= 0)
                text2 = text2.substring(text2.indexOf("\"") + 1, text2.lastIndexOf("\""));
            broadcastCallStateChanged("RINGING", caller);
            mContext.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
            ccCall.setState(Call.State.INCOMING);
            ccConn.setUserData(null);
            ccConn.setAddress(text, text2);
            ccConn.setIncoming(true);
            ccConn.date = System.currentTimeMillis();
            ccCall.base = 0;
            AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
            int rm = am.getRingerMode();
            int vs = am.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);
            KeyguardManager mKeyguardManager = (KeyguardManager) mContext
                    .getSystemService(Context.KEYGUARD_SERVICE);
            if (v == null)
                v = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
            if ((pstn_state == null || pstn_state.equals("IDLE"))
                    && PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean(
                            org.sipdroid.sipua.ui.Settings.PREF_AUTO_ON,
                            org.sipdroid.sipua.ui.Settings.DEFAULT_AUTO_ON)
                    && !mKeyguardManager.inKeyguardRestrictedInputMode())
                v.vibrate(vibratePattern, 1);
            else {
                if ((pstn_state == null || pstn_state.equals("IDLE")) && (rm == AudioManager.RINGER_MODE_VIBRATE
                        || (rm == AudioManager.RINGER_MODE_NORMAL && vs == AudioManager.VIBRATE_SETTING_ON)))
                    v.vibrate(vibratePattern, 1);
                if (am.getStreamVolume(AudioManager.STREAM_RING) > 0) {
                    String sUriSipRingtone = PreferenceManager.getDefaultSharedPreferences(mContext).getString(
                            org.sipdroid.sipua.ui.Settings.PREF_SIPRINGTONE,
                            Settings.System.DEFAULT_RINGTONE_URI.toString());
                    if (!TextUtils.isEmpty(sUriSipRingtone)) {
                        oRingtone = RingtoneManager.getRingtone(mContext, Uri.parse(sUriSipRingtone));
                        if (oRingtone != null)
                            oRingtone.play();
                    }
                }
            }
            moveTop();
            if (wl == null) {
                PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
                wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP,
                        "Sipdroid.onState");
            }
            wl.acquire();
            Checkin.checkin(true);
            break;
        case UserAgent.UA_STATE_OUTGOING_CALL:
            RtpStreamReceiver.good = RtpStreamReceiver.lost = RtpStreamReceiver.loss = RtpStreamReceiver.late = 0;
            RtpStreamReceiver.speakermode = speakermode();
            bluetooth = -1;
            onText(MISSED_CALL_NOTIFICATION, null, 0, 0);
            engine(mContext).register();
            broadcastCallStateChanged("OFFHOOK", caller);
            ccCall.setState(Call.State.DIALING);
            ccConn.setUserData(null);
            ccConn.setAddress(caller, caller);
            ccConn.setIncoming(false);
            ccConn.date = System.currentTimeMillis();
            ccCall.base = 0;
            moveTop();
            Checkin.checkin(true);
            break;
        case UserAgent.UA_STATE_IDLE:
            broadcastCallStateChanged("IDLE", null);
            onText(CALL_NOTIFICATION, null, 0, 0);
            ccCall.setState(Call.State.DISCONNECTED);
            if (listener_video != null)
                listener_video.onHangup();
            stopRingtone();
            if (wl != null && wl.isHeld())
                wl.release();
            mContext.startActivity(createIntent(InCallScreen.class));
            ccConn.log(ccCall.base);
            ccConn.date = 0;
            engine(mContext).listen();
            break;
        case UserAgent.UA_STATE_INCALL:
            broadcastCallStateChanged("OFFHOOK", null);
            if (ccCall.base == 0) {
                ccCall.base = SystemClock.elapsedRealtime();
            }
            progress();
            ccCall.setState(Call.State.ACTIVE);
            stopRingtone();
            if (wl != null && wl.isHeld())
                wl.release();
            mContext.startActivity(createIntent(InCallScreen.class));
            break;
        case UserAgent.UA_STATE_HOLD:
            onText(CALL_NOTIFICATION, mContext.getString(R.string.card_title_on_hold),
                    android.R.drawable.stat_sys_phone_call_on_hold, ccCall.base);
            ccCall.setState(Call.State.HOLDING);
            if (InCallScreen.started && (pstn_state == null || !pstn_state.equals("RINGING")))
                mContext.startActivity(createIntent(InCallScreen.class));
            break;
        }
        pos(true);
        RtpStreamReceiver.ringback(false);
    }
}

From source file:com.nbplus.vbroadlauncher.RealtimeBroadcastActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
    acquireCpuWakeLock();/*w ww . j a v  a 2s. co  m*/

    KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
    km.inKeyguardRestrictedInputMode();
    if (km.inKeyguardRestrictedInputMode()) {
        Log.i(TAG, " ??");
        isKeyguardRestrictedInputMode = true;
    } else {
        Log.i(TAG, "   ??");
    }

    mLastNetworkStatus = NetworkUtils.isConnected(this);
    Intent intent = getIntent();
    if (intent == null || !PushConstants.ACTION_PUSH_MESSAGE_RECEIVED.equals(intent.getAction())) {
        Log.d(TAG, "empty or none broadcast intent value ...");
        finishActivity();
        return;
    }

    mBroadcastData = intent.getParcelableExtra(Constants.EXTRA_BROADCAST_PAYLOAD_DATA);
    if (mBroadcastData == null) {
        Log.d(TAG, ">> payload data is null");
        finishActivity();
        return;
    }

    mBroadcastPayloadIdx = intent.getLongExtra(Constants.EXTRA_BROADCAST_PAYLOAD_INDEX, -1);
    Log.d(TAG, ">> onCreate() mBroadcastPayloadIdx= " + mBroadcastPayloadIdx);

    // ? ms  ? ?? ? ?   ?  ????
    // broadcast ? .
    //  ?? ?? ??.
    Intent i = new Intent(this, RealtimeBroadcastActivity.class);
    i.setAction(intent.getAction());
    i.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_DATA, mBroadcastData);
    i.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_INDEX, mBroadcastPayloadIdx);
    LocalBroadcastManager.getInstance(this).sendBroadcast(i);

    IntentFilter filter = new IntentFilter();
    filter.addAction(PushConstants.ACTION_PUSH_MESSAGE_RECEIVED);
    filter.addAction(Constants.ACTION_BROWSER_ACTIVITY_CLOSE);
    LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, filter);

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(mBroadcastReceiver, intentFilter);

    hideSystemUI();
    /*
    final Window win = getWindow();
    win.setFlags(
        WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                | WindowManager.LayoutParams.FLAG_FULLSCREEN
                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD,
        WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                | WindowManager.LayoutParams.FLAG_FULLSCREEN
                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
            
    win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
    */

    if (Constants.PUSH_PAYLOAD_TYPE_TEXT_BROADCAST.equals(mBroadcastData.getServiceType())) {
        setContentView(R.layout.fragment_text_broadcast);
    } else {
        setContentView(R.layout.fragment_audio_broadcast);
    }
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);

    if (Constants.PUSH_PAYLOAD_TYPE_TEXT_BROADCAST.equals(mBroadcastData.getServiceType())) {
        mcheckText2SpeechLister = this;
        // ?
        mTextView = (TextView) findViewById(R.id.broadcast_text);
        mTextView.setText(mBroadcastData.getMessage());
        mTextView.setVerticalScrollBarEnabled(true);
        mTextView.setHorizontalScrollBarEnabled(false);
        mTextView.setMovementMethod(new ScrollingMovementMethod());

        mHandler.sendEmptyMessageDelayed(HANDLER_MESSAGE_SETUP_CURRENT_PLAYING, 800);
        Log.d(TAG, "text broadcast = " + mBroadcastData.getMessage());

        mText2SpeechHandler = new TextToSpeechHandler(this, this);
        checkText2SpeechAvailable();
        mIsTTS = true;
    } else {
        // , ??
        mWebView = (WebView) findViewById(R.id.webview);
        mWebViewClient = new RealtimeBroadcastWebViewClient(this, mWebView, this);
        mWebViewClient.setBackgroundTransparent();

        String url = mBroadcastData.getMessage();
        if (url.indexOf("?") > 0) {
            if (!url.contains("UUID=")) {
                url += ("&UUID=" + LauncherSettings.getInstance(this).getDeviceID());
            }
            if (!url.contains("APPID=")) {
                url += ("&APPID=" + getApplicationContext().getPackageName());
            }
        } else {
            if (!url.contains("UUID=")) {
                url += ("?UUID=" + LauncherSettings.getInstance(this).getDeviceID());
            }
            if (!url.contains("APPID=")) {
                if (!url.contains("UUID=")) {
                    url += ("?APPID=" + getApplicationContext().getPackageName());
                } else {
                    url += ("&APPID=" + getApplicationContext().getPackageName());
                }
            }
        }

        mWebViewClient.loadUrl(url);
        mIsTTS = false;
    }
    AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mStreamMusicVolume = audio.getStreamVolume(AudioManager.STREAM_MUSIC);
    audio.setStreamVolume(AudioManager.STREAM_MUSIC, audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC),
            AudioManager.FLAG_PLAY_SOUND);

    if (Constants.OPEN_BETA_PHONE && LauncherSettings.getInstance(this).isSmartPhone()) {
        StateListener phoneStateListener = new StateListener();
        TelephonyManager telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
    }
}

From source file:com.android.mms.quickmessage.QuickMessage.java

private void unlockScreen() {
    // See if the lock screen should be disabled
    if (!mWakeAndUnlock) {
        return;//w ww . jav  a  2  s  . c  o  m
    }

    // See if the screen is locked and get the wake lock to turn on the screen
    mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
    if (mKeyguardManager.inKeyguardRestrictedInputMode()) {
        ManageWakeLock.acquireFull(mContext);
        mScreenUnlocked = true;
    }
}