Add testing features to devtools
Fixed manifest with missing permission. Added some connectivity api-tweakers Change-Id: I10007938e28e8c0f550ae78a7cd6df4a817a8800
This commit is contained in:
committed by
Robert Greenwalt
parent
6f1718bab5
commit
40f7d44cac
@@ -18,6 +18,7 @@
|
|||||||
package="com.android.development"
|
package="com.android.development"
|
||||||
android:versionCode="1" android:versionName="1.0">
|
android:versionCode="1" android:versionName="1.0">
|
||||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
||||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
||||||
<uses-permission android:name="android.permission.DEVICE_POWER" />
|
<uses-permission android:name="android.permission.DEVICE_POWER" />
|
||||||
|
|||||||
@@ -17,12 +17,14 @@
|
|||||||
** limitations under the License.
|
** limitations under the License.
|
||||||
*/
|
*/
|
||||||
-->
|
-->
|
||||||
<LinearLayout
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -202,5 +204,59 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/crash" />
|
android:text="@string/crash" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
<Button android:id="@+id/add_default_route"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/add_default_route" />
|
||||||
|
<Button android:id="@+id/remove_default_route"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/remove_default_route" />
|
||||||
|
</LinearLayout>
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
<Button android:id="@+id/default_request"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/default_request" />
|
||||||
|
<Button android:id="@+id/default_socket"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/default_socket" />
|
||||||
|
</LinearLayout>
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
<Button android:id="@+id/bound_http_request"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/bound_http_request" />
|
||||||
|
<Button android:id="@+id/bound_socket_request"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/bound_socket_request" />
|
||||||
|
</LinearLayout>
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
<Button android:id="@+id/routed_http_request"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/routed_http_request" />
|
||||||
|
<Button android:id="@+id/routed_socket_request"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/routed_socket_request" />
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,14 @@
|
|||||||
<string name="start_hipri">Start HiPri</string>
|
<string name="start_hipri">Start HiPri</string>
|
||||||
<string name="stop_hipri">Stop HiPri</string>
|
<string name="stop_hipri">Stop HiPri</string>
|
||||||
<string name="crash">CRASH</string>
|
<string name="crash">CRASH</string>
|
||||||
|
<string name="add_default_route">Add Default Route</string>
|
||||||
|
<string name="remove_default_route">Remove Default Route</string>
|
||||||
|
<string name="default_request">Make a http request</string>
|
||||||
|
<string name="default_socket">Make a raw request</string>
|
||||||
|
<string name="bound_http_request">Make bound http request</string>
|
||||||
|
<string name="bound_socket_request">Make bound socket request</string>
|
||||||
|
<string name="routed_http_request">Make routed http request</string>
|
||||||
|
<string name="routed_socket_request">Make routed socket request</string>
|
||||||
|
|
||||||
|
|
||||||
<string name="device_info_default">unknown</string>
|
<string name="device_info_default">unknown</string>
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import android.content.IntentFilter;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.NetworkUtils;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@@ -58,19 +59,27 @@ import com.android.internal.telephony.Phone;
|
|||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.NetworkInterface;
|
||||||
|
import java.net.Socket;
|
||||||
|
import java.util.Enumeration;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.conn.params.ConnRouteParams;
|
||||||
|
import org.apache.http.params.BasicHttpParams;
|
||||||
|
import org.apache.http.params.HttpParams;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
|
|
||||||
public class Connectivity extends Activity {
|
public class Connectivity extends Activity {
|
||||||
private static final String TAG = "Connectivity";
|
private static final String TAG = "DevTools - Connectivity";
|
||||||
|
|
||||||
private static final int EVENT_TOGGLE_WIFI = 1;
|
private static final int EVENT_TOGGLE_WIFI = 1;
|
||||||
private static final int EVENT_TOGGLE_SCREEN = 2;
|
private static final int EVENT_TOGGLE_SCREEN = 2;
|
||||||
|
|
||||||
private Button mEnableWifiButton;
|
|
||||||
private Button mDisableWifiButton;
|
|
||||||
|
|
||||||
private Button mStartDelayedCycleButton;
|
|
||||||
private Button mStopDelayedCycleButton;
|
|
||||||
private EditText mDCOnDurationEdit;
|
private EditText mDCOnDurationEdit;
|
||||||
private EditText mDCOffDurationEdit;
|
private EditText mDCOffDurationEdit;
|
||||||
private TextView mDCCycleCountView;
|
private TextView mDCCycleCountView;
|
||||||
@@ -78,8 +87,6 @@ public class Connectivity extends Activity {
|
|||||||
private long mDCOffDuration = 120000;
|
private long mDCOffDuration = 120000;
|
||||||
private int mDCCycleCount = 0;
|
private int mDCCycleCount = 0;
|
||||||
|
|
||||||
private Button mStartScreenCycleButton;
|
|
||||||
private Button mStopScreenCycleButton;
|
|
||||||
private EditText mSCOnDurationEdit;
|
private EditText mSCOnDurationEdit;
|
||||||
private EditText mSCOffDurationEdit;
|
private EditText mSCOffDurationEdit;
|
||||||
private TextView mSCCycleCountView;
|
private TextView mSCCycleCountView;
|
||||||
@@ -87,12 +94,6 @@ public class Connectivity extends Activity {
|
|||||||
private long mSCOffDuration = 12000;
|
private long mSCOffDuration = 12000;
|
||||||
private int mSCCycleCount = 0;
|
private int mSCCycleCount = 0;
|
||||||
|
|
||||||
private Button mStartMmsButton;
|
|
||||||
private Button mStopMmsButton;
|
|
||||||
private Button mStartHiPriButton;
|
|
||||||
private Button mStopHiPriButton;
|
|
||||||
private Button mCrashButton;
|
|
||||||
|
|
||||||
private boolean mDelayedCycleStarted = false;
|
private boolean mDelayedCycleStarted = false;
|
||||||
|
|
||||||
private WifiManager mWm;
|
private WifiManager mWm;
|
||||||
@@ -191,15 +192,11 @@ public class Connectivity extends Activity {
|
|||||||
mPm = (PowerManager)getSystemService(Context.POWER_SERVICE);
|
mPm = (PowerManager)getSystemService(Context.POWER_SERVICE);
|
||||||
mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
|
||||||
mEnableWifiButton = (Button)findViewById(R.id.enableWifi);
|
findViewById(R.id.enableWifi).setOnClickListener(mClickListener);
|
||||||
mEnableWifiButton.setOnClickListener(mEnableWifiClicked);
|
findViewById(R.id.disableWifi).setOnClickListener(mClickListener);
|
||||||
mDisableWifiButton = (Button)findViewById(R.id.disableWifi);
|
|
||||||
mDisableWifiButton.setOnClickListener(mDisableWifiClicked);
|
|
||||||
|
|
||||||
mStartDelayedCycleButton = (Button)findViewById(R.id.startDelayedCycle);
|
findViewById(R.id.startDelayedCycle).setOnClickListener(mClickListener);
|
||||||
mStartDelayedCycleButton.setOnClickListener(mStartDelayedCycleClicked);
|
findViewById(R.id.stopDelayedCycle).setOnClickListener(mClickListener);
|
||||||
mStopDelayedCycleButton = (Button)findViewById(R.id.stopDelayedCycle);
|
|
||||||
mStopDelayedCycleButton.setOnClickListener(mStopDelayedCycleClicked);
|
|
||||||
mDCOnDurationEdit = (EditText)findViewById(R.id.dc_wifi_on_duration);
|
mDCOnDurationEdit = (EditText)findViewById(R.id.dc_wifi_on_duration);
|
||||||
mDCOnDurationEdit.setText(Long.toString(mDCOnDuration));
|
mDCOnDurationEdit.setText(Long.toString(mDCOnDuration));
|
||||||
mDCOffDurationEdit = (EditText)findViewById(R.id.dc_wifi_off_duration);
|
mDCOffDurationEdit = (EditText)findViewById(R.id.dc_wifi_off_duration);
|
||||||
@@ -207,10 +204,8 @@ public class Connectivity extends Activity {
|
|||||||
mDCCycleCountView = (TextView)findViewById(R.id.dc_wifi_cycles_done);
|
mDCCycleCountView = (TextView)findViewById(R.id.dc_wifi_cycles_done);
|
||||||
mDCCycleCountView.setText(Integer.toString(mDCCycleCount));
|
mDCCycleCountView.setText(Integer.toString(mDCCycleCount));
|
||||||
|
|
||||||
mStartScreenCycleButton = (Button)findViewById(R.id.startScreenCycle);
|
findViewById(R.id.startScreenCycle).setOnClickListener(mClickListener);
|
||||||
mStartScreenCycleButton.setOnClickListener(mStartScreenCycleClicked);
|
findViewById(R.id.stopScreenCycle).setOnClickListener(mClickListener);
|
||||||
mStopScreenCycleButton = (Button)findViewById(R.id.stopScreenCycle);
|
|
||||||
mStopScreenCycleButton.setOnClickListener(mStopScreenCycleClicked);
|
|
||||||
mSCOnDurationEdit = (EditText)findViewById(R.id.sc_wifi_on_duration);
|
mSCOnDurationEdit = (EditText)findViewById(R.id.sc_wifi_on_duration);
|
||||||
mSCOnDurationEdit.setText(Long.toString(mSCOnDuration));
|
mSCOnDurationEdit.setText(Long.toString(mSCOnDuration));
|
||||||
mSCOffDurationEdit = (EditText)findViewById(R.id.sc_wifi_off_duration);
|
mSCOffDurationEdit = (EditText)findViewById(R.id.sc_wifi_off_duration);
|
||||||
@@ -218,16 +213,20 @@ public class Connectivity extends Activity {
|
|||||||
mSCCycleCountView = (TextView)findViewById(R.id.sc_wifi_cycles_done);
|
mSCCycleCountView = (TextView)findViewById(R.id.sc_wifi_cycles_done);
|
||||||
mSCCycleCountView.setText(Integer.toString(mSCCycleCount));
|
mSCCycleCountView.setText(Integer.toString(mSCCycleCount));
|
||||||
|
|
||||||
mStartMmsButton = (Button)findViewById(R.id.start_mms);
|
findViewById(R.id.start_mms).setOnClickListener(mClickListener);
|
||||||
mStartMmsButton.setOnClickListener(mStartMmsClicked);
|
findViewById(R.id.stop_mms).setOnClickListener(mClickListener);
|
||||||
mStopMmsButton = (Button)findViewById(R.id.stop_mms);
|
findViewById(R.id.start_hipri).setOnClickListener(mClickListener);
|
||||||
mStopMmsButton.setOnClickListener(mStopMmsClicked);
|
findViewById(R.id.stop_hipri).setOnClickListener(mClickListener);
|
||||||
mStartHiPriButton = (Button)findViewById(R.id.start_hipri);
|
findViewById(R.id.crash).setOnClickListener(mClickListener);
|
||||||
mStartHiPriButton.setOnClickListener(mStartHiPriClicked);
|
|
||||||
mStopHiPriButton = (Button)findViewById(R.id.stop_hipri);
|
findViewById(R.id.add_default_route).setOnClickListener(mClickListener);
|
||||||
mStopHiPriButton.setOnClickListener(mStopHiPriClicked);
|
findViewById(R.id.remove_default_route).setOnClickListener(mClickListener);
|
||||||
mCrashButton = (Button)findViewById(R.id.crash);
|
findViewById(R.id.bound_http_request).setOnClickListener(mClickListener);
|
||||||
mCrashButton.setOnClickListener(mCrashClicked);
|
findViewById(R.id.bound_socket_request).setOnClickListener(mClickListener);
|
||||||
|
findViewById(R.id.routed_http_request).setOnClickListener(mClickListener);
|
||||||
|
findViewById(R.id.routed_socket_request).setOnClickListener(mClickListener);
|
||||||
|
findViewById(R.id.default_request).setOnClickListener(mClickListener);
|
||||||
|
findViewById(R.id.default_socket).setOnClickListener(mClickListener);
|
||||||
|
|
||||||
registerReceiver(mReceiver, new IntentFilter(CONNECTIVITY_TEST_ALARM));
|
registerReceiver(mReceiver, new IntentFilter(CONNECTIVITY_TEST_ALARM));
|
||||||
}
|
}
|
||||||
@@ -239,8 +238,76 @@ public class Connectivity extends Activity {
|
|||||||
super.onResume();
|
super.onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
private View.OnClickListener mStartDelayedCycleClicked = new View.OnClickListener() {
|
private View.OnClickListener mClickListener = new View.OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
switch (v.getId()) {
|
||||||
|
case R.id.enableWifi:
|
||||||
|
mWm.setWifiEnabled(true);
|
||||||
|
break;
|
||||||
|
case R.id.disableWifi:
|
||||||
|
mWm.setWifiEnabled(false);
|
||||||
|
break;
|
||||||
|
case R.id.startDelayedCycle:
|
||||||
|
onStartDelayedCycle();
|
||||||
|
break;
|
||||||
|
case R.id.stopDelayedCycle:
|
||||||
|
onStopDelayedCycle();
|
||||||
|
break;
|
||||||
|
case R.id.startScreenCycle:
|
||||||
|
onStartScreenCycle();
|
||||||
|
break;
|
||||||
|
case R.id.stopScreenCycle:
|
||||||
|
onStopScreenCycle();
|
||||||
|
break;
|
||||||
|
case R.id.start_mms:
|
||||||
|
mCm.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
|
||||||
|
Phone.FEATURE_ENABLE_MMS);
|
||||||
|
break;
|
||||||
|
case R.id.stop_mms:
|
||||||
|
mCm.stopUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
|
||||||
|
Phone.FEATURE_ENABLE_MMS);
|
||||||
|
break;
|
||||||
|
case R.id.default_socket:
|
||||||
|
onDefaultSocket();
|
||||||
|
break;
|
||||||
|
case R.id.default_request:
|
||||||
|
onDefaultRequest();
|
||||||
|
break;
|
||||||
|
case R.id.routed_socket_request:
|
||||||
|
onRoutedSocketRequest();
|
||||||
|
break;
|
||||||
|
case R.id.routed_http_request:
|
||||||
|
onRoutedHttpRequest();
|
||||||
|
break;
|
||||||
|
case R.id.bound_socket_request:
|
||||||
|
onBoundSocketRequest();
|
||||||
|
break;
|
||||||
|
case R.id.bound_http_request:
|
||||||
|
onBoundHttpRequest();
|
||||||
|
break;
|
||||||
|
case R.id.remove_default_route:
|
||||||
|
onRemoveDefaultRoute();
|
||||||
|
break;
|
||||||
|
case R.id.add_default_route:
|
||||||
|
onAddDefaultRoute();
|
||||||
|
break;
|
||||||
|
case R.id.crash:
|
||||||
|
onCrash();
|
||||||
|
break;
|
||||||
|
case R.id.start_hipri:
|
||||||
|
mCm.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
|
||||||
|
Phone.FEATURE_ENABLE_HIPRI);
|
||||||
|
break;
|
||||||
|
case R.id.stop_hipri:
|
||||||
|
mCm.stopUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
|
||||||
|
Phone.FEATURE_ENABLE_HIPRI);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
private void onStartDelayedCycle() {
|
||||||
if (!mDelayedCycleStarted) {
|
if (!mDelayedCycleStarted) {
|
||||||
mDelayedCycleStarted = true;
|
mDelayedCycleStarted = true;
|
||||||
try {
|
try {
|
||||||
@@ -254,9 +321,8 @@ public class Connectivity extends Activity {
|
|||||||
mHandler2.sendMessage(mHandler2.obtainMessage(EVENT_TOGGLE_WIFI));
|
mHandler2.sendMessage(mHandler2.obtainMessage(EVENT_TOGGLE_WIFI));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
private View.OnClickListener mStopDelayedCycleClicked = new View.OnClickListener() {
|
private void onStopDelayedCycle() {
|
||||||
public void onClick(View v) {
|
|
||||||
if (mDelayedCycleStarted) {
|
if (mDelayedCycleStarted) {
|
||||||
mDelayedCycleStarted = false;
|
mDelayedCycleStarted = false;
|
||||||
mWakeLock.release();
|
mWakeLock.release();
|
||||||
@@ -266,22 +332,8 @@ public class Connectivity extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
private View.OnClickListener mEnableWifiClicked = new View.OnClickListener() {
|
|
||||||
public void onClick(View v) {
|
|
||||||
mWm.setWifiEnabled(true);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
private View.OnClickListener mDisableWifiClicked = new View.OnClickListener() {
|
|
||||||
public void onClick(View v) {
|
|
||||||
mWm.setWifiEnabled(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private View.OnClickListener mStartScreenCycleClicked = new View.OnClickListener() {
|
|
||||||
public void onClick(View v) {
|
|
||||||
|
|
||||||
|
private void onStartScreenCycle() {
|
||||||
try {
|
try {
|
||||||
mSCOnDuration = Long.parseLong(mSCOnDurationEdit.getText().toString());
|
mSCOnDuration = Long.parseLong(mSCOnDurationEdit.getText().toString());
|
||||||
mSCOffDuration = Long.parseLong(mSCOffDurationEdit.getText().toString());
|
mSCOffDuration = Long.parseLong(mSCOffDurationEdit.getText().toString());
|
||||||
@@ -294,7 +346,6 @@ public class Connectivity extends Activity {
|
|||||||
|
|
||||||
scheduleAlarm(10, SCREEN_OFF);
|
scheduleAlarm(10, SCREEN_OFF);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
private void scheduleAlarm(long delayMs, String eventType) {
|
private void scheduleAlarm(long delayMs, String eventType) {
|
||||||
AlarmManager am = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
|
AlarmManager am = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
|
||||||
@@ -310,42 +361,189 @@ public class Connectivity extends Activity {
|
|||||||
am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + delayMs, p);
|
am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + delayMs, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
private View.OnClickListener mStopScreenCycleClicked = new View.OnClickListener() {
|
private void onStopScreenCycle() {
|
||||||
public void onClick(View v) {
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
private View.OnClickListener mStartMmsClicked = new View.OnClickListener() {
|
private void onCrash() {
|
||||||
public void onClick(View v) {
|
|
||||||
mCm.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE, Phone.FEATURE_ENABLE_MMS);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private View.OnClickListener mStopMmsClicked = new View.OnClickListener() {
|
|
||||||
public void onClick(View v) {
|
|
||||||
mCm.stopUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE, Phone.FEATURE_ENABLE_MMS);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private View.OnClickListener mStartHiPriClicked = new View.OnClickListener() {
|
|
||||||
public void onClick(View v) {
|
|
||||||
mCm.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
|
|
||||||
Phone.FEATURE_ENABLE_HIPRI);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private View.OnClickListener mStopHiPriClicked = new View.OnClickListener() {
|
|
||||||
public void onClick(View v) {
|
|
||||||
mCm.stopUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
|
|
||||||
Phone.FEATURE_ENABLE_HIPRI);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private View.OnClickListener mCrashClicked = new View.OnClickListener() {
|
|
||||||
public void onClick(View v) {
|
|
||||||
ConnectivityManager foo = null;
|
ConnectivityManager foo = null;
|
||||||
foo.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
|
foo.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
|
||||||
Phone.FEATURE_ENABLE_MMS);
|
Phone.FEATURE_ENABLE_MMS);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
private void onAddDefaultRoute() {
|
||||||
|
try {
|
||||||
|
NetworkUtils.addRoute("eth0", "0.0.0.0", 0, "8.8.8.8");
|
||||||
|
} catch (Exception e) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onRemoveDefaultRoute() {
|
||||||
|
Log.e(TAG, "removeDefaultRoute returned "+NetworkUtils.removeDefaultRoute("eth0"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onRoutedHttpRequest() {
|
||||||
|
onRoutedRequest(HTTP);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onRoutedSocketRequest() {
|
||||||
|
onRoutedRequest(SOCKET);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final static int SOCKET = 1;
|
||||||
|
private final static int HTTP = 2;
|
||||||
|
|
||||||
|
private void onRoutedRequest(int type) {
|
||||||
|
String url = "www.google.com";
|
||||||
|
|
||||||
|
InetAddress inetAddress = null;
|
||||||
|
try {
|
||||||
|
inetAddress = InetAddress.getByName(url);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "error fetching address for " + url);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mCm.requestRouteToHostAddress(ConnectivityManager.TYPE_MOBILE_HIPRI, inetAddress);
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case SOCKET:
|
||||||
|
onBoundSocketRequest();
|
||||||
|
break;
|
||||||
|
case HTTP:
|
||||||
|
HttpGet get = new HttpGet("http://" + url);
|
||||||
|
HttpClient client = new DefaultHttpClient();
|
||||||
|
try {
|
||||||
|
HttpResponse httpResponse = client.execute(get);
|
||||||
|
Log.d(TAG, "routed http request gives " + httpResponse.getStatusLine());
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "routed http request exception = " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onBoundHttpRequest() {
|
||||||
|
NetworkInterface networkInterface = null;
|
||||||
|
try {
|
||||||
|
networkInterface = NetworkInterface.getByName("rmnet0");
|
||||||
|
Log.d(TAG, "networkInterface is " + networkInterface);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, " exception getByName: " + e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (networkInterface != null) {
|
||||||
|
Enumeration inetAddressess = networkInterface.getInetAddresses();
|
||||||
|
while(inetAddressess.hasMoreElements()) {
|
||||||
|
Log.d(TAG, " inetAddress:" + ((InetAddress)inetAddressess.nextElement()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpParams httpParams = new BasicHttpParams();
|
||||||
|
if (networkInterface != null) {
|
||||||
|
ConnRouteParams.setLocalAddress(httpParams,
|
||||||
|
networkInterface.getInetAddresses().nextElement());
|
||||||
|
}
|
||||||
|
HttpGet get = new HttpGet("http://www.bbc.com");
|
||||||
|
HttpClient client = new DefaultHttpClient(httpParams);
|
||||||
|
try {
|
||||||
|
HttpResponse response = client.execute(get);
|
||||||
|
Log.d(TAG, "response code = " + response.getStatusLine());
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "Exception = "+ e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onBoundSocketRequest() {
|
||||||
|
NetworkInterface networkInterface = null;
|
||||||
|
try {
|
||||||
|
networkInterface = NetworkInterface.getByName("rmnet0");
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "exception getByName: " + e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (networkInterface == null) {
|
||||||
|
try {
|
||||||
|
Log.d(TAG, "getting any networkInterface");
|
||||||
|
networkInterface = NetworkInterface.getNetworkInterfaces().nextElement();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "exception getting any networkInterface: " + e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (networkInterface == null) {
|
||||||
|
Log.e(TAG, "couldn't find a local interface");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Enumeration inetAddressess = networkInterface.getInetAddresses();
|
||||||
|
while(inetAddressess.hasMoreElements()) {
|
||||||
|
Log.d(TAG, " addr:" + ((InetAddress)inetAddressess.nextElement()));
|
||||||
|
}
|
||||||
|
InetAddress local = null;
|
||||||
|
InetAddress remote = null;
|
||||||
|
try {
|
||||||
|
local = networkInterface.getInetAddresses().nextElement();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "exception getting local InetAddress: " + e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
remote = InetAddress.getByName("www.flickr.com");
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "exception getting remote InetAddress: " + e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Log.d(TAG, "remote addr ="+remote);
|
||||||
|
Log.d(TAG, "local addr ="+local);
|
||||||
|
Socket socket = null;
|
||||||
|
try {
|
||||||
|
socket = new Socket(remote, 80, local, 6000);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "Exception creating socket: " + e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
|
||||||
|
out.println("Hi flickr");
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "Exception writing to socket: " + e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onDefaultRequest() {
|
||||||
|
HttpParams params = new BasicHttpParams();
|
||||||
|
HttpGet get = new HttpGet("http://www.cnn.com");
|
||||||
|
HttpClient client = new DefaultHttpClient(params);
|
||||||
|
try {
|
||||||
|
HttpResponse response = client.execute(get);
|
||||||
|
Log.e(TAG, "response code = " + response.getStatusLine());
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "Exception = " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onDefaultSocket() {
|
||||||
|
InetAddress remote = null;
|
||||||
|
try {
|
||||||
|
remote = InetAddress.getByName("www.flickr.com");
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "exception getting remote InetAddress: " + e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Log.e(TAG, "remote addr =" + remote);
|
||||||
|
Socket socket = null;
|
||||||
|
try {
|
||||||
|
socket = new Socket(remote, 80);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "Exception creating socket: " + e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
|
||||||
|
out.println("Hi flickr");
|
||||||
|
Log.e(TAG, "written");
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "Exception writing to socket: " + e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user