Methods Summary |
---|
void | bindAutoExpectResult(android.content.Intent service)
TestConnection conn = new TestConnection(false, true);
boolean success = false;
try {
conn.setMonitor(true);
mStartState = STATE_START_1;
getContext().bindService(
service, conn, Context.BIND_AUTO_CREATE);
waitForResultOrThrow(5 * 1000, "connection to start and receive service");
success = true;
} finally {
if (!success) {
try {
getContext().unbindService(conn);
} catch (Exception e) {
// eat
}
}
}
mStartState = STATE_UNBIND;
getContext().unbindService(conn);
waitForResultOrThrow(5 * 1000, "disconnecting from service");
|
void | bindExpectNoPermission(android.content.Intent service)
TestConnection conn = new TestConnection(false, false);
try {
getContext().bindService(service, conn, Context.BIND_AUTO_CREATE);
fail("Expected security exception when binding " + service);
} catch (SecurityException e) {
// expected
} finally {
getContext().unbindService(conn);
}
|
void | bindExpectResult(android.content.Intent service)
TestConnection conn = new TestConnection(true, false);
TestConnection conn2 = new TestConnection(false, false);
boolean success = false;
try {
// Expect to see the TestConnection connected.
mStartState = STATE_START_1;
getContext().bindService(service, conn, 0);
getContext().startService(service);
waitForResultOrThrow(5 * 1000, "existing connection to receive service");
// Expect to see the second TestConnection connected.
getContext().bindService(service, conn2, 0);
waitForResultOrThrow(5 * 1000, "new connection to receive service");
getContext().unbindService(conn2);
success = true;
} finally {
if (!success) {
try {
getContext().stopService(service);
getContext().unbindService(conn);
getContext().unbindService(conn2);
} catch (Exception e) {
// eat
}
}
}
// Expect to see the TestConnection disconnected.
mStartState = STATE_DESTROY;
getContext().stopService(service);
waitForResultOrThrow(5 * 1000, "existing connection to lose service");
getContext().unbindService(conn);
conn = new TestConnection(true, true);
success = false;
try {
// Expect to see the TestConnection connected.
conn.setMonitor(true);
mStartState = STATE_START_1;
getContext().bindService(service, conn, 0);
getContext().startService(service);
waitForResultOrThrow(5 * 1000, "existing connection to receive service");
success = true;
} finally {
if (!success) {
try {
getContext().stopService(service);
getContext().unbindService(conn);
} catch (Exception e) {
// eat
}
}
}
// Expect to see the service unbind and then destroyed.
conn.setMonitor(false);
mStartState = STATE_UNBIND;
getContext().stopService(service);
waitForResultOrThrow(5 * 1000, "existing connection to lose service");
getContext().unbindService(conn);
conn = new TestConnection(true, true);
success = false;
try {
// Expect to see the TestConnection connected.
conn.setMonitor(true);
mStartState = STATE_START_1;
getContext().bindService(service, conn, 0);
getContext().startService(service);
waitForResultOrThrow(5 * 1000, "existing connection to receive service");
success = true;
} finally {
if (!success) {
try {
getContext().stopService(service);
getContext().unbindService(conn);
} catch (Exception e) {
// eat
}
}
}
// Expect to see the service unbind but not destroyed.
conn.setMonitor(false);
mStartState = STATE_UNBIND_ONLY;
getContext().unbindService(conn);
waitForResultOrThrow(5 * 1000, "existing connection to unbind service");
// Expect to see the service rebound.
mStartState = STATE_REBIND;
getContext().bindService(service, conn, 0);
waitForResultOrThrow(5 * 1000, "existing connection to rebind service");
// Expect to see the service unbind and then destroyed.
mStartState = STATE_UNBIND;
getContext().stopService(service);
waitForResultOrThrow(5 * 1000, "existing connection to lose service");
getContext().unbindService(conn);
|
void | startExpectNoPermission(android.content.Intent service)
try {
getContext().startService(service);
fail("Expected security exception when starting " + service);
} catch (SecurityException e) {
// expected
}
|
void | startExpectResult(android.content.Intent service)
startExpectResult(service, new Bundle());
|
void | startExpectResult(android.content.Intent service, android.os.Bundle bundle)
bundle.putIBinder(REPORT_OBJ_NAME, mStartReceiver);
boolean success = false;
try {
//Log.i("foo", "STATE_START_1");
mStartState = STATE_START_1;
getContext().startService(new Intent(service).putExtras(bundle));
waitForResultOrThrow(5 * 1000, "service to start first time");
//Log.i("foo", "STATE_START_2");
mStartState = STATE_START_2;
getContext().startService(new Intent(service).putExtras(bundle));
waitForResultOrThrow(5 * 1000, "service to start second time");
success = true;
} finally {
if (!success) {
try {
getContext().stopService(service);
} catch (Exception e) {
// eat
}
}
}
//Log.i("foo", "STATE_DESTROY");
mStartState = STATE_DESTROY;
getContext().stopService(service);
waitForResultOrThrow(5 * 1000, "service to be destroyed");
|
public void | testLocalBindAction()
bindExpectResult(new Intent(SERVICE_LOCAL));
|
public void | testLocalBindActionPermissionDenied()
bindExpectNoPermission(new Intent(SERVICE_LOCAL_DENIED));
|
public void | testLocalBindActionPermissionGranted()
bindExpectResult(new Intent(SERVICE_LOCAL_GRANTED));
|
public void | testLocalBindAutoAction()
bindAutoExpectResult(new Intent(SERVICE_LOCAL));
|
public void | testLocalBindAutoActionPermissionGranted()
bindAutoExpectResult(new Intent(SERVICE_LOCAL_GRANTED));
|
public void | testLocalBindAutoClass()
bindAutoExpectResult(new Intent(getContext(), LocalService.class));
|
public void | testLocalBindAutoClassPermissionGranted()
bindAutoExpectResult(new Intent(getContext(), LocalGrantedService.class));
|
public void | testLocalBindClass()
bindExpectResult(new Intent(getContext(), LocalService.class));
|
public void | testLocalBindClassPermissionDenied()
bindExpectNoPermission(new Intent(getContext(), LocalDeniedService.class));
|
public void | testLocalBindClassPermissionGranted()
bindExpectResult(new Intent(getContext(), LocalGrantedService.class));
|
public void | testLocalStartAction()
startExpectResult(new Intent(SERVICE_LOCAL));
|
public void | testLocalStartActionPermissionDenied()
startExpectNoPermission(new Intent(SERVICE_LOCAL_DENIED));
|
public void | testLocalStartActionPermissionGranted()
startExpectResult(new Intent(SERVICE_LOCAL_GRANTED));
|
public void | testLocalStartClass()
startExpectResult(new Intent(getContext(), LocalService.class));
|
public void | testLocalStartClassPermissionDenied()
startExpectNoPermission(new Intent(getContext(), LocalDeniedService.class));
|
public void | testLocalStartClassPermissionGranted()
startExpectResult(new Intent(getContext(), LocalGrantedService.class));
|
public void | testLocalUnbindTwice()
EmptyConnection conn = new EmptyConnection();
getContext().bindService(
new Intent(SERVICE_LOCAL_GRANTED), conn, 0);
getContext().unbindService(conn);
try {
getContext().unbindService(conn);
fail("No exception thrown on second unbind");
} catch (IllegalArgumentException e) {
//Log.i("foo", "Unbind exception", e);
}
|