blob: 59076d8a0a03be8259fa579f6007a100244adcf9 [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
David Benjamina63f1d12018-09-06 17:27:1716#include "base/strings/string_piece.h"
[email protected]71f4b272013-02-13 19:13:4917#include "net/android/cert_verify_result_android.h"
pauljensenf3ef7a582017-01-10 16:14:5018#include "net/base/ip_endpoint.h"
[email protected]3b455502012-12-11 18:22:5819#include "net/base/mime_util.h"
[email protected]be363b22012-11-01 17:38:4720#include "net/base/net_export.h"
Paul Jensen43b695ff2018-05-29 21:04:0521#include "net/dns/dns_config_service_posix.h"
Paul Jensenec3c11122017-11-28 16:48:3822#include "net/socket/socket_descriptor.h"
[email protected]6dbdaa82011-08-11 16:05:5623
24namespace net {
25namespace android {
26
[email protected]6dbdaa82011-08-11 16:05:5627// |cert_chain| is DER encoded chain of certificates, with the server's own
28// certificate listed first.
[email protected]b47feba2012-04-24 01:34:4129// |auth_type| is as per the Java X509Certificate.checkServerTrusted method.
[email protected]23073f92014-01-17 22:52:1730void VerifyX509CertChain(const std::vector<std::string>& cert_chain,
David Benjamina63f1d12018-09-06 17:27:1731 base::StringPiece auth_type,
32 base::StringPiece host,
[email protected]23073f92014-01-17 22:52:1733 CertVerifyStatusAndroid* status,
34 bool* is_issued_by_known_root,
35 std::vector<std::string>* verified_chain);
[email protected]6dbdaa82011-08-11 16:05:5636
[email protected]87ccb992012-12-12 01:31:5537// Adds a certificate as a root trust certificate to the trust manager.
38// |cert| is DER encoded certificate, |len| is its length in bytes.
wtc69f8ea82015-06-04 00:08:1339void AddTestRootCertificate(const uint8_t* cert, size_t len);
[email protected]87ccb992012-12-12 01:31:5540
41// Removes all root certificates added by |AddTestRootCertificate| calls.
42void ClearTestRootCertificates();
43
mgershd21d6d142016-12-14 23:06:3644// Returns true if cleartext traffic to |host| is allowed by the app. Always
45// true on L and older.
46bool IsCleartextPermitted(const std::string& host);
47
[email protected]c470e1b2012-06-15 07:46:3948// Returns true if it can determine that only loopback addresses are configured.
49// i.e. if only 127.0.0.1 and ::1 are routable.
50// Also returns false if it cannot determine this.
51bool HaveOnlyLoopbackAddresses();
52
[email protected]6dbdaa82011-08-11 16:05:5653// Get the mime type (if any) that is associated with the file extension.
54// Returns true if a corresponding mime type exists.
55bool GetMimeTypeFromExtension(const std::string& extension,
56 std::string* result);
57
[email protected]74d9c5242014-05-01 05:10:0358// Returns the ISO country code equivalent of the current MCC (mobile country
59// code).
60NET_EXPORT std::string GetTelephonyNetworkCountryIso();
61
62// Returns MCC+MNC (mobile country code + mobile network code) as
63// the numeric name of the current registered operator.
64NET_EXPORT std::string GetTelephonyNetworkOperator();
65
tbansala2e9f20c2015-09-03 20:05:0866// Returns MCC+MNC (mobile country code + mobile network code) as
67// the numeric name of the current SIM operator.
68NET_EXPORT std::string GetTelephonySimOperator();
69
70// Returns true if the device is roaming on the currently active network. When
71// true, it suggests that use of data may incur extra costs.
72NET_EXPORT bool GetIsRoaming();
73
tbansala7581d82016-11-24 18:00:3374// Returns true if the system's captive portal probe was blocked for the current
75// default data network. The method will return false if the captive portal
76// probe was not blocked, the login process to the captive portal has been
77// successfully completed, or if the captive portal status can't be determined.
78// Requires ACCESS_NETWORK_STATE permission. Only available on Android
79// Marshmallow and later versions. Returns false on earlier versions.
80NET_EXPORT bool GetIsCaptivePortal();
81
Tarun Bansaled90e45182018-04-06 03:07:1782// Gets the SSID of the currently associated WiFi access point if there is one,
83// and it is available. SSID may not be available if the app does not have
84// permissions to access it. On Android M+, the app accessing SSID needs to have
85// ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION. If there is no WiFi access
86// point or its SSID is unavailable, an empty string is returned.
tbansalc5a1c912016-07-01 22:11:5687NET_EXPORT_PRIVATE std::string GetWifiSSID();
88
pauljensenf3ef7a582017-01-10 16:14:5089// Gets the DNS servers and puts them in |dns_servers|.
90// Only callable on Marshmallow and newer releases.
Paul Jensen43b695ff2018-05-29 21:04:0591// Returns CONFIG_PARSE_POSIX_OK upon success,
92// CONFIG_PARSE_POSIX_NO_NAMESERVERS if no DNS servers found, or
93// CONFIG_PARSE_POSIX_PRIVATE_DNS_ACTIVE if private DNS active.
94NET_EXPORT_PRIVATE internal::ConfigParsePosixResult GetDnsServers(
95 std::vector<IPEndPoint>* dns_servers);
pauljensenf3ef7a582017-01-10 16:14:5096
Paul Jensenec3c11122017-11-28 16:48:3897// Apply TrafficStats tag |tag| and UID |uid| to |socket|. Future network
98// traffic used by |socket| will be attributed to |uid| and |tag|.
99NET_EXPORT_PRIVATE void TagSocket(SocketDescriptor socket,
100 uid_t uid,
101 int32_t tag);
102
[email protected]6dbdaa82011-08-11 16:05:56103} // namespace android
104} // namespace net
105
106#endif // NET_ANDROID_NETWORK_LIBRARY_H_