version:
update:根据网址获取重定向网址加入白名单 fix: add:
This commit is contained in:
@@ -105,8 +105,8 @@ android {
|
|||||||
|
|
||||||
newl {
|
newl {
|
||||||
flavorDimensions "default"
|
flavorDimensions "default"
|
||||||
versionCode 168
|
// versionCode 168
|
||||||
// versionCode 1036
|
versionCode 1036
|
||||||
versionName "1.2.8"
|
versionName "1.2.8"
|
||||||
/*********************************极光推送************************************/
|
/*********************************极光推送************************************/
|
||||||
manifestPlaceholders = [
|
manifestPlaceholders = [
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import android.content.DialogInterface;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
@@ -299,6 +300,7 @@ public class MainActivity extends BaseActivity implements MainContact.MainView {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getBrowserBookmarksFinished() {
|
public void getBrowserBookmarksFinished() {
|
||||||
|
mPresenter.getBrowserWhiteList();
|
||||||
mPresenter.getDesktopIcon();
|
mPresenter.getDesktopIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,6 +369,26 @@ public class MainActivity extends BaseActivity implements MainContact.MainView {
|
|||||||
mPresenter.detachView();
|
mPresenter.detachView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
|
if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||||
|
lazyExit();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.onKeyDown(keyCode, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
private long mPreClickTime;
|
||||||
|
|
||||||
|
private void lazyExit() {
|
||||||
|
if (System.currentTimeMillis() - mPreClickTime > 3000) {
|
||||||
|
ToastUtil.show("再按一次,退出");
|
||||||
|
mPreClickTime = System.currentTimeMillis();
|
||||||
|
} else {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@OnClick({R.id.back, R.id.chkupd})
|
@OnClick({R.id.back, R.id.chkupd})
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
@@ -425,17 +447,6 @@ public class MainActivity extends BaseActivity implements MainContact.MainView {
|
|||||||
.subscribe(mObserver);
|
.subscribe(mObserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
private long mPreClickTime;
|
|
||||||
|
|
||||||
private void lazyExit() {
|
|
||||||
if (System.currentTimeMillis() - mPreClickTime > 1000) {
|
|
||||||
ToastUtil.show("再按一次,退出");
|
|
||||||
mPreClickTime = System.currentTimeMillis();
|
|
||||||
} else {
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//jiguang
|
//jiguang
|
||||||
public void registerMessageReceiver() {
|
public void registerMessageReceiver() {
|
||||||
mMessageReceiver = new MessageReceiver();
|
mMessageReceiver = new MessageReceiver();
|
||||||
|
|||||||
@@ -108,6 +108,8 @@ public class MainContact {
|
|||||||
//获取浏览器上网管控设置
|
//获取浏览器上网管控设置
|
||||||
void getBrowserBookmarks(String whitelist);
|
void getBrowserBookmarks(String whitelist);
|
||||||
//获取浏览器书签设置管控
|
//获取浏览器书签设置管控
|
||||||
|
void getBrowserWhiteList();
|
||||||
|
//设置白名单的url
|
||||||
void getDesktopIcon();
|
void getDesktopIcon();
|
||||||
//获取应用图标桌面可见性管控
|
//获取应用图标桌面可见性管控
|
||||||
void getAppAutoStartUpdateAndNet();
|
void getAppAutoStartUpdateAndNet();
|
||||||
|
|||||||
@@ -40,9 +40,11 @@ import com.jiaoguanyi.appstore.utils.JGYUtils;
|
|||||||
import com.jiaoguanyi.appstore.utils.SPUtils;
|
import com.jiaoguanyi.appstore.utils.SPUtils;
|
||||||
import com.jiaoguanyi.appstore.utils.SysSettingUtils;
|
import com.jiaoguanyi.appstore.utils.SysSettingUtils;
|
||||||
import com.jiaoguanyi.appstore.utils.TimeUtils;
|
import com.jiaoguanyi.appstore.utils.TimeUtils;
|
||||||
|
import com.jiaoguanyi.appstore.utils.URLUtils;
|
||||||
import com.jiaoguanyi.appstore.utils.Utils;
|
import com.jiaoguanyi.appstore.utils.Utils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -764,7 +766,7 @@ public class MainPresenter implements MainContact.Presenter {
|
|||||||
Log.e("getBrowserList", "onNext: ");
|
Log.e("getBrowserList", "onNext: ");
|
||||||
if (browserDataBaseResponse.code == 200) {
|
if (browserDataBaseResponse.code == 200) {
|
||||||
String white = browserDataBaseResponse.data.getWhite();
|
String white = browserDataBaseResponse.data.getWhite();
|
||||||
mView.getBrowserListFinished(white);
|
|
||||||
if (!TextUtils.isEmpty(white)) {
|
if (!TextUtils.isEmpty(white)) {
|
||||||
String homePage = Settings.System.getString(mContext.getContentResolver(), "homepagURL");
|
String homePage = Settings.System.getString(mContext.getContentResolver(), "homepagURL");
|
||||||
if (!TextUtils.isEmpty(homePage) && !white.contains(homePage)) {
|
if (!TextUtils.isEmpty(homePage) && !white.contains(homePage)) {
|
||||||
@@ -772,8 +774,10 @@ public class MainPresenter implements MainContact.Presenter {
|
|||||||
}
|
}
|
||||||
boolean whiteList = Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", white);
|
boolean whiteList = Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", white);
|
||||||
Log.e("getBrowserList", "setBrowserList white: " + white + ":" + whiteList);
|
Log.e("getBrowserList", "setBrowserList white: " + white + ":" + whiteList);
|
||||||
|
mView.getBrowserListFinished(white);
|
||||||
} else {
|
} else {
|
||||||
Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", " ");
|
Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", " ");
|
||||||
|
mView.getBrowserListFinished("");
|
||||||
}
|
}
|
||||||
String black = browserDataBaseResponse.data.getBlack();
|
String black = browserDataBaseResponse.data.getBlack();
|
||||||
if (!TextUtils.isEmpty(black)) {
|
if (!TextUtils.isEmpty(black)) {
|
||||||
@@ -815,15 +819,15 @@ public class MainPresenter implements MainContact.Presenter {
|
|||||||
@Override
|
@Override
|
||||||
public void onNext(@NonNull BaseResponse<BrowserBookmarks> browserBookmarksBaseResponse) {
|
public void onNext(@NonNull BaseResponse<BrowserBookmarks> browserBookmarksBaseResponse) {
|
||||||
Log.e("getBrowserBookmarks", "onNext: ");
|
Log.e("getBrowserBookmarks", "onNext: ");
|
||||||
String whiteString = whitelist;
|
StringBuilder whiteString = new StringBuilder(whitelist);
|
||||||
if (browserBookmarksBaseResponse.code == 200) {
|
if (browserBookmarksBaseResponse.code == 200) {
|
||||||
//主页
|
//主页
|
||||||
String homepagURL = browserBookmarksBaseResponse.data.getHomepage();
|
String homepagURL = browserBookmarksBaseResponse.data.getHomepage();
|
||||||
boolean home = Settings.System.putString(mContext.getContentResolver(), "homepagURL", homepagURL);
|
boolean home = Settings.System.putString(mContext.getContentResolver(), "homepagURL", homepagURL);
|
||||||
Log.e("getBrowserBookmarks", "onNext: homepagURL: save homepagURL = " + home);
|
Log.e("getBrowserBookmarks", "onNext: homepagURL: save homepagURL = " + home);
|
||||||
if (whiteLists.size() <= 0 || !whiteLists.contains(homepagURL)) {
|
if (whiteLists.size() <= 0 || !whiteLists.contains(homepagURL)) {
|
||||||
whiteString += "," + homepagURL;
|
whiteString.append(",").append(homepagURL);
|
||||||
boolean white = Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", whiteString);
|
boolean white = Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", whiteString.toString());
|
||||||
Log.e("getBrowserBookmarks", "onNext: homepagURL: add to whiteList = " + whiteString + "write: " + white);
|
Log.e("getBrowserBookmarks", "onNext: homepagURL: add to whiteList = " + whiteString + "write: " + white);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -885,6 +889,11 @@ public class MainPresenter implements MainContact.Presenter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getBrowserWhiteList() {
|
||||||
|
new URLUtils(mContext).setBrowserList();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getDesktopIcon() {
|
public void getDesktopIcon() {
|
||||||
NetInterfaceManager.getInstance()
|
NetInterfaceManager.getInstance()
|
||||||
|
|||||||
@@ -91,7 +91,6 @@ import static com.jiaoguanyi.appstore.jpush.TagAliasOperatorHelper.sequence;
|
|||||||
|
|
||||||
public class OldActivity extends AppCompatActivity {
|
public class OldActivity extends AppCompatActivity {
|
||||||
private static final String TAG = OldActivity.class.getSimpleName();
|
private static final String TAG = OldActivity.class.getSimpleName();
|
||||||
private long mPreClickTime;
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private final String ACTION_HrReceiver_JGY_DIS = "qch_jgy_network_disallow";
|
private final String ACTION_HrReceiver_JGY_DIS = "qch_jgy_network_disallow";
|
||||||
private final String ACTION_HrReceiver_JGY = "qch_jgy_network_allow";
|
private final String ACTION_HrReceiver_JGY = "qch_jgy_network_allow";
|
||||||
@@ -999,6 +998,7 @@ public class OldActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
// 用来计算返回键的点击间隔时间
|
// 用来计算返回键的点击间隔时间
|
||||||
private long exitTime = 0;
|
private long exitTime = 0;
|
||||||
|
private long mPreClickTime;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import android.content.Intent;
|
|||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.webkit.WebSettings;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.webkit.WebViewClient;
|
import android.webkit.WebViewClient;
|
||||||
|
|
||||||
@@ -17,17 +17,21 @@ import androidx.appcompat.app.AppCompatActivity;
|
|||||||
|
|
||||||
import com.jiaoguanyi.appstore.BuildConfig;
|
import com.jiaoguanyi.appstore.BuildConfig;
|
||||||
import com.jiaoguanyi.appstore.R;
|
import com.jiaoguanyi.appstore.R;
|
||||||
import com.jiaoguanyi.appstore.utils.Utils;
|
import com.lzy.okgo.model.HttpHeaders;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.nio.file.Files;
|
import java.net.URI;
|
||||||
import java.nio.file.Path;
|
import java.util.regex.Matcher;
|
||||||
import java.nio.file.Paths;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import okhttp3.Call;
|
||||||
|
import okhttp3.Callback;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
|
|
||||||
public class SplashActivity extends AppCompatActivity {
|
public class SplashActivity extends AppCompatActivity {
|
||||||
@@ -52,11 +56,14 @@ public class SplashActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
private void DebugTest() {
|
private void DebugTest() {
|
||||||
// Utils.getHardware(this);
|
// Utils.getHardware(this);
|
||||||
// hookWebView();
|
hookWebView();
|
||||||
// setWebView();
|
// setWebView();
|
||||||
// hideStatusBar();
|
// hideStatusBar();
|
||||||
|
Log.e(TAG, "DebugTest: " + HttpHeaders.getUserAgent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
private void hideStatusBar() {
|
private void hideStatusBar() {
|
||||||
StatusBarManager mStatusBarManager = (StatusBarManager) getApplicationContext().getSystemService(Context.STATUS_BAR_SERVICE);
|
StatusBarManager mStatusBarManager = (StatusBarManager) getApplicationContext().getSystemService(Context.STATUS_BAR_SERVICE);
|
||||||
@@ -68,6 +75,8 @@ public class SplashActivity extends AppCompatActivity {
|
|||||||
mStatusBarManager.disable(StatusBarManager.DISABLE_NONE);//显示隐藏的虚拟按键
|
mStatusBarManager.disable(StatusBarManager.DISABLE_NONE);//显示隐藏的虚拟按键
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void bootanimotion() {
|
private void bootanimotion() {
|
||||||
// File file = new File(Environment.getExternalStorageDirectory() + File.separator + "bootanimation.zip");
|
// File file = new File(Environment.getExternalStorageDirectory() + File.separator + "bootanimation.zip");
|
||||||
// String path0 = "/data/local/qchmedia/bootanimation.zip";
|
// String path0 = "/data/local/qchmedia/bootanimation.zip";
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import android.util.Log;
|
|||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONException;
|
import com.alibaba.fastjson.JSONException;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.jiaoguanyi.appstore.utils.URLUtils;
|
||||||
import com.lzy.okgo.OkGo;
|
import com.lzy.okgo.OkGo;
|
||||||
import com.lzy.okgo.callback.StringCallback;
|
import com.lzy.okgo.callback.StringCallback;
|
||||||
import com.jiaoguanyi.appstore.base.BaseApplication;
|
import com.jiaoguanyi.appstore.base.BaseApplication;
|
||||||
@@ -506,6 +507,8 @@ public class HTTPInterface {
|
|||||||
white += "," + homePage;
|
white += "," + homePage;
|
||||||
}
|
}
|
||||||
boolean whiteList = Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", white);
|
boolean whiteList = Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", white);
|
||||||
|
new URLUtils(context).setBrowserList();
|
||||||
|
|
||||||
Log.e("SystemSetting", "setBrowserList----white-----" + whiteList + ":" + white);
|
Log.e("SystemSetting", "setBrowserList----white-----" + whiteList + ":" + white);
|
||||||
} else {
|
} else {
|
||||||
Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", " ");
|
Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", " ");
|
||||||
|
|||||||
231
app/src/main/java/com/jiaoguanyi/appstore/utils/URLUtils.java
Normal file
231
app/src/main/java/com/jiaoguanyi/appstore/utils/URLUtils.java
Normal file
@@ -0,0 +1,231 @@
|
|||||||
|
package com.jiaoguanyi.appstore.utils;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.webkit.WebSettings;
|
||||||
|
|
||||||
|
import com.jiaoguanyi.appstore.activity.SplashActivity;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import io.reactivex.Observable;
|
||||||
|
import io.reactivex.ObservableEmitter;
|
||||||
|
import io.reactivex.ObservableOnSubscribe;
|
||||||
|
import io.reactivex.Observer;
|
||||||
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
|
import io.reactivex.disposables.Disposable;
|
||||||
|
import io.reactivex.schedulers.Schedulers;
|
||||||
|
import okhttp3.Call;
|
||||||
|
import okhttp3.Callback;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
|
public class URLUtils {
|
||||||
|
private static String TAG = URLUtils.class.getSimpleName();
|
||||||
|
private Context mContext;
|
||||||
|
private List<String> baseURLList = new ArrayList<>();
|
||||||
|
|
||||||
|
public URLUtils(Context context) {
|
||||||
|
this.mContext = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBrowserList() {
|
||||||
|
String whiteList = Settings.System.getString(mContext.getContentResolver(), "DeselectBrowserArray");
|
||||||
|
if (TextUtils.isEmpty(whiteList)) {
|
||||||
|
Log.e(TAG, "getBrowserWhiteList: " + "whiteList is empty");
|
||||||
|
} else {
|
||||||
|
List<String> URLList = Arrays.asList(whiteList.split(","));
|
||||||
|
Observable.create(new ObservableOnSubscribe<String>() {
|
||||||
|
@Override
|
||||||
|
public void subscribe(ObservableEmitter<String> emitter) throws Exception {
|
||||||
|
baseURLList.clear();
|
||||||
|
baseURLList.addAll(URLList);
|
||||||
|
for (String url : URLList) {
|
||||||
|
if (url.startsWith("http://")) {
|
||||||
|
String noHttp = url.substring(7);
|
||||||
|
if (!baseURLList.contains(noHttp)) {
|
||||||
|
baseURLList.add(noHttp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (url.startsWith("https://")) {
|
||||||
|
String noHttps = url.substring(8);
|
||||||
|
if (!baseURLList.contains(noHttps)) {
|
||||||
|
baseURLList.add(noHttps);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
emitter.onNext(getOkHttpURL(url));
|
||||||
|
Log.e(TAG, "subscribe: " + url);
|
||||||
|
}
|
||||||
|
emitter.onComplete();
|
||||||
|
}
|
||||||
|
}).subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(new Observer<String>() {
|
||||||
|
@Override
|
||||||
|
public void onSubscribe(Disposable d) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNext(String s) {
|
||||||
|
Log.e(TAG, "onNext: " + s);
|
||||||
|
if (!baseURLList.contains(s)) {
|
||||||
|
baseURLList.add(s);
|
||||||
|
}
|
||||||
|
if (s.startsWith("http://")) {
|
||||||
|
String noHttp = s.substring(7);
|
||||||
|
Log.e(TAG, "onNext: noHttp: " + noHttp);
|
||||||
|
if (!baseURLList.contains(noHttp)) {
|
||||||
|
baseURLList.add(noHttp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (s.startsWith("https://")) {
|
||||||
|
String noHttps = s.substring(8);
|
||||||
|
Log.e(TAG, "onNext: noHttps: " + noHttps);
|
||||||
|
if (!baseURLList.contains(noHttps)) {
|
||||||
|
baseURLList.add(noHttps);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Throwable e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onComplete() {
|
||||||
|
Log.e(TAG, "onComplete: ");
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
for (String s : baseURLList) {
|
||||||
|
if (stringBuilder.length() > 0) {
|
||||||
|
stringBuilder.append(",");
|
||||||
|
}
|
||||||
|
stringBuilder.append(s);
|
||||||
|
}
|
||||||
|
String DeselectBrowserArray = stringBuilder.toString();
|
||||||
|
boolean write = Settings.System.putString(mContext.getContentResolver(), "DeselectBrowserArray", DeselectBrowserArray);
|
||||||
|
Log.e(TAG, "onComplete: " + "white list: " + DeselectBrowserArray);
|
||||||
|
Log.e(TAG, "onComplete: " + "write :" + write);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getOkHttpURL(String URL) {
|
||||||
|
OkHttpClient okHttpClient = new OkHttpClient();
|
||||||
|
final Request request = new Request.Builder()
|
||||||
|
.url(URL)
|
||||||
|
.removeHeader("User-Agent")
|
||||||
|
.addHeader("User-Agent", getUserAgent())
|
||||||
|
.get()//默认就是GET请求,可以不写
|
||||||
|
.build();
|
||||||
|
Call call = okHttpClient.newCall(request);
|
||||||
|
// call.enqueue(new Callback() {
|
||||||
|
// @Override
|
||||||
|
// public void onFailure(Call call, IOException e) {
|
||||||
|
// Log.e(TAG, "onFailure: ");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public void onResponse(Call call, Response response) throws IOException {
|
||||||
|
// Log.e(TAG, "onResponse: " + getIP(response.request().url().uri()));
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
try {
|
||||||
|
Response response = call.execute();
|
||||||
|
if (response.isSuccessful()) {
|
||||||
|
Log.e(TAG, "getOkHttpURL: " + response.request().url().toString());
|
||||||
|
return getIP(response.request().url().uri()).toString();
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Log.e(TAG, "getOkHttpURL: " + e.getMessage());
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets ip.
|
||||||
|
* 通过url获取到域名
|
||||||
|
*
|
||||||
|
* @param url the url
|
||||||
|
* @return the ip
|
||||||
|
*/
|
||||||
|
public String getIP(String url) {
|
||||||
|
//使用正则表达式过滤,
|
||||||
|
String re = "((http|ftp|https)://)(([a-zA-Z0-9._-]+)|([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}))(([a-zA-Z]{2,6})|(:[0-9]{1,4})?)";
|
||||||
|
String str = "";
|
||||||
|
// 编译正则表达式
|
||||||
|
Pattern pattern = Pattern.compile(re);
|
||||||
|
// 忽略大小写的写法
|
||||||
|
// Pattern pat = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE);
|
||||||
|
Matcher matcher = pattern.matcher(url);
|
||||||
|
//若url==http://127.0.0.1:9040或www.baidu.com的,正则表达式表示匹配
|
||||||
|
if (matcher.matches()) {
|
||||||
|
str = url;
|
||||||
|
} else {
|
||||||
|
String[] split2 = url.split(re);
|
||||||
|
if (split2.length > 1) {
|
||||||
|
String substring = url.substring(0, url.length() - split2[1].length());
|
||||||
|
str = substring;
|
||||||
|
} else {
|
||||||
|
str = split2[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
private URI getIP(URI uri) {
|
||||||
|
URI effectiveURI = null;
|
||||||
|
try {
|
||||||
|
// URI(String scheme, String userInfo, String host, int port, String
|
||||||
|
// path, String query,String fragment)
|
||||||
|
effectiveURI = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null);
|
||||||
|
} catch (Throwable var4) {
|
||||||
|
effectiveURI = null;
|
||||||
|
}
|
||||||
|
return effectiveURI;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 获取浏览器的UA
|
||||||
|
*/
|
||||||
|
private String getUserAgent() {
|
||||||
|
String userAgent = "";
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||||
|
try {
|
||||||
|
userAgent = WebSettings.getDefaultUserAgent(mContext);
|
||||||
|
//需要hook webview
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "getUserAgent: " + e.getMessage());
|
||||||
|
userAgent = System.getProperty("http.agent");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
userAgent = System.getProperty("http.agent");
|
||||||
|
}
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
for (int i = 0, length = userAgent.length(); i < length; i++) {
|
||||||
|
char c = userAgent.charAt(i);
|
||||||
|
if (c <= '\u001f' || c >= '\u007f') {
|
||||||
|
sb.append(String.format("\\u%04x", (int) c));
|
||||||
|
} else {
|
||||||
|
sb.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user