Skip to content

Commit 28fe43b

Browse files
Hung DangAndroid (Google) Code Review
authored andcommitted
Merge "Add the hook which can set the device to connect to wifi and in airplane mode after reboot. This is for the power test." into froyo
2 parents 2a8dd4e + ba1348e commit 28fe43b

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import android.os.Bundle;
2525
import android.provider.Settings;
2626
import android.util.Log;
27+
import android.view.KeyEvent;
2728
import java.util.List;
2829
import android.widget.LinearLayout;
2930
import android.net.ConnectivityManager;
@@ -64,6 +65,8 @@ public class ConnectivityManagerTestActivity extends Activity {
6465
public int mWifiState;
6566
public NetworkInfo mWifiNetworkInfo;
6667
public String mBssid;
68+
public String mPowerSsid = "GoogleGuest"; //Default power SSID
69+
private Context mContext;
6770

6871
/*
6972
* Control Wifi States
@@ -404,4 +407,44 @@ protected void onDestroy() {
404407
}
405408
Log.v(LOG_TAG, "onDestroy, inst=" + Integer.toHexString(hashCode()));
406409
}
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+
}
407450
}

0 commit comments

Comments
 (0)