blob: ce5afd1668bd2f251e19ef292454f57d16dae15c [file] [log] [blame]
[email protected]b47feba2012-04-24 01:34:411// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]6dbdaa82011-08-11 16:05:562// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef NET_ANDROID_NETWORK_LIBRARY_H_
6#define NET_ANDROID_NETWORK_LIBRARY_H_
[email protected]6dbdaa82011-08-11 16:05:567
8#include <jni.h>
Avi Drissman13fc8932015-12-20 04:40:469#include <stddef.h>
wtc69f8ea82015-06-04 00:08:1310#include <stdint.h>
Paul Jensenec3c11122017-11-28 16:48:3811#include <sys/types.h>
[email protected]6dbdaa82011-08-11 16:05:5612
13#include <string>
14#include <vector>
15
[email protected]71f4b272013-02-13 19:13:4916#include "net/android/cert_verify_result_android.h"
pauljensenf3ef7a582017-01-10 16:14:5017#include "net/base/ip_endpoint.h"
[email protected]3b455502012-12-11 18:22:5818#include "net/base/mime_util.h"
[email protected]be363b22012-11-01 17:38:4719#include "net/base/net_export.h"
Paul Jensenec3c11122017-11-28 16:48:3820#include "net/socket/socket_descriptor.h"
[email protected]6dbdaa82011-08-11 16:05:5621
22namespace net {
23namespace android {
24
[email protected]6dbdaa82011-08-11 16:05:5625// |cert_chain| is DER encoded chain of certificates, with the server's own
26// certificate listed first.
[email protected]b47feba2012-04-24 01:34:4127// |auth_type| is as per the Java X509Certificate.checkServerTrusted method.
[email protected]23073f92014-01-17 22:52:1728void VerifyX509CertChain(const std::vector<std::string>& cert_chain,
29 const std::string& auth_type,
30 const std::string& host,
31 CertVerifyStatusAndroid* status,
32 bool* is_issued_by_known_root,
33 std::vector<std::string>* verified_chain);
[email protected]6dbdaa82011-08-11 16:05:5634
[email protected]87ccb992012-12-12 01:31:5535// Adds a certificate as a root trust certificate to the trust manager.
36// |cert| is DER encoded certificate, |len| is its length in bytes.
wtc69f8ea82015-06-04 00:08:1337void AddTestRootCertificate(const uint8_t* cert, size_t len);
[email protected]87ccb992012-12-12 01:31:5538
39// Removes all root certificates added by |AddTestRootCertificate| calls.
40void ClearTestRootCertificates();
41
mgershd21d6d142016-12-14 23:06:3642// Returns true if cleartext traffic to |host| is allowed by the app. Always
43// true on L and older.
44bool IsCleartextPermitted(const std::string& host);
45
[email protected]c470e1b2012-06-15 07:46:3946// Returns true if it can determine that only loopback addresses are configured.
47// i.e. if only 127.0.0.1 and ::1 are routable.
48// Also returns false if it cannot determine this.
49bool HaveOnlyLoopbackAddresses();
50
[email protected]6dbdaa82011-08-11 16:05:5651// Get the mime type (if any) that is associated with the file extension.
52// Returns true if a corresponding mime type exists.
53bool GetMimeTypeFromExtension(const std::string& extension,
54 std::string* result);
55
[email protected]74d9c5242014-05-01 05:10:0356// Returns the ISO country code equivalent of the current MCC (mobile country
57// code).
58NET_EXPORT std::string GetTelephonyNetworkCountryIso();
59
60// Returns MCC+MNC (mobile country code + mobile network code) as
61// the numeric name of the current registered operator.
62NET_EXPORT std::string GetTelephonyNetworkOperator();
63
tbansala2e9f20c2015-09-03 20:05:0864// Returns MCC+MNC (mobile country code + mobile network code) as
65// the numeric name of the current SIM operator.
66NET_EXPORT std::string GetTelephonySimOperator();
67
68// Returns true if the device is roaming on the currently active network. When
69// true, it suggests that use of data may incur extra costs.
70NET_EXPORT bool GetIsRoaming();
71
tbansala7581d82016-11-24 18:00:3372// Returns true if the system's captive portal probe was blocked for the current
73// default data network. The method will return false if the captive portal
74// probe was not blocked, the login process to the captive portal has been
75// successfully completed, or if the captive portal status can't be determined.
76// Requires ACCESS_NETWORK_STATE permission. Only available on Android
77// Marshmallow and later versions. Returns false on earlier versions.
78NET_EXPORT bool GetIsCaptivePortal();
79
tbansalc5a1c912016-07-01 22:11:5680// Gets the SSID of the currently associated WiFi access point if there is one.
81// Otherwise, returns empty string.
82NET_EXPORT_PRIVATE std::string GetWifiSSID();
83
pauljensenf3ef7a582017-01-10 16:14:5084// Gets the DNS servers and puts them in |dns_servers|.
85// Only callable on Marshmallow and newer releases.
86NET_EXPORT_PRIVATE void GetDnsServers(std::vector<IPEndPoint>* dns_servers);
87
Paul Jensenec3c11122017-11-28 16:48:3888// Apply TrafficStats tag |tag| and UID |uid| to |socket|. Future network
89// traffic used by |socket| will be attributed to |uid| and |tag|.
90NET_EXPORT_PRIVATE void TagSocket(SocketDescriptor socket,
91 uid_t uid,
92 int32_t tag);
93
[email protected]6dbdaa82011-08-11 16:05:5694} // namespace android
95} // namespace net
96
97#endif // NET_ANDROID_NETWORK_LIBRARY_H_