зеркало из https://github.com/mozilla/pjs.git
Bug 742216: Battery sensor cleanup in the similar lines of GeckoConnectivityReceiver. [r=mfinkle]
This commit is contained in:
Родитель
499282017e
Коммит
0bef526bac
|
@ -129,7 +129,7 @@ abstract public class GeckoApp
|
||||||
public static int mOrientation;
|
public static int mOrientation;
|
||||||
|
|
||||||
private GeckoConnectivityReceiver mConnectivityReceiver;
|
private GeckoConnectivityReceiver mConnectivityReceiver;
|
||||||
private BroadcastReceiver mBatteryReceiver;
|
private GeckoBatteryManager mBatteryReceiver;
|
||||||
|
|
||||||
public static BrowserToolbar mBrowserToolbar;
|
public static BrowserToolbar mBrowserToolbar;
|
||||||
public static DoorHangerPopup mDoorHangerPopup;
|
public static DoorHangerPopup mDoorHangerPopup;
|
||||||
|
@ -1731,15 +1731,13 @@ abstract public class GeckoApp
|
||||||
GeckoAppShell.registerGeckoEventListener("Session:StatePurged", GeckoApp.mAppContext);
|
GeckoAppShell.registerGeckoEventListener("Session:StatePurged", GeckoApp.mAppContext);
|
||||||
GeckoAppShell.registerGeckoEventListener("Bookmark:Insert", GeckoApp.mAppContext);
|
GeckoAppShell.registerGeckoEventListener("Bookmark:Insert", GeckoApp.mAppContext);
|
||||||
|
|
||||||
IntentFilter batteryFilter = new IntentFilter();
|
|
||||||
batteryFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
|
|
||||||
mBatteryReceiver = new GeckoBatteryManager();
|
|
||||||
registerReceiver(mBatteryReceiver, batteryFilter);
|
|
||||||
|
|
||||||
if (SmsManager.getInstance() != null) {
|
if (SmsManager.getInstance() != null) {
|
||||||
SmsManager.getInstance().start();
|
SmsManager.getInstance().start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mBatteryReceiver = new GeckoBatteryManager();
|
||||||
|
mBatteryReceiver.registerFor(mAppContext);
|
||||||
|
|
||||||
mConnectivityReceiver = new GeckoConnectivityReceiver();
|
mConnectivityReceiver = new GeckoConnectivityReceiver();
|
||||||
mConnectivityReceiver.registerFor(mAppContext);
|
mConnectivityReceiver.registerFor(mAppContext);
|
||||||
|
|
||||||
|
@ -2088,7 +2086,7 @@ abstract public class GeckoApp
|
||||||
|
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
|
||||||
unregisterReceiver(mBatteryReceiver);
|
mBatteryReceiver.unregisterFor(mAppContext);
|
||||||
|
|
||||||
if (mAboutHomeContent != null) {
|
if (mAboutHomeContent != null) {
|
||||||
mAboutHomeContent.onDestroy();
|
mAboutHomeContent.onDestroy();
|
||||||
|
|
|
@ -42,10 +42,11 @@ import java.util.Date;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
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;
|
||||||
|
@ -68,6 +69,24 @@ public class GeckoBatteryManager
|
||||||
private static boolean sCharging = kDefaultCharging;
|
private static boolean sCharging = kDefaultCharging;
|
||||||
private static double sRemainingTime = kDefaultRemainingTime;;
|
private static double sRemainingTime = kDefaultRemainingTime;;
|
||||||
|
|
||||||
|
private static boolean isRegistered = false;
|
||||||
|
|
||||||
|
public void registerFor(Activity activity) {
|
||||||
|
if (!isRegistered) {
|
||||||
|
IntentFilter filter = new IntentFilter();
|
||||||
|
filter.addAction(Intent.ACTION_BATTERY_CHANGED);
|
||||||
|
activity.registerReceiver(this, filter);
|
||||||
|
isRegistered = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unregisterFor(Activity activity) {
|
||||||
|
if (isRegistered) {
|
||||||
|
activity.unregisterReceiver(this);
|
||||||
|
isRegistered = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (!intent.getAction().equals(Intent.ACTION_BATTERY_CHANGED)) {
|
if (!intent.getAction().equals(Intent.ACTION_BATTERY_CHANGED)) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче