diff options
Diffstat (limited to 'apps/Development')
| -rw-r--r-- | apps/Development/AndroidManifest.xml | 7 | ||||
| -rw-r--r-- | apps/Development/res/layout/connectivity.xml | 68 | ||||
| -rw-r--r-- | apps/Development/res/layout/development_settings.xml | 8 | ||||
| -rw-r--r-- | apps/Development/res/layout/media_scanner_activity.xml | 49 | ||||
| -rwxr-xr-x | apps/Development/res/mipmap-hdpi/ic_launcher_devtools.png (renamed from apps/Development/res/drawable-hdpi/ic_launcher_devtools.png) | bin | 5141 -> 5141 bytes | |||
| -rw-r--r-- | apps/Development/res/mipmap-mdpi/ic_launcher_devtools.png (renamed from apps/Development/res/drawable-mdpi/ic_launcher_devtools.png) | bin | 3133 -> 3133 bytes | |||
| -rw-r--r-- | apps/Development/res/values/strings.xml | 13 | ||||
| -rw-r--r-- | apps/Development/src/com/android/development/Connectivity.java | 414 | ||||
| -rw-r--r-- | apps/Development/src/com/android/development/DevelopmentSettings.java | 75 | ||||
| -rw-r--r-- | apps/Development/src/com/android/development/MediaScannerActivity.java | 215 |
10 files changed, 704 insertions, 145 deletions
diff --git a/apps/Development/AndroidManifest.xml b/apps/Development/AndroidManifest.xml index c8095542c..c91e21be3 100644 --- a/apps/Development/AndroidManifest.xml +++ b/apps/Development/AndroidManifest.xml @@ -18,6 +18,7 @@ package="com.android.development" android:versionCode="1" android:versionName="1.0"> <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_WIFI_STATE" /> <uses-permission android:name="android.permission.DEVICE_POWER" /> @@ -43,12 +44,12 @@ <uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH.YouTubeUser" /> <application android:label="Dev Tools" - android:icon="@drawable/ic_launcher_devtools"> + android:icon="@mipmap/ic_launcher_devtools"> <uses-library android:name="android.test.runner" /> <activity android:name="Development" android:label="Dev Tools" - android:icon="@drawable/ic_launcher_devtools"> + android:icon="@mipmap/ic_launcher_devtools"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> @@ -117,7 +118,7 @@ </intent-filter> </activity> - <activity android:name="MediaScannerActivity" android:label="Media Scanner"> + <activity android:name="MediaScannerActivity" android:label="Media Provider"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.TEST" /> diff --git a/apps/Development/res/layout/connectivity.xml b/apps/Development/res/layout/connectivity.xml index 612304fa7..ff0c6ea6b 100644 --- a/apps/Development/res/layout/connectivity.xml +++ b/apps/Development/res/layout/connectivity.xml @@ -17,12 +17,14 @@ ** limitations under the License. */ --> -<LinearLayout - xmlns:android="http://schemas.android.com/apk/res/android" - android:orientation="vertical" - android:layout_width="match_parent" - android:layout_height="match_parent"> +<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent"> + <LinearLayout + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="wrap_content"> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" @@ -202,5 +204,59 @@ android:layout_height="wrap_content" android:text="@string/crash" /> </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> diff --git a/apps/Development/res/layout/development_settings.xml b/apps/Development/res/layout/development_settings.xml index 16c2cdf58..fbb6a404f 100644 --- a/apps/Development/res/layout/development_settings.xml +++ b/apps/Development/res/layout/development_settings.xml @@ -74,10 +74,16 @@ android:layout_alignParentLeft="true" android:text="@string/development_settings_show_updates_text" /> + <Spinner android:id="@+id/strictmode_visual" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/show_updates" + android:layout_alignParentLeft="true" /> + <CheckBox android:id="@+id/compatibility_mode" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_below="@id/show_updates" + android:layout_below="@id/strictmode_visual" android:layout_alignParentLeft="true" android:text="@string/development_settings_compatibility_mode_text" /> diff --git a/apps/Development/res/layout/media_scanner_activity.xml b/apps/Development/res/layout/media_scanner_activity.xml index 974f68378..480684355 100644 --- a/apps/Development/res/layout/media_scanner_activity.xml +++ b/apps/Development/res/layout/media_scanner_activity.xml @@ -4,9 +4,9 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - + http://www.apache.org/licenses/LICENSE-2.0 - + Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -14,12 +14,45 @@ limitations under the License. --> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:orientation="horizontal"> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + + <TextView + android:id="@+id/title" + android:textSize="16sp" + android:textStyle="bold" + android:layout_width="match_parent" + android:layout_height="wrap_content" /> + + <Button + android:layout_width="160dip" + android:layout_height="wrap_content" + android:layout_gravity="center_horizontal" + android:text="@string/scancard" + android:onClick="startScan" /> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="horizontal" + android:layout_marginTop="30dip"> + + <EditText + android:id="@+id/numsongs" + android:layout_width="150dip" + android:layout_height="wrap_content" + android:hint="@string/numsongs" + android:numeric="integer" + /> + + <Button + android:id="@+id/insertbutton" + android:layout_width="150dip" + android:layout_height="wrap_content" + android:onClick="insertItems" /> - <TextView android:id="@+id/title" android:textSize="16sp" android:textStyle="bold" - android:layout_width="match_parent" android:layout_height="wrap_content" /> + </LinearLayout> </LinearLayout> diff --git a/apps/Development/res/drawable-hdpi/ic_launcher_devtools.png b/apps/Development/res/mipmap-hdpi/ic_launcher_devtools.png Binary files differindex 60fbdf5d0..60fbdf5d0 100755 --- a/apps/Development/res/drawable-hdpi/ic_launcher_devtools.png +++ b/apps/Development/res/mipmap-hdpi/ic_launcher_devtools.png diff --git a/apps/Development/res/drawable-mdpi/ic_launcher_devtools.png b/apps/Development/res/mipmap-mdpi/ic_launcher_devtools.png Binary files differindex cb40a1988..cb40a1988 100644 --- a/apps/Development/res/drawable-mdpi/ic_launcher_devtools.png +++ b/apps/Development/res/mipmap-mdpi/ic_launcher_devtools.png diff --git a/apps/Development/res/values/strings.xml b/apps/Development/res/values/strings.xml index 181c4fa7d..422bd7f59 100644 --- a/apps/Development/res/values/strings.xml +++ b/apps/Development/res/values/strings.xml @@ -36,6 +36,14 @@ <string name="start_hipri">Start HiPri</string> <string name="stop_hipri">Stop HiPri</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> @@ -208,4 +216,9 @@ <string name="bad_behavior_anr_service_label">ANR starting a Service</string> <string name="bad_behavior_anr_system_label">System ANR (in ActivityManager)</string> <string name="bad_behavior_wedge_system_label">Wedge system (5 minute system ANR)</string> + + <!-- MediaScannerActivity --> + <string name="scancard">Scan SD card</string> + <string name="numsongs"># of albums</string> + <string name="insertbutton">Insert %1s albums</string> </resources> diff --git a/apps/Development/src/com/android/development/Connectivity.java b/apps/Development/src/com/android/development/Connectivity.java index 59157bfb6..c7029ecc7 100644 --- a/apps/Development/src/com/android/development/Connectivity.java +++ b/apps/Development/src/com/android/development/Connectivity.java @@ -28,6 +28,7 @@ import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.PackageManager.NameNotFoundException; import android.net.ConnectivityManager; +import android.net.NetworkUtils; import android.net.wifi.WifiManager; import android.os.RemoteException; import android.os.Handler; @@ -58,19 +59,27 @@ import com.android.internal.telephony.Phone; import java.io.FileInputStream; 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 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 { - 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_SCREEN = 2; - private Button mEnableWifiButton; - private Button mDisableWifiButton; - - private Button mStartDelayedCycleButton; - private Button mStopDelayedCycleButton; private EditText mDCOnDurationEdit; private EditText mDCOffDurationEdit; private TextView mDCCycleCountView; @@ -78,8 +87,6 @@ public class Connectivity extends Activity { private long mDCOffDuration = 120000; private int mDCCycleCount = 0; - private Button mStartScreenCycleButton; - private Button mStopScreenCycleButton; private EditText mSCOnDurationEdit; private EditText mSCOffDurationEdit; private TextView mSCCycleCountView; @@ -87,12 +94,6 @@ public class Connectivity extends Activity { private long mSCOffDuration = 12000; private int mSCCycleCount = 0; - private Button mStartMmsButton; - private Button mStopMmsButton; - private Button mStartHiPriButton; - private Button mStopHiPriButton; - private Button mCrashButton; - private boolean mDelayedCycleStarted = false; private WifiManager mWm; @@ -191,15 +192,11 @@ public class Connectivity extends Activity { mPm = (PowerManager)getSystemService(Context.POWER_SERVICE); mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); - mEnableWifiButton = (Button)findViewById(R.id.enableWifi); - mEnableWifiButton.setOnClickListener(mEnableWifiClicked); - mDisableWifiButton = (Button)findViewById(R.id.disableWifi); - mDisableWifiButton.setOnClickListener(mDisableWifiClicked); + findViewById(R.id.enableWifi).setOnClickListener(mClickListener); + findViewById(R.id.disableWifi).setOnClickListener(mClickListener); - mStartDelayedCycleButton = (Button)findViewById(R.id.startDelayedCycle); - mStartDelayedCycleButton.setOnClickListener(mStartDelayedCycleClicked); - mStopDelayedCycleButton = (Button)findViewById(R.id.stopDelayedCycle); - mStopDelayedCycleButton.setOnClickListener(mStopDelayedCycleClicked); + findViewById(R.id.startDelayedCycle).setOnClickListener(mClickListener); + findViewById(R.id.stopDelayedCycle).setOnClickListener(mClickListener); mDCOnDurationEdit = (EditText)findViewById(R.id.dc_wifi_on_duration); mDCOnDurationEdit.setText(Long.toString(mDCOnDuration)); 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.setText(Integer.toString(mDCCycleCount)); - mStartScreenCycleButton = (Button)findViewById(R.id.startScreenCycle); - mStartScreenCycleButton.setOnClickListener(mStartScreenCycleClicked); - mStopScreenCycleButton = (Button)findViewById(R.id.stopScreenCycle); - mStopScreenCycleButton.setOnClickListener(mStopScreenCycleClicked); + findViewById(R.id.startScreenCycle).setOnClickListener(mClickListener); + findViewById(R.id.stopScreenCycle).setOnClickListener(mClickListener); mSCOnDurationEdit = (EditText)findViewById(R.id.sc_wifi_on_duration); mSCOnDurationEdit.setText(Long.toString(mSCOnDuration)); 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.setText(Integer.toString(mSCCycleCount)); - mStartMmsButton = (Button)findViewById(R.id.start_mms); - mStartMmsButton.setOnClickListener(mStartMmsClicked); - mStopMmsButton = (Button)findViewById(R.id.stop_mms); - mStopMmsButton.setOnClickListener(mStopMmsClicked); - mStartHiPriButton = (Button)findViewById(R.id.start_hipri); - mStartHiPriButton.setOnClickListener(mStartHiPriClicked); - mStopHiPriButton = (Button)findViewById(R.id.stop_hipri); - mStopHiPriButton.setOnClickListener(mStopHiPriClicked); - mCrashButton = (Button)findViewById(R.id.crash); - mCrashButton.setOnClickListener(mCrashClicked); + findViewById(R.id.start_mms).setOnClickListener(mClickListener); + findViewById(R.id.stop_mms).setOnClickListener(mClickListener); + findViewById(R.id.start_hipri).setOnClickListener(mClickListener); + findViewById(R.id.stop_hipri).setOnClickListener(mClickListener); + findViewById(R.id.crash).setOnClickListener(mClickListener); + + findViewById(R.id.add_default_route).setOnClickListener(mClickListener); + findViewById(R.id.remove_default_route).setOnClickListener(mClickListener); + findViewById(R.id.bound_http_request).setOnClickListener(mClickListener); + 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)); } @@ -239,62 +238,114 @@ public class Connectivity extends Activity { super.onResume(); } - private View.OnClickListener mStartDelayedCycleClicked = new View.OnClickListener() { - public void onClick(View v) { - if (!mDelayedCycleStarted) { - mDelayedCycleStarted = true; - try { - mDCOnDuration = Long.parseLong(mDCOnDurationEdit.getText().toString()); - mDCOffDuration = Long.parseLong(mDCOffDurationEdit.getText().toString()); - } catch (Exception e) { }; - mDCCycleCount = 0; - - mWakeLock = mPm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "ConnectivityTest"); - mWakeLock.acquire(); - mHandler2.sendMessage(mHandler2.obtainMessage(EVENT_TOGGLE_WIFI)); - } - } - }; - private View.OnClickListener mStopDelayedCycleClicked = new View.OnClickListener() { + private View.OnClickListener mClickListener = new View.OnClickListener() { public void onClick(View v) { - if (mDelayedCycleStarted) { - mDelayedCycleStarted = false; - mWakeLock.release(); - mWakeLock = null; - if(mHandler2.hasMessages(EVENT_TOGGLE_WIFI)) { - mHandler2.removeMessages(EVENT_TOGGLE_WIFI); - } + 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 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 onStartDelayedCycle() { + if (!mDelayedCycleStarted) { + mDelayedCycleStarted = true; try { - mSCOnDuration = Long.parseLong(mSCOnDurationEdit.getText().toString()); - mSCOffDuration = Long.parseLong(mSCOffDurationEdit.getText().toString()); + mDCOnDuration = Long.parseLong(mDCOnDurationEdit.getText().toString()); + mDCOffDuration = Long.parseLong(mDCOffDurationEdit.getText().toString()); } catch (Exception e) { }; - mSCCycleCount = 0; + mDCCycleCount = 0; - mScreenonWakeLock = mPm.newWakeLock(PowerManager.FULL_WAKE_LOCK, - "ConnectivityTest"); - mScreenonWakeLock.acquire(); + mWakeLock = mPm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "ConnectivityTest"); + mWakeLock.acquire(); + mHandler2.sendMessage(mHandler2.obtainMessage(EVENT_TOGGLE_WIFI)); + } + } - scheduleAlarm(10, SCREEN_OFF); + private void onStopDelayedCycle() { + if (mDelayedCycleStarted) { + mDelayedCycleStarted = false; + mWakeLock.release(); + mWakeLock = null; + if(mHandler2.hasMessages(EVENT_TOGGLE_WIFI)) { + mHandler2.removeMessages(EVENT_TOGGLE_WIFI); + } } - }; + } + + private void onStartScreenCycle() { + try { + mSCOnDuration = Long.parseLong(mSCOnDurationEdit.getText().toString()); + mSCOffDuration = Long.parseLong(mSCOffDurationEdit.getText().toString()); + } catch (Exception e) { }; + mSCCycleCount = 0; + + mScreenonWakeLock = mPm.newWakeLock(PowerManager.FULL_WAKE_LOCK, + "ConnectivityTest"); + mScreenonWakeLock.acquire(); + + scheduleAlarm(10, SCREEN_OFF); + } private void scheduleAlarm(long delayMs, String eventType) { 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); } - private View.OnClickListener mStopScreenCycleClicked = new View.OnClickListener() { - public void onClick(View v) { + private void onStopScreenCycle() { + } + + private void onCrash() { + ConnectivityManager foo = null; + foo.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE, + 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; } - }; - private View.OnClickListener mStartMmsClicked = new View.OnClickListener() { - public void onClick(View v) { - mCm.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE, Phone.FEATURE_ENABLE_MMS); + 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 View.OnClickListener mStopMmsClicked = new View.OnClickListener() { - public void onClick(View v) { - mCm.stopUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE, Phone.FEATURE_ENABLE_MMS); + } + + 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())); + } } - }; - private View.OnClickListener mStartHiPriClicked = new View.OnClickListener() { - public void onClick(View v) { - mCm.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE, - Phone.FEATURE_ENABLE_HIPRI); + 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 View.OnClickListener mStopHiPriClicked = new View.OnClickListener() { - public void onClick(View v) { - mCm.stopUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE, - Phone.FEATURE_ENABLE_HIPRI); + 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 View.OnClickListener mCrashClicked = new View.OnClickListener() { - public void onClick(View v) { - ConnectivityManager foo = null; - foo.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE, - Phone.FEATURE_ENABLE_MMS); + 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; + } + } } diff --git a/apps/Development/src/com/android/development/DevelopmentSettings.java b/apps/Development/src/com/android/development/DevelopmentSettings.java index c01ea59d6..4cc1c911b 100644 --- a/apps/Development/src/com/android/development/DevelopmentSettings.java +++ b/apps/Development/src/com/android/development/DevelopmentSettings.java @@ -23,23 +23,26 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager.NameNotFoundException; -import android.os.RemoteException; +import android.os.Bundle; import android.os.IBinder; import android.os.Parcel; +import android.os.RemoteException; import android.os.ServiceManager; import android.os.ServiceManagerNative; +import android.os.StrictMode; +import android.os.SystemProperties; import android.provider.Settings; -import android.os.Bundle; +import android.text.TextUtils; import android.util.Log; import android.view.IWindowManager; import android.view.View; +import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.Spinner; import android.widget.Toast; -import android.widget.AdapterView.OnItemSelectedListener; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -53,6 +56,7 @@ public class DevelopmentSettings extends Activity { private CheckBox mWaitForDebuggerCB; private CheckBox mAlwaysFinishCB; private Spinner mPointerLocationSpinner; + private Spinner mStrictModeVisualSpinner; private CheckBox mShowLoadCB; private CheckBox mShowCpuCB; private CheckBox mEnableGLCB; @@ -106,6 +110,17 @@ public class DevelopmentSettings extends Activity { "Pointer Location" }); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mPointerLocationSpinner.setAdapter(adapter); + mStrictModeVisualSpinner = (Spinner)findViewById(R.id.strictmode_visual); + adapter = new ArrayAdapter<String>( + this, + android.R.layout.simple_spinner_item, + new String[] { + "StrictMode visual indicator: build variant default", + "StrictMode visual indicator: on", + "StrictMode visual indicator: off" }); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + mStrictModeVisualSpinner.setAdapter(adapter); + mStrictModeVisualSpinner.setOnItemSelectedListener(mStrictModeVisualChanged); mShowLoadCB = (CheckBox)findViewById(R.id.show_load); mShowLoadCB.setOnClickListener(mShowLoadClicked); mShowCpuCB = (CheckBox)findViewById(R.id.show_cpu); @@ -182,6 +197,7 @@ public class DevelopmentSettings extends Activity { updateDebugOptions(); updateFinishOptions(); updatePointerLocationOptions(); + updateStrictModeVisualOptions(); updateProcessLimitOptions(); updateSharedOptions(); updateFlingerOptions(); @@ -245,6 +261,24 @@ public class DevelopmentSettings extends Activity { mPointerLocationSpinner.setSelection(mPointerLocation); } + // Returns the current state of the system property that controls + // strictmode flashes. One of: + // 0: not explicitly set one way or another + // 1: on + // 2: off + // These are the indices in the Spinner's ArrayAdapter. + private int currentStrictModeActiveIndex() { + if (TextUtils.isEmpty(SystemProperties.get(StrictMode.VISUAL_PROPERTY))) { + return 0; + } + boolean enabled = SystemProperties.getBoolean(StrictMode.VISUAL_PROPERTY, false); + return enabled ? 1 : 2; + } + + private void updateStrictModeVisualOptions() { + mStrictModeVisualSpinner.setSelection(currentStrictModeActiveIndex()); + } + private void writeProcessLimitOptions() { try { ActivityManagerNative.getDefault().setProcessLimit(mProcessLimit); @@ -456,6 +490,41 @@ public class DevelopmentSettings extends Activity { } }; + private Spinner.OnItemSelectedListener mStrictModeVisualChanged + = new Spinner.OnItemSelectedListener() { + public void onItemSelected(android.widget.AdapterView av, View v, + int position, long id) { + if (position == currentStrictModeActiveIndex()) { + // at the existing position, so don't show a Toast. + return; + } + + try { + switch (position) { + case 0: // default + mWindowManager.setStrictModeVisualIndicatorPreference(""); + break; + case 1: // on + mWindowManager.setStrictModeVisualIndicatorPreference("1"); + break; + case 2: // off + mWindowManager.setStrictModeVisualIndicatorPreference("0"); + break; + } + } catch (RemoteException e) { + Log.w(TAG, "Error calling setStrictModeVisualIndicatorPreference", e); + } + + Toast.makeText( + DevelopmentSettings.this, + "Setting changed; will take effect per-app next launch, or on reboot", + Toast.LENGTH_LONG).show(); + } + + public void onNothingSelected(android.widget.AdapterView av) { + } + }; + private Spinner.OnItemSelectedListener mMaxProcsChanged = new Spinner.OnItemSelectedListener() { public void onItemSelected(android.widget.AdapterView av, View v, diff --git a/apps/Development/src/com/android/development/MediaScannerActivity.java b/apps/Development/src/com/android/development/MediaScannerActivity.java index f78910ac4..04f641422 100644 --- a/apps/Development/src/com/android/development/MediaScannerActivity.java +++ b/apps/Development/src/com/android/development/MediaScannerActivity.java @@ -17,56 +17,239 @@ package com.android.development; import android.app.Activity; +import android.content.ContentResolver; +import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.BroadcastReceiver; +import android.database.sqlite.SQLiteConstraintException; import android.net.Uri; +import android.os.Bundle; import android.os.Environment; +import android.os.Handler; +import android.os.Message; +import android.provider.MediaStore; +import android.provider.MediaStore.Audio; +import android.text.Editable; +import android.text.TextWatcher; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; import android.widget.TextView; +import java.util.Random; + public class MediaScannerActivity extends Activity { + private TextView mTitle; + private int mNumToInsert = 20; + private int mArtists; + private int mAlbums; + private int mSongs; + private ContentResolver mResolver; + private Uri mAudioUri; + ContentValues mValues[] = new ContentValues[10]; + Random mRandom = new Random(); + StringBuilder mBuilder = new StringBuilder(); + public MediaScannerActivity() { } - + /** Called when the activity is first created or resumed. */ @Override - public void onResume() { - super.onResume(); - + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + setContentView(R.layout.media_scanner_activity); - + IntentFilter intentFilter = new IntentFilter(Intent.ACTION_MEDIA_SCANNER_STARTED); intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED); intentFilter.addDataScheme("file"); registerReceiver(mReceiver, intentFilter); - - sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" - + Environment.getExternalStorageDirectory()))); - + + EditText t = (EditText) findViewById(R.id.numsongs); + t.addTextChangedListener(new TextWatcher() { + + public void afterTextChanged(Editable s) { + String text = s.toString(); + try { + mNumToInsert = Integer.valueOf(text); + } catch (NumberFormatException ex) { + mNumToInsert = 20; + } + setInsertButtonText(); + } + + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + + }); mTitle = (TextView) findViewById(R.id.title); - mTitle.setText("Sent ACTION_MEDIA_MOUNTED to trigger the Media Scanner."); + mResolver = getContentResolver(); + mAudioUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; + + for (int i = 0; i < 10; i++) { + mValues[i] = new ContentValues(); + } + setInsertButtonText(); } /** Called when the activity going into the background or being destroyed. */ @Override - public void onPause() { - super.onPause(); + public void onDestroy() { unregisterReceiver(mReceiver); + mInsertHandler.removeMessages(0); + super.onDestroy(); } - + private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Intent.ACTION_MEDIA_SCANNER_STARTED)) { - mTitle.setText("Media Scanner started scanning " + intent.getData().getPath()); + mTitle.setText("Media Scanner started scanning " + intent.getData().getPath()); } else if (intent.getAction().equals(Intent.ACTION_MEDIA_SCANNER_FINISHED)) { - mTitle.setText("Media Scanner finished scanning " + intent.getData().getPath()); + mTitle.setText("Media Scanner finished scanning " + intent.getData().getPath()); } } }; - private TextView mTitle; + public void startScan(View v) { + sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + + Environment.getExternalStorageDirectory()))); + + mTitle.setText("Sent ACTION_MEDIA_MOUNTED to trigger the Media Scanner."); + } + + private void setInsertButtonText() { + String label = getString(R.string.insertbutton, Integer.valueOf(mNumToInsert)); + Button b = (Button) findViewById(R.id.insertbutton); + b.setText(label); + } + + + public void insertItems(View v) { + if (mInsertHandler.hasMessages(0)) { + mInsertHandler.removeMessages(0); + setInsertButtonText(); + } else { + mInsertHandler.sendEmptyMessage(0); + } + } + + Handler mInsertHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + + if (mNumToInsert-- > 0) { + addAlbum(); + runOnUiThread(mDisplayUpdater); + + if (!isFinishing()) { + sendEmptyMessage(0); + } + } + } + }; + + Runnable mDisplayUpdater = new Runnable() { + public void run() { + mTitle.setText("Added " + mArtists + " artists, " + mAlbums + " albums, " + + mSongs + " songs."); + } + }; + + // Add one more album (with 10 songs) to the database. This will be a compilation album, + // with one album artist for the album, and a separate artist for each song. + private void addAlbum() { + try { + String albumArtist = "Various Artists"; + String albumName = getRandomWord(3); + int baseYear = 1969 + mRandom.nextInt(30); + for (int i = 0; i < 10; i++) { + mValues[i].clear(); + String artist = getRandomName(); + final ContentValues map = mValues[i]; + map.put(MediaStore.MediaColumns.DATA, + "http://bogus/" + albumName + "/" + artist + "_" + i); + map.put(MediaStore.MediaColumns.TITLE, + getRandomWord(4) + " " + getRandomWord(2) + " " + (i + 1)); + map.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3"); + + map.put(Audio.Media.ARTIST, artist); + map.put("album_artist", albumArtist); + map.put(Audio.Media.ALBUM, albumName); + map.put(Audio.Media.TRACK, i + 1); + map.put(Audio.Media.DURATION, 4*60*1000); + map.put(Audio.Media.IS_MUSIC, 1); + map.put(Audio.Media.YEAR, baseYear + mRandom.nextInt(10)); + } + mResolver.bulkInsert(mAudioUri, mValues); + mSongs += 10; + mAlbums++; + mArtists += 11; + } catch (SQLiteConstraintException ex) { + Log.d("@@@@", "insert failed", ex); + } + } + + /** + * Some code to generate random names. This just strings together random + * syllables, and randomly inserts a modifier between the first + * and last name. + */ + private String[] elements = new String[] { + "ab", "am", + "bra", "bri", + "ci", "co", + "de", "di", "do", + "fa", "fi", + "ki", + "la", "li", + "ma", "me", "mi", "mo", + "na", "ni", + "pa", + "ta", "ti", + "vi", "vo" + }; + + private String getRandomWord(int len) { + int max = elements.length; + mBuilder.setLength(0); + for (int i = 0; i < len; i++) { + mBuilder.append(elements[mRandom.nextInt(max)]); + } + char c = mBuilder.charAt(0); + c = Character.toUpperCase(c); + mBuilder.setCharAt(0, c); + return mBuilder.toString(); + } + + private String getRandomName() { + boolean longfirst = mRandom.nextInt(5) < 3; + String first = getRandomWord(longfirst ? 3 : 2); + String last = getRandomWord(3); + switch (mRandom.nextInt(6)) { + case 1: + if (!last.startsWith("Di")) { + last = "di " + last; + } + break; + case 2: + last = "van " + last; + break; + case 3: + last = "de " + last; + break; + } + return first + " " + last; + } + + + } |
