aboutsummaryrefslogtreecommitdiffstats
path: root/sdk
diff options
context:
space:
mode:
authorLuis Vidal <lvidal@cyngn.com>2016-04-06 15:39:49 -0700
committerLuis Vidal <lvidal@cyngn.com>2016-04-07 22:42:43 -0700
commit343245f4e6331b1059240150e62e0c9a9d8d3a54 (patch)
tree2a8901d3268646f2576033895e95be7a7aed4410 /sdk
parent2eddb5f7c706d37004e06ecd5c39d0f3ab724f55 (diff)
downloadvendor_cmsdk-343245f4e6331b1059240150e62e0c9a9d8d3a54.zip
vendor_cmsdk-343245f4e6331b1059240150e62e0c9a9d8d3a54.tar.gz
vendor_cmsdk-343245f4e6331b1059240150e62e0c9a9d8d3a54.tar.bz2
Add API to cancel an active weather request
Add new API cancelRequest to CMWeatherManager. This will allow clients to cancel a request that was previuosly submitted to the weather service. As part of this change, requestWeatherUpdate(weatherLocation), requestWeatherUpdate(Location) and lookupCity(cityName) will now return the RequestInfo object created if the request was successfully submitted to the weather manager service TICKET: CYNGNOS-2383 TICKET: CYNGNOS-2385 Change-Id: Ic122f91e0ea8a24d81dbed48741ef1e33567b56c
Diffstat (limited to 'sdk')
-rw-r--r--sdk/src/java/cyanogenmod/weather/CMWeatherManager.java45
-rw-r--r--sdk/src/java/cyanogenmod/weather/ICMWeatherManager.aidl1
-rw-r--r--sdk/src/java/cyanogenmod/weather/RequestInfo.java4
-rw-r--r--sdk/src/java/cyanogenmod/weatherservice/IWeatherProviderService.aidl1
-rw-r--r--sdk/src/java/cyanogenmod/weatherservice/WeatherProviderService.java38
5 files changed, 76 insertions, 13 deletions
diff --git a/sdk/src/java/cyanogenmod/weather/CMWeatherManager.java b/sdk/src/java/cyanogenmod/weather/CMWeatherManager.java
index 32eab52..3ab510e 100644
--- a/sdk/src/java/cyanogenmod/weather/CMWeatherManager.java
+++ b/sdk/src/java/cyanogenmod/weather/CMWeatherManager.java
@@ -131,11 +131,14 @@ public class CMWeatherManager {
* @param listener {@link WeatherUpdateRequestListener} To be notified once the active weather
* service provider has finished
* processing your request
+ * @return A {@link RequestInfo} identifying the request submitted to the weather service.
+ * Note that this method might return null if an error occurred while trying to submit
+ * the request.
*/
- public void requestWeatherUpdate(@NonNull Location location,
+ public RequestInfo requestWeatherUpdate(@NonNull Location location,
@NonNull WeatherUpdateRequestListener listener) {
if (sWeatherManagerService == null) {
- return;
+ return null;
}
try {
@@ -145,7 +148,9 @@ public class CMWeatherManager {
.build();
if (listener != null) mWeatherUpdateRequestListeners.put(info, listener);
sWeatherManagerService.updateWeather(info);
+ return info;
} catch (RemoteException e) {
+ return null;
}
}
@@ -159,11 +164,14 @@ public class CMWeatherManager {
* @param listener {@link WeatherUpdateRequestListener} To be notified once the active weather
* service provider has finished
* processing your request
+ * @return A {@link RequestInfo} identifying the request submitted to the weather service.
+ * Note that this method might return null if an error occurred while trying to submit
+ * the request.
*/
- public void requestWeatherUpdate(@NonNull WeatherLocation weatherLocation,
+ public RequestInfo requestWeatherUpdate(@NonNull WeatherLocation weatherLocation,
@NonNull WeatherUpdateRequestListener listener) {
if (sWeatherManagerService == null) {
- return;
+ return null;
}
try {
@@ -173,7 +181,9 @@ public class CMWeatherManager {
.build();
if (listener != null) mWeatherUpdateRequestListeners.put(info, listener);
sWeatherManagerService.updateWeather(info);
+ return info;
} catch (RemoteException e) {
+ return null;
}
}
@@ -185,10 +195,13 @@ public class CMWeatherManager {
* completed. Upon success, a list of
* {@link cyanogenmod.weather.WeatherLocation}
* will be provided
+ * @return A {@link RequestInfo} identifying the request submitted to the weather service.
+ * Note that this method might return null if an error occurred while trying to submit
+ * the request.
*/
- public void lookupCity(@NonNull String city, @NonNull LookupCityRequestListener listener) {
+ public RequestInfo lookupCity(@NonNull String city, @NonNull LookupCityRequestListener listener) {
if (sWeatherManagerService == null) {
- return;
+ return null;
}
try {
RequestInfo info = new RequestInfo
@@ -197,7 +210,27 @@ public class CMWeatherManager {
.build();
if (listener != null) mLookupNameRequestListeners.put(info, listener);
sWeatherManagerService.lookupCity(info);
+ return info;
} catch (RemoteException e) {
+ return null;
+ }
+ }
+
+ /**
+ * Cancels a request that was previously submitted to the weather service.
+ * @param info The {@link RequestInfo} that you received when the request was submitted
+ */
+ public void cancelRequest(RequestInfo info) {
+ if (sWeatherManagerService == null) {
+ return;
+ }
+ if (info == null) {
+ return;
+ }
+
+ try {
+ sWeatherManagerService.cancelRequest(info);
+ }catch (RemoteException e){
}
}
diff --git a/sdk/src/java/cyanogenmod/weather/ICMWeatherManager.aidl b/sdk/src/java/cyanogenmod/weather/ICMWeatherManager.aidl
index 21e1d26..8caac49 100644
--- a/sdk/src/java/cyanogenmod/weather/ICMWeatherManager.aidl
+++ b/sdk/src/java/cyanogenmod/weather/ICMWeatherManager.aidl
@@ -28,4 +28,5 @@ interface ICMWeatherManager {
oneway void unregisterWeatherServiceProviderChangeListener(
in IWeatherServiceProviderChangeListener listener);
String getActiveWeatherServiceProviderLabel();
+ oneway void cancelRequest(in RequestInfo info);
} \ No newline at end of file
diff --git a/sdk/src/java/cyanogenmod/weather/RequestInfo.java b/sdk/src/java/cyanogenmod/weather/RequestInfo.java
index 353b5fd..4086c62 100644
--- a/sdk/src/java/cyanogenmod/weather/RequestInfo.java
+++ b/sdk/src/java/cyanogenmod/weather/RequestInfo.java
@@ -85,7 +85,7 @@ public final class RequestInfo implements Parcelable {
* set, will null out the city name and weather location.
*/
public Builder setLocation(Location location) {
- this.mLocation = location;
+ this.mLocation = new Location(location);
this.mCityName = null;
this.mWeatherLocation = null;
this.mRequestType = TYPE_GEO_LOCATION_REQ;
@@ -208,7 +208,7 @@ public final class RequestInfo implements Parcelable {
* otherwise
*/
public Location getLocation() {
- return mLocation;
+ return new Location(mLocation);
}
/**
diff --git a/sdk/src/java/cyanogenmod/weatherservice/IWeatherProviderService.aidl b/sdk/src/java/cyanogenmod/weatherservice/IWeatherProviderService.aidl
index d9eceb3..2a1deb5 100644
--- a/sdk/src/java/cyanogenmod/weatherservice/IWeatherProviderService.aidl
+++ b/sdk/src/java/cyanogenmod/weatherservice/IWeatherProviderService.aidl
@@ -25,4 +25,5 @@ oneway interface IWeatherProviderService {
void processCityNameLookupRequest(in RequestInfo request);
void setServiceClient(in IWeatherProviderServiceClient client);
void cancelOngoingRequests();
+ void cancelRequest(in RequestInfo request);
} \ No newline at end of file
diff --git a/sdk/src/java/cyanogenmod/weatherservice/WeatherProviderService.java b/sdk/src/java/cyanogenmod/weatherservice/WeatherProviderService.java
index 759d5fc..8a1f30c 100644
--- a/sdk/src/java/cyanogenmod/weatherservice/WeatherProviderService.java
+++ b/sdk/src/java/cyanogenmod/weatherservice/WeatherProviderService.java
@@ -35,8 +35,8 @@ import java.util.WeakHashMap;
* can handle weather update requests and update the weather content provider data by processing
* a {@link ServiceRequest}
*
- * A print service is declared as any other service in an AndroidManifest.xml but it must also
- * specify that in handles the {@link android.content.Intent} with action
+ * A weather provider service is declared as any other service in an AndroidManifest.xml but it must
+ * also specify that in handles the {@link android.content.Intent} with action
* {@link #SERVICE_INTERFACE cyanogenmod.weatherservice.WeatherProviderService}. Failure to declare
* this intent will cause the system to ignore the weather provider service. Additionally, a
* weather provider service must request the
@@ -108,7 +108,13 @@ public abstract class WeatherProviderService extends Service {
@Override
public void cancelOngoingRequests() {
- mHandler.obtainMessage(ServiceHandler.MSG_CANCEL_ONGOING_REQUESTS).sendToTarget();
+ mHandler.obtainMessage(ServiceHandler.MSG_CANCEL_ALL_OUTSTANDING_REQUESTS)
+ .sendToTarget();
+ }
+
+ @Override
+ public void cancelRequest(RequestInfo info) {
+ mHandler.obtainMessage(ServiceHandler.MSG_CANCEL_REQUEST, info).sendToTarget();
}
};
@@ -119,7 +125,8 @@ public abstract class WeatherProviderService extends Service {
}
public static final int MSG_SET_CLIENT = 1;
public static final int MSG_ON_NEW_REQUEST = 2;
- public static final int MSG_CANCEL_ONGOING_REQUESTS = 3;
+ public static final int MSG_CANCEL_ALL_OUTSTANDING_REQUESTS = 3;
+ public static final int MSG_CANCEL_REQUEST = 4;
@Override
public void handleMessage(Message msg) {
@@ -144,7 +151,7 @@ public abstract class WeatherProviderService extends Service {
}
return;
}
- case MSG_CANCEL_ONGOING_REQUESTS: {
+ case MSG_CANCEL_ALL_OUTSTANDING_REQUESTS: {
synchronized (mWeakRequestsSet) {
for (final ServiceRequest request : mWeakRequestsSet) {
if (request != null) {
@@ -159,6 +166,27 @@ public abstract class WeatherProviderService extends Service {
}
}
}
+ return;
+ }
+ case MSG_CANCEL_REQUEST: {
+ synchronized (mWeakRequestsSet) {
+ RequestInfo info = (RequestInfo) msg.obj;
+ if (info == null) return;
+ for (final ServiceRequest request : mWeakRequestsSet) {
+ if (request.getRequestInfo().equals(info)) {
+ request.cancel();
+ mWeakRequestsSet.remove(request);
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ onRequestCancelled(request);
+ }
+ });
+ break;
+ }
+ }
+ }
+ return;
}
}
}