OCT 1. 更换HTTP Client库

This commit is contained in:
黄昕 2023-10-20 14:47:24 +08:00
parent 2258e3e315
commit dd25cb57e4
8 changed files with 1206 additions and 385 deletions

View File

@ -16,7 +16,7 @@ android {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
ndk {
//abiFilters.add("armeabi-v7a")
abiFilters.add("armeabi-v7a")
}
}

View File

@ -5,8 +5,6 @@
# Sets the minimum CMake version required for this project.
cmake_minimum_required(VERSION 3.22.1)
OPTION(SCG_ENABLE "Enable SCG Proxy Service" OFF)
# Declares the project name. The project name can be accessed via ${ PROJECT_NAME},
# Since this is the top level CMakeLists.txt, the project name is also accessible
# with ${CMAKE_PROJECT_NAME} (both CMake variables are in-sync within the top level
@ -32,14 +30,14 @@ ADD_DEFINITIONS(-D_LINUX)
# used in the AndroidManifest.xml file.
ADD_LIBRARY(${CMAKE_PROJECT_NAME} SHARED
# List C/C++ source files with relative paths to this CMakeLists.txt.
native-lib.cpp http/http-client.cpp srcs/ipcalc.cpp srcs/scc-service.cpp srcs/tunnel-proxy.cpp cJSON/cJSON.c ${C_HEADS})
native-lib.cpp srcs/ipcalc.cpp srcs/scc-service.cpp srcs/tunnel-proxy.cpp cJSON/cJSON.c ${C_HEADS})
MESSAGE(STATUS "SRC DIRECTORY: ${CMAKE_SOURCE_DIR}")
# Specifies libraries CMake should link to your target library. You
# can link libraries from various origins, such as libraries defined in this
# build script, prebuilt third-party libraries, or Android system libraries.
IF (SCG_ENABLE)
IF (TRUE)
ADD_DEFINITIONS(-DSCG_ON)
TARGET_LINK_LIBRARIES(${CMAKE_PROJECT_NAME}
# List libraries link to the target library

View File

@ -1,267 +0,0 @@
#include <cstdio>
#include <cstdlib>
#include <unistd.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <cstring>
#include "log.h"
#include "http-client.h"
#include "sccproxy.h"
#include "scg-service.h"
#define MY_HTTP_DEFAULT_PORT 80
#define BUFFER_SIZE 1024
#define HTTP_POST "POST /%s HTTP/1.1\r\nHOST: %s:%d\r\nAccept: */*\r\n"\
"Content-Type:application/json\r\nContent-Length: %d\r\n\r\n%s"
#define HTTP_GET "GET /%s HTTP/1.1\r\nHOST: %s:%d\r\nAccept: */*\r\n\r\n"
static void send_scg_head(int sock, int vmId) {
int ret;
unsigned char vmid[4];
unsigned char *p;
const unsigned int id = htonl(vmId);
const auto svrId = static_cast<unsigned char>(WG_CTRL_SCG_ID);
unsigned char scgProxy[] = {0x01, // VERSION
0x09, // Length
0xF0, // ++++++ INFO[0] TYPE
0x04, // INFO[0] LENGTH
0, // INFO[0] VMID[0]
0, // INFO[0] VMID[1]
0, // INFO[0] VMID[2]
0, // INFO[0] VMID[3]
0xF1, // INFO[1] TYPE
0x01, // INFO[1] LENGTH
svrId}; // ------ INFO[1] SCG Service ID
p = scgProxy;
memcpy(vmid, &id, 4);
scgProxy[4] = vmid[0];
scgProxy[5] = vmid[1];
scgProxy[6] = vmid[2];
scgProxy[7] = vmid[3];
ret = send(sock, reinterpret_cast<const char *>(p), sizeof(scgProxy), 0);
if (ret != sizeof(scgProxy)) {
ANDROID_LOG(ANDROID_LOG_WARN, "SCGPROXY", "Service Connected To SCG Server(vmid = %d, SCGAppId = %d) error: %d\n",
vmId, WG_CTRL_SCG_ID, ret);
}
ANDROID_LOG(ANDROID_LOG_DEBUG, "SCGPROXY", "Service Connected To SCG Server:vmid = %d, SCGAppId = %d: %d\n",
vmId, WG_CTRL_SCG_ID, sock);
}
static int http_tcpclient_create(const char *host, int port) {
struct hostent *he;
struct sockaddr_in server_addr {};
int socket_fd;
if ((he = gethostbyname(host)) == nullptr) {
return -1;
}
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(port);
server_addr.sin_addr = *((struct in_addr *) he->h_addr);
if ((socket_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
return -1;
}
if (connect(socket_fd, (struct sockaddr *) &server_addr, sizeof(struct sockaddr)) == -1) {
return -1;
}
//if(get_scg_cur_vmid() > 0) {
send_scg_head(socket_fd, get_scg_cur_vmid());
//}
return socket_fd;
}
static void http_tcpclient_close(int socket) {
close(socket);
}
static int http_parse_url(const char *url, char *host, char *file, int *port) {
char *ptr1, *ptr2;
int len = 0;
if (!url || !host || !file || !port) {
return -1;
}
ptr1 = (char *) url;
if (!strncmp(ptr1, "http://", strlen("http://"))) {
ptr1 += strlen("http://");
} else {
return -1;
}
ptr2 = strchr(ptr1, '/');
if (ptr2) {
len = strlen(ptr1) - strlen(ptr2);
memcpy(host, ptr1, len);
host[len] = '\0';
if (*(ptr2 + 1)) {
memcpy(file, ptr2 + 1, strlen(ptr2) - 1);
file[strlen(ptr2) - 1] = '\0';
}
} else {
memcpy(host, ptr1, strlen(ptr1));
host[strlen(ptr1)] = '\0';
}
//get host and ip
ptr1 = strchr(host, ':');
if (ptr1) {
*ptr1++ = '\0';
*port = atoi(ptr1);
} else {
*port = MY_HTTP_DEFAULT_PORT;
}
return 0;
}
static int http_tcpclient_recv(int socket, char *lpbuff) {
int recvnum = 0;
recvnum = recv(socket, lpbuff, BUFFER_SIZE * 4, 0);
return recvnum;
}
static int http_tcpclient_send(int socket, char *buff, int size) {
int sent = 0, tmpres = 0;
while (sent < size) {
tmpres = send(socket, buff + sent, size - sent, 0);
if (tmpres == -1) {
return -1;
}
sent += tmpres;
}
return sent;
}
static char *http_parse_result(const char *lpbuf) {
char *ptmp = nullptr;
char *response = nullptr;
ptmp = (char *) strstr(lpbuf, "HTTP/1.1");
if (!ptmp) {
printf("http/1.1 not faind\n");
return nullptr;
}
if (atoi(ptmp + 9) != 200) {
printf("result:\n%s\n", lpbuf);
return nullptr;
}
ptmp = (char *) strstr(lpbuf, "\r\n\r\n");
if (!ptmp) {
printf("ptmp is nullptr\n");
return nullptr;
}
response = (char *) malloc(strlen(ptmp) + 1);
if (!response) {
printf("malloc failed \n");
return nullptr;
}
strcpy(response, ptmp + 4);
return response;
}
char *http_post(const char *url, const char *post_str) {
char post[BUFFER_SIZE] = {'\0'};
int socket_fd = -1;
char lpbuf[BUFFER_SIZE * 4] = {'\0'};
char *ptmp;
char host_addr[BUFFER_SIZE] = {'\0'};
char file[BUFFER_SIZE] = {'\0'};
int port = 0;
int len = 0;
char *response = nullptr;
if (!url || !post_str) {
printf(" failed!\n");
return nullptr;
}
if (http_parse_url(url, host_addr, file, &port)) {
printf("http_parse_url failed!\n");
return nullptr;
}
//printf("host_addr : %s\tfile:%s\t,%d\n",host_addr,file,port);
socket_fd = http_tcpclient_create(host_addr, port);
if (socket_fd < 0) {
printf("http_tcpclient_create failed\n");
return nullptr;
}
sprintf(lpbuf, HTTP_POST, file, host_addr, port, static_cast<int>(strlen(post_str)), post_str);
if (http_tcpclient_send(socket_fd, lpbuf, static_cast<int>(strlen(lpbuf))) < 0) {
printf("http_tcpclient_send failed..\n");
return nullptr;
}
//printf("发送请求:\n%s\n",lpbuf);
/*it's time to recv from server*/
if (http_tcpclient_recv(socket_fd, lpbuf) <= 0) {
printf("http_tcpclient_recv failed\n");
return nullptr;
}
http_tcpclient_close(socket_fd);
return http_parse_result(lpbuf);
}
char *http_get(const char *url) {
char post[BUFFER_SIZE] = {'\0'};
int socket_fd = -1;
char lpbuf[BUFFER_SIZE * 4] = {'\0'};
char *ptmp;
char host_addr[BUFFER_SIZE] = {'\0'};
char file[BUFFER_SIZE] = {'\0'};
int port = 0;
int len = 0;
if (!url) {
printf(" failed!\n");
return nullptr;
}
if (http_parse_url(url, host_addr, file, &port)) {
printf("http_parse_url failed!\n");
return nullptr;
}
//printf("host_addr : %s\tfile:%s\t,%d\n",host_addr,file,port);
socket_fd = http_tcpclient_create(host_addr, port);
if (socket_fd < 0) {
printf("http_tcpclient_create failed\n");
return nullptr;
}
sprintf(lpbuf, HTTP_GET, file, host_addr, port);
if (http_tcpclient_send(socket_fd, lpbuf, static_cast<int>(strlen(lpbuf))) < 0) {
printf("http_tcpclient_send failed..\n");
return nullptr;
}
// printf("发送请求:\n%s\n",lpbuf);
if (http_tcpclient_recv(socket_fd, lpbuf) <= 0) {
printf("http_tcpclient_recv failed\n");
return nullptr;
}
http_tcpclient_close(socket_fd);
return http_parse_result(lpbuf);
}

View File

@ -1,5 +0,0 @@
#pragma once
char * http_get(const char *url);
char * http_post(const char *url,const char * post_str);

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,6 @@
#ifdef SCG_ON
static void connect_scg_server() {
//1、设置token
jwae_set_token("token1234");

View File

@ -8,7 +8,7 @@
#include "ipcalc.h"
#include "scg-service.h"
#include "../cJSON/cJSON.h"
#include "../http/http-client.h"
#include "sion.h"
#define SET_CLIENTCFG_PATH ("/tunnel/setconfig")
#define SET_CLIENTSTART_TUNNEL ("/tunnel/start")
@ -24,6 +24,42 @@ typedef struct {
static SCGPROXY_CONFIG g_scgProxyCfg;
static void http_connected_cb(sion::Socket sock) {
int ret;
unsigned char vmid[4];
unsigned char *p;
const unsigned int id = htonl(g_scgProxyCfg.curConnVmId);
const auto svrId = static_cast<unsigned char>(WG_CTRL_SCG_ID);
unsigned char scgProxy[] = {0x01, // VERSION
0x09, // Length
0xF0, // ++++++ INFO[0] TYPE
0x04, // INFO[0] LENGTH
0, // INFO[0] VMID[0]
0, // INFO[0] VMID[1]
0, // INFO[0] VMID[2]
0, // INFO[0] VMID[3]
0xF1, // INFO[1] TYPE
0x01, // INFO[1] LENGTH
svrId}; // ------ INFO[1] SCG Service ID
p = scgProxy;
memcpy(vmid, &id, 4);
scgProxy[4] = vmid[0];
scgProxy[5] = vmid[1];
scgProxy[6] = vmid[2];
scgProxy[7] = vmid[3];
ret = send(sock, reinterpret_cast<const char *>(p), sizeof(scgProxy), 0);
if (ret != sizeof(scgProxy)) {
ANDROID_LOG(ANDROID_LOG_WARN, "SCGPROXY", "Service Connected To SCG Server(vmid = %d, SCGAppId = %d) error: %d\n",
g_scgProxyCfg.curConnVmId, WG_CTRL_SCG_ID, ret);
}
ANDROID_LOG(ANDROID_LOG_DEBUG, "SCGPROXY", "Service Connected To SCG Server:vmid = %d, SCGAppId = %d: %d\n",
g_scgProxyCfg.curConnVmId, WG_CTRL_SCG_ID, sock);
}
int get_scg_cur_vmid() {
return g_scgProxyCfg.curConnVmId;
}
@ -136,7 +172,7 @@ static int remote_tunnel_service_control(int vmId, bool start) {
cJSON *pMsgContent;
cJSON *rspCode;
char url[1024];
char *pSvrResp;
sion::Response resp;
if (vmId < 0) {
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Input pSCGIpAddr params error: %d\n", vmId);
@ -176,36 +212,49 @@ static int remote_tunnel_service_control(int vmId, bool start) {
memset(url, 0, 1024);
snprintf(url, 1024, "%s%s", g_scgProxyCfg.scgProxyUrl, SET_CLIENTSTART_TUNNEL);
pSvrResp = http_post(url, pJsonString);
// res = g_scgProxyCfg.g_tunCtrlCtx->Post(SET_CLIENTSTART_TUNNEL, pJsonString, "application/json");
resp = sion::Request()
.SetUrl(url)
.SetHttpMethod(sion::Method::Post)
.SetHeader("Content-type", "application/json")
.SetBody(pJsonString)
.SetConnectedCb(http_connected_cb)
.Send();
if (pSvrResp == nullptr) {
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "[%s]:Post Data %s error\n", SET_CLIENTSTART_TUNNEL, pJsonString);
if (resp.Status() != "OK") {
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "[%s]:Post Data %s error: %s\n", SET_CLIENTCFG_PATH, pJsonString, resp.Status().c_str());
free(pJsonString);
return -ERR_HTTP_POST_DATA;
}
ANDROID_LOG(ANDROID_LOG_DEBUG, "SCGPROXY", "+++++ Http Request %s\n---- Http Response %s\n", pJsonString, pSvrResp);
if (resp.Code() != "200") {
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "[%s]:Post Data %s server return HTTP error: %s\n", SET_CLIENTCFG_PATH,
pJsonString,
resp.Code().c_str());
free(pJsonString);
return -ERR_HTTP_SERVER_RSP;
}
ANDROID_LOG(ANDROID_LOG_DEBUG, "SCGPROXY", "+++++ Http Request %s\n---- Http Response %s\n", pJsonString, resp.StrBody().c_str());
free(pJsonString);
if (strlen(pSvrResp) == 0) {
if (strlen(resp.Code().c_str()) == 0) {
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Server response empty message.\n");
return -ERR_READ_FILE;
}
pRoot = cJSON_Parse(pSvrResp);
pRoot = cJSON_Parse(resp.StrBody().c_str());
if (pRoot == nullptr) {
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode JSON %s Error.\n", pSvrResp);
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode JSON %s Error.\n", resp.StrBody().c_str());
return -ERR_JSON_DECODE;
}
pMsgContent = cJSON_GetObjectItem(pRoot, "msgContent");
if (pMsgContent == nullptr) {
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode(msgContent) JSON %s Error.\n", pSvrResp);
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode(msgContent) JSON %s Error.\n", resp.StrBody().c_str());
cJSON_Delete(pRoot);
return -ERR_JSON_DECODE;
}
@ -213,7 +262,7 @@ static int remote_tunnel_service_control(int vmId, bool start) {
rspCode = cJSON_GetObjectItem(pMsgContent, "errCode");
if (rspCode == nullptr) {
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode(msgContent.rspCode) JSON %s Error.\n", pSvrResp);
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode(msgContent.rspCode) JSON %s Error.\n", resp.StrBody().c_str());
cJSON_Delete(pRoot);
return -ERR_JSON_DECODE;
}
@ -263,7 +312,7 @@ int remote_tunnel_set_params(const char *pCliPubKey, const char *pCliNetwork, co
cJSON *pRspCode;
cJSON *pSvrNet;
char url[1024];
char *pSvrResp;
sion::Response resp;
if (pCliPubKey == nullptr || strlen(pCliPubKey) == 0) {
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Input pCliPubKey params error: %s\n", pCliPubKey ? pCliPubKey : "NULL String");
@ -323,8 +372,28 @@ int remote_tunnel_set_params(const char *pCliPubKey, const char *pCliNetwork, co
memset(url, 0, 1024);
snprintf(url, 1024, "%s%s", g_scgProxyCfg.scgProxyUrl, SET_CLIENTCFG_PATH);
pSvrResp = http_post(url, pJsonString);
resp = sion::Request()
.SetUrl(url)
.SetHttpMethod(sion::Method::Post)
.SetHeader("Content-type", "application/json")
.SetBody(pJsonString)
.SetConnectedCb(http_connected_cb)
.Send();
if (resp.Status() != "OK") {
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "[%s]:Post Data %s error: %s\n", SET_CLIENTCFG_PATH, pJsonString, resp.Status().c_str());
free(pJsonString);
return -ERR_HTTP_POST_DATA;
}
if (resp.Code() != "200") {
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "[%s]:Post Data %s server return HTTP error: %s\n", SET_CLIENTCFG_PATH,
pJsonString,
resp.Code().c_str());
free(pJsonString);
return -ERR_HTTP_SERVER_RSP;
}
#if 0
memset(url, 0, 1024);
//sprintf(url, "%s", g_scgProxyCfg.)
@ -340,31 +409,22 @@ int remote_tunnel_set_params(const char *pCliPubKey, const char *pCliNetwork, co
}
res = g_scgProxyCfg.g_tunCtrlCtx->Post(SET_CLIENTCFG_PATH, pJsonString, "application/json");
#endif
if (pSvrResp == nullptr) {
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "[%s]:Post Data %s error", SET_CLIENTCFG_PATH, pJsonString);
free(pJsonString);
return -ERR_HTTP_POST_DATA;
}
ANDROID_LOG(ANDROID_LOG_DEBUG, "SCGPROXY", "+++++ Http Request %s\n---- Http Response %s\n", pJsonString, pSvrResp);
ANDROID_LOG(ANDROID_LOG_DEBUG, "SCGPROXY", "+++++ Http Request %s\n---- Http Response %s\n", pJsonString, resp.StrBody().c_str());
free(pJsonString);
if (strlen(pSvrResp) == 0) {
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Server response empty message.\n");
return -ERR_READ_FILE;
}
pRoot = cJSON_Parse(pSvrResp);
pRoot = cJSON_Parse(resp.StrBody().c_str());
if (pRoot == nullptr) {
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode JSON %s Error.\n", pSvrResp);
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode JSON %s Error.\n", resp.StrBody().c_str());
return -ERR_JSON_DECODE;
}
pMsgContent = cJSON_GetObjectItem(pRoot, "msgContent");
if (pMsgContent == nullptr) {
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode(msgContent) JSON %s Error.\n", pSvrResp);
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode(msgContent) JSON %s Error.\n", resp.StrBody().c_str());
cJSON_Delete(pRoot);
return -ERR_JSON_DECODE;
}
@ -372,7 +432,7 @@ int remote_tunnel_set_params(const char *pCliPubKey, const char *pCliNetwork, co
pRspCode = cJSON_GetObjectItem(pMsgContent, "errCode");
if (pRspCode == nullptr) {
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode(msgContent.pRspCode) JSON %s Error.\n", pSvrResp);
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode(msgContent.pRspCode) JSON %s Error.\n", resp.StrBody().c_str());
cJSON_Delete(pRoot);
return -ERR_JSON_DECODE;
}
@ -385,7 +445,7 @@ int remote_tunnel_set_params(const char *pCliPubKey, const char *pCliNetwork, co
pSvrNet = cJSON_GetObjectItem(pMsgContent, "svrNetwork");
if (pSvrNet == nullptr) {
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode(msgContent.pSvrNet) JSON %s Error.\n", pSvrResp);
ANDROID_LOG(ANDROID_LOG_ERROR, "SCGPROXY", "Decode(msgContent.pSvrNet) JSON %s Error.\n", resp.StrBody().c_str());
cJSON_Delete(pRoot);
return -ERR_JSON_DECODE;
}

View File

@ -35,67 +35,67 @@ public class MainActivity extends AppCompatActivity {
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
requestPermission();
//requestPermission();
// Example of a call to a native method
TextView tv = binding.sampleText;
tv.setText(stringFromJNI());
}
private void requestPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// 先判断有没有权限
if (Environment.isExternalStorageManager()) {
writeFile();
} else {
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
intent.setData(Uri.parse("package:" + this.getPackageName()));
startActivityForResult(intent, REQUEST_CODE);
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// 先判断有没有权限
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
writeFile();
} else {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE);
}
} else {
writeFile();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQUEST_CODE) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
writeFile();
} else {
//ToastUtils.show("存储权限获取失败");
}
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (Environment.isExternalStorageManager()) {
writeFile();
} else {
//ToastUtils.show("存储权限获取失败");
}
}
}
/**
* 模拟文件写入
*/
private void writeFile() {
//ToastUtils.show("写入文件成功");
}
//
// private void requestPermission() {
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// // 先判断有没有权限
// if (Environment.isExternalStorageManager()) {
// writeFile();
// } else {
// Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
// intent.setData(Uri.parse("package:" + this.getPackageName()));
// startActivityForResult(intent, REQUEST_CODE);
// }
// } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// // 先判断有没有权限
// if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED &&
// ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
// writeFile();
// } else {
// ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE);
// }
// } else {
// writeFile();
// }
// }
//
// @Override
// public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
// super.onRequestPermissionsResult(requestCode, permissions, grantResults);
// if (requestCode == REQUEST_CODE) {
// if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED &&
// ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
// writeFile();
// } else {
// //ToastUtils.show("存储权限获取失败");
// }
// }
// }
//
// @Override
// protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
// super.onActivityResult(requestCode, resultCode, data);
// if (requestCode == REQUEST_CODE && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// if (Environment.isExternalStorageManager()) {
// writeFile();
// } else {
// //ToastUtils.show("存储权限获取失败");
// }
// }
// }
//
// /**
// * 模拟文件写入
// */
// private void writeFile() {
// //ToastUtils.show("写入文件成功");
// }
/**
* A native method that is implemented by the 'sccproxy' native library,