Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qnetworkproxy_android.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qnetworkproxy.h"
5
6#include <QtCore/qcoreapplication_platform.h>
7#include <QtCore/qjnienvironment.h>
8#include <QtCore/qjniobject.h>
9
10#ifndef QT_NO_NETWORKPROXY
11
13
15{
16public:
19};
20
21using namespace QNativeInterface;
22
23Q_GLOBAL_STATIC(ProxyInfoObject, proxyInfoInstance)
24
25static const char networkClass[] = "org/qtproject/qt/android/network/QtNetwork";
26
27Q_DECLARE_JNI_CLASS(ProxyInfo, "android/net/ProxyInfo")
28Q_DECLARE_JNI_TYPE(JStringArray, "[Ljava/lang/String;")
29
31{
32 QJniObject::callStaticMethod<void>(networkClass,
33 "registerReceiver",
34 QAndroidApplication::context());
35}
36
38{
39 QJniObject::callStaticMethod<void>(networkClass,
40 "unregisterReceiver",
41 QAndroidApplication::context());
42}
43
45{
46 QList<QNetworkProxy> proxyList;
47 if (!proxyInfoInstance)
48 return proxyList;
49
50 QJniObject proxyInfo = QJniObject::callStaticObjectMethod<QtJniTypes::ProxyInfo>(
51 networkClass, "getProxyInfo", QAndroidApplication::context());
52 if (proxyInfo.isValid()) {
53 QJniObject exclusionList =
54 proxyInfo.callObjectMethod<QtJniTypes::JStringArray>("getExclusionList");
55 bool exclude = false;
56 if (exclusionList.isValid()) {
57 jobjectArray listObject = exclusionList.object<jobjectArray>();
60 const int size = env->GetArrayLength(listObject);
61 QUrl host = QUrl(query.url().host());
62 for (int i = 0; i < size; ++i) {
63 entry = env->GetObjectArrayElement(listObject, i);
64 if (host.matches(QUrl(entry.toString()), QUrl::RemoveScheme)) {
65 exclude = true;
66 break;
67 }
68 }
69 }
70 if (!exclude) {
71 QJniObject hostName = proxyInfo.callObjectMethod<jstring>("getHost");
72 const int port = proxyInfo.callMethod<jint>("getPort");
73 QNetworkProxy proxy(QNetworkProxy::HttpProxy, hostName.toString(), port);
74 proxyList << proxy;
75 }
76 }
77 if (proxyList.isEmpty())
78 proxyList << QNetworkProxy::NoProxy;
79
80 return proxyList;
81}
82
84
85#endif
Q_DECLARE_JNI_TYPE(StringArray, "[Ljava/lang/String;")
\inmodule QtCore
\inmodule QtCore
static QList< QNetworkProxy > systemProxyForQuery(const QNetworkProxyQuery &query=QNetworkProxyQuery())
This function takes the query request, query, examines the details of the type of socket or request a...
The QNetworkProxyQuery class is used to query the proxy settings for a socket.
The QNetworkProxy class provides a network layer proxy.
\inmodule QtCore
Definition qurl.h:94
bool matches(const QUrl &url, FormattingOptions options) const
Definition qurl.cpp:3180
@ RemoveScheme
Definition qurl.h:105
Combined button and popup list for selecting options.
EGLOutputPortEXT port
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
static const char networkClass[]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum query
GLuint entry
QT_BEGIN_NAMESPACE Q_DECLARE_JNI_CLASS(Environment, "android/os/Environment")
QNetworkProxy proxy
[0]