Test to ensure a toast doesn't affect app standby am: 87c10012b4
am: a79fdc6a3e
Change-Id: Ifc27411d8075cd7174037707f80f4be36e2581a6
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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. *
|
||||
********************/
|
||||
|
||||
Reference in New Issue
Block a user