diff --git a/entry/src/main/config.json b/entry/src/main/config.json index 5d5031ff4832b316b82a9bdba02ab96b25752c02..26946a5ff3f05263f450c2a586e99794dda9cc0a 100644 --- a/entry/src/main/config.json +++ b/entry/src/main/config.json @@ -16,16 +16,72 @@ ], "reqPermissions": [ { - "name": "ohos.permission.INTERNET" + "name": "ohos.permission.INTERNET", + "reason": "get internet info", + "usedScene": { + "ability": [ + "com.wordplat.quickstart.ability.MainAbility", + "com.wordplat.quickstart.ability.Disable_Left_And_Right_Refresh_Ability", + "com.wordplat.quickstart.ability.Enable_Left_And_Right_Refresh_Ability", + "com.wordplat.quickstart.ability.MACD_RSI_KDJ_Show_Together_Ability", + "com.wordplat.quickstart.ability.Simple_TimeLine_Example_Ability", + "com.wordplat.quickstart.ability.With_Fragment_And_TabLayout_Switcher_Example_Ability", + "com.wordplat.quickstart.ability.With_Pull_To_Refresh_Example_Ability", + "com.wordplat.quickstart.ability.With_RecyclerView_Example_Ability" + ], + "when": "always" + } }, { - "name": "ohos.permission.WRITE_MEDIA" + "name": "ohos.permission.WRITE_MEDIA", + "reason": "get write info", + "usedScene": { + "ability": [ + "com.wordplat.quickstart.ability.MainAbility", + "com.wordplat.quickstart.ability.Disable_Left_And_Right_Refresh_Ability", + "com.wordplat.quickstart.ability.Enable_Left_And_Right_Refresh_Ability", + "com.wordplat.quickstart.ability.MACD_RSI_KDJ_Show_Together_Ability", + "com.wordplat.quickstart.ability.Simple_TimeLine_Example_Ability", + "com.wordplat.quickstart.ability.With_Fragment_And_TabLayout_Switcher_Example_Ability", + "com.wordplat.quickstart.ability.With_Pull_To_Refresh_Example_Ability", + "com.wordplat.quickstart.ability.With_RecyclerView_Example_Ability" + ], + "when": "always" + } }, { - "name": "ohos.permission.GET_WIFI_INFO" + "name": "ohos.permission.GET_WIFI_INFO", + "reason": "get wifi info", + "usedScene": { + "ability": [ + "com.wordplat.quickstart.ability.MainAbility", + "com.wordplat.quickstart.ability.Disable_Left_And_Right_Refresh_Ability", + "com.wordplat.quickstart.ability.Enable_Left_And_Right_Refresh_Ability", + "com.wordplat.quickstart.ability.MACD_RSI_KDJ_Show_Together_Ability", + "com.wordplat.quickstart.ability.Simple_TimeLine_Example_Ability", + "com.wordplat.quickstart.ability.With_Fragment_And_TabLayout_Switcher_Example_Ability", + "com.wordplat.quickstart.ability.With_Pull_To_Refresh_Example_Ability", + "com.wordplat.quickstart.ability.With_RecyclerView_Example_Ability" + ], + "when": "always" + } }, { - "name": "ohos.permission.GET_NETWORK_INFO" + "name": "ohos.permission.GET_NETWORK_INFO", + "reason": "get network info", + "usedScene": { + "ability": [ + "com.wordplat.quickstart.ability.MainAbility", + "com.wordplat.quickstart.ability.Disable_Left_And_Right_Refresh_Ability", + "com.wordplat.quickstart.ability.Enable_Left_And_Right_Refresh_Ability", + "com.wordplat.quickstart.ability.MACD_RSI_KDJ_Show_Together_Ability", + "com.wordplat.quickstart.ability.Simple_TimeLine_Example_Ability", + "com.wordplat.quickstart.ability.With_Fragment_And_TabLayout_Switcher_Example_Ability", + "com.wordplat.quickstart.ability.With_Pull_To_Refresh_Example_Ability", + "com.wordplat.quickstart.ability.With_RecyclerView_Example_Ability" + ], + "when": "always" + } } ], "distro": { @@ -73,6 +129,7 @@ "orientation": "unspecified", "name": "com.wordplat.quickstart.ability.Enable_Left_And_Right_Refresh_Ability", "icon": "$media:icon", + "visible": false, "label": "$string:app_name", "type": "page", "launchType": "standard" @@ -89,6 +146,7 @@ "orientation": "unspecified", "name": "com.wordplat.quickstart.ability.Disable_Left_And_Right_Refresh_Ability", "icon": "$media:icon", + "visible": false, "label": "$string:app_name", "type": "page", "launchType": "standard" @@ -105,6 +163,7 @@ "orientation": "unspecified", "name": "com.wordplat.quickstart.ability.MACD_RSI_KDJ_Show_Together_Ability", "icon": "$media:icon", + "visible": false, "label": "$string:app_name", "type": "page", "launchType": "standard" @@ -120,6 +179,7 @@ "orientation": "unspecified", "name": "com.wordplat.quickstart.ability.Simple_TimeLine_Example_Ability", "icon": "$media:icon", + "visible": false, "label": "$string:app_name", "type": "page", "launchType": "standard" @@ -135,6 +195,7 @@ "orientation": "unspecified", "name": "com.wordplat.quickstart.ability.With_Pull_To_Refresh_Example_Ability", "icon": "$media:icon", + "visible": false, "label": "$string:app_name", "type": "page", "launchType": "standard" @@ -150,6 +211,7 @@ "orientation": "unspecified", "name": "com.wordplat.quickstart.ability.With_Fragment_And_TabLayout_Switcher_Example_Ability", "icon": "$media:icon", + "visible": false, "label": "$string:app_name", "type": "page", "launchType": "standard" diff --git a/entry/src/main/java/com/wordplat/quickstart/xutils/http/BaseParams.java b/entry/src/main/java/com/wordplat/quickstart/xutils/http/BaseParams.java index 919c98d242bb4b7f90c26d4a22ee4ba30e3cc200..06f89305fb2c1a5074494de6e3d13ebe432d80d8 100644 --- a/entry/src/main/java/com/wordplat/quickstart/xutils/http/BaseParams.java +++ b/entry/src/main/java/com/wordplat/quickstart/xutils/http/BaseParams.java @@ -13,6 +13,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Array; +import java.security.NoSuchAlgorithmException; import java.util.*; /** @@ -339,7 +340,7 @@ public abstract class BaseParams { * @return RequestBody * @throws IOException */ - public RequestBody getRequestBody() throws IOException { + public RequestBody getRequestBody() throws IOException, NoSuchAlgorithmException { checkBodyParams(); if (this.requestBody != null) { return this.requestBody; diff --git a/entry/src/main/java/com/wordplat/quickstart/xutils/http/body/MultipartBody.java b/entry/src/main/java/com/wordplat/quickstart/xutils/http/body/MultipartBody.java index f5fe776a1d541930eef3eae46ff287081d16880c..db9e87d620d5cecca46a362a75f170b1321664fe 100644 --- a/entry/src/main/java/com/wordplat/quickstart/xutils/http/body/MultipartBody.java +++ b/entry/src/main/java/com/wordplat/quickstart/xutils/http/body/MultipartBody.java @@ -9,6 +9,8 @@ import com.wordplat.quickstart.xutils.http.BaseParams.BodyItemWrapper; import com.wordplat.quickstart.xutils.http.ProgressHandler; import java.io.*; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; import java.util.List; import java.util.Random; import java.util.concurrent.atomic.AtomicLong; @@ -30,7 +32,8 @@ public class MultipartBody implements ProgressBody { private final List multipartParams; private long total = 0; private long current = 0; - private final Random random = new Random(); + + SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); /** * \ * MultipartBody @@ -38,7 +41,7 @@ public class MultipartBody implements ProgressBody { * @param multipartParams * @param charset */ - public MultipartBody(List multipartParams, String charset) { + public MultipartBody(List multipartParams, String charset) throws NoSuchAlgorithmException { if (!TextUtils.isEmpty(charset)) { this.charset = charset; } diff --git a/entry/src/main/java/com/wordplat/quickstart/xutils/http/request/HttpRequest.java b/entry/src/main/java/com/wordplat/quickstart/xutils/http/request/HttpRequest.java index 07c280a17afaf28d3ea1f2ffa9488acec6465e1e..bbd70d59d0d70bbd0cc92036a27180b9f35bebf9 100644 --- a/entry/src/main/java/com/wordplat/quickstart/xutils/http/request/HttpRequest.java +++ b/entry/src/main/java/com/wordplat/quickstart/xutils/http/request/HttpRequest.java @@ -98,138 +98,138 @@ public class HttpRequest extends UriRequest { @Override public void sendRequest() throws Throwable { - isLoading = false; - responseCode = 0; - - URL url = new URL(queryUrl); - - Proxy proxy = params.getProxy(); - if (proxy != null) { - connection = (HttpURLConnection) url.openConnection(proxy); - } else { - connection = (HttpURLConnection) url.openConnection(); - } - connection.setReadTimeout(params.getReadTimeout()); - connection.setConnectTimeout(params.getConnectTimeout()); - connection.setInstanceFollowRedirects(params.getRedirectHandler() == null); - if (connection instanceof HttpsURLConnection) { - SSLSocketFactory sslSocketFactory = params.getSslSocketFactory(); - if (sslSocketFactory != null) { - ((HttpsURLConnection) connection).setSSLSocketFactory(sslSocketFactory); - } - - HostnameVerifier hostnameVerifier = params.getHostnameVerifier(); - if (hostnameVerifier != null) { - ((HttpsURLConnection) connection).setHostnameVerifier(hostnameVerifier); - } - } - - if (params.isUseCookie()) { - try { - Map> singleMap = - COOKIE_MANAGER.get(url.toURI(), new HashMap>(0)); - List cookies = singleMap.get("Cookie"); - if (cookies != null) { - connection.setRequestProperty("Cookie", TextUtils.join(";", cookies)); - } - } catch (Throwable ex) { - LogUtil.e(ex.getMessage(), ex); - } - } - - List headers = params.getHeaders(); - if (headers != null) { - for (RequestParams.Header header : headers) { - String name = header.key; - String value = header.getValueStrOrNull(); - if (!TextUtils.isEmpty(name)) { - if (header.setHeader) { - connection.setRequestProperty(name, value); - } else { - connection.addRequestProperty(name, value); - } - } - } - } - if (responseParser != null) { - responseParser.beforeRequest(this); - } - if (requestInterceptListener != null) { - requestInterceptListener.beforeRequest(this); - } - - { // write body - HttpMethod method = params.getMethod(); - try { - connection.setRequestMethod(method.toString()); - } catch (ProtocolException ex) { - try { // fix: HttpURLConnection not support PATCH method. - Field methodField = HttpURLConnection.class.getDeclaredField("method"); - methodField.setAccessible(true); - methodField.set(connection, method.toString()); - } catch (Throwable ignored) { - throw ex; - } - } - if (HttpMethod.permitsRequestBody(method)) { - RequestBody body = params.getRequestBody(); - if (body != null) { - if (body instanceof ProgressBody) { - ((ProgressBody) body).setProgressHandler(progressHandler); - } - String contentType = body.getContentType(); - if (!TextUtils.isEmpty(contentType)) { - connection.setRequestProperty("Content-Type", contentType); - } - boolean isChunkedMode = false; - long contentLength = body.getContentLength(); - if (contentLength < 0) { - connection.setChunkedStreamingMode(256 * 1024); - isChunkedMode = true; - } else { - if (contentLength < Integer.MAX_VALUE) { - connection.setFixedLengthStreamingMode((int) contentLength); - } else { - connection.setChunkedStreamingMode(256 * 1024); - isChunkedMode = true; - } - } - - if (isChunkedMode) { - connection.setRequestProperty("Transfer-Encoding", "chunked"); - } else { - connection.setRequestProperty("Content-Length", String.valueOf(contentLength)); - } - - connection.setDoOutput(true); - body.writeTo(connection.getOutputStream()); - } - } - } - - responseCode = connection.getResponseCode(); - { - if (responseParser != null) { - responseParser.afterRequest(this); - } - if (requestInterceptListener != null) { - requestInterceptListener.afterRequest(this); - } - } - if (responseCode == 204 || responseCode == 205) { // empty content - throw new HttpException(responseCode, this.getResponseMessage()); - } else if (responseCode >= 300) { - HttpException httpException = new HttpException(responseCode, this.getResponseMessage()); - try { - httpException.setResult(IOUtil.readStr(this.getInputStream(), params.getCharset())); - } catch (Throwable ex) { - LogUtil.w(ex.getMessage(), ex); - } - LogUtil.e(httpException.toString() + ", url: " + queryUrl); - throw httpException; - } - - isLoading = true; +// isLoading = false; +// responseCode = 0; +// +// URL url = new URL(queryUrl); +// +// Proxy proxy = params.getProxy(); +// if (proxy != null) { +// connection = (HttpURLConnection) url.openConnection(proxy); +// } else { +// connection = (HttpURLConnection) url.openConnection(); +// } +// connection.setReadTimeout(params.getReadTimeout()); +// connection.setConnectTimeout(params.getConnectTimeout()); +// connection.setInstanceFollowRedirects(params.getRedirectHandler() == null); +// if (connection instanceof HttpsURLConnection) { +// SSLSocketFactory sslSocketFactory = params.getSslSocketFactory(); +// if (sslSocketFactory != null) { +// ((HttpsURLConnection) connection).setSSLSocketFactory(sslSocketFactory); +// } +// +// HostnameVerifier hostnameVerifier = params.getHostnameVerifier(); +// if (hostnameVerifier != null) { +// ((HttpsURLConnection) connection).setHostnameVerifier(hostnameVerifier); +// } +// } +// +// if (params.isUseCookie()) { +// try { +// Map> singleMap = +// COOKIE_MANAGER.get(url.toURI(), new HashMap>(0)); +// List cookies = singleMap.get("Cookie"); +// if (cookies != null) { +// connection.setRequestProperty("Cookie", TextUtils.join(";", cookies)); +// } +// } catch (Throwable ex) { +// LogUtil.e(ex.getMessage(), ex); +// } +// } +// +// List headers = params.getHeaders(); +// if (headers != null) { +// for (RequestParams.Header header : headers) { +// String name = header.key; +// String value = header.getValueStrOrNull(); +// if (!TextUtils.isEmpty(name)) { +// if (header.setHeader) { +// connection.setRequestProperty(name, value); +// } else { +// connection.addRequestProperty(name, value); +// } +// } +// } +// } +// if (responseParser != null) { +// responseParser.beforeRequest(this); +// } +// if (requestInterceptListener != null) { +// requestInterceptListener.beforeRequest(this); +// } +// +// { // write body +// HttpMethod method = params.getMethod(); +// try { +// connection.setRequestMethod(method.toString()); +// } catch (ProtocolException ex) { +// try { // fix: HttpURLConnection not support PATCH method. +// Field methodField = HttpURLConnection.class.getDeclaredField("method"); +// methodField.setAccessible(true); +// methodField.set(connection, method.toString()); +// } catch (Throwable ignored) { +// throw ex; +// } +// } +// if (HttpMethod.permitsRequestBody(method)) { +// RequestBody body = params.getRequestBody(); +// if (body != null) { +// if (body instanceof ProgressBody) { +// ((ProgressBody) body).setProgressHandler(progressHandler); +// } +// String contentType = body.getContentType(); +// if (!TextUtils.isEmpty(contentType)) { +// connection.setRequestProperty("Content-Type", contentType); +// } +// boolean isChunkedMode = false; +// long contentLength = body.getContentLength(); +// if (contentLength < 0) { +// connection.setChunkedStreamingMode(256 * 1024); +// isChunkedMode = true; +// } else { +// if (contentLength < Integer.MAX_VALUE) { +// connection.setFixedLengthStreamingMode((int) contentLength); +// } else { +// connection.setChunkedStreamingMode(256 * 1024); +// isChunkedMode = true; +// } +// } +// +// if (isChunkedMode) { +// connection.setRequestProperty("Transfer-Encoding", "chunked"); +// } else { +// connection.setRequestProperty("Content-Length", String.valueOf(contentLength)); +// } +// +// connection.setDoOutput(true); +// body.writeTo(connection.getOutputStream()); +// } +// } +// } +// +// responseCode = connection.getResponseCode(); +// { +// if (responseParser != null) { +// responseParser.afterRequest(this); +// } +// if (requestInterceptListener != null) { +// requestInterceptListener.afterRequest(this); +// } +// } +// if (responseCode == 204 || responseCode == 205) { // empty content +// throw new HttpException(responseCode, this.getResponseMessage()); +// } else if (responseCode >= 300) { +// HttpException httpException = new HttpException(responseCode, this.getResponseMessage()); +// try { +// httpException.setResult(IOUtil.readStr(this.getInputStream(), params.getCharset())); +// } catch (Throwable ex) { +// LogUtil.w(ex.getMessage(), ex); +// } +// LogUtil.e(httpException.toString() + ", url: " + queryUrl); +// throw httpException; +// } +// +// isLoading = true; } @Override diff --git a/entry/src/main/java/com/wordplat/quickstart/xutils/x.java b/entry/src/main/java/com/wordplat/quickstart/xutils/x.java index dcd54f22edeef46c175c6c8a419b65a5572a53a8..0f261bb7667a465059cc151f3bc6871e0506c2c0 100644 --- a/entry/src/main/java/com/wordplat/quickstart/xutils/x.java +++ b/entry/src/main/java/com/wordplat/quickstart/xutils/x.java @@ -152,14 +152,5 @@ public final class x { public static void setViewInjector(ViewInjector viewInjector) { Ext.viewInjector = viewInjector; } - - /** - * setDefaultHostnameVerifier - * - * @param hostnameVerifier - */ - public static void setDefaultHostnameVerifier(HostnameVerifier hostnameVerifier) { - HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); - } } }