Example usage for android.net.wifi WifiManager createWifiLock

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

Introduction

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

Prototype

public WifiLock createWifiLock(int lockType, String tag) 

Source Link

Document

Creates a new WifiLock.

Usage

From source file:Main.java

public static boolean acquireWifiLock(Context context) {
    //We only allow backup on wifi connection. Make sure we are connected and if so lock the wifi connection
    ConnectivityManager connManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (wifi.isConnected()) {
        if (wifiLock == null) {
            WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL, "com.zns.comicdroid.wifilock");
            wifiLock.setReferenceCounted(true);
            wifiLock.acquire();/*from  ww  w. j  a va 2s .c  om*/
        } else {
            wifiLock.acquire();
        }
        return true;
    }
    return false;
}

From source file:Main.java

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

    int lockType = WifiManager.WIFI_MODE_FULL;

    // Use WIFI_MODE_FULL_HIGH_PERF if API level 12 or higher.
    if (Build.VERSION.SDK_INT >= 12) {
        lockType = 3; // WifiManager.WIFI_MODE_FULL_HIGH_PERF
    }//ww  w  .  j  ava2 s.c  o  m

    return wm.createWifiLock(lockType, tag);
}

From source file:fr.inria.ucn.Helpers.java

/**
 * Acquire the wifi wakelock.//from  w ww.  jav  a  2 s.  c o m
 * @param c
 */
public static synchronized void acquireWifiLock(Context c) {
    WifiManager mgr = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
    if (wifilock == null) {
        wifilock = mgr.createWifiLock(WifiManager.WIFI_MODE_SCAN_ONLY, "ucn");
        wifilock.setReferenceCounted(false);
    }
    Log.d(Constants.LOGTAG, "acquire wifilock");
    wifilock.acquire();
    acquireLock(c);
}

From source file:it.evilsocket.dsploit.core.System.java

public static void init(Context context) throws Exception {
    mContext = context;/*  w w w.  ja  v  a2s .  co  m*/
    try {
        mStoragePath = getSettings().getString("PREF_SAVE_PATH",
                Environment.getExternalStorageDirectory().toString());
        mSessionName = "dsploit-session-" + java.lang.System.currentTimeMillis();
        mUpdateManager = new UpdateManager(mContext);
        mPlugins = new ArrayList<Plugin>();
        mTargets = new Vector<Target>();
        mOpenPorts = new SparseIntArray(3);

        // if we are here, network initialization didn't throw any error, lock wifi
        WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);

        if (mWifiLock == null)
            mWifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "wifiLock");

        if (mWifiLock.isHeld() == false)
            mWifiLock.acquire();

        // wake lock if enabled
        if (getSettings().getBoolean("PREF_WAKE_LOCK", true) == true) {
            PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);

            if (mWakeLock == null)
                mWakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "wakeLock");

            if (mWakeLock.isHeld() == false)
                mWakeLock.acquire();
        }

        // set ports
        try {
            HTTP_PROXY_PORT = Integer.parseInt(getSettings().getString("PREF_HTTP_PROXY_PORT", "8080"));
            HTTP_SERVER_PORT = Integer.parseInt(getSettings().getString("PREF_HTTP_SERVER_PORT", "8081"));
            HTTPS_REDIR_PORT = Integer.parseInt(getSettings().getString("PREF_HTTPS_REDIRECTOR_PORT", "8082"));
        } catch (NumberFormatException e) {
            HTTP_PROXY_PORT = 8080;
            HTTP_SERVER_PORT = 8081;
            HTTPS_REDIR_PORT = 8082;
        }

        mNmap = new NMap(mContext);
        mArpSpoof = new ArpSpoof(mContext);
        mEttercap = new Ettercap(mContext);
        mIptables = new IPTables();
        mHydra = new Hydra(mContext);
        mTcpdump = new TcpDump(mContext);

        // initialize network data at the end
        mNetwork = new Network(mContext);

        Target network = new Target(mNetwork),
                gateway = new Target(mNetwork.getGatewayAddress(), mNetwork.getGatewayHardware()),
                device = new Target(mNetwork.getLocalAddress(), mNetwork.getLocalHardware());

        gateway.setAlias(mNetwork.getSSID());
        device.setAlias(android.os.Build.MODEL);

        mTargets.add(network);
        mTargets.add(gateway);
        mTargets.add(device);

        mInitialized = true;
    } catch (Exception e) {
        errorLogging(TAG, e);

        throw e;
    }
}

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

protected synchronized void acquireLocks() {
    if (wakeLock == null) {
        PowerManager pMgr = (PowerManager) getSystemService(POWER_SERVICE);
        wakeLock = pMgr.newWakeLock(wakeLockType(), TAG);
    }//from ww w . j  a v a 2  s  .  c  o  m
    wakeLock.acquire();

    if (isConnectedViaWifi()) {
        // we have Wifi, lock it
        WifiManager wMgr = getWifiManager();
        if (wifiLock == null) {
            wifiLock = wMgr.createWifiLock(getWifiLockType(), TAG);
        }
        wifiLock.acquire();
    }
}

From source file:com.mplayer_remote.ServicePlayAFile.java

/**
 * Metoda uruchamiana po przekazaniu do usugi dziedziczcej po <code>IntentService</code> wiadomoci <code>Intent</code>, w tym wypadku zawierajcej nazw i ciek do pliku multimedialnego wybranego przez uytkownika.
 * @see android.app.IntentService#onHandleIntent(android.content.Intent)
 *//*from   w w w . j  a v  a2 s  . co m*/
@Override
protected void onHandleIntent(Intent intent) {

    Log.v(TAG, "stopExecuteIntents = " + stopExecuteIntents);

    if (stopExecuteIntents == false) {

        fileToPlayString = intent.getStringExtra("file_to_play");
        Log.v(TAG, "file_to_play przekazane przez intent z FileChoosera: " + fileToPlayString);
        absolutePathString = intent.getStringExtra("absolute_path");
        Log.v(TAG, "absolute_path przekazane przez intent z FileChoosera: " + absolutePathString);

        showNotyfications();

        WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL, "MyWifiLock");
        if (!wifiLock.isHeld()) {
            wifiLock.acquire();
        }

        if (isfifofileExist() == false) { // isfifofileExist() luck for a true fifo
            while (ConnectToServer.sendCommandAndWaitForExitStatus("mkfifo fifofile") != 0) {
                ConnectToServer.sendCommand("rm fifofile");
            }
        }

        Intent intent_start_RemoteControl = new Intent(getApplicationContext(), RemoteControl.class);
        intent_start_RemoteControl.putExtra("file_to_play", fileToPlayString);
        intent_start_RemoteControl.putExtra("absolute_path", absolutePathString);
        intent_start_RemoteControl.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        //intent_start_RemoteControl.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
        startActivity(intent_start_RemoteControl);

        ConnectToServer.sendCommandAndSaveOutputToLockedArrayList(
                "export DISPLAY=:0.0 && mplayer -fs -slave -quiet -input file=fifofile " + "\""
                        + fileToPlayString + "\"",
                mplayerOutputArrayList, mplayerOutputArrayListLock, newMplayerOutputCondition);

        //RemoteControl.RemoteControlActivityObject.finish();

        //ConnectToServer.sendCommand("rm fifofile");

    }
}

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

private void start(String host, int port) {
    try {//www.  j  a va  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:org.csploit.android.core.System.java

public static void init(Context context) throws Exception {
    mContext = context;/*from   www . j  a  va 2  s.  co  m*/
    try {
        Logger.debug("initializing System...");
        mStoragePath = getSettings().getString("PREF_SAVE_PATH",
                Environment.getExternalStorageDirectory().toString());
        mSessionName = "csploit-session-" + java.lang.System.currentTimeMillis();
        mKnownIssues = new KnownIssues();
        mPlugins = new ArrayList<>();
        mOpenPorts = new SparseIntArray(3);
        mServices = new HashMap<>();
        mPorts = new HashMap<>();

        // if we are here, network initialization didn't throw any error, lock wifi
        WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);

        if (mWifiLock == null)
            mWifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "wifiLock");

        if (!mWifiLock.isHeld())
            mWifiLock.acquire();

        // wake lock if enabled
        if (getSettings().getBoolean("PREF_WAKE_LOCK", true)) {
            PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);

            if (mWakeLock == null)
                mWakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "wakeLock");

            if (!mWakeLock.isHeld())
                mWakeLock.acquire();
        }

        // set ports
        try {
            HTTP_PROXY_PORT = Integer.parseInt(getSettings().getString("PREF_HTTP_PROXY_PORT", "8080"));
            HTTP_SERVER_PORT = Integer.parseInt(getSettings().getString("PREF_HTTP_SERVER_PORT", "8081"));
            HTTPS_REDIR_PORT = Integer.parseInt(getSettings().getString("PREF_HTTPS_REDIRECTOR_PORT", "8082"));
            MSF_RPC_PORT = Integer.parseInt(getSettings().getString("MSF_RPC_PORT", "55553"));
        } catch (NumberFormatException e) {
            HTTP_PROXY_PORT = 8080;
            HTTP_SERVER_PORT = 8081;
            HTTPS_REDIR_PORT = 8082;
            MSF_RPC_PORT = 55553;
        }

        uncaughtReloadNetworkMapping();

        ThreadHelper.getSharedExecutor().execute(new Runnable() {
            @Override
            public void run() {
                preloadServices();
                preloadVendors();
            }
        });
    } catch (Exception e) {
        if (!(e instanceof NoRouteToHostException))
            errorLogging(e);

        throw e;
    }
}

From source file:github.daneren2005.dsub.util.Util.java

public static WifiManager.WifiLock createWifiLock(Context context, String tag) {
    WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    int lockType = WifiManager.WIFI_MODE_FULL;
    if (Build.VERSION.SDK_INT >= 12) {
        lockType = 3;/*w w  w  . j  a  v  a  2  s.  co  m*/
    }
    return wm.createWifiLock(lockType, tag);
}

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);
}