diff --git a/app/build.gradle b/app/build.gradle
index 15988fc..e38b829 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -249,6 +249,13 @@ dependencies {
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
+// implementation "androidx.datastore:datastore:1.0.0"
+// // optional - RxJava2 support
+//// implementation "androidx.datastore:datastore-rxjava2:1.0.0"
+// // optional - RxJava3 support
+// implementation "androidx.datastore:datastore-rxjava3:1.0.0"
+// implementation "androidx.datastore:datastore-core:1.0.0"
+
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
@@ -284,17 +291,18 @@ dependencies {
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.google.zxing:core:3.3.0'
implementation 'com.google.android.material:material:1.4.0'
+
//Jackson
implementation 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
implementation 'org.codehaus.jackson:jackson-core-asl:1.9.13'
//view绑定
- implementation 'com.jakewharton:butterknife:10.2.1'
+ implementation 'com.jakewharton:butterknife:10.2.3'
// If you are using Kotlin, replace annotationProcessor with kapt.
// annotationProcessor rootProject.ext.dependencies["butterknife-compiler"]
- annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1'
+ annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
//MMKV
- implementation 'com.tencent:mmkv-static:1.2.10'
+ implementation 'com.tencent:mmkv-static:1.2.13'
//腾讯移动推送 TPNS
implementation 'com.tencent.tpns:tpns:1.2.2.0-release'
@@ -331,7 +339,7 @@ dependencies {
//动态权限框架
implementation 'com.yanzhenjie:permission:2.0.3'
//沉浸状态栏
- implementation 'com.gitee.zackratos:UltimateBarX:0.7.1'
+ implementation 'com.gitee.zackratos:UltimateBarX:0.8.0'
// implementation 'com.gyf.barlibrary:barlibrary:2.2.8'
// 基础依赖包,必须要依赖
diff --git a/app/src/main/java/com/tt/ttutils/activity/AoleyunTestActivity.java b/app/src/main/java/com/tt/ttutils/activity/AoleyunTestActivity.java
index dc574b7..ae8bdee 100644
--- a/app/src/main/java/com/tt/ttutils/activity/AoleyunTestActivity.java
+++ b/app/src/main/java/com/tt/ttutils/activity/AoleyunTestActivity.java
@@ -1,5 +1,6 @@
package com.tt.ttutils.activity;
+import android.app.StatusBarManager;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
@@ -7,6 +8,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
+import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
@@ -18,7 +20,10 @@ import androidx.appcompat.app.AppCompatActivity;
import com.tt.ttutils.BuildConfig;
import com.tt.ttutils.R;
import com.tt.ttutils.base.BaseActivity;
+import com.tt.ttutils.utils.java.JGYUtils;
+import com.tt.ttutils.utils.java.ToastUtil;
+import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -87,6 +92,15 @@ public class AoleyunTestActivity extends BaseActivity {
@BindView(R.id.bt_status_off)
Button bt_status_off;
+ @BindView(R.id.bt_statusbar_collapse)
+ Button bt_statusbar_collapse;
+ @BindView(R.id.bt_collapse_statu)
+ Button bt_collapse_statu;
+ @BindView(R.id.bt_collapse_on)
+ Button bt_collapse_on;
+ @BindView(R.id.bt_collapse_off)
+ Button bt_collapse_off;
+
@BindView(R.id.bt_hotspot)
Button bt_hotspot;
@BindView(R.id.bt_hotspot_statu)
@@ -205,6 +219,10 @@ public class AoleyunTestActivity extends BaseActivity {
sendBroadcast(intent);
});
+ bt_sd_statu.setOnClickListener(view -> {
+ int aole_sdcard_forbid_on = Settings.System.getInt(getContentResolver(), "aole_sdcard_forbid_on", 0);
+ bt_sd_statu.setText("状态:" + aole_sdcard_forbid_on);
+ });
bt_sd_on.setOnClickListener(view -> Settings.System.putInt(getContentResolver(), "aole_sdcard_forbid_on", 0));
bt_sd_off.setOnClickListener(view -> Settings.System.putInt(getContentResolver(), "aole_sdcard_forbid_on", 1));
@@ -216,8 +234,8 @@ public class AoleyunTestActivity extends BaseActivity {
bt_developer_statu.setText("状态:" + aole_Developeroptions);
}
});
- bt_developer_on.setOnClickListener(view -> Settings.System.putInt(getContentResolver(), "aole_Developeroptions", 0));
- bt_developer_off.setOnClickListener(view -> Settings.System.putInt(getContentResolver(), "aole_Developeroptions", 1));
+ bt_developer_on.setOnClickListener(view -> setDeveloperOptions(0));
+ bt_developer_off.setOnClickListener(view -> setDeveloperOptions(1));
bt_navigation_on.setOnClickListener(view -> {
Intent navIntent = new Intent("aole_show_NavigationBar").setPackage("com.android.systemui");
@@ -237,6 +255,24 @@ public class AoleyunTestActivity extends BaseActivity {
sendBroadcast(navIntent);
});
+ bt_collapse_on.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ StatusBarManager mStatusBarManager = (StatusBarManager) getApplicationContext().getSystemService(Context.STATUS_BAR_SERVICE);
+ mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND);
+// mStatusBarManager.disable(StatusBarManager.DISABLE2_NOTIFICATION_SHADE);
+ }
+ });
+
+ bt_collapse_off.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ StatusBarManager mStatusBarManager = (StatusBarManager) getApplicationContext().getSystemService(Context.STATUS_BAR_SERVICE);
+ mStatusBarManager.disable(StatusBarManager.DISABLE_NONE);
+// mStatusBarManager.disable(StatusBarManager.DISABLE2_NONE);
+ }
+ });
+
bt_hotspot_on.setOnClickListener(view -> {
Settings.System.putInt(getContentResolver(), "aole_hotspot_forbid_on", 0);
});
@@ -304,6 +340,26 @@ public class AoleyunTestActivity extends BaseActivity {
});
}
+ @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 > 5000) {
+ ToastUtil.show("再按一次,退出");
+ mPreClickTime = System.currentTimeMillis();
+ } else {
+ finish();
+ }
+ }
+
private void gotoLauncher() {
Intent i = new Intent(Intent.ACTION_MAIN);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //android123提示如果是服务里调用,必须加入new task标识
@@ -322,4 +378,26 @@ public class AoleyunTestActivity extends BaseActivity {
Log.e(TAG, "getInputMethodId: " + id);
return id;
}
+
+ public void setDeveloperOptions(int state) {
+ Log.e(TAG, "setDeveloperOptions: " + state);
+ Settings.System.putInt(getContentResolver(), "aole_Developeroptions", state);
+ int old_dev_enabled = Settings.Global.getInt(getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
+ Log.e(TAG, "setDeveloperOptions: old_dev_enabled = " + old_dev_enabled);
+ int new_state = (state == 1 ? 0 : 1);
+ if (old_dev_enabled != new_state) {
+ Settings.Global.putInt(getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, new_state);
+ Settings.Global.putInt(getContentResolver(), Settings.Global.ADB_ENABLED, new_state);
+ }
+ if (state == 1) {
+// Intent intent = new Intent();
+// intent.setAction("qch_developeroptions_close");
+// intent.setPackage(JGYActions.ANDROID_SETTINGS_PACKAGE_NAME);
+// sendBroadcast(intent);
+ Log.e(TAG, "setDeveloperOptions: " + "关闭开发者模式");
+ } else {
+ Log.e(TAG, "setDeveloperOptions: " + "打开开发者模式");
+ }
+
+ }
}
diff --git a/app/src/main/java/com/tt/ttutils/disklrucache/CacheHelper.java b/app/src/main/java/com/tt/ttutils/disklrucache/CacheHelper.java
index 5fd778e..0277d21 100644
--- a/app/src/main/java/com/tt/ttutils/disklrucache/CacheHelper.java
+++ b/app/src/main/java/com/tt/ttutils/disklrucache/CacheHelper.java
@@ -455,7 +455,13 @@ public class CacheHelper {
String cachePath;
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
|| !Environment.isExternalStorageRemovable()) {
- cachePath = context.getExternalCacheDir().getPath();
+ if (context.getExternalCacheDir() != null) {
+ cachePath = context.getExternalCacheDir().getPath();
+ } else if (context.getExternalFilesDir("cache") != null) {
+ cachePath = context.getExternalFilesDir("cache").getPath();
+ } else {
+ cachePath = context.getCacheDir().getPath();
+ }
} else {
cachePath = context.getCacheDir().getPath();
}
diff --git a/app/src/main/java/com/tt/ttutils/network/interceptor/RepeatRequestInterceptor.java b/app/src/main/java/com/tt/ttutils/network/interceptor/RepeatRequestInterceptor.java
index cee780d..6201b2e 100644
--- a/app/src/main/java/com/tt/ttutils/network/interceptor/RepeatRequestInterceptor.java
+++ b/app/src/main/java/com/tt/ttutils/network/interceptor/RepeatRequestInterceptor.java
@@ -2,6 +2,7 @@ package com.tt.ttutils.network.interceptor;
import android.util.Log;
+import com.tt.ttutils.BuildConfig;
import com.tt.ttutils.utils.java.MD5Util;
import org.jetbrains.annotations.NotNull;
@@ -12,9 +13,14 @@ import java.util.concurrent.ConcurrentHashMap;
import okhttp3.Interceptor;
import okhttp3.Protocol;
import okhttp3.Request;
+import okhttp3.RequestBody;
import okhttp3.Response;
+import okhttp3.ResponseBody;
import okio.Buffer;
+/**
+ * v1.0 2022-07-15 16:16:52
+ */
public class RepeatRequestInterceptor implements Interceptor {
private static final String TAG = RepeatRequestInterceptor.class.getSimpleName();
@@ -25,17 +31,22 @@ public class RepeatRequestInterceptor implements Interceptor {
@Override
public Response intercept(@NotNull Chain chain) throws IOException {
Request request = chain.request();
+ Response response = chain.proceed(request);
+ ResponseBody responseBody = response.body();
- Response response = chain.proceed(chain.request());
- String content = response.body().string();
-// Log.e(TAG, "请求体返回:| Response:" + content);
+ //会消费请求,导致请求多次
+ String content = responseBody.string();
+// Response copy = response.newBuilder().body(responseBody).build();
+ ResponseBody copy = ResponseBody.create(responseBody.contentType(), content);
+ if (BuildConfig.DEBUG) {
+ Log.e(TAG, "请求体返回:| Response: " + request.url().encodedPath() + "\t body: " + content);
+ }
//相同的请求
- String requestKey = MD5Util.getUpperMD5Str(request.method() + request.url().toString() + request.body());
+ String requestKey = MD5Util.getUpperMD5Str(request.method() + request.url().toString() + requestBodyToString(request.body()));
long time = System.currentTimeMillis();//请求时间
try {
if (requestIdsMap.size() > 0 && requestIdsMap.containsKey(requestKey)) {
-// Log.e("REPEAT-REQUEST", "重复请求:" + requestKey + " Method @" + request.method() + " --- " + " URL = " + request.url() + "\t" + bodyToString(request));
- Log.e("REPEAT-REQUEST", "重复请求:" + requestKey + " Method @" + request.method() + " --- " + " URL = " + request.url());
+ log("重复请求:", requestKey, request);
//下面这行写了不会抛出onerror
// chain.call().cancel();
return new Response.Builder()
@@ -44,32 +55,53 @@ public class RepeatRequestInterceptor implements Interceptor {
.build();
}
requestIdsMap.put(requestKey, time);
-// Log.e("REPEAT-REQUEST", "注册请求:" + requestKey + " Method @" + request.method() + " --- " + " URL = " + request.url() + "\t" + bodyToString(request));
- Log.e("REPEAT-REQUEST", "注册请求:" + requestKey + " Method @" + request.method() + " --- " + " URL = " + request.url());
+ log("注册请求:", requestKey, request);
// RepeatRequestInterceptor.Builder builder = request.newBuilder();
// builder.addHeader("header", jsonObject.toString());
- return chain.proceed(request);
+ return response.newBuilder().body(copy).build();
} catch (IOException e) {
Log.e(TAG, "intercept: " + e.getMessage());
throw e;
} finally {
if (requestIdsMap.containsKey(requestKey) && requestIdsMap.containsValue(time)) {//请求任务完成删除map中的数据
requestIdsMap.remove(requestKey);
- Log.e("REPEAT-REQUEST", "移除请求:" + requestKey + " Method @" + request.method() + " --- " + " URL = " + request.url() + "\t" + bodyToString(request));
-// Log.e("REPEAT-REQUEST", "移除请求:" + requestKey + " Method @" + request.method() + " --- " + " URL = " + request.url());
+ log("移除请求:", requestKey, request);
}
}
}
+ private void log(String action, String requestKey, Request request) {
+ if (BuildConfig.DEBUG) {
+ Log.e("REPEAT-REQUEST", action + requestKey + " Method @" + request.method() + " --- " + " URL = " + request.url().encodedPath() + "\t" + bodyToString(request));
+ } else {
+ Log.e("REPEAT-REQUEST", action + requestKey + " Method @" + request.method());
+ }
+ }
+
private static String bodyToString(final Request request) {
try {
final Request copy = request.newBuilder().build();
final Buffer buffer = new Buffer();
copy.body().writeTo(buffer);
+ if (buffer.size() > 4096) {
+ return "-too long";
+ }
return buffer.readUtf8();
} catch (Exception e) {
return "-";
}
}
+ private static String requestBodyToString(RequestBody body) {
+ try {
+ final Buffer buffer = new Buffer();
+ body.writeTo(buffer);
+ if (buffer.size() > 4096) {
+ return "-too long";
+ }
+ return buffer.readUtf8();
+ } catch (Exception e) {
+ return "-";
+ }
+ }
}
diff --git a/app/src/main/java/com/tt/ttutils/utils/java/JGYUtils.java b/app/src/main/java/com/tt/ttutils/utils/java/JGYUtils.java
index ac90f06..39b0834 100644
--- a/app/src/main/java/com/tt/ttutils/utils/java/JGYUtils.java
+++ b/app/src/main/java/com/tt/ttutils/utils/java/JGYUtils.java
@@ -7,6 +7,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
+import android.provider.Settings;
import android.util.Log;
import com.tt.ttutils.BuildConfig;
@@ -203,4 +204,5 @@ public class JGYUtils {
bootIntent.setComponent(new ComponentName(PACKAGE_NOTIFY, CLASS_NOTIFY));
mContext.sendBroadcast(bootIntent);
}
+
}
diff --git a/app/src/main/res/layout/activity_aoleyun_test.xml b/app/src/main/res/layout/activity_aoleyun_test.xml
index 325e550..aee82da 100644
--- a/app/src/main/res/layout/activity_aoleyun_test.xml
+++ b/app/src/main/res/layout/activity_aoleyun_test.xml
@@ -250,6 +250,43 @@
android:text="off" />
+
+
+
+
+
+
+
+
+
+
+