|
24 | 24 | import android.os.Bundle; |
25 | 25 | import android.provider.Settings; |
26 | 26 | import android.util.Log; |
| 27 | +import android.view.KeyEvent; |
27 | 28 | import java.util.List; |
28 | 29 | import android.widget.LinearLayout; |
29 | 30 | import android.net.ConnectivityManager; |
@@ -64,6 +65,8 @@ public class ConnectivityManagerTestActivity extends Activity { |
64 | 65 | public int mWifiState; |
65 | 66 | public NetworkInfo mWifiNetworkInfo; |
66 | 67 | public String mBssid; |
| 68 | + public String mPowerSsid = "GoogleGuest"; //Default power SSID |
| 69 | + private Context mContext; |
67 | 70 |
|
68 | 71 | /* |
69 | 72 | * Control Wifi States |
@@ -404,4 +407,44 @@ protected void onDestroy() { |
404 | 407 | } |
405 | 408 | Log.v(LOG_TAG, "onDestroy, inst=" + Integer.toHexString(hashCode())); |
406 | 409 | } |
| 410 | + |
| 411 | + @Override |
| 412 | + public void onStart() { |
| 413 | + super.onStart(); |
| 414 | + mContext = this; |
| 415 | + Bundle bundle = this.getIntent().getExtras(); |
| 416 | + if (bundle != null){ |
| 417 | + mPowerSsid = bundle.getString("power_ssid"); |
| 418 | + } |
| 419 | + } |
| 420 | + //A thread to set the device into airplane mode then turn on wifi. |
| 421 | + Thread setDeviceWifiAndAirplaneThread = new Thread(new Runnable() { |
| 422 | + public void run() { |
| 423 | + setAirplaneMode(mContext, true); |
| 424 | + connectToWifi(mPowerSsid); |
| 425 | + } |
| 426 | + }); |
| 427 | + |
| 428 | + //A thread to set the device into wifi |
| 429 | + Thread setDeviceInWifiOnlyThread = new Thread(new Runnable() { |
| 430 | + public void run() { |
| 431 | + connectToWifi(mPowerSsid); |
| 432 | + } |
| 433 | + }); |
| 434 | + |
| 435 | + @Override |
| 436 | + public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 437 | + switch (keyCode) { |
| 438 | + //This is a tricky way for the scripted monkey to |
| 439 | + //set the device in wifi and wifi in airplane mode. |
| 440 | + case KeyEvent.KEYCODE_1: |
| 441 | + setDeviceWifiAndAirplaneThread.start(); |
| 442 | + break; |
| 443 | + |
| 444 | + case KeyEvent.KEYCODE_2: |
| 445 | + setDeviceInWifiOnlyThread.start(); |
| 446 | + break; |
| 447 | + } |
| 448 | + return super.onKeyDown(keyCode, event); |
| 449 | + } |
407 | 450 | } |
0 commit comments