下面列出了android.app.job.JobInfo#NETWORK_BYTES_UNKNOWN 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private long computeEstimatedNetworkBytesLocked() {
// If any component of the job has unknown usage, we don't have a
// complete picture of what data will be used, and we have to treat the
// entire job as unknown.
long totalNetworkBytes = 0;
long networkBytes = job.getEstimatedNetworkBytes();
if (networkBytes == JobInfo.NETWORK_BYTES_UNKNOWN) {
return JobInfo.NETWORK_BYTES_UNKNOWN;
} else {
totalNetworkBytes += networkBytes;
}
if (pendingWork != null) {
for (int i = 0; i < pendingWork.size(); i++) {
networkBytes = pendingWork.get(i).getEstimatedNetworkBytes();
if (networkBytes == JobInfo.NETWORK_BYTES_UNKNOWN) {
return JobInfo.NETWORK_BYTES_UNKNOWN;
} else {
totalNetworkBytes += networkBytes;
}
}
}
return totalNetworkBytes;
}
/**
* Test to see if running the given job on the given network is insane.
* <p>
* For example, if a job is trying to send 10MB over a 128Kbps EDGE
* connection, it would take 10.4 minutes, and has no chance of succeeding
* before the job times out, so we'd be insane to try running it.
*/
@SuppressWarnings("unused")
private static boolean isInsane(JobStatus jobStatus, Network network,
NetworkCapabilities capabilities, Constants constants) {
final long estimatedBytes = jobStatus.getEstimatedNetworkBytes();
if (estimatedBytes == JobInfo.NETWORK_BYTES_UNKNOWN) {
// We don't know how large the job is; cross our fingers!
return false;
}
// We don't ask developers to differentiate between upstream/downstream
// in their size estimates, so test against the slowest link direction.
final long slowest = NetworkCapabilities.minBandwidth(
capabilities.getLinkDownstreamBandwidthKbps(),
capabilities.getLinkUpstreamBandwidthKbps());
if (slowest == LINK_BANDWIDTH_UNSPECIFIED) {
// We don't know what the network is like; cross our fingers!
return false;
}
final long estimatedMillis = ((estimatedBytes * DateUtils.SECOND_IN_MILLIS)
/ (slowest * TrafficStats.KB_IN_BYTES / 8));
if (estimatedMillis > JobServiceContext.EXECUTING_TIMESLICE_MILLIS) {
// If we'd never finish before the timeout, we'd be insane!
Slog.w(TAG, "Estimated " + estimatedBytes + " bytes over " + slowest
+ " kbps network would take " + estimatedMillis + "ms; that's insane!");
return true;
} else {
return false;
}
}