aboutsummaryrefslogtreecommitdiffstats
path: root/sdk/src/java/cyanogenmod/weather
diff options
context:
space:
mode:
authorLuis Vidal <lvidal@cyngn.com>2016-04-13 01:08:11 -0700
committerLuis Vidal <lvidal@cyngn.com>2016-04-13 15:22:40 -0700
commitfe1812fd38633e3c90abfa022d2d0d4a6029e2bf (patch)
treedaf94e5c77692e5baa0475f01bd8edbb6034780c /sdk/src/java/cyanogenmod/weather
parent377fffca6989304ec61e33dacb0dd3fba8345262 (diff)
downloadvendor_cmsdk-fe1812fd38633e3c90abfa022d2d0d4a6029e2bf.tar.gz
vendor_cmsdk-fe1812fd38633e3c90abfa022d2d0d4a6029e2bf.tar.bz2
vendor_cmsdk-fe1812fd38633e3c90abfa022d2d0d4a6029e2bf.zip
Weather API: Delegate the responsability of rejecting back to back requests [1/2]
The Weather Manager Service should not impose rules regarding how a weather provide service wants to react to back to back weather update requests, nor impose the time a caller should wait before a new request can be submitted. These constraints vary between weather services, so it's up the each implementation to enforce these constraints. With this patch, the Weather manager service will pass the requests as they come from the requester and it will be up to the active service provider decide whether process or reject the request. Changes to API: - Moved the request statuses to new inner class RequestStatus in CMWeatherManager - Pass status arg to onLookupCityRequestCompleted() - Added reject(int) method to ServiceRequest Change-Id: I3512490688255e25395e955d506fe42ed52f8fe0 TICKET: CYNGNOS-2430
Diffstat (limited to 'sdk/src/java/cyanogenmod/weather')
-rw-r--r--sdk/src/java/cyanogenmod/weather/CMWeatherManager.java81
-rw-r--r--sdk/src/java/cyanogenmod/weather/IRequestInfoListener.aidl4
2 files changed, 38 insertions, 47 deletions
diff --git a/sdk/src/java/cyanogenmod/weather/CMWeatherManager.java b/sdk/src/java/cyanogenmod/weather/CMWeatherManager.java
index 545c3ce..8292b58 100644
--- a/sdk/src/java/cyanogenmod/weather/CMWeatherManager.java
+++ b/sdk/src/java/cyanogenmod/weather/CMWeatherManager.java
@@ -53,40 +53,32 @@ public class CMWeatherManager {
private static final String TAG = CMWeatherManager.class.getSimpleName();
- /**
- * Weather update request state: Successfully completed
- */
- public static final int WEATHER_REQUEST_COMPLETED = 1;
-
- /**
- * Weather update request state: You need to wait a bit longer before requesting an update
- * again.
- * <p>Please bear in mind that the weather does not change very often. A threshold of 10 minutes
- * is enforced by the system</p>
- */
- public static final int WEATHER_REQUEST_SUBMITTED_TOO_SOON = -1;
-
- /**
- * Weather update request state: An error occurred while trying to update the weather. You
- * should wait before trying again, or your request will be rejected with
- * {@link #WEATHER_REQUEST_SUBMITTED_TOO_SOON}
- */
- public static final int WEATHER_REQUEST_FAILED = -2;
/**
- * Weather update request state: Only one update request can be processed at a given time.
+ * The different request statuses
*/
- public static final int WEATHER_REQUEST_ALREADY_IN_PROGRESS = -3;
-
- /** @hide */
- public static final int LOOKUP_REQUEST_COMPLETED = 100;
-
- /** @hide */
- public static final int LOOKUP_REQUEST_FAILED = -100;
-
- /** @hide */
- public static final int LOOKUP_REQUEST_NO_MATCH_FOUND = -101;
-
+ public static class RequestStatus {
+ /**
+ * Request Successfully completed
+ */
+ public static final int COMPLETED = 1;
+ /**
+ * An error occurred while trying to honor the request.
+ */
+ public static final int FAILED = -1;
+ /**
+ * The request can't be processed at this time
+ */
+ public static final int SUBMITTED_TOO_SOON = -2;
+ /**
+ * Another request in already in progress
+ */
+ public static final int ALREADY_IN_PROGRESS = -3;
+ /**
+ * No match found for the query
+ */
+ public static final int NO_MATCH_FOUND = -4;
+ }
private CMWeatherManager(Context context) {
Context appContext = context.getApplicationContext();
@@ -330,7 +322,7 @@ public class CMWeatherManager {
private final IRequestInfoListener mRequestInfoListener = new IRequestInfoListener.Stub() {
@Override
- public void onWeatherRequestCompleted(final RequestInfo requestInfo, final int state,
+ public void onWeatherRequestCompleted(final RequestInfo requestInfo, final int status,
final WeatherInfo weatherInfo) {
final WeatherUpdateRequestListener listener
= mWeatherUpdateRequestListeners.remove(requestInfo);
@@ -338,14 +330,14 @@ public class CMWeatherManager {
mHandler.post(new Runnable() {
@Override
public void run() {
- listener.onWeatherRequestCompleted(state, weatherInfo);
+ listener.onWeatherRequestCompleted(status, weatherInfo);
}
});
}
}
@Override
- public void onLookupCityRequestCompleted(RequestInfo requestInfo,
+ public void onLookupCityRequestCompleted(RequestInfo requestInfo, final int status,
final List<WeatherLocation> weatherLocations) {
final LookupCityRequestListener listener
@@ -354,7 +346,7 @@ public class CMWeatherManager {
mHandler.post(new Runnable() {
@Override
public void run() {
- listener.onLookupCityRequestCompleted(weatherLocations);
+ listener.onLookupCityRequestCompleted(status, weatherLocations);
}
});
}
@@ -369,16 +361,12 @@ public class CMWeatherManager {
* This method will be called when the weather service provider has finished processing the
* request
*
- * @param state Any of the following values
- * {@link #WEATHER_REQUEST_COMPLETED}
- * {@link #WEATHER_REQUEST_ALREADY_IN_PROGRESS}
- * {@link #WEATHER_REQUEST_SUBMITTED_TOO_SOON}
- * {@link #WEATHER_REQUEST_FAILED}
+ * @param status See {@link RequestStatus}
*
* @param weatherInfo A fully populated {@link WeatherInfo} if state is
- * {@link #WEATHER_REQUEST_COMPLETED}, null otherwise
+ * {@link RequestStatus#COMPLETED}, null otherwise
*/
- void onWeatherRequestCompleted(int state, WeatherInfo weatherInfo);
+ void onWeatherRequestCompleted(int status, WeatherInfo weatherInfo);
}
/**
@@ -387,11 +375,14 @@ public class CMWeatherManager {
public interface LookupCityRequestListener {
/**
* This method will be called when the weather service provider has finished processing the
- * request. The argument can be null if the provider couldn't find a match
+ * request.
+ *
+ * @param status See {@link RequestStatus}
*
- * @param locations
+ * @param locations A list of {@link WeatherLocation} if the status is
+ * {@link RequestStatus#COMPLETED}, null otherwise
*/
- void onLookupCityRequestCompleted(List<WeatherLocation> locations);
+ void onLookupCityRequestCompleted(int status, List<WeatherLocation> locations);
}
/**
diff --git a/sdk/src/java/cyanogenmod/weather/IRequestInfoListener.aidl b/sdk/src/java/cyanogenmod/weather/IRequestInfoListener.aidl
index 553da71..d35db44 100644
--- a/sdk/src/java/cyanogenmod/weather/IRequestInfoListener.aidl
+++ b/sdk/src/java/cyanogenmod/weather/IRequestInfoListener.aidl
@@ -24,8 +24,8 @@ import java.util.List;
/** @hide */
oneway interface IRequestInfoListener {
- void onWeatherRequestCompleted(in RequestInfo requestInfo, int state,
+ void onWeatherRequestCompleted(in RequestInfo requestInfo, int status,
in WeatherInfo weatherInfo);
- void onLookupCityRequestCompleted(in RequestInfo requestInfo,
+ void onLookupCityRequestCompleted(in RequestInfo requestInfo, int status,
in List<WeatherLocation> weatherLocation);
} \ No newline at end of file