本文整理汇总了Java中com.musala.atmosphere.commons.ad.service.ServiceRequest类的典型用法代码示例。如果您正苦于以下问题:Java ServiceRequest类的具体用法?Java ServiceRequest怎么用?Java ServiceRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServiceRequest类属于com.musala.atmosphere.commons.ad.service包,在下文中一共展示了ServiceRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import com.musala.atmosphere.commons.ad.service.ServiceRequest; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
Log4JConfigurator.configure(getApplicationContext());
IntentFilter controlIntentFilter = new IntentFilter(ATMOSPHERE_SERVICE_CONTROL_INTENT);
serviceControlReceiver = new ServiceControlReceiver();
registerReceiver(serviceControlReceiver, controlIntentFilter);
Context serviceContext = this.getApplicationContext();
LocationManager locationManager = (LocationManager) serviceContext.getSystemService(Context.LOCATION_SERVICE);
mockLocationHandler = new LocationMockHandler(locationManager, serviceContext);
agentRequestHandler = new AgentRequestHandler(serviceContext, mockLocationHandler);
try {
serviceSocketServer = new OnDeviceSocketServer<ServiceRequest>(agentRequestHandler,
ConnectionConstants.SERVICE_PORT);
serviceSocketServer.start();
LOGGER.info("Service socket server started successfully.");
} catch (IOException e) {
LOGGER.error("Could not start ATMOSPHERE socket server", e);
}
LOGGER.info("Atmosphere service has been created.");
}
示例2: getDeviceOrientation
import com.musala.atmosphere.commons.ad.service.ServiceRequest; //导入依赖的package包/类
/**
* Fetches the sensor orientation readings of the device.
*
* @return a {@link DeviceOrientation} instance.
* @throws CommandFailedException
* if getting the device orientation fails
*/
public DeviceOrientation getDeviceOrientation() throws CommandFailedException {
Request<ServiceRequest> request = new Request<>(ServiceRequest.GET_ORIENTATION_READINGS);
try {
float[] response = (float[]) requestSender.request(request);
float orientationAzimuth = response[0];
float orientationPitch = response[1];
float orientationRoll = response[2];
DeviceOrientation deviceOrientation = new DeviceOrientation(orientationAzimuth,
orientationPitch,
orientationRoll);
return deviceOrientation;
} catch (ClassNotFoundException | IOException e) {
throw new CommandFailedException("Getting device orientation failed.", e);
}
}
示例3: getBatteryState
import com.musala.atmosphere.commons.ad.service.ServiceRequest; //导入依赖的package包/类
/**
* Gets the battery state of the device.
*
* @return a member of the {@link BatteryState BatteryState} enumeration.
* @throws CommandFailedException
* if getting the battery state fails
*/
public BatteryState getBatteryState() throws CommandFailedException {
Request<ServiceRequest> serviceRequest = new Request<>(ServiceRequest.GET_POWER_PROPERTIES);
try {
Integer serviceResponse = (Integer) requestSender.request(serviceRequest);
if (serviceResponse != -1) {
BatteryState currentBatteryState = BatteryState.getStateById(serviceResponse);
return currentBatteryState;
} else {
throw new CommandFailedException("The service could not retrieve the battery status.");
}
} catch (ClassNotFoundException | IOException e) {
throw new CommandFailedException("Getting battery status failed.", e);
}
}
示例4: setWiFi
import com.musala.atmosphere.commons.ad.service.ServiceRequest; //导入依赖的package包/类
/**
* Turns on the WiFi of the device.
*
* @param state
* true if the WiFi should be on; false if it should be off.
* @return a fake response, since we are not requesting any information.
*/
private Object setWiFi(Object[] arguments) {
boolean state = (Boolean) arguments[0];
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(state);
return ServiceRequest.ANY_RESPONSE;
}
示例5: setKeyguard
import com.musala.atmosphere.commons.ad.service.ServiceRequest; //导入依赖的package包/类
/**
* Dismisses and re enables the keyguard of the device in order to Lock and Unlock it.
*
* @param locked
* - <code>true</code> if the keyguard should be re-enabled and <code>false</code> to dismiss it.
* @return a {@link ServiceRequest#ANY_RESPONSE}, since we are not requesting any information.
*/
@SuppressWarnings("deprecation")
private Object setKeyguard(Object[] args) {
boolean keyguardState = (Boolean) args[0];
if (keyguardState) {
keyguardLock.reenableKeyguard();
} else {
keyguardLock.disableKeyguard();
}
return ServiceRequest.ANY_RESPONSE;
}
示例6: openLocationSettings
import com.musala.atmosphere.commons.ad.service.ServiceRequest; //导入依赖的package包/类
/**
* Opens the location settings activity.
*
* @return a {@link ServiceRequest#ANY_RESPONSE}, since we are not requesting any information
*/
private Object openLocationSettings() {
Intent openLocationSettingsIntent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
openLocationSettingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(openLocationSettingsIntent);
return ServiceRequest.ANY_RESPONSE;
}
示例7: showTapLocation
import com.musala.atmosphere.commons.ad.service.ServiceRequest; //导入依赖的package包/类
/**
* Shows a tap location on the current device screen.
*
* @param arguments
* - the point where the tap will be placed
* @return a {@link ServiceRequest#ANY_RESPONSE}, since we are not requesting any information
*/
private Object showTapLocation(Object[] arguments) {
Point tapPoint = (Point) arguments[0];
Intent intent = new Intent(context, LocationPointerService.class);
intent.putExtra(LocationPointerConstants.CENTER_POINT_INTENT_NAME.getValue(), tapPoint);
context.startService(intent);
return ServiceRequest.ANY_RESPONSE;
}
示例8: stopBackgroundProcess
import com.musala.atmosphere.commons.ad.service.ServiceRequest; //导入依赖的package包/类
/**
* Stops all background processes associated with the given package.
*
* @param arguments
* - args[0] contains the given package name
* @return a {@link ServiceRequest#ANY_RESPONSE}, since we are not requesting any information
*/
private Object stopBackgroundProcess(Object[] arguments) {
String packageName = (String) arguments[0];
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
activityManager.killBackgroundProcesses(packageName);
return ServiceRequest.ANY_RESPONSE;
}
示例9: sendBroadcast
import com.musala.atmosphere.commons.ad.service.ServiceRequest; //导入依赖的package包/类
/**
* Broadcast the given intent to all interested BroadcastReceivers.
*
* @param args
* - args[0] should contain the AtmoshereIntent object for the broadcast
* @return a {@link ServiceRequest#ANY_RESPONSE}, since we are not requesting any information
*
* @see {@link Context#sendBroadcast(Intent)}
*/
private Object sendBroadcast(Object[] args) {
if (args != null && args.length > 0) {
Object intent = args[0];
if (intent != null && intent instanceof AtmosphereIntent) {
context.sendBroadcast(((AtmosphereIntent) intent).toIntent());
}
}
return ServiceRequest.ANY_RESPONSE;
}
示例10: handle
import com.musala.atmosphere.commons.ad.service.ServiceRequest; //导入依赖的package包/类
@Override
public Object handle(Request<RequestType> request) {
Object response = null;
Object requestType = request.getType();
if (requestType instanceof ServiceRequest) {
response = fakeServiceRequestHandler.handleRequest(request);
} else if (requestType instanceof UIAutomatorRequest) {
response = fakeGesturePlayerRequestHandler.handleRequest(request);
} else {
System.out.println("Fake On-Device components Answer: WARNING: request could not be recognized as a known request type!");
}
return response;
}
示例11: handleRequest
import com.musala.atmosphere.commons.ad.service.ServiceRequest; //导入依赖的package包/类
@Override
public Object handleRequest(Request<?> request) {
ServiceRequest requestType = (ServiceRequest) request.getType();
switch (requestType) {
case VALIDATION:
return ServiceRequest.VALIDATION;
case GET_POWER_PROPERTIES:
return FAKE_POWER_PROPERTIES;
case SET_WIFI:
case GET_CONNECTION_TYPE:
return 5;
case GET_ACCELERATION_READINGS:
Float[] acceleration = new Float[3];
acceleration[0] = 3.7f;
acceleration[1] = 5.2f;
acceleration[2] = -7.1f;
return acceleration;
case GET_ORIENTATION_READINGS:
return new float[] {6.0f, 1.0f, 9.0f};
case GET_PROXIMITY_READINGS:
return 0.0f;
case GET_CAMERA_AVAILABILITY:
return true;
case GET_TOTAL_RAM:
return 10;
default:
return null;
}
}
示例12: getPowerProperties
import com.musala.atmosphere.commons.ad.service.ServiceRequest; //导入依赖的package包/类
/**
* Gets the device power environment properties.
*
* @return a {@link PowerProperties} data container instance.
* @throws CommandFailedException
* if getting the power properties fails
*/
public PowerProperties getPowerProperties() throws CommandFailedException {
Request<ServiceRequest> serviceRequest = new Request<>(ServiceRequest.GET_POWER_PROPERTIES);
try {
PowerProperties properties = (PowerProperties) requestSender.request(serviceRequest);
return properties;
} catch (ClassNotFoundException | IOException e) {
// Redirect the exception to the server
throw new CommandFailedException("Getting environment power properties failed.", e);
}
}
示例13: getTatalRamMemory
import com.musala.atmosphere.commons.ad.service.ServiceRequest; //导入依赖的package包/类
/**
* Gets the total RAM of the device.
*
* @return the total RAM of the device.
* @throws CommandFailedException
* if getting the total ram fails
*/
public int getTatalRamMemory() throws CommandFailedException {
Request<ServiceRequest> serviceRequest = new Request<>(ServiceRequest.GET_TOTAL_RAM);
try {
int serviceResponse = (int) requestSender.request(serviceRequest);
return serviceResponse;
} catch (ClassNotFoundException | IOException | CommandFailedException e) {
throw new CommandFailedException("Getting device's total RAM memory failed.", e);
}
}
示例14: getConnectionType
import com.musala.atmosphere.commons.ad.service.ServiceRequest; //导入依赖的package包/类
/**
* Gets the connection type of the device.
*
* @return a member of the {@link ConnectionType} enumeration.
* @throws CommandFailedException
* if getting the connection type fails
*/
public ConnectionType getConnectionType() throws CommandFailedException {
Request<ServiceRequest> serviceRequest = new Request<>(ServiceRequest.GET_CONNECTION_TYPE);
try {
Integer serviceResponse = (Integer) requestSender.request(serviceRequest);
return ConnectionType.getById(serviceResponse);
} catch (ClassNotFoundException | IOException e) {
throw new CommandFailedException("Getting connection type failed. See enclosed exception for more information.",
e);
}
}
示例15: setWiFi
import com.musala.atmosphere.commons.ad.service.ServiceRequest; //导入依赖的package包/类
/**
* Sets the WiFi state on the device.
*
* @param state
* - true if the WiFi should be on; false if it should be off.
* @throws CommandFailedException
* if setting the WiFi fails
*
*/
public void setWiFi(boolean state) throws CommandFailedException {
Request<ServiceRequest> serviceRequest = new Request<>(ServiceRequest.SET_WIFI);
Boolean[] arguments = new Boolean[] {state};
serviceRequest.setArguments(arguments);
try {
requestSender.request(serviceRequest);
} catch (ClassNotFoundException | IOException e) {
throw new CommandFailedException("Setting WiFi failed. See enclosed exception for more information.", e);
}
}