Java Code Examples for android.app.job.JobInfo#NETWORK_BYTES_UNKNOWN

The following examples show how to use android.app.job.JobInfo#NETWORK_BYTES_UNKNOWN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobStatus.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: ConnectivityController.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
    }
}