Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 17 | package com.android.server.job.controllers; |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 18 | |
Jeff Sharkey | 1b6519b | 2016-04-28 15:33:18 -0600 | [diff] [blame] | 19 | import android.app.job.JobInfo; |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 20 | import android.content.Context; |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 21 | import android.net.ConnectivityManager; |
Christopher Tate | 8bbe704 | 2017-03-15 11:07:46 -0700 | [diff] [blame] | 22 | import android.net.ConnectivityManager.NetworkCallback; |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 23 | import android.net.INetworkPolicyListener; |
Christopher Tate | 8bbe704 | 2017-03-15 11:07:46 -0700 | [diff] [blame] | 24 | import android.net.Network; |
| 25 | import android.net.NetworkCapabilities; |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 26 | import android.net.NetworkInfo; |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 27 | import android.net.NetworkPolicyManager; |
Jeff Sharkey | caa3f8d | 2017-10-25 16:12:00 -0600 | [diff] [blame] | 28 | import android.net.TrafficStats; |
Christopher Tate | 8bbe704 | 2017-03-15 11:07:46 -0700 | [diff] [blame] | 29 | import android.os.Process; |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 30 | import android.os.UserHandle; |
Jeff Sharkey | caa3f8d | 2017-10-25 16:12:00 -0600 | [diff] [blame] | 31 | import android.text.format.DateUtils; |
Dianne Hackborn | f9bac16 | 2017-04-20 17:17:48 -0700 | [diff] [blame] | 32 | import android.util.ArraySet; |
Matthew Williams | 9b9244b6 | 2014-05-14 11:06:04 -0700 | [diff] [blame] | 33 | import android.util.Slog; |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 34 | |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 35 | import com.android.internal.annotations.GuardedBy; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 36 | import com.android.server.job.JobSchedulerService; |
Jeff Sharkey | caa3f8d | 2017-10-25 16:12:00 -0600 | [diff] [blame] | 37 | import com.android.server.job.JobServiceContext; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 38 | import com.android.server.job.StateChangedListener; |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 39 | |
Matthew Williams | effacfa | 2014-06-05 20:56:40 -0700 | [diff] [blame] | 40 | import java.io.PrintWriter; |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 41 | |
| 42 | /** |
Matthew Williams | 9b9244b6 | 2014-05-14 11:06:04 -0700 | [diff] [blame] | 43 | * Handles changes in connectivity. |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 44 | * <p> |
| 45 | * Each app can have a different default networks or different connectivity |
| 46 | * status due to user-requested network policies, so we need to check |
| 47 | * constraints on a per-UID basis. |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 48 | */ |
Dianne Hackborn | 6466c1c | 2017-06-13 10:33:19 -0700 | [diff] [blame] | 49 | public final class ConnectivityController extends StateController implements |
Matthew Williams | effacfa | 2014-06-05 20:56:40 -0700 | [diff] [blame] | 50 | ConnectivityManager.OnNetworkActiveListener { |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 51 | private static final String TAG = "JobScheduler.Conn"; |
Christopher Tate | 8bbe704 | 2017-03-15 11:07:46 -0700 | [diff] [blame] | 52 | private static final boolean DEBUG = false; |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 53 | |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 54 | private final ConnectivityManager mConnManager; |
| 55 | private final NetworkPolicyManager mNetPolicyManager; |
Christopher Tate | 8bbe704 | 2017-03-15 11:07:46 -0700 | [diff] [blame] | 56 | private boolean mConnected; |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 57 | |
| 58 | @GuardedBy("mLock") |
Dianne Hackborn | f9bac16 | 2017-04-20 17:17:48 -0700 | [diff] [blame] | 59 | private final ArraySet<JobStatus> mTrackedJobs = new ArraySet<>(); |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 60 | |
Matthew Williams | 9b9244b6 | 2014-05-14 11:06:04 -0700 | [diff] [blame] | 61 | /** Singleton. */ |
| 62 | private static ConnectivityController mSingleton; |
Matthew Williams | effacfa | 2014-06-05 20:56:40 -0700 | [diff] [blame] | 63 | private static Object sCreationLock = new Object(); |
Matthew Williams | 691e93e | 2014-05-12 15:33:09 -0700 | [diff] [blame] | 64 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 65 | public static ConnectivityController get(JobSchedulerService jms) { |
Matthew Williams | effacfa | 2014-06-05 20:56:40 -0700 | [diff] [blame] | 66 | synchronized (sCreationLock) { |
| 67 | if (mSingleton == null) { |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 68 | mSingleton = new ConnectivityController(jms, jms.getContext(), jms.getLock()); |
Matthew Williams | effacfa | 2014-06-05 20:56:40 -0700 | [diff] [blame] | 69 | } |
| 70 | return mSingleton; |
Matthew Williams | 9b9244b6 | 2014-05-14 11:06:04 -0700 | [diff] [blame] | 71 | } |
Matthew Williams | 9b9244b6 | 2014-05-14 11:06:04 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 74 | private ConnectivityController(StateChangedListener stateChangedListener, Context context, |
| 75 | Object lock) { |
| 76 | super(stateChangedListener, context, lock); |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 77 | |
| 78 | mConnManager = mContext.getSystemService(ConnectivityManager.class); |
| 79 | mNetPolicyManager = mContext.getSystemService(NetworkPolicyManager.class); |
| 80 | |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 81 | mConnected = false; |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 82 | |
Christopher Tate | 8bbe704 | 2017-03-15 11:07:46 -0700 | [diff] [blame] | 83 | mConnManager.registerDefaultNetworkCallback(mNetworkCallback); |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 84 | mNetPolicyManager.registerListener(mNetPolicyListener); |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | @Override |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 88 | public void maybeStartTrackingJobLocked(JobStatus jobStatus, JobStatus lastJob) { |
Christopher Tate | 60977f4 | 2017-04-13 13:48:46 -0700 | [diff] [blame] | 89 | if (jobStatus.hasConnectivityConstraint()) { |
Jeff Sharkey | 43d2a17 | 2017-07-12 10:50:42 -0600 | [diff] [blame] | 90 | updateConstraintsSatisfied(jobStatus); |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 91 | mTrackedJobs.add(jobStatus); |
Dianne Hackborn | f9bac16 | 2017-04-20 17:17:48 -0700 | [diff] [blame] | 92 | jobStatus.setTrackingController(JobStatus.TRACKING_CONNECTIVITY); |
Matthew Williams | effacfa | 2014-06-05 20:56:40 -0700 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | |
| 96 | @Override |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 97 | public void maybeStopTrackingJobLocked(JobStatus jobStatus, JobStatus incomingJob, |
| 98 | boolean forUpdate) { |
Dianne Hackborn | f9bac16 | 2017-04-20 17:17:48 -0700 | [diff] [blame] | 99 | if (jobStatus.clearTrackingController(JobStatus.TRACKING_CONNECTIVITY)) { |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 100 | mTrackedJobs.remove(jobStatus); |
Matthew Williams | effacfa | 2014-06-05 20:56:40 -0700 | [diff] [blame] | 101 | } |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Jeff Sharkey | caa3f8d | 2017-10-25 16:12:00 -0600 | [diff] [blame] | 104 | /** |
| 105 | * Test to see if running the given job on the given network is sane. |
| 106 | * <p> |
| 107 | * For example, if a job is trying to send 10MB over a 128Kbps EDGE |
| 108 | * connection, it would take 10.4 minutes, and has no chance of succeeding |
| 109 | * before the job times out, so we'd be insane to try running it. |
| 110 | */ |
| 111 | private boolean isSane(JobStatus jobStatus, NetworkCapabilities capabilities) { |
| 112 | final long estimatedBytes = jobStatus.getEstimatedNetworkBytes(); |
| 113 | if (estimatedBytes == JobInfo.NETWORK_BYTES_UNKNOWN) { |
| 114 | // We don't know how large the job is; cross our fingers! |
| 115 | return true; |
| 116 | } |
| 117 | if (capabilities == null) { |
| 118 | // We don't know what the network is like; cross our fingers! |
| 119 | return true; |
| 120 | } |
| 121 | |
| 122 | // We don't ask developers to differentiate between upstream/downstream |
| 123 | // in their size estimates, so test against the slowest link direction. |
| 124 | final long downstream = capabilities.getLinkDownstreamBandwidthKbps(); |
| 125 | final long upstream = capabilities.getLinkUpstreamBandwidthKbps(); |
| 126 | final long slowest; |
| 127 | if (downstream > 0 && upstream > 0) { |
| 128 | slowest = Math.min(downstream, upstream); |
| 129 | } else if (downstream > 0) { |
| 130 | slowest = downstream; |
| 131 | } else if (upstream > 0) { |
| 132 | slowest = upstream; |
| 133 | } else { |
| 134 | // We don't know what the network is like; cross our fingers! |
| 135 | return true; |
| 136 | } |
| 137 | |
| 138 | final long estimatedMillis = ((estimatedBytes * DateUtils.SECOND_IN_MILLIS) |
| 139 | / (slowest * TrafficStats.KB_IN_BYTES / 8)); |
| 140 | if (estimatedMillis > JobServiceContext.EXECUTING_TIMESLICE_MILLIS) { |
| 141 | // If we'd never finish before the timeout, we'd be insane! |
| 142 | Slog.w(TAG, "Estimated " + estimatedBytes + " bytes over " + slowest |
| 143 | + " kbps network would take " + estimatedMillis + "ms; that's insane!"); |
| 144 | return false; |
| 145 | } else { |
| 146 | return true; |
| 147 | } |
| 148 | } |
| 149 | |
Jeff Sharkey | 43d2a17 | 2017-07-12 10:50:42 -0600 | [diff] [blame] | 150 | private boolean updateConstraintsSatisfied(JobStatus jobStatus) { |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 151 | // TODO: consider matching against non-active networks |
| 152 | |
Christopher Tate | 8bbe704 | 2017-03-15 11:07:46 -0700 | [diff] [blame] | 153 | final int jobUid = jobStatus.getSourceUid(); |
Jeff Sharkey | 1b6519b | 2016-04-28 15:33:18 -0600 | [diff] [blame] | 154 | final boolean ignoreBlocked = (jobStatus.getFlags() & JobInfo.FLAG_WILL_BE_FOREGROUND) != 0; |
Jeff Sharkey | 43d2a17 | 2017-07-12 10:50:42 -0600 | [diff] [blame] | 155 | final Network network = mConnManager.getActiveNetworkForUid(jobUid, ignoreBlocked); |
Jeff Sharkey | caa3f8d | 2017-10-25 16:12:00 -0600 | [diff] [blame] | 156 | final NetworkInfo info = mConnManager.getNetworkInfoForUid(network, jobUid, ignoreBlocked); |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 157 | final NetworkCapabilities capabilities = mConnManager.getNetworkCapabilities(network); |
Christopher Tate | 8bbe704 | 2017-03-15 11:07:46 -0700 | [diff] [blame] | 158 | |
Jeff Sharkey | caa3f8d | 2017-10-25 16:12:00 -0600 | [diff] [blame] | 159 | final boolean connected = (info != null) && info.isConnected(); |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 160 | final boolean satisfied = jobStatus.getJob().getRequiredNetwork().networkCapabilities |
| 161 | .satisfiedByNetworkCapabilities(capabilities); |
Jeff Sharkey | caa3f8d | 2017-10-25 16:12:00 -0600 | [diff] [blame] | 162 | final boolean sane = isSane(jobStatus, capabilities); |
Jeff Sharkey | 43d2a17 | 2017-07-12 10:50:42 -0600 | [diff] [blame] | 163 | |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 164 | final boolean changed = jobStatus |
| 165 | .setConnectivityConstraintSatisfied(connected && satisfied && sane); |
Christopher Tate | 8bbe704 | 2017-03-15 11:07:46 -0700 | [diff] [blame] | 166 | |
Jeff Sharkey | 76a0241 | 2017-10-24 16:55:04 -0600 | [diff] [blame] | 167 | // Pass along the evaluated network for job to use; prevents race |
| 168 | // conditions as default routes change over time, and opens the door to |
| 169 | // using non-default routes. |
| 170 | jobStatus.network = network; |
| 171 | |
Christopher Tate | 8bbe704 | 2017-03-15 11:07:46 -0700 | [diff] [blame] | 172 | // Track system-uid connected/validated as a general reportable proxy for the |
| 173 | // overall state of connectivity constraint satisfiability. |
| 174 | if (jobUid == Process.SYSTEM_UID) { |
| 175 | mConnected = connected; |
Christopher Tate | 8bbe704 | 2017-03-15 11:07:46 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | if (DEBUG) { |
| 179 | Slog.i(TAG, "Connectivity " + (changed ? "CHANGED" : "unchanged") |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 180 | + " for " + jobStatus + ": connected=" + connected |
| 181 | + " satisfied=" + satisfied |
| 182 | + " sane=" + sane); |
Christopher Tate | 8bbe704 | 2017-03-15 11:07:46 -0700 | [diff] [blame] | 183 | } |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 184 | return changed; |
| 185 | } |
| 186 | |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 187 | /** |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 188 | * Update all jobs tracked by this controller. |
| 189 | * |
| 190 | * @param uid only update jobs belonging to this UID, or {@code -1} to |
| 191 | * update all tracked jobs. |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 192 | */ |
Jeff Sharkey | 43d2a17 | 2017-07-12 10:50:42 -0600 | [diff] [blame] | 193 | private void updateTrackedJobs(int uid) { |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 194 | synchronized (mLock) { |
Matthew Williams | effacfa | 2014-06-05 20:56:40 -0700 | [diff] [blame] | 195 | boolean changed = false; |
Dianne Hackborn | f9bac16 | 2017-04-20 17:17:48 -0700 | [diff] [blame] | 196 | for (int i = mTrackedJobs.size()-1; i >= 0; i--) { |
| 197 | final JobStatus js = mTrackedJobs.valueAt(i); |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 198 | if (uid == -1 || uid == js.getSourceUid()) { |
Jeff Sharkey | 43d2a17 | 2017-07-12 10:50:42 -0600 | [diff] [blame] | 199 | changed |= updateConstraintsSatisfied(js); |
Matthew Williams | effacfa | 2014-06-05 20:56:40 -0700 | [diff] [blame] | 200 | } |
Matthew Williams | effacfa | 2014-06-05 20:56:40 -0700 | [diff] [blame] | 201 | } |
| 202 | if (changed) { |
| 203 | mStateChangedListener.onControllerStateChanged(); |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 204 | } |
| 205 | } |
Matthew Williams | effacfa | 2014-06-05 20:56:40 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | /** |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 209 | * We know the network has just come up. We want to run any jobs that are ready. |
Matthew Williams | effacfa | 2014-06-05 20:56:40 -0700 | [diff] [blame] | 210 | */ |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 211 | @Override |
Dianne Hackborn | 532ea26 | 2017-03-17 17:50:55 -0700 | [diff] [blame] | 212 | public void onNetworkActive() { |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 213 | synchronized (mLock) { |
Dianne Hackborn | f9bac16 | 2017-04-20 17:17:48 -0700 | [diff] [blame] | 214 | for (int i = mTrackedJobs.size()-1; i >= 0; i--) { |
| 215 | final JobStatus js = mTrackedJobs.valueAt(i); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 216 | if (js.isReady()) { |
Matthew Williams | effacfa | 2014-06-05 20:56:40 -0700 | [diff] [blame] | 217 | if (DEBUG) { |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 218 | Slog.d(TAG, "Running " + js + " due to network activity."); |
Matthew Williams | effacfa | 2014-06-05 20:56:40 -0700 | [diff] [blame] | 219 | } |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 220 | mStateChangedListener.onRunJobNow(js); |
Matthew Williams | effacfa | 2014-06-05 20:56:40 -0700 | [diff] [blame] | 221 | } |
| 222 | } |
Matthew Williams | 9b9244b6 | 2014-05-14 11:06:04 -0700 | [diff] [blame] | 223 | } |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Christopher Tate | 8bbe704 | 2017-03-15 11:07:46 -0700 | [diff] [blame] | 226 | private final NetworkCallback mNetworkCallback = new NetworkCallback() { |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 227 | @Override |
Christopher Tate | 8bbe704 | 2017-03-15 11:07:46 -0700 | [diff] [blame] | 228 | public void onCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities) { |
| 229 | if (DEBUG) { |
| 230 | Slog.v(TAG, "onCapabilitiesChanged() : " + networkCapabilities); |
| 231 | } |
Jeff Sharkey | 43d2a17 | 2017-07-12 10:50:42 -0600 | [diff] [blame] | 232 | updateTrackedJobs(-1); |
Christopher Tate | 8bbe704 | 2017-03-15 11:07:46 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | @Override |
| 236 | public void onLost(Network network) { |
| 237 | if (DEBUG) { |
| 238 | Slog.v(TAG, "Network lost"); |
| 239 | } |
Jeff Sharkey | 43d2a17 | 2017-07-12 10:50:42 -0600 | [diff] [blame] | 240 | updateTrackedJobs(-1); |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 241 | } |
| 242 | }; |
| 243 | |
Christopher Tate | 8bbe704 | 2017-03-15 11:07:46 -0700 | [diff] [blame] | 244 | private final INetworkPolicyListener mNetPolicyListener = new INetworkPolicyListener.Stub() { |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 245 | @Override |
| 246 | public void onUidRulesChanged(int uid, int uidRules) { |
Christopher Tate | 8bbe704 | 2017-03-15 11:07:46 -0700 | [diff] [blame] | 247 | if (DEBUG) { |
| 248 | Slog.v(TAG, "Uid rules changed for " + uid); |
| 249 | } |
Jeff Sharkey | 43d2a17 | 2017-07-12 10:50:42 -0600 | [diff] [blame] | 250 | updateTrackedJobs(uid); |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | @Override |
| 254 | public void onMeteredIfacesChanged(String[] meteredIfaces) { |
Christopher Tate | 8bbe704 | 2017-03-15 11:07:46 -0700 | [diff] [blame] | 255 | // We track this via our NetworkCallback |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | @Override |
| 259 | public void onRestrictBackgroundChanged(boolean restrictBackground) { |
Christopher Tate | 8bbe704 | 2017-03-15 11:07:46 -0700 | [diff] [blame] | 260 | if (DEBUG) { |
| 261 | Slog.v(TAG, "Background restriction change to " + restrictBackground); |
| 262 | } |
Jeff Sharkey | 43d2a17 | 2017-07-12 10:50:42 -0600 | [diff] [blame] | 263 | updateTrackedJobs(-1); |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | @Override |
Felipe Leme | 0ecfcd1 | 2016-09-06 12:49:48 -0700 | [diff] [blame] | 267 | public void onUidPoliciesChanged(int uid, int uidPolicies) { |
Christopher Tate | 8bbe704 | 2017-03-15 11:07:46 -0700 | [diff] [blame] | 268 | if (DEBUG) { |
| 269 | Slog.v(TAG, "Uid policy changed for " + uid); |
| 270 | } |
Jeff Sharkey | 43d2a17 | 2017-07-12 10:50:42 -0600 | [diff] [blame] | 271 | updateTrackedJobs(uid); |
Felipe Leme | 99d5d3d | 2016-05-16 13:30:57 -0700 | [diff] [blame] | 272 | } |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 273 | }; |
Matthew Williams | effacfa | 2014-06-05 20:56:40 -0700 | [diff] [blame] | 274 | |
| 275 | @Override |
Dianne Hackborn | ef3aa6e | 2016-04-29 18:18:08 -0700 | [diff] [blame] | 276 | public void dumpControllerStateLocked(PrintWriter pw, int filterUid) { |
Christopher Tate | 8bbe704 | 2017-03-15 11:07:46 -0700 | [diff] [blame] | 277 | pw.print("Connectivity: connected="); |
| 278 | pw.print(mConnected); |
Dianne Hackborn | e9a988c | 2016-05-27 17:59:40 -0700 | [diff] [blame] | 279 | pw.print("Tracking "); |
| 280 | pw.print(mTrackedJobs.size()); |
| 281 | pw.println(":"); |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 282 | for (int i = 0; i < mTrackedJobs.size(); i++) { |
Dianne Hackborn | f9bac16 | 2017-04-20 17:17:48 -0700 | [diff] [blame] | 283 | final JobStatus js = mTrackedJobs.valueAt(i); |
Dianne Hackborn | ef3aa6e | 2016-04-29 18:18:08 -0700 | [diff] [blame] | 284 | if (js.shouldDump(filterUid)) { |
Dianne Hackborn | e9a988c | 2016-05-27 17:59:40 -0700 | [diff] [blame] | 285 | pw.print(" #"); |
| 286 | js.printUniqueId(pw); |
| 287 | pw.print(" from "); |
| 288 | UserHandle.formatUid(pw, js.getSourceUid()); |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 289 | pw.print(": "); pw.print(js.getJob().getRequiredNetwork()); |
Dianne Hackborn | ef3aa6e | 2016-04-29 18:18:08 -0700 | [diff] [blame] | 290 | } |
Matthew Williams | effacfa | 2014-06-05 20:56:40 -0700 | [diff] [blame] | 291 | } |
| 292 | } |
Robert Greenwalt | 6078b50 | 2014-06-11 16:05:07 -0700 | [diff] [blame] | 293 | } |