13c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt/* 23c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt * Copyright (C) 2014 The Android Open Source Project 33c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt * 43c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt * Licensed under the Apache License, Version 2.0 (the "License"); 53c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt * you may not use this file except in compliance with the License. 63c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt * You may obtain a copy of the License at 73c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt * 83c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt * http://www.apache.org/licenses/LICENSE-2.0 93c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt * 103c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt * Unless required by applicable law or agreed to in writing, software 113c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt * distributed under the License is distributed on an "AS IS" BASIS, 123c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 133c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt * See the License for the specific language governing permissions and 143c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt * limitations under the License. 153c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt */ 163c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt 173c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwaltpackage android.net; 183c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt 193c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwaltimport android.os.Parcel; 203c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwaltimport android.os.Parcelable; 213c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt 223c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt/** 237569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * Defines a request for a network, made through {@link NetworkRequest.Builder} and used 247569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * to request a network via {@link ConnectivityManager#requestNetwork} or listen for changes 256078b50b017fbcf8d6cbf9f83226ed5667d5729eRobert Greenwalt * via {@link ConnectivityManager#registerNetworkCallback}. 263c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt */ 273c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwaltpublic class NetworkRequest implements Parcelable { 287b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt /** 297569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * The {@link NetworkCapabilities} that define this request. 307569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * @hide 317b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt */ 323c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt public final NetworkCapabilities networkCapabilities; 337b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt 347b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt /** 357b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt * Identifies the request. NetworkRequests should only be constructed by 367b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt * the Framework and given out to applications as tokens to be used to identify 377b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt * the request. 3834524f06fb77607884c69f891471725f4ac0889aRobert Greenwalt * @hide 397b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt */ 403c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt public final int requestId; 413c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt 427b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt /** 4332aa65a11207e1fb7d346a68fdf3299f87a20db4Robert Greenwalt * Set for legacy requests and the default. Set to TYPE_NONE for none. 447b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt * Causes CONNECTIVITY_ACTION broadcasts to be sent. 457b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt * @hide 467b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt */ 4732aa65a11207e1fb7d346a68fdf3299f87a20db4Robert Greenwalt public final int legacyType; 487b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt 497b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt /** 507b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt * @hide 517b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt */ 5232aa65a11207e1fb7d346a68fdf3299f87a20db4Robert Greenwalt public NetworkRequest(NetworkCapabilities nc, int legacyType, int rId) { 53f5b74f981fb4e67f77a78b7038785fb3871acaa6Robert Greenwalt if (nc == null) { 54f5b74f981fb4e67f77a78b7038785fb3871acaa6Robert Greenwalt throw new NullPointerException(); 55f5b74f981fb4e67f77a78b7038785fb3871acaa6Robert Greenwalt } 563c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt requestId = rId; 573c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt networkCapabilities = nc; 5832aa65a11207e1fb7d346a68fdf3299f87a20db4Robert Greenwalt this.legacyType = legacyType; 597b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt } 607b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt 6134524f06fb77607884c69f891471725f4ac0889aRobert Greenwalt /** 6234524f06fb77607884c69f891471725f4ac0889aRobert Greenwalt * @hide 6334524f06fb77607884c69f891471725f4ac0889aRobert Greenwalt */ 647b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt public NetworkRequest(NetworkRequest that) { 657b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt networkCapabilities = new NetworkCapabilities(that.networkCapabilities); 667b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt requestId = that.requestId; 6732aa65a11207e1fb7d346a68fdf3299f87a20db4Robert Greenwalt this.legacyType = that.legacyType; 683c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt } 693c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt 707569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt /** 717569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * Builder used to create {@link NetworkRequest} objects. Specify the Network features 727569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * needed in terms of {@link NetworkCapabilities} features 737569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt */ 747569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt public static class Builder { 757569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt private final NetworkCapabilities mNetworkCapabilities = new NetworkCapabilities(); 767569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt 777569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt /** 787569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * Default constructor for Builder. 797569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt */ 807569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt public Builder() {} 817569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt 827569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt /** 837569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * Build {@link NetworkRequest} give the current set of capabilities. 847569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt */ 857569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt public NetworkRequest build() { 86487ffe7d3d84bf65212158f7098e8a84b5b55e09Paul Jensen // Make a copy of mNetworkCapabilities so we don't inadvertently remove NOT_RESTRICTED 87487ffe7d3d84bf65212158f7098e8a84b5b55e09Paul Jensen // when later an unrestricted capability could be added to mNetworkCapabilities, in 88487ffe7d3d84bf65212158f7098e8a84b5b55e09Paul Jensen // which case NOT_RESTRICTED should be returned to mNetworkCapabilities, which 89487ffe7d3d84bf65212158f7098e8a84b5b55e09Paul Jensen // maybeMarkCapabilitiesRestricted() doesn't add back. 90487ffe7d3d84bf65212158f7098e8a84b5b55e09Paul Jensen final NetworkCapabilities nc = new NetworkCapabilities(mNetworkCapabilities); 91487ffe7d3d84bf65212158f7098e8a84b5b55e09Paul Jensen nc.maybeMarkCapabilitiesRestricted(); 92487ffe7d3d84bf65212158f7098e8a84b5b55e09Paul Jensen return new NetworkRequest(nc, ConnectivityManager.TYPE_NONE, 937569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt ConnectivityManager.REQUEST_ID_UNSET); 947569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt } 957569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt 967569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt /** 977569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * Add the given capability requirement to this builder. These represent 987569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * the requested network's required capabilities. Note that when searching 997569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * for a network to satisfy a request, all capabilities requested must be 1007569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * satisfied. See {@link NetworkCapabilities} for {@code NET_CAPABILITIY_*} 1017569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * definitions. 1027569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * 1037569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * @param capability The {@code NetworkCapabilities.NET_CAPABILITY_*} to add. 1047569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * @return The builder to facilitate chaining 1057569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * {@code builder.addCapability(...).addCapability();}. 1067569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt */ 1077569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt public Builder addCapability(int capability) { 1087569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt mNetworkCapabilities.addCapability(capability); 1097569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt return this; 1107569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt } 1117569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt 1127569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt /** 1137569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * Removes (if found) the given capability from this builder instance. 1147569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * 1157569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * @param capability The {@code NetworkCapabilities.NET_CAPABILITY_*} to remove. 1167569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * @return The builder to facilitate chaining. 1177569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt */ 1187569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt public Builder removeCapability(int capability) { 1197569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt mNetworkCapabilities.removeCapability(capability); 1207569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt return this; 1217569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt } 1227569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt 1237569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt /** 12484b83c5a95c9822683eec5a348893c1afba17444Lorenzo Colitti * Completely clears all the {@code NetworkCapabilities} from this builder instance, 12584b83c5a95c9822683eec5a348893c1afba17444Lorenzo Colitti * removing even the capabilities that are set by default when the object is constructed. 12684b83c5a95c9822683eec5a348893c1afba17444Lorenzo Colitti * 12784b83c5a95c9822683eec5a348893c1afba17444Lorenzo Colitti * @return The builder to facilitate chaining. 12884b83c5a95c9822683eec5a348893c1afba17444Lorenzo Colitti * @hide 12984b83c5a95c9822683eec5a348893c1afba17444Lorenzo Colitti */ 13084b83c5a95c9822683eec5a348893c1afba17444Lorenzo Colitti public Builder clearCapabilities() { 13184b83c5a95c9822683eec5a348893c1afba17444Lorenzo Colitti mNetworkCapabilities.clearAll(); 13284b83c5a95c9822683eec5a348893c1afba17444Lorenzo Colitti return this; 13384b83c5a95c9822683eec5a348893c1afba17444Lorenzo Colitti } 13484b83c5a95c9822683eec5a348893c1afba17444Lorenzo Colitti 13584b83c5a95c9822683eec5a348893c1afba17444Lorenzo Colitti /** 1367569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * Adds the given transport requirement to this builder. These represent 1377569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * the set of allowed transports for the request. Only networks using one 1387569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * of these transports will satisfy the request. If no particular transports 1397569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * are required, none should be specified here. See {@link NetworkCapabilities} 1407569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * for {@code TRANSPORT_*} definitions. 1417569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * 1427569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * @param transportType The {@code NetworkCapabilities.TRANSPORT_*} to add. 1437569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * @return The builder to facilitate chaining. 1447569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt */ 1457569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt public Builder addTransportType(int transportType) { 1467569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt mNetworkCapabilities.addTransportType(transportType); 1477569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt return this; 1487569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt } 1497569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt 1507569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt /** 1517569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * Removes (if found) the given transport from this builder instance. 1527569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * 1537569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * @param transportType The {@code NetworkCapabilities.TRANSPORT_*} to remove. 1547569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * @return The builder to facilitate chaining. 1557569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt */ 1567569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt public Builder removeTransportType(int transportType) { 1577569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt mNetworkCapabilities.removeTransportType(transportType); 1587569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt return this; 1597569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt } 1607569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt 1617569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt /** 1627569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * @hide 1637569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt */ 1647569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt public Builder setLinkUpstreamBandwidthKbps(int upKbps) { 1657569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt mNetworkCapabilities.setLinkUpstreamBandwidthKbps(upKbps); 1667569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt return this; 1677569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt } 1687569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt /** 1697569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt * @hide 1707569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt */ 1717569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt public Builder setLinkDownstreamBandwidthKbps(int downKbps) { 1727569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt mNetworkCapabilities.setLinkDownstreamBandwidthKbps(downKbps); 1737569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt return this; 1747569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt } 1755f90bccd96397f23b988c5e668b13f5344fd104bRobert Greenwalt 1765f90bccd96397f23b988c5e668b13f5344fd104bRobert Greenwalt /** 1775f90bccd96397f23b988c5e668b13f5344fd104bRobert Greenwalt * Sets the optional bearer specific network specifier. 1785f90bccd96397f23b988c5e668b13f5344fd104bRobert Greenwalt * This has no meaning if a single transport is also not specified, so calling 1795f90bccd96397f23b988c5e668b13f5344fd104bRobert Greenwalt * this without a single transport set will generate an exception, as will 1805f90bccd96397f23b988c5e668b13f5344fd104bRobert Greenwalt * subsequently adding or removing transports after this is set. 1815f90bccd96397f23b988c5e668b13f5344fd104bRobert Greenwalt * </p> 1825f90bccd96397f23b988c5e668b13f5344fd104bRobert Greenwalt * The interpretation of this {@code String} is bearer specific and bearers that use 1835f90bccd96397f23b988c5e668b13f5344fd104bRobert Greenwalt * it should document their particulars. For example, Bluetooth may use some sort of 1845f90bccd96397f23b988c5e668b13f5344fd104bRobert Greenwalt * device id while WiFi could used ssid and/or bssid. Cellular may use carrier spn. 1855f90bccd96397f23b988c5e668b13f5344fd104bRobert Greenwalt * 1865f90bccd96397f23b988c5e668b13f5344fd104bRobert Greenwalt * @param networkSpecifier An {@code String} of opaque format used to specify the bearer 1875f90bccd96397f23b988c5e668b13f5344fd104bRobert Greenwalt * specific network specifier where the bearer has a choice of 1885f90bccd96397f23b988c5e668b13f5344fd104bRobert Greenwalt * networks. 1895f90bccd96397f23b988c5e668b13f5344fd104bRobert Greenwalt */ 1905f90bccd96397f23b988c5e668b13f5344fd104bRobert Greenwalt public Builder setNetworkSpecifier(String networkSpecifier) { 1915f90bccd96397f23b988c5e668b13f5344fd104bRobert Greenwalt mNetworkCapabilities.setNetworkSpecifier(networkSpecifier); 1925f90bccd96397f23b988c5e668b13f5344fd104bRobert Greenwalt return this; 1935f90bccd96397f23b988c5e668b13f5344fd104bRobert Greenwalt } 1947569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt } 1957569f1811f6061b2a6605c69bca1bb7af72ae1a0Robert Greenwalt 1963c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt // implement the Parcelable interface 1973c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt public int describeContents() { 1983c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt return 0; 1993c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt } 2003c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt public void writeToParcel(Parcel dest, int flags) { 2013c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt dest.writeParcelable(networkCapabilities, flags); 20232aa65a11207e1fb7d346a68fdf3299f87a20db4Robert Greenwalt dest.writeInt(legacyType); 2033c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt dest.writeInt(requestId); 2043c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt } 2053c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt public static final Creator<NetworkRequest> CREATOR = 2063c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt new Creator<NetworkRequest>() { 2073c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt public NetworkRequest createFromParcel(Parcel in) { 2083c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt NetworkCapabilities nc = (NetworkCapabilities)in.readParcelable(null); 20932aa65a11207e1fb7d346a68fdf3299f87a20db4Robert Greenwalt int legacyType = in.readInt(); 2103c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt int requestId = in.readInt(); 21132aa65a11207e1fb7d346a68fdf3299f87a20db4Robert Greenwalt NetworkRequest result = new NetworkRequest(nc, legacyType, requestId); 2127b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt return result; 2133c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt } 2143c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt public NetworkRequest[] newArray(int size) { 2153c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt return new NetworkRequest[size]; 2163c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt } 2173c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt }; 2183c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt 2193c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt public String toString() { 22032aa65a11207e1fb7d346a68fdf3299f87a20db4Robert Greenwalt return "NetworkRequest [ id=" + requestId + ", legacyType=" + legacyType + 2217b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt ", " + networkCapabilities.toString() + " ]"; 2223c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt } 2233c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt 2243c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt public boolean equals(Object obj) { 2253c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt if (obj instanceof NetworkRequest == false) return false; 2263c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt NetworkRequest that = (NetworkRequest)obj; 22732aa65a11207e1fb7d346a68fdf3299f87a20db4Robert Greenwalt return (that.legacyType == this.legacyType && 2283c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt that.requestId == this.requestId && 2293c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt ((that.networkCapabilities == null && this.networkCapabilities == null) || 2303c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt (that.networkCapabilities != null && 2313c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt that.networkCapabilities.equals(this.networkCapabilities)))); 2323c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt } 2333c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt 2343c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt public int hashCode() { 23532aa65a11207e1fb7d346a68fdf3299f87a20db4Robert Greenwalt return requestId + (legacyType * 1013) + 2367b81602f3c18df8a4ca0342c514af8f7e394c0d7Robert Greenwalt (networkCapabilities.hashCode() * 1051); 2373c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt } 2383c0bf5e536ea6ee59385065d1d4830d3647cffafRobert Greenwalt} 239