cmsdk: Prevent NPE in CMWeatherManager
Verify that we have an instance of to the weather manager service before we try to register/unregister a listener or query the current weather provider. Change-Id: Iec09073615f85626c6f64e4a55758aae52231ca8
This commit is contained in:
parent
ee2dc2db08
commit
46bed1698d
@ -246,6 +246,8 @@ public class CMWeatherManager {
|
||||
*/
|
||||
public void registerWeatherServiceProviderChangeListener(
|
||||
@NonNull WeatherServiceProviderChangeListener listener) {
|
||||
if (sWeatherManagerService == null) return;
|
||||
|
||||
synchronized (mProviderChangedListeners) {
|
||||
if (mProviderChangedListeners.contains(listener)) {
|
||||
throw new IllegalArgumentException("Listener already registered");
|
||||
@ -267,6 +269,8 @@ public class CMWeatherManager {
|
||||
*/
|
||||
public void unregisterWeatherServiceProviderChangeListener(
|
||||
@NonNull WeatherServiceProviderChangeListener listener) {
|
||||
if (sWeatherManagerService == null) return;
|
||||
|
||||
synchronized (mProviderChangedListeners) {
|
||||
if (!mProviderChangedListeners.contains(listener)) {
|
||||
throw new IllegalArgumentException("Listener was never registered");
|
||||
@ -287,6 +291,8 @@ public class CMWeatherManager {
|
||||
* @return the service's label
|
||||
*/
|
||||
public String getActiveWeatherServiceProviderLabel() {
|
||||
if (sWeatherManagerService == null) return null;
|
||||
|
||||
try {
|
||||
return sWeatherManagerService.getActiveWeatherServiceProviderLabel();
|
||||
} catch(RemoteException e){
|
||||
|
Loading…
Reference in New Issue
Block a user