Example usage for android.net.wifi WifiManager WIFI_MODE_FULL_HIGH_PERF

List of usage examples for android.net.wifi WifiManager WIFI_MODE_FULL_HIGH_PERF

Introduction

In this page you can find the example usage for android.net.wifi WifiManager WIFI_MODE_FULL_HIGH_PERF.

Prototype

int WIFI_MODE_FULL_HIGH_PERF

To view the source code for android.net.wifi WifiManager WIFI_MODE_FULL_HIGH_PERF.

Click Source Link

Document

In this Wi-Fi lock mode, Wi-Fi will be kept active as in mode #WIFI_MODE_FULL but it operates at high performance with minimum packet loss and low packet latency even when the device screen is off.

Usage

From source file:com.zegoggles.smssync.service.ServiceBase.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
private int getWifiLockType() {
    return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1 ? WifiManager.WIFI_MODE_FULL_HIGH_PERF
            : WifiManager.WIFI_MODE_FULL;
}

From source file:at.alladin.rmbt.android.test.RMBTService.java

@Override
public void onCreate() {
    Log.d(DEBUG_TAG, "created");
    super.onCreate();

    handler = new Handler();

    // initialise the locks
    loopMode = ConfigHelper.isLoopMode(this);

    // initialise the locks
    wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "RMBTWifiLock");
    wakeLock = ((PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "RMBTWakeLock");

    // mNetworkStateIntentReceiver = new BroadcastReceiver() {
    // @Override// w  w w. j a  v a2 s.  com
    // public void onReceive(Context context, Intent intent) {
    // if
    // (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION))
    // {
    //
    // final boolean connected = !
    // intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY,
    // false);
    // if (! connected)
    // stopTest();
    // }
    // }
    // };
    // final IntentFilter networkStateChangedFilter = new IntentFilter();
    // networkStateChangedFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    //
    // registerReceiver(mNetworkStateIntentReceiver,
    // networkStateChangedFilter);
}

From source file:org.mozilla.gecko.updater.UpdateService.java

@Override
public void onCreate() {
    mCrashHandler = CrashHandler.createDefaultCrashHandler(getApplicationContext());

    super.onCreate();

    mPrefs = getSharedPreferences(PREFS_NAME, 0);
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    mWifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE))
            .createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, PREFS_NAME);
    mCancelDownload = false;//from  ww w  .  ja v  a  2 s .c  o  m
}

From source file:de.badaix.snapcast.SnapclientService.java

private void start(String host, int port) {
    try {//from w ww .j  ava  2 s. co  m
        //https://code.google.com/p/android/issues/detail?id=22763
        if (running)
            return;
        File binary = new File(getFilesDir(), "snapclient");
        android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);

        PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
        wakeLock = powerManager.newWakeLock(PARTIAL_WAKE_LOCK, "SnapcastWakeLock");
        wakeLock.acquire();

        WifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE);
        wifiWakeLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "SnapcastWifiWakeLock");
        wifiWakeLock.acquire();

        process = new ProcessBuilder()
                .command(binary.getAbsolutePath(), "-h", host, "-p", Integer.toString(port))
                .redirectErrorStream(true).start();

        Thread reader = new Thread(new Runnable() {
            @Override
            public void run() {
                BufferedReader bufferedReader = new BufferedReader(
                        new InputStreamReader(process.getInputStream()));
                String line;
                try {
                    while ((line = bufferedReader.readLine()) != null) {
                        log(line);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
        logReceived = false;
        reader.start();

        //TODO: wait for started message on stdout
        /*            long now = System.currentTimeMillis();
                    while (!logReceived) {
        if (System.currentTimeMillis() > now + 1000)
            throw new Exception("start timeout");
        Thread.sleep(100, 0);
                    }
        */
    } catch (Exception e) {
        e.printStackTrace();
        if (listener != null)
            listener.onError(this, e.getMessage(), e);
        stop();
    }
}

From source file:com.github.notizklotz.derbunddownloader.download.IssueDownloadService.java

private boolean waitForWifiConnection() {
    boolean connected = false;
    if (wifiManager != null) {
        //WIFI_MODE_FULL was not enough on Xperia Tablet Z Android 4.2 to reconnect to the AP if Wifi was enabled but connection
        //was lost
        myWifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "IssueDownloadWifilock");
        myWifiLock.setReferenceCounted(false);
        myWifiLock.acquire();/*from   w w w .j a  v a2 s .c o  m*/

        //Wait for Wifi coming up
        long firstCheckMillis = System.currentTimeMillis();
        if (!wifiManager.isWifiEnabled()) {
            notifyUser(getText(R.string.download_connection_failed),
                    getText(R.string.download_connection_failed_no_wifi_text), R.drawable.ic_stat_newspaper);
        } else {
            do {
                NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
                assert networkInfo != null;
                connected = networkInfo.isConnected();

                if (!connected) {
                    Log.d(LOG_TAG, "Wifi connection is not yet ready. Wait and recheck");

                    if (System.currentTimeMillis() - firstCheckMillis > WIFI_CHECK_MAX_MILLIS) {
                        break;
                    }

                    try {
                        Thread.sleep(WIFI_RECHECK_WAIT_MILLIS);
                    } catch (InterruptedException e) {
                        Log.wtf(LOG_TAG, "Interrupted while waiting for Wifi connection", e);
                    }
                }
            } while (!connected);
        }
    }
    return connected;
}

From source file:com.thejoshwa.ultrasonic.androidapp.util.Util.java

public static WifiManager.WifiLock createWifiLock(Context context, String tag) {
    WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    return wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, tag);
}