зеркало из https://github.com/mozilla/gecko-dev.git
Bug 744850 - java.lang.IllegalArgumentException: Receiver not registered (ignore the crash) r=kats
This commit is contained in:
Родитель
691bab3d66
Коммит
e2b18e817b
|
@ -8,8 +8,6 @@ package org.mozilla.gecko;
|
||||||
import java.lang.Math;
|
import java.lang.Math;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
@ -18,11 +16,12 @@ import android.content.IntentFilter;
|
||||||
import android.os.BatteryManager;
|
import android.os.BatteryManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
public class GeckoBatteryManager
|
public class GeckoBatteryManager
|
||||||
extends BroadcastReceiver
|
extends BroadcastReceiver
|
||||||
{
|
{
|
||||||
private static final String LOGTAG = "GeckoBatteryManager";
|
private static final String LOGTAG = "GeckoBatteryManager";
|
||||||
|
|
||||||
// Those constants should be keep in sync with the ones in:
|
// Those constants should be keep in sync with the ones in:
|
||||||
// dom/battery/Constants.h
|
// dom/battery/Constants.h
|
||||||
|
@ -44,7 +43,7 @@ public class GeckoBatteryManager
|
||||||
IntentFilter filter = new IntentFilter();
|
IntentFilter filter = new IntentFilter();
|
||||||
filter.addAction(Intent.ACTION_BATTERY_CHANGED);
|
filter.addAction(Intent.ACTION_BATTERY_CHANGED);
|
||||||
|
|
||||||
// registerReciever can return null if registering fails
|
// registerReceiver can return null if registering fails
|
||||||
isRegistered = activity.registerReceiver(this, filter) != null;
|
isRegistered = activity.registerReceiver(this, filter) != null;
|
||||||
if (!isRegistered)
|
if (!isRegistered)
|
||||||
Log.e(LOGTAG, "Registering receiver failed");
|
Log.e(LOGTAG, "Registering receiver failed");
|
||||||
|
@ -53,7 +52,11 @@ public class GeckoBatteryManager
|
||||||
|
|
||||||
public void unregisterFor(Activity activity) {
|
public void unregisterFor(Activity activity) {
|
||||||
if (isRegistered) {
|
if (isRegistered) {
|
||||||
activity.unregisterReceiver(this);
|
try {
|
||||||
|
activity.unregisterReceiver(this);
|
||||||
|
} catch (IllegalArgumentException iae) {
|
||||||
|
Log.e(LOGTAG, "Unregistering receiver failed", iae);
|
||||||
|
}
|
||||||
isRegistered = false;
|
isRegistered = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,6 @@
|
||||||
|
|
||||||
package org.mozilla.gecko;
|
package org.mozilla.gecko;
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
@ -14,6 +12,7 @@ import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
public class GeckoConnectivityReceiver extends BroadcastReceiver {
|
public class GeckoConnectivityReceiver extends BroadcastReceiver {
|
||||||
/*
|
/*
|
||||||
|
@ -24,7 +23,7 @@ public class GeckoConnectivityReceiver extends BroadcastReceiver {
|
||||||
private static final String LINK_DATA_DOWN = "down";
|
private static final String LINK_DATA_DOWN = "down";
|
||||||
private static final String LINK_DATA_UNKNOWN = "unknown";
|
private static final String LINK_DATA_UNKNOWN = "unknown";
|
||||||
|
|
||||||
private static final String LOGTAG = "GeckoConnectivityReciever";
|
private static final String LOGTAG = "GeckoConnectivityReceiver";
|
||||||
|
|
||||||
private IntentFilter mFilter;
|
private IntentFilter mFilter;
|
||||||
|
|
||||||
|
@ -54,7 +53,7 @@ public class GeckoConnectivityReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
public void registerFor(Activity activity) {
|
public void registerFor(Activity activity) {
|
||||||
if (!isRegistered) {
|
if (!isRegistered) {
|
||||||
// registerReciever will return null if registering throws a RemoteException
|
// registerReciever will return null if registering fails
|
||||||
isRegistered = activity.registerReceiver(this, mFilter) != null;
|
isRegistered = activity.registerReceiver(this, mFilter) != null;
|
||||||
if (!isRegistered)
|
if (!isRegistered)
|
||||||
Log.e(LOGTAG, "Registering receiver failed");
|
Log.e(LOGTAG, "Registering receiver failed");
|
||||||
|
@ -63,7 +62,11 @@ public class GeckoConnectivityReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
public void unregisterFor(Activity activity) {
|
public void unregisterFor(Activity activity) {
|
||||||
if (isRegistered) {
|
if (isRegistered) {
|
||||||
activity.unregisterReceiver(this);
|
try {
|
||||||
|
activity.unregisterReceiver(this);
|
||||||
|
} catch (IllegalArgumentException iae) {
|
||||||
|
Log.e(LOGTAG, "Unregistering receiver failed", iae);
|
||||||
|
}
|
||||||
isRegistered = false;
|
isRegistered = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче