summaryrefslogtreecommitdiffstats
path: root/services/core/java/com/android/server/job
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2015-04-08 16:55:47 -0700
committerDianne Hackborn <hackbod@google.com>2015-04-09 14:05:17 -0700
commit4870e9d5eba59fb257a87f97f1adf0b734cf48d3 (patch)
tree5162b64339f8b47f807c7b709a832be0c1574676 /services/core/java/com/android/server/job
parent7c6a34e64a52b71a6ea00efd2127a4814b5c72a6 (diff)
downloadframeworks_base-4870e9d5eba59fb257a87f97f1adf0b734cf48d3.zip
frameworks_base-4870e9d5eba59fb257a87f97f1adf0b734cf48d3.tar.gz
frameworks_base-4870e9d5eba59fb257a87f97f1adf0b734cf48d3.tar.bz2
More work on device idle mode and other power stuff.
Add idle mode support to the alarm manager. Introduce a new concept of flags associated with alarms to tell the alarm manager how to treat the alarm -- they allow everything from the alarm that will bring us out of idle mode, to alarms that are allowed when idle or should also bring us out of idle. The standalone boolean is now also a flag. (Note there is currently no protection from user space setting the flags however it wants; I will be working on that in a follow-up change.) When in idle mode, the alarm manager pushes all alarms that shouldn't execute during that time over to a separate list that is not executed until out of idle. To help with this, I reworked a bit how Alarm objects are managed, so that when rebatching or moving between lists we don't have to allocated new objects but can just use the same existing instance. Also tweaked the sync manager to deal with idle mode, which currently just means doing the same thing as when low on storage -- turning off sync. Add new ACTION_CHARGING and ACTION_DISCHARGING broadcasts that apps can listen for to know when the device is actively charging and discharging. These are better than the old POWER_CONNECTED and POWER_DISCONNECTED ones because we only report charging when we actually see that there is enough power being provided to charge the battery (and will report discharging if there is not enough power). The job controller uses these new actions for scheduling jobs that want to run while plugged in. Removed the "stable charging" stuff while doing so, since the new charging state serves as an even better signal for that. Introduced two new process states: FOREGROUND_SERVICE and TOP_SLEEPING. This will allow us to treat foreground services specially (such as still allowing network access to them for background music playback) while not mixing them together with whatever happens to be the top activity while the device is asleep. Also some other small cleanup here and there. Change-Id: I7a9808b578bad6f50deb8e1baf919298512a0d3a
Diffstat (limited to 'services/core/java/com/android/server/job')
-rw-r--r--services/core/java/com/android/server/job/controllers/BatteryController.java54
1 files changed, 8 insertions, 46 deletions
diff --git a/services/core/java/com/android/server/job/controllers/BatteryController.java b/services/core/java/com/android/server/job/controllers/BatteryController.java
index 309e034..7c2aead 100644
--- a/services/core/java/com/android/server/job/controllers/BatteryController.java
+++ b/services/core/java/com/android/server/job/controllers/BatteryController.java
@@ -47,10 +47,6 @@ public class BatteryController extends StateController {
private static final Object sCreationLock = new Object();
private static volatile BatteryController sController;
- private static final String ACTION_CHARGING_STABLE =
- "com.android.server.task.controllers.BatteryController.ACTION_CHARGING_STABLE";
- /** Wait this long after phone is plugged in before doing any work. */
- private static final long STABLE_CHARGING_THRESHOLD_MILLIS = 2 * 60 * 1000; // 2 minutes.
private List<JobStatus> mTrackedTasks = new ArrayList<JobStatus>();
private ChargingTracker mChargeTracker;
@@ -91,9 +87,6 @@ public class BatteryController extends StateController {
taskStatus.chargingConstraintSatisfied.set(isOnStablePower);
}
}
- if (isOnStablePower) {
- mChargeTracker.setStableChargingAlarm();
- }
}
@Override
@@ -131,8 +124,6 @@ public class BatteryController extends StateController {
}
public class ChargingTracker extends BroadcastReceiver {
- private final AlarmManager mAlarm;
- private final PendingIntent mStableChargingTriggerIntent;
/**
* Track whether we're "charging", where charging means that we're ready to commit to
* doing work.
@@ -142,9 +133,6 @@ public class BatteryController extends StateController {
private boolean mBatteryHealthy;
public ChargingTracker() {
- mAlarm = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
- Intent intent = new Intent(ACTION_CHARGING_STABLE);
- mStableChargingTriggerIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
}
public void startTracking() {
@@ -154,10 +142,8 @@ public class BatteryController extends StateController {
filter.addAction(Intent.ACTION_BATTERY_LOW);
filter.addAction(Intent.ACTION_BATTERY_OKAY);
// Charging/not charging.
- filter.addAction(Intent.ACTION_POWER_CONNECTED);
- filter.addAction(Intent.ACTION_POWER_DISCONNECTED);
- // Charging stable.
- filter.addAction(ACTION_CHARGING_STABLE);
+ filter.addAction(BatteryManager.ACTION_CHARGING);
+ filter.addAction(BatteryManager.ACTION_DISCHARGING);
mContext.registerReceiver(this, filter);
// Initialise tracker state.
@@ -195,44 +181,20 @@ public class BatteryController extends StateController {
}
mBatteryHealthy = true;
maybeReportNewChargingState();
- } else if (Intent.ACTION_POWER_CONNECTED.equals(action)) {
+ } else if (BatteryManager.ACTION_CHARGING.equals(action)) {
if (DEBUG) {
- Slog.d(TAG, "Received charging intent, setting alarm for "
- + STABLE_CHARGING_THRESHOLD_MILLIS);
+ Slog.d(TAG, "Received charging intent, fired @ "
+ + SystemClock.elapsedRealtime());
}
- // Set up an alarm for ACTION_CHARGING_STABLE - we don't want to kick off tasks
- // here if the user unplugs the phone immediately.
- setStableChargingAlarm();
mCharging = true;
- } else if (Intent.ACTION_POWER_DISCONNECTED.equals(action)) {
+ maybeReportNewChargingState();
+ } else if (BatteryManager.ACTION_DISCHARGING.equals(action)) {
if (DEBUG) {
- Slog.d(TAG, "Disconnected from power, cancelling any set alarms.");
+ Slog.d(TAG, "Disconnected from power.");
}
- // If an alarm is set, breathe a sigh of relief and cancel it - crisis averted.
- mAlarm.cancel(mStableChargingTriggerIntent);
mCharging = false;
maybeReportNewChargingState();
- }else if (ACTION_CHARGING_STABLE.equals(action)) {
- // Here's where we actually do the notify for a task being ready.
- if (DEBUG) {
- Slog.d(TAG, "Stable charging fired @ " + SystemClock.elapsedRealtime()
- + " charging: " + mCharging);
- }
- if (mCharging) { // Should never receive this intent if mCharging is false.
- maybeReportNewChargingState();
- }
- }
- }
-
- void setStableChargingAlarm() {
- final long alarmTriggerElapsed =
- SystemClock.elapsedRealtime() + STABLE_CHARGING_THRESHOLD_MILLIS;
- if (DEBUG) {
- Slog.d(TAG, "Setting stable alarm to go off in " +
- (STABLE_CHARGING_THRESHOLD_MILLIS / 1000) + "s");
}
- mAlarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, alarmTriggerElapsed,
- mStableChargingTriggerIntent);
}
}