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(
|
public void registerWeatherServiceProviderChangeListener(
|
||||||
@NonNull WeatherServiceProviderChangeListener listener) {
|
@NonNull WeatherServiceProviderChangeListener listener) {
|
||||||
|
if (sWeatherManagerService == null) return;
|
||||||
|
|
||||||
synchronized (mProviderChangedListeners) {
|
synchronized (mProviderChangedListeners) {
|
||||||
if (mProviderChangedListeners.contains(listener)) {
|
if (mProviderChangedListeners.contains(listener)) {
|
||||||
throw new IllegalArgumentException("Listener already registered");
|
throw new IllegalArgumentException("Listener already registered");
|
||||||
@ -267,6 +269,8 @@ public class CMWeatherManager {
|
|||||||
*/
|
*/
|
||||||
public void unregisterWeatherServiceProviderChangeListener(
|
public void unregisterWeatherServiceProviderChangeListener(
|
||||||
@NonNull WeatherServiceProviderChangeListener listener) {
|
@NonNull WeatherServiceProviderChangeListener listener) {
|
||||||
|
if (sWeatherManagerService == null) return;
|
||||||
|
|
||||||
synchronized (mProviderChangedListeners) {
|
synchronized (mProviderChangedListeners) {
|
||||||
if (!mProviderChangedListeners.contains(listener)) {
|
if (!mProviderChangedListeners.contains(listener)) {
|
||||||
throw new IllegalArgumentException("Listener was never registered");
|
throw new IllegalArgumentException("Listener was never registered");
|
||||||
@ -287,6 +291,8 @@ public class CMWeatherManager {
|
|||||||
* @return the service's label
|
* @return the service's label
|
||||||
*/
|
*/
|
||||||
public String getActiveWeatherServiceProviderLabel() {
|
public String getActiveWeatherServiceProviderLabel() {
|
||||||
|
if (sWeatherManagerService == null) return null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return sWeatherManagerService.getActiveWeatherServiceProviderLabel();
|
return sWeatherManagerService.getActiveWeatherServiceProviderLabel();
|
||||||
} catch(RemoteException e){
|
} catch(RemoteException e){
|
||||||
|
Loading…
Reference in New Issue
Block a user