Test to ensure a toast doesn't affect app standby

Put an app in standby, make it show a toast and ensure
that it doesn't come out of standby. This is to test
for a bug fix for the same behavior.

Bug: 31544592
Test: cts-tradefed run commandAndExit cts -m CtsHostsideNetworkTests -t com.android.cts.net.HostsideRestrictBackgroundNetworkTests#testAppIdle_toast
Change-Id: I796ecde8e346c308a27969d873e3ce384414fee3
This commit is contained in:
Amith Yamasani
2016-09-21 11:45:30 -07:00
parent 2855028c8e
commit 87c10012b4
6 changed files with 45 additions and 0 deletions

View File

@@ -16,6 +16,7 @@
package com.android.cts.net.hostside;
import android.os.SystemClock;
import android.util.Log;
/**
@@ -162,4 +163,16 @@ abstract class AbstractAppIdleTestCase extends AbstractRestrictBackgroundNetwork
turnBatteryOff();
assertBackgroundNetworkAccess(true);
}
public void testAppIdle_toast() throws Exception {
if (!isSupported()) return;
setAppIdle(true);
assertAppIdle(true);
assertEquals("Shown", showToast());
assertAppIdle(true);
// Wait for a couple of seconds for the toast to actually be shown
SystemClock.sleep(2000);
assertAppIdle(true);
}
}

View File

@@ -64,6 +64,8 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation
"com.android.cts.net.hostside.app2.action.RECEIVER_READY";
static final String ACTION_SEND_NOTIFICATION =
"com.android.cts.net.hostside.app2.action.SEND_NOTIFICATION";
static final String ACTION_SHOW_TOAST =
"com.android.cts.net.hostside.app2.action.SHOW_TOAST";
private static final String EXTRA_ACTION = "com.android.cts.net.hostside.app2.extra.ACTION";
private static final String EXTRA_RECEIVER_NAME =
"com.android.cts.net.hostside.app2.extra.RECEIVER_NAME";
@@ -782,6 +784,17 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation
mContext.sendBroadcast(intent);
}
protected String showToast() {
final Intent intent = new Intent(ACTION_SHOW_TOAST);
intent.setPackage(TEST_APP2_PKG);
Log.d(TAG, "Sending request to show toast");
try {
return sendOrderedBroadcast(intent, 3 * SECOND_IN_MS);
} catch (Exception e) {
return "";
}
}
private String toString(int status) {
switch (status) {
case RESTRICT_BACKGROUND_STATUS_DISABLED:

View File

@@ -46,6 +46,7 @@
<action android:name="com.android.cts.net.hostside.app2.action.GET_RESTRICT_BACKGROUND_STATUS" />
<action android:name="com.android.cts.net.hostside.app2.action.CHECK_NETWORK" />
<action android:name="com.android.cts.net.hostside.app2.action.SEND_NOTIFICATION" />
<action android:name="com.android.cts.net.hostside.app2.action.SHOW_TOAST" />
</intent-filter>
</receiver>
</application>

View File

@@ -38,6 +38,8 @@ public final class Common {
"com.android.cts.net.hostside.app2.action.FINISH_ACTIVITY";
static final String ACTION_SEND_NOTIFICATION =
"com.android.cts.net.hostside.app2.action.SEND_NOTIFICATION";
static final String ACTION_SHOW_TOAST =
"com.android.cts.net.hostside.app2.action.SHOW_TOAST";
static final String EXTRA_ACTION = "com.android.cts.net.hostside.app2.extra.ACTION";
static final String EXTRA_RECEIVER_NAME =
"com.android.cts.net.hostside.app2.extra.RECEIVER_NAME";

View File

@@ -23,6 +23,7 @@ import static com.android.cts.net.hostside.app2.Common.ACTION_GET_COUNTERS;
import static com.android.cts.net.hostside.app2.Common.ACTION_GET_RESTRICT_BACKGROUND_STATUS;
import static com.android.cts.net.hostside.app2.Common.ACTION_RECEIVER_READY;
import static com.android.cts.net.hostside.app2.Common.ACTION_SEND_NOTIFICATION;
import static com.android.cts.net.hostside.app2.Common.ACTION_SHOW_TOAST;
import static com.android.cts.net.hostside.app2.Common.EXTRA_ACTION;
import static com.android.cts.net.hostside.app2.Common.EXTRA_NOTIFICATION_ID;
import static com.android.cts.net.hostside.app2.Common.EXTRA_NOTIFICATION_TYPE;
@@ -51,6 +52,7 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import java.net.HttpURLConnection;
import java.net.URL;
@@ -104,6 +106,9 @@ public class MyBroadcastReceiver extends BroadcastReceiver {
case ACTION_SEND_NOTIFICATION:
sendNotification(context, intent);
break;
case ACTION_SHOW_TOAST:
showToast(context);
break;
default:
Log.e(TAG, "received unexpected action: " + action);
}
@@ -302,4 +307,9 @@ public class MyBroadcastReceiver extends BroadcastReceiver {
((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE))
.notify(notificationId, notification);
}
private void showToast(Context context) {
Toast.makeText(context, "Toast from CTS test", Toast.LENGTH_SHORT).show();
setResultData("Shown");
}
}

View File

@@ -181,6 +181,12 @@ public class HostsideRestrictBackgroundNetworkTests extends HostsideNetworkTestC
"testAppIdleNetworkAccess_whenCharging");
}
public void testAppIdle_toast() throws Exception {
// Check that showing a toast doesn't bring an app out of standby
runDeviceTests(TEST_PKG, TEST_PKG + ".AppIdleNonMeteredTest",
"testAppIdle_toast");
}
/********************
* Doze Mode tests. *
********************/