Merge "CTS coverage: connectivity change, photo, + video" into nyc-dev
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
<target_preparer class="com.android.compatibility.common.tradefed.targetprep.ApkInstaller">
|
<target_preparer class="com.android.compatibility.common.tradefed.targetprep.ApkInstaller">
|
||||||
<option name="cleanup-apks" value="true" />
|
<option name="cleanup-apks" value="true" />
|
||||||
<option name="test-file-name" value="CtsNetTestCases.apk" />
|
<option name="test-file-name" value="CtsNetTestCases.apk" />
|
||||||
|
<option name="test-file-name" value="CtsNetTestAppForApi23.apk" />
|
||||||
</target_preparer>
|
</target_preparer>
|
||||||
<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
|
<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
|
||||||
<option name="package" value="android.net.cts" />
|
<option name="package" value="android.net.cts" />
|
||||||
|
|||||||
38
tests/cts/net/appForApi23/Android.mk
Normal file
38
tests/cts/net/appForApi23/Android.mk
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# Copyright (C) 2016 The Android Open Source Project
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
LOCAL_PATH:= $(call my-dir)
|
||||||
|
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
|
||||||
|
# don't include this package in any target
|
||||||
|
LOCAL_MODULE_TAGS := optional
|
||||||
|
# and when built explicitly put it in the data partition
|
||||||
|
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
|
||||||
|
|
||||||
|
# Include both the 32 and 64 bit versions
|
||||||
|
LOCAL_MULTILIB := both
|
||||||
|
|
||||||
|
LOCAL_SRC_FILES := $(call all-java-files-under, src)
|
||||||
|
|
||||||
|
LOCAL_PACKAGE_NAME := CtsNetTestAppForApi23
|
||||||
|
|
||||||
|
LOCAL_SDK_VERSION := 23
|
||||||
|
|
||||||
|
# Tag this module as a cts test artifact
|
||||||
|
LOCAL_COMPATIBILITY_SUITE := cts
|
||||||
|
|
||||||
|
include $(BUILD_CTS_PACKAGE)
|
||||||
|
|
||||||
|
include $(call all-makefiles-under,$(LOCAL_PATH))
|
||||||
47
tests/cts/net/appForApi23/AndroidManifest.xml
Normal file
47
tests/cts/net/appForApi23/AndroidManifest.xml
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
* Copyright (C) 2016 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="android.net.cts.appForApi23">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
|
||||||
|
<application>
|
||||||
|
<receiver android:name=".ConnectivityReceiver">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
|
||||||
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.net.cts.appForApi23.getConnectivityActionCount" />
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
|
||||||
|
<activity android:name=".ConnectivityListeningActivity"
|
||||||
|
android:label="ConnectivityListeningActivity"
|
||||||
|
android:exported="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</manifest>
|
||||||
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package android.net.cts.appForApi23;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
|
||||||
|
// Stub activity used to start the app
|
||||||
|
public class ConnectivityListeningActivity extends Activity {
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package android.net.cts.appForApi23;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
|
||||||
|
public class ConnectivityReceiver extends BroadcastReceiver {
|
||||||
|
public static String GET_CONNECTIVITY_ACTION_COUNT =
|
||||||
|
"android.net.cts.appForApi23.getConnectivityActionCount";
|
||||||
|
|
||||||
|
private static int sConnectivityActionCount = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
|
||||||
|
sConnectivityActionCount++;
|
||||||
|
}
|
||||||
|
if (GET_CONNECTIVITY_ACTION_COUNT.equals(intent.getAction())) {
|
||||||
|
setResultCode(sConnectivityActionCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,6 +21,7 @@ import static android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET;
|
|||||||
|
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
@@ -35,11 +36,11 @@ import android.net.NetworkInfo.DetailedState;
|
|||||||
import android.net.NetworkInfo.State;
|
import android.net.NetworkInfo.State;
|
||||||
import android.net.NetworkRequest;
|
import android.net.NetworkRequest;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.test.AndroidTestCase;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
import android.system.Os;
|
import android.system.Os;
|
||||||
import android.system.OsConstants;
|
import android.system.OsConstants;
|
||||||
|
import android.test.AndroidTestCase;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.internal.telephony.PhoneConstants;
|
import com.android.internal.telephony.PhoneConstants;
|
||||||
|
|
||||||
@@ -48,12 +49,9 @@ import java.io.IOException;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class ConnectivityManagerTest extends AndroidTestCase {
|
public class ConnectivityManagerTest extends AndroidTestCase {
|
||||||
@@ -68,6 +66,7 @@ public class ConnectivityManagerTest extends AndroidTestCase {
|
|||||||
private static final int HOST_ADDRESS = 0x7f000001;// represent ip 127.0.0.1
|
private static final int HOST_ADDRESS = 0x7f000001;// represent ip 127.0.0.1
|
||||||
private static final String TEST_HOST = "connectivitycheck.gstatic.com";
|
private static final String TEST_HOST = "connectivitycheck.gstatic.com";
|
||||||
private static final int SOCKET_TIMEOUT_MS = 2000;
|
private static final int SOCKET_TIMEOUT_MS = 2000;
|
||||||
|
private static final int SEND_BROADCAST_TIMEOUT = 30000;
|
||||||
private static final int HTTP_PORT = 80;
|
private static final int HTTP_PORT = 80;
|
||||||
private static final String HTTP_REQUEST =
|
private static final String HTTP_REQUEST =
|
||||||
"GET /generate_204 HTTP/1.0\r\n" +
|
"GET /generate_204 HTTP/1.0\r\n" +
|
||||||
@@ -78,9 +77,14 @@ public class ConnectivityManagerTest extends AndroidTestCase {
|
|||||||
private static final String NETWORK_CALLBACK_ACTION =
|
private static final String NETWORK_CALLBACK_ACTION =
|
||||||
"ConnectivityManagerTest.NetworkCallbackAction";
|
"ConnectivityManagerTest.NetworkCallbackAction";
|
||||||
|
|
||||||
|
// Intent string to get the number of CONNECTIVITY_ACTION callbacks the test app has seen
|
||||||
|
public static final String GET_CONNECTIVITY_ACTION_COUNT =
|
||||||
|
"android.net.cts.appForApi23.getConnectivityActionCount";
|
||||||
|
|
||||||
// device could have only one interface: data, wifi.
|
// device could have only one interface: data, wifi.
|
||||||
private static final int MIN_NUM_NETWORK_TYPES = 1;
|
private static final int MIN_NUM_NETWORK_TYPES = 1;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
private ConnectivityManager mCm;
|
private ConnectivityManager mCm;
|
||||||
private WifiManager mWifiManager;
|
private WifiManager mWifiManager;
|
||||||
private PackageManager mPackageManager;
|
private PackageManager mPackageManager;
|
||||||
@@ -90,13 +94,14 @@ public class ConnectivityManagerTest extends AndroidTestCase {
|
|||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
mCm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
|
mContext = getContext();
|
||||||
mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
|
mCm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
mPackageManager = getContext().getPackageManager();
|
mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
|
||||||
|
mPackageManager = mContext.getPackageManager();
|
||||||
|
|
||||||
// Get com.android.internal.R.array.networkAttributes
|
// Get com.android.internal.R.array.networkAttributes
|
||||||
int resId = getContext().getResources().getIdentifier("networkAttributes", "array", "android");
|
int resId = mContext.getResources().getIdentifier("networkAttributes", "array", "android");
|
||||||
String[] naStrings = getContext().getResources().getStringArray(resId);
|
String[] naStrings = mContext.getResources().getStringArray(resId);
|
||||||
//TODO: What is the "correct" way to determine if this is a wifi only device?
|
//TODO: What is the "correct" way to determine if this is a wifi only device?
|
||||||
boolean wifiOnly = SystemProperties.getBoolean("ro.radio.noril", false);
|
boolean wifiOnly = SystemProperties.getBoolean("ro.radio.noril", false);
|
||||||
for (String naString : naStrings) {
|
for (String naString : naStrings) {
|
||||||
@@ -381,19 +386,10 @@ public class ConnectivityManagerTest extends AndroidTestCase {
|
|||||||
/**
|
/**
|
||||||
* Tests reporting of connectivity changed.
|
* Tests reporting of connectivity changed.
|
||||||
*/
|
*/
|
||||||
public void testConnectivityChanged() {
|
public void testConnectivityChanged_manifestRequestOnly_shouldNotReceiveIntent() {
|
||||||
// We are going to ensure that we *don't* see the connectivity in the manifest.
|
|
||||||
ConnectivityReceiver.prepare();
|
ConnectivityReceiver.prepare();
|
||||||
|
|
||||||
// We will toggle the state of wifi to generate a connectivity change.
|
toggleWifi();
|
||||||
final boolean previousWifiEnabledState = mWifiManager.isWifiEnabled();
|
|
||||||
|
|
||||||
if (previousWifiEnabledState) {
|
|
||||||
Network wifiNetwork = getWifiNetwork();
|
|
||||||
disconnectFromWifi(wifiNetwork);
|
|
||||||
} else {
|
|
||||||
connectToWifi();
|
|
||||||
}
|
|
||||||
|
|
||||||
// The connectivity broadcast has been sent; push through a terminal broadcast
|
// The connectivity broadcast has been sent; push through a terminal broadcast
|
||||||
// to wait for in the receive to confirm it didn't see the connectivity change.
|
// to wait for in the receive to confirm it didn't see the connectivity change.
|
||||||
@@ -401,12 +397,63 @@ public class ConnectivityManagerTest extends AndroidTestCase {
|
|||||||
finalIntent.setClass(mContext, ConnectivityReceiver.class);
|
finalIntent.setClass(mContext, ConnectivityReceiver.class);
|
||||||
mContext.sendBroadcast(finalIntent);
|
mContext.sendBroadcast(finalIntent);
|
||||||
assertFalse(ConnectivityReceiver.waitForBroadcast());
|
assertFalse(ConnectivityReceiver.waitForBroadcast());
|
||||||
|
}
|
||||||
|
|
||||||
// Now restore previous state.
|
public void testConnectivityChanged_whenRegistered_shouldReceiveIntent() {
|
||||||
if (previousWifiEnabledState) {
|
ConnectivityReceiver.prepare();
|
||||||
|
ConnectivityReceiver receiver = new ConnectivityReceiver();
|
||||||
|
IntentFilter filter = new IntentFilter();
|
||||||
|
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||||
|
mContext.registerReceiver(receiver, filter);
|
||||||
|
|
||||||
|
toggleWifi();
|
||||||
|
Intent finalIntent = new Intent(ConnectivityReceiver.FINAL_ACTION);
|
||||||
|
finalIntent.setClass(mContext, ConnectivityReceiver.class);
|
||||||
|
mContext.sendBroadcast(finalIntent);
|
||||||
|
|
||||||
|
assertTrue(ConnectivityReceiver.waitForBroadcast());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testConnectivityChanged_manifestRequestOnlyPreN_shouldReceiveIntent()
|
||||||
|
throws InterruptedException {
|
||||||
|
Intent startIntent = new Intent();
|
||||||
|
startIntent.setComponent(new ComponentName("android.net.cts.appForApi23",
|
||||||
|
"android.net.cts.appForApi23.ConnectivityListeningActivity"));
|
||||||
|
mContext.startActivity(startIntent);
|
||||||
|
|
||||||
|
toggleWifi();
|
||||||
|
|
||||||
|
Intent getConnectivityCount = new Intent(GET_CONNECTIVITY_ACTION_COUNT);
|
||||||
|
assertEquals(2, sendOrderedBroadcastAndReturnResultCode(
|
||||||
|
getConnectivityCount, SEND_BROADCAST_TIMEOUT));
|
||||||
|
}
|
||||||
|
|
||||||
|
private int sendOrderedBroadcastAndReturnResultCode(
|
||||||
|
Intent intent, int timeoutMs) throws InterruptedException {
|
||||||
|
final LinkedBlockingQueue<Integer> result = new LinkedBlockingQueue<>(1);
|
||||||
|
mContext.sendOrderedBroadcast(intent, null, new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
result.offer(getResultCode());
|
||||||
|
}
|
||||||
|
}, null, 0, null, null);
|
||||||
|
|
||||||
|
Integer resultCode = result.poll(timeoutMs, TimeUnit.MILLISECONDS);
|
||||||
|
assertNotNull("Timed out (more than " + timeoutMs +
|
||||||
|
" milliseconds) waiting for result code for broadcast", resultCode);
|
||||||
|
return resultCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Toggle WiFi twice, leaving it in the state it started in
|
||||||
|
private void toggleWifi() {
|
||||||
|
if (mWifiManager.isWifiEnabled()) {
|
||||||
|
Network wifiNetwork = getWifiNetwork();
|
||||||
|
disconnectFromWifi(wifiNetwork);
|
||||||
connectToWifi();
|
connectToWifi();
|
||||||
} else {
|
} else {
|
||||||
disconnectFromWifi(null);
|
connectToWifi();
|
||||||
|
Network wifiNetwork = getWifiNetwork();
|
||||||
|
disconnectFromWifi(wifiNetwork);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user