blob: 13873e476894f17ecc32a8a142bad0c442c58646 [file] [log] [blame]
Matthew Williams6de79e22014-05-01 10:47:00 -07001/*
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 Tate7060b042014-06-09 19:50:00 -070017package com.android.server.job.controllers;
Matthew Williams6de79e22014-05-01 10:47:00 -070018
Jeff Sharkey9252b342018-01-19 07:58:35 +090019import static android.net.NetworkCapabilities.LINK_BANDWIDTH_UNSPECIFIED;
20import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_CONGESTED;
21import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_METERED;
22
Jeff Sharkey1b6519b2016-04-28 15:33:18 -060023import android.app.job.JobInfo;
Matthew Williams6de79e22014-05-01 10:47:00 -070024import android.content.Context;
Matthew Williams6de79e22014-05-01 10:47:00 -070025import android.net.ConnectivityManager;
Christopher Tate8bbe7042017-03-15 11:07:46 -070026import android.net.ConnectivityManager.NetworkCallback;
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -060027import android.net.INetworkPolicyListener;
Christopher Tate8bbe7042017-03-15 11:07:46 -070028import android.net.Network;
29import android.net.NetworkCapabilities;
Matthew Williams6de79e22014-05-01 10:47:00 -070030import android.net.NetworkInfo;
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -060031import android.net.NetworkPolicyManager;
Kweku Adams85f2fbc2017-12-18 12:04:12 -080032import android.net.NetworkRequest;
Jeff Sharkeycaa3f8d2017-10-25 16:12:00 -060033import android.net.TrafficStats;
Christopher Tate8bbe7042017-03-15 11:07:46 -070034import android.os.Process;
Matthew Williams6de79e22014-05-01 10:47:00 -070035import android.os.UserHandle;
Jeff Sharkeycaa3f8d2017-10-25 16:12:00 -060036import android.text.format.DateUtils;
Dianne Hackbornf9bac162017-04-20 17:17:48 -070037import android.util.ArraySet;
Matthew Williams9b9244b62014-05-14 11:06:04 -070038import android.util.Slog;
Kweku Adams85f2fbc2017-12-18 12:04:12 -080039import android.util.proto.ProtoOutputStream;
Matthew Williams6de79e22014-05-01 10:47:00 -070040
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -060041import com.android.internal.annotations.GuardedBy;
Jeff Sharkey9252b342018-01-19 07:58:35 +090042import com.android.internal.annotations.VisibleForTesting;
Christopher Tate7060b042014-06-09 19:50:00 -070043import com.android.server.job.JobSchedulerService;
Jeff Sharkeycaa3f8d2017-10-25 16:12:00 -060044import com.android.server.job.JobServiceContext;
Christopher Tate7060b042014-06-09 19:50:00 -070045import com.android.server.job.StateChangedListener;
Kweku Adams85f2fbc2017-12-18 12:04:12 -080046import com.android.server.job.StateControllerProto;
Matthew Williams6de79e22014-05-01 10:47:00 -070047
Matthew Williamseffacfa2014-06-05 20:56:40 -070048import java.io.PrintWriter;
Matthew Williams6de79e22014-05-01 10:47:00 -070049
50/**
Matthew Williams9b9244b62014-05-14 11:06:04 -070051 * Handles changes in connectivity.
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -060052 * <p>
53 * Each app can have a different default networks or different connectivity
54 * status due to user-requested network policies, so we need to check
55 * constraints on a per-UID basis.
Matthew Williams6de79e22014-05-01 10:47:00 -070056 */
Dianne Hackborn6466c1c2017-06-13 10:33:19 -070057public final class ConnectivityController extends StateController implements
Matthew Williamseffacfa2014-06-05 20:56:40 -070058 ConnectivityManager.OnNetworkActiveListener {
Christopher Tate7060b042014-06-09 19:50:00 -070059 private static final String TAG = "JobScheduler.Conn";
Christopher Tate8bbe7042017-03-15 11:07:46 -070060 private static final boolean DEBUG = false;
Matthew Williams6de79e22014-05-01 10:47:00 -070061
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -060062 private final ConnectivityManager mConnManager;
63 private final NetworkPolicyManager mNetPolicyManager;
Christopher Tate8bbe7042017-03-15 11:07:46 -070064 private boolean mConnected;
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -060065
66 @GuardedBy("mLock")
Dianne Hackbornf9bac162017-04-20 17:17:48 -070067 private final ArraySet<JobStatus> mTrackedJobs = new ArraySet<>();
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -060068
Matthew Williams9b9244b62014-05-14 11:06:04 -070069 /** Singleton. */
Jeff Sharkey9252b342018-01-19 07:58:35 +090070 private static ConnectivityController sSingleton;
Matthew Williamseffacfa2014-06-05 20:56:40 -070071 private static Object sCreationLock = new Object();
Matthew Williams691e93e2014-05-12 15:33:09 -070072
Christopher Tate7060b042014-06-09 19:50:00 -070073 public static ConnectivityController get(JobSchedulerService jms) {
Matthew Williamseffacfa2014-06-05 20:56:40 -070074 synchronized (sCreationLock) {
Jeff Sharkey9252b342018-01-19 07:58:35 +090075 if (sSingleton == null) {
76 sSingleton = new ConnectivityController(jms, jms.getContext(), jms.getLock());
Matthew Williamseffacfa2014-06-05 20:56:40 -070077 }
Jeff Sharkey9252b342018-01-19 07:58:35 +090078 return sSingleton;
Matthew Williams9b9244b62014-05-14 11:06:04 -070079 }
Matthew Williams9b9244b62014-05-14 11:06:04 -070080 }
81
Dianne Hackborn33d31c52016-02-16 10:30:33 -080082 private ConnectivityController(StateChangedListener stateChangedListener, Context context,
83 Object lock) {
84 super(stateChangedListener, context, lock);
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -060085
86 mConnManager = mContext.getSystemService(ConnectivityManager.class);
87 mNetPolicyManager = mContext.getSystemService(NetworkPolicyManager.class);
88
Jeff Sharkeyd0fff2e2017-11-07 16:55:06 -070089 mConnected = false;
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -060090
Christopher Tate8bbe7042017-03-15 11:07:46 -070091 mConnManager.registerDefaultNetworkCallback(mNetworkCallback);
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -060092 mNetPolicyManager.registerListener(mNetPolicyListener);
Matthew Williams6de79e22014-05-01 10:47:00 -070093 }
94
95 @Override
Dianne Hackbornb0001f62016-02-16 10:30:33 -080096 public void maybeStartTrackingJobLocked(JobStatus jobStatus, JobStatus lastJob) {
Christopher Tate60977f42017-04-13 13:48:46 -070097 if (jobStatus.hasConnectivityConstraint()) {
Jeff Sharkey43d2a172017-07-12 10:50:42 -060098 updateConstraintsSatisfied(jobStatus);
Dianne Hackbornb0001f62016-02-16 10:30:33 -080099 mTrackedJobs.add(jobStatus);
Dianne Hackbornf9bac162017-04-20 17:17:48 -0700100 jobStatus.setTrackingController(JobStatus.TRACKING_CONNECTIVITY);
Matthew Williamseffacfa2014-06-05 20:56:40 -0700101 }
102 }
103
104 @Override
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -0600105 public void maybeStopTrackingJobLocked(JobStatus jobStatus, JobStatus incomingJob,
106 boolean forUpdate) {
Dianne Hackbornf9bac162017-04-20 17:17:48 -0700107 if (jobStatus.clearTrackingController(JobStatus.TRACKING_CONNECTIVITY)) {
Dianne Hackbornb0001f62016-02-16 10:30:33 -0800108 mTrackedJobs.remove(jobStatus);
Matthew Williamseffacfa2014-06-05 20:56:40 -0700109 }
Matthew Williams6de79e22014-05-01 10:47:00 -0700110 }
111
Jeff Sharkeycaa3f8d2017-10-25 16:12:00 -0600112 /**
Jeff Sharkey9252b342018-01-19 07:58:35 +0900113 * Test to see if running the given job on the given network is insane.
Jeff Sharkeycaa3f8d2017-10-25 16:12:00 -0600114 * <p>
115 * For example, if a job is trying to send 10MB over a 128Kbps EDGE
116 * connection, it would take 10.4 minutes, and has no chance of succeeding
117 * before the job times out, so we'd be insane to try running it.
118 */
Jeff Sharkey9252b342018-01-19 07:58:35 +0900119 @SuppressWarnings("unused")
120 private static boolean isInsane(JobStatus jobStatus, Network network,
121 NetworkCapabilities capabilities) {
Jeff Sharkeycaa3f8d2017-10-25 16:12:00 -0600122 final long estimatedBytes = jobStatus.getEstimatedNetworkBytes();
123 if (estimatedBytes == JobInfo.NETWORK_BYTES_UNKNOWN) {
124 // We don't know how large the job is; cross our fingers!
Jeff Sharkey9252b342018-01-19 07:58:35 +0900125 return false;
Jeff Sharkeycaa3f8d2017-10-25 16:12:00 -0600126 }
127
128 // We don't ask developers to differentiate between upstream/downstream
129 // in their size estimates, so test against the slowest link direction.
Jeff Sharkey9252b342018-01-19 07:58:35 +0900130 final long slowest = NetworkCapabilities.minBandwidth(
131 capabilities.getLinkDownstreamBandwidthKbps(),
132 capabilities.getLinkUpstreamBandwidthKbps());
133 if (slowest == LINK_BANDWIDTH_UNSPECIFIED) {
Jeff Sharkeycaa3f8d2017-10-25 16:12:00 -0600134 // We don't know what the network is like; cross our fingers!
Jeff Sharkey9252b342018-01-19 07:58:35 +0900135 return false;
Jeff Sharkeycaa3f8d2017-10-25 16:12:00 -0600136 }
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!");
Jeff Sharkeycaa3f8d2017-10-25 16:12:00 -0600144 return true;
Jeff Sharkey9252b342018-01-19 07:58:35 +0900145 } else {
146 return false;
Jeff Sharkeycaa3f8d2017-10-25 16:12:00 -0600147 }
148 }
149
Jeff Sharkey9252b342018-01-19 07:58:35 +0900150 @SuppressWarnings("unused")
151 private static boolean isCongestionDelayed(JobStatus jobStatus, Network network,
152 NetworkCapabilities capabilities) {
153 // If network is congested, and job is less than 50% through the
154 // developer-requested window, then we're okay delaying the job.
155 if (!capabilities.hasCapability(NET_CAPABILITY_NOT_CONGESTED)) {
156 return jobStatus.getFractionRunTime() < 0.5;
157 } else {
158 return false;
159 }
160 }
161
162 @SuppressWarnings("unused")
163 private static boolean isStrictSatisfied(JobStatus jobStatus, Network network,
164 NetworkCapabilities capabilities) {
165 return jobStatus.getJob().getRequiredNetwork().networkCapabilities
166 .satisfiedByNetworkCapabilities(capabilities);
167 }
168
169 @SuppressWarnings("unused")
170 private static boolean isRelaxedSatisfied(JobStatus jobStatus, Network network,
171 NetworkCapabilities capabilities) {
172 // Only consider doing this for prefetching jobs
173 if ((jobStatus.getJob().getFlags() & JobInfo.FLAG_IS_PREFETCH) == 0) {
174 return false;
175 }
176
177 // See if we match after relaxing any unmetered request
178 final NetworkCapabilities relaxed = new NetworkCapabilities(
179 jobStatus.getJob().getRequiredNetwork().networkCapabilities)
180 .removeCapability(NET_CAPABILITY_NOT_METERED);
181 if (relaxed.satisfiedByNetworkCapabilities(capabilities)) {
182 // TODO: treat this as "maybe" response; need to check quotas
183 return jobStatus.getFractionRunTime() > 0.5;
184 } else {
185 return false;
186 }
187 }
188
189 @VisibleForTesting
190 static boolean isSatisfied(JobStatus jobStatus, Network network,
191 NetworkCapabilities capabilities) {
192 // Zeroth, we gotta have a network to think about being satisfied
193 if (network == null || capabilities == null) return false;
194
195 // First, are we insane?
196 if (isInsane(jobStatus, network, capabilities)) return false;
197
198 // Second, is the network congested?
199 if (isCongestionDelayed(jobStatus, network, capabilities)) return false;
200
201 // Third, is the network a strict match?
202 if (isStrictSatisfied(jobStatus, network, capabilities)) return true;
203
204 // Third, is the network a relaxed match?
205 if (isRelaxedSatisfied(jobStatus, network, capabilities)) return true;
206
207 return false;
208 }
209
Jeff Sharkey43d2a172017-07-12 10:50:42 -0600210 private boolean updateConstraintsSatisfied(JobStatus jobStatus) {
Jeff Sharkeyd0fff2e2017-11-07 16:55:06 -0700211 // TODO: consider matching against non-active networks
212
Christopher Tate8bbe7042017-03-15 11:07:46 -0700213 final int jobUid = jobStatus.getSourceUid();
Jeff Sharkey1b6519b2016-04-28 15:33:18 -0600214 final boolean ignoreBlocked = (jobStatus.getFlags() & JobInfo.FLAG_WILL_BE_FOREGROUND) != 0;
Jeff Sharkey9252b342018-01-19 07:58:35 +0900215
Jeff Sharkey43d2a172017-07-12 10:50:42 -0600216 final Network network = mConnManager.getActiveNetworkForUid(jobUid, ignoreBlocked);
Jeff Sharkeycaa3f8d2017-10-25 16:12:00 -0600217 final NetworkInfo info = mConnManager.getNetworkInfoForUid(network, jobUid, ignoreBlocked);
Jeff Sharkeyd0fff2e2017-11-07 16:55:06 -0700218 final NetworkCapabilities capabilities = mConnManager.getNetworkCapabilities(network);
Christopher Tate8bbe7042017-03-15 11:07:46 -0700219
Jeff Sharkeycaa3f8d2017-10-25 16:12:00 -0600220 final boolean connected = (info != null) && info.isConnected();
Jeff Sharkey9252b342018-01-19 07:58:35 +0900221 final boolean satisfied = isSatisfied(jobStatus, network, capabilities);
Jeff Sharkey43d2a172017-07-12 10:50:42 -0600222
Jeff Sharkeyd0fff2e2017-11-07 16:55:06 -0700223 final boolean changed = jobStatus
Jeff Sharkey9252b342018-01-19 07:58:35 +0900224 .setConnectivityConstraintSatisfied(connected && satisfied);
Christopher Tate8bbe7042017-03-15 11:07:46 -0700225
Jeff Sharkey76a02412017-10-24 16:55:04 -0600226 // Pass along the evaluated network for job to use; prevents race
227 // conditions as default routes change over time, and opens the door to
228 // using non-default routes.
229 jobStatus.network = network;
230
Christopher Tate8bbe7042017-03-15 11:07:46 -0700231 // Track system-uid connected/validated as a general reportable proxy for the
232 // overall state of connectivity constraint satisfiability.
233 if (jobUid == Process.SYSTEM_UID) {
234 mConnected = connected;
Christopher Tate8bbe7042017-03-15 11:07:46 -0700235 }
236
237 if (DEBUG) {
238 Slog.i(TAG, "Connectivity " + (changed ? "CHANGED" : "unchanged")
Jeff Sharkeyd0fff2e2017-11-07 16:55:06 -0700239 + " for " + jobStatus + ": connected=" + connected
Jeff Sharkey9252b342018-01-19 07:58:35 +0900240 + " satisfied=" + satisfied);
Christopher Tate8bbe7042017-03-15 11:07:46 -0700241 }
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -0600242 return changed;
243 }
244
Matthew Williams6de79e22014-05-01 10:47:00 -0700245 /**
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -0600246 * Update all jobs tracked by this controller.
247 *
248 * @param uid only update jobs belonging to this UID, or {@code -1} to
249 * update all tracked jobs.
Matthew Williams6de79e22014-05-01 10:47:00 -0700250 */
Jeff Sharkey43d2a172017-07-12 10:50:42 -0600251 private void updateTrackedJobs(int uid) {
Dianne Hackborn33d31c52016-02-16 10:30:33 -0800252 synchronized (mLock) {
Matthew Williamseffacfa2014-06-05 20:56:40 -0700253 boolean changed = false;
Dianne Hackbornf9bac162017-04-20 17:17:48 -0700254 for (int i = mTrackedJobs.size()-1; i >= 0; i--) {
255 final JobStatus js = mTrackedJobs.valueAt(i);
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -0600256 if (uid == -1 || uid == js.getSourceUid()) {
Jeff Sharkey43d2a172017-07-12 10:50:42 -0600257 changed |= updateConstraintsSatisfied(js);
Matthew Williamseffacfa2014-06-05 20:56:40 -0700258 }
Matthew Williamseffacfa2014-06-05 20:56:40 -0700259 }
260 if (changed) {
261 mStateChangedListener.onControllerStateChanged();
Matthew Williams6de79e22014-05-01 10:47:00 -0700262 }
263 }
Matthew Williamseffacfa2014-06-05 20:56:40 -0700264 }
265
266 /**
Christopher Tate7060b042014-06-09 19:50:00 -0700267 * We know the network has just come up. We want to run any jobs that are ready.
Matthew Williamseffacfa2014-06-05 20:56:40 -0700268 */
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -0600269 @Override
Dianne Hackborn532ea262017-03-17 17:50:55 -0700270 public void onNetworkActive() {
Dianne Hackborn33d31c52016-02-16 10:30:33 -0800271 synchronized (mLock) {
Dianne Hackbornf9bac162017-04-20 17:17:48 -0700272 for (int i = mTrackedJobs.size()-1; i >= 0; i--) {
273 final JobStatus js = mTrackedJobs.valueAt(i);
Christopher Tate7060b042014-06-09 19:50:00 -0700274 if (js.isReady()) {
Matthew Williamseffacfa2014-06-05 20:56:40 -0700275 if (DEBUG) {
Christopher Tate7060b042014-06-09 19:50:00 -0700276 Slog.d(TAG, "Running " + js + " due to network activity.");
Matthew Williamseffacfa2014-06-05 20:56:40 -0700277 }
Christopher Tate7060b042014-06-09 19:50:00 -0700278 mStateChangedListener.onRunJobNow(js);
Matthew Williamseffacfa2014-06-05 20:56:40 -0700279 }
280 }
Matthew Williams9b9244b62014-05-14 11:06:04 -0700281 }
Matthew Williams6de79e22014-05-01 10:47:00 -0700282 }
283
Christopher Tate8bbe7042017-03-15 11:07:46 -0700284 private final NetworkCallback mNetworkCallback = new NetworkCallback() {
Matthew Williams6de79e22014-05-01 10:47:00 -0700285 @Override
Christopher Tate8bbe7042017-03-15 11:07:46 -0700286 public void onCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities) {
287 if (DEBUG) {
288 Slog.v(TAG, "onCapabilitiesChanged() : " + networkCapabilities);
289 }
Jeff Sharkey43d2a172017-07-12 10:50:42 -0600290 updateTrackedJobs(-1);
Christopher Tate8bbe7042017-03-15 11:07:46 -0700291 }
292
293 @Override
294 public void onLost(Network network) {
295 if (DEBUG) {
296 Slog.v(TAG, "Network lost");
297 }
Jeff Sharkey43d2a172017-07-12 10:50:42 -0600298 updateTrackedJobs(-1);
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -0600299 }
300 };
301
Jeff Sharkey75d31892018-01-18 22:01:59 +0900302 private final INetworkPolicyListener mNetPolicyListener = new NetworkPolicyManager.Listener() {
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -0600303 @Override
304 public void onUidRulesChanged(int uid, int uidRules) {
Christopher Tate8bbe7042017-03-15 11:07:46 -0700305 if (DEBUG) {
306 Slog.v(TAG, "Uid rules changed for " + uid);
307 }
Jeff Sharkey43d2a172017-07-12 10:50:42 -0600308 updateTrackedJobs(uid);
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -0600309 }
310
311 @Override
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -0600312 public void onRestrictBackgroundChanged(boolean restrictBackground) {
Christopher Tate8bbe7042017-03-15 11:07:46 -0700313 if (DEBUG) {
314 Slog.v(TAG, "Background restriction change to " + restrictBackground);
315 }
Jeff Sharkey43d2a172017-07-12 10:50:42 -0600316 updateTrackedJobs(-1);
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -0600317 }
318
319 @Override
Felipe Leme0ecfcd12016-09-06 12:49:48 -0700320 public void onUidPoliciesChanged(int uid, int uidPolicies) {
Christopher Tate8bbe7042017-03-15 11:07:46 -0700321 if (DEBUG) {
322 Slog.v(TAG, "Uid policy changed for " + uid);
323 }
Jeff Sharkey43d2a172017-07-12 10:50:42 -0600324 updateTrackedJobs(uid);
Felipe Leme99d5d3d2016-05-16 13:30:57 -0700325 }
Matthew Williams6de79e22014-05-01 10:47:00 -0700326 };
Matthew Williamseffacfa2014-06-05 20:56:40 -0700327
328 @Override
Dianne Hackbornef3aa6e2016-04-29 18:18:08 -0700329 public void dumpControllerStateLocked(PrintWriter pw, int filterUid) {
Christopher Tate8bbe7042017-03-15 11:07:46 -0700330 pw.print("Connectivity: connected=");
Makoto Onukide10e242018-02-05 12:56:20 -0800331 pw.println(mConnected);
332
Dianne Hackborne9a988c2016-05-27 17:59:40 -0700333 pw.print("Tracking ");
334 pw.print(mTrackedJobs.size());
Makoto Onukide10e242018-02-05 12:56:20 -0800335 pw.println(" jobs");
336
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -0600337 for (int i = 0; i < mTrackedJobs.size(); i++) {
Dianne Hackbornf9bac162017-04-20 17:17:48 -0700338 final JobStatus js = mTrackedJobs.valueAt(i);
Dianne Hackbornef3aa6e2016-04-29 18:18:08 -0700339 if (js.shouldDump(filterUid)) {
Dianne Hackborne9a988c2016-05-27 17:59:40 -0700340 pw.print(" #");
341 js.printUniqueId(pw);
342 pw.print(" from ");
343 UserHandle.formatUid(pw, js.getSourceUid());
Makoto Onukide10e242018-02-05 12:56:20 -0800344 pw.print(": ");
345 pw.print(js.getJob().getRequiredNetwork());
346 pw.println();
Dianne Hackbornef3aa6e2016-04-29 18:18:08 -0700347 }
Matthew Williamseffacfa2014-06-05 20:56:40 -0700348 }
349 }
Kweku Adams85f2fbc2017-12-18 12:04:12 -0800350
351 @Override
352 public void dumpControllerStateLocked(ProtoOutputStream proto, long fieldId, int filterUid) {
353 final long token = proto.start(fieldId);
354 final long mToken = proto.start(StateControllerProto.CONNECTIVITY);
355
356 proto.write(StateControllerProto.ConnectivityController.IS_CONNECTED, mConnected);
357
358 for (int i = 0; i < mTrackedJobs.size(); i++) {
359 final JobStatus js = mTrackedJobs.valueAt(i);
360 if (!js.shouldDump(filterUid)) {
361 continue;
362 }
363 final long jsToken = proto.start(StateControllerProto.ConnectivityController.TRACKED_JOBS);
364 js.writeToShortProto(proto, StateControllerProto.ConnectivityController.TrackedJob.INFO);
365 proto.write(StateControllerProto.ConnectivityController.TrackedJob.SOURCE_UID,
366 js.getSourceUid());
367 NetworkRequest rn = js.getJob().getRequiredNetwork();
368 if (rn != null) {
369 rn.writeToProto(proto,
370 StateControllerProto.ConnectivityController.TrackedJob.REQUIRED_NETWORK);
371 }
372 proto.end(jsToken);
373 }
374
375 proto.end(mToken);
376 proto.end(token);
377 }
Robert Greenwalt6078b502014-06-11 16:05:07 -0700378}