|
|
@@ -3,11 +3,6 @@ import android.app.Activity;
|
|
|
import android.os.Bundle;
|
|
|
import com.felgo.helper.FelgoActivity;
|
|
|
import android.view.WindowManager;
|
|
|
-import android.util.Log;
|
|
|
-import android.content.pm.PackageManager;
|
|
|
-import java.io.File;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
|
|
|
public class MyQtActivity extends FelgoActivity {
|
|
|
private static Activity currentActivity;
|
|
|
@@ -20,248 +15,13 @@ public class MyQtActivity extends FelgoActivity {
|
|
|
|
|
|
@Override
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
- // ========== 关键:在super.onCreate之前就清理缓存 ==========
|
|
|
- // 这是防止花屏的最重要步骤
|
|
|
- Log.d("MyQtActivity", "===== START: Pre-clearing all caches BEFORE onCreate =====");
|
|
|
- clearAllCaches(this);
|
|
|
- Log.d("MyQtActivity", "===== END: Pre-clearing all caches =====");
|
|
|
-
|
|
|
super.onCreate(savedInstanceState);
|
|
|
currentActivity = this;
|
|
|
-
|
|
|
- // ========== 再次清理(确保彻底)==========
|
|
|
- Log.d("MyQtActivity", "===== Second cache clearing pass =====");
|
|
|
- clearAllCaches(this);
|
|
|
-
|
|
|
- // 初始化权限管理
|
|
|
- initPermissions();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 初始化权限申请
|
|
|
- */
|
|
|
- private void initPermissions() {
|
|
|
- Log.d("MyQtActivity", "Initializing permissions...");
|
|
|
-
|
|
|
- // 检查并申请权限
|
|
|
- boolean allGranted = PermissionManager.checkAndRequestPermissions(this);
|
|
|
-
|
|
|
- if (allGranted) {
|
|
|
- Log.d("MyQtActivity", "All permissions already granted");
|
|
|
- onPermissionsGranted();
|
|
|
- } else {
|
|
|
- Log.d("MyQtActivity", "Requesting permissions from user");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 权限申请结果回调
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
|
|
- super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
-
|
|
|
- PermissionManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
-
|
|
|
- if (requestCode == PermissionManager.PERMISSION_REQUEST_CODE) {
|
|
|
- boolean allGranted = true;
|
|
|
- for (int result : grantResults) {
|
|
|
- if (result != PackageManager.PERMISSION_GRANTED) {
|
|
|
- allGranted = false;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (allGranted) {
|
|
|
- Log.d("MyQtActivity", "All permissions granted by user");
|
|
|
- onPermissionsGranted();
|
|
|
- } else {
|
|
|
- Log.w("MyQtActivity", "Some permissions were denied");
|
|
|
- onPermissionsDenied();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 权限全部授权后的回调
|
|
|
- */
|
|
|
- private void onPermissionsGranted() {
|
|
|
- Log.d("MyQtActivity", "Permissions granted, application can proceed");
|
|
|
- // 这里可以通知Qt层权限已就绪
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 权限被拒绝后的回调
|
|
|
- */
|
|
|
- private void onPermissionsDenied() {
|
|
|
- Log.w("MyQtActivity", "Some permissions were denied, application may not function properly");
|
|
|
- // 这里可以处理权限被拒绝的情况
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 检查特定权限状态
|
|
|
- */
|
|
|
- public static boolean hasPermission(String permission) {
|
|
|
- if (currentActivity != null) {
|
|
|
- return PermissionManager.isPermissionGranted(currentActivity, permission);
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 检查文件读写权限
|
|
|
- */
|
|
|
- public static boolean hasStoragePermission() {
|
|
|
- if (currentActivity != null) {
|
|
|
- return PermissionManager.hasStoragePermission(currentActivity);
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 检查相机权限
|
|
|
- */
|
|
|
- public static boolean hasCameraPermission() {
|
|
|
- if (currentActivity != null) {
|
|
|
- return PermissionManager.hasCameraPermission(currentActivity);
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 检查位置权限
|
|
|
- */
|
|
|
- public static boolean hasLocationPermission() {
|
|
|
- if (currentActivity != null) {
|
|
|
- return PermissionManager.hasLocationPermission(currentActivity);
|
|
|
- }
|
|
|
- return false;
|
|
|
}
|
|
|
|
|
|
public static Activity getCurrentActivity() {
|
|
|
return currentActivity;
|
|
|
}
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onDestroy() {
|
|
|
- Log.d("MyQtActivity", "===== onDestroy: Final cache clearing =====");
|
|
|
- clearAllCaches(this);
|
|
|
- super.onDestroy();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onPause() {
|
|
|
- super.onPause();
|
|
|
- Log.d("MyQtActivity", "===== onPause: Clearing caches =====");
|
|
|
- clearAllCaches(this);
|
|
|
- }
|
|
|
-
|
|
|
- // ========== 全志A133P专用:彻底清理所有缓存 ==========
|
|
|
- public static void clearAllCaches(Activity activity) {
|
|
|
- try {
|
|
|
- Log.d("CacheCleaner", "Starting comprehensive cache clearing...");
|
|
|
-
|
|
|
- // ========== 1. 清理应用缓存目录 ==========
|
|
|
- File cacheDir = activity.getCacheDir();
|
|
|
- if (cacheDir != null && cacheDir.exists()) {
|
|
|
- deleteDirectory(cacheDir);
|
|
|
- Log.d("CacheCleaner", "Cleared app cache dir: " + cacheDir.getAbsolutePath());
|
|
|
- }
|
|
|
-
|
|
|
- // ========== 2. 清理代码缓存目录 ==========
|
|
|
- File codeCacheDir = activity.getCodeCacheDir();
|
|
|
- if (codeCacheDir != null && codeCacheDir.exists()) {
|
|
|
- deleteDirectory(codeCacheDir);
|
|
|
- Log.d("CacheCleaner", "Cleared code cache dir: " + codeCacheDir.getAbsolutePath());
|
|
|
- }
|
|
|
-
|
|
|
- // ========== 3. 清理外部缓存目录 ==========
|
|
|
- File externalCacheDir = activity.getExternalCacheDir();
|
|
|
- if (externalCacheDir != null && externalCacheDir.exists()) {
|
|
|
- deleteDirectory(externalCacheDir);
|
|
|
- Log.d("CacheCleaner", "Cleared external cache dir: " + externalCacheDir.getAbsolutePath());
|
|
|
- }
|
|
|
-
|
|
|
- // ========== 4. 清理数据目录中的特定缓存 ==========
|
|
|
- File dataDir = activity.getFilesDir().getParentFile();
|
|
|
- if (dataDir != null && dataDir.exists()) {
|
|
|
- List<String> cacheSubdirs = new ArrayList<String>();
|
|
|
- cacheSubdirs.add("cache");
|
|
|
- cacheSubdirs.add("code_cache");
|
|
|
- cacheSubdirs.add("app_texturecache");
|
|
|
- cacheSubdirs.add("app_qmlcache");
|
|
|
- cacheSubdirs.add("app_qt_shader_cache");
|
|
|
- cacheSubdirs.add("app_rhi_cache");
|
|
|
- cacheSubdirs.add("app_scenegraph_cache");
|
|
|
- cacheSubdirs.add("app_shader_cache");
|
|
|
- // cacheSubdirs.add("shared_prefs"); // 注意:这会清除SharedPreferences,暂时禁用
|
|
|
-
|
|
|
- for (String subdir : cacheSubdirs) {
|
|
|
- File dir = new File(dataDir, subdir);
|
|
|
- if (dir.exists()) {
|
|
|
- deleteDirectory(dir);
|
|
|
- Log.d("CacheCleaner", "Cleared cache subdir: " + dir.getAbsolutePath());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // ========== 5. 清理整个应用数据目录(谨慎!)==========
|
|
|
- // 警告:这会清除所有数据,包括用户设置和数据库
|
|
|
- // 只在需要完全重置时启用
|
|
|
- // clearApplicationData(activity);
|
|
|
-
|
|
|
- Log.d("CacheCleaner", "Cache clearing completed successfully!");
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- Log.e("CacheCleaner", "Error clearing caches: " + e.getMessage(), e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // ========== 递归删除目录 ==========
|
|
|
- private static boolean deleteDirectory(File dir) {
|
|
|
- if (dir == null || !dir.exists()) {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- boolean success = true;
|
|
|
-
|
|
|
- File[] files = dir.listFiles();
|
|
|
- if (files != null) {
|
|
|
- for (File file : files) {
|
|
|
- if (file.isDirectory()) {
|
|
|
- success = success && deleteDirectory(file);
|
|
|
- } else {
|
|
|
- success = success && file.delete();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- success = success && dir.delete();
|
|
|
- return success;
|
|
|
- }
|
|
|
-
|
|
|
- // ========== 清理整个应用数据(谨慎使用)==========
|
|
|
- public static void clearApplicationData(Activity activity) {
|
|
|
- try {
|
|
|
- Log.w("CacheCleaner", "===== WARNING: Clearing ALL application data! =====");
|
|
|
-
|
|
|
- File dataDir = activity.getFilesDir().getParentFile();
|
|
|
- if (dataDir != null && dataDir.exists()) {
|
|
|
- String[] children = dataDir.list();
|
|
|
- if (children != null) {
|
|
|
- for (String child : children) {
|
|
|
- // 不删除lib目录
|
|
|
- if (!"lib".equals(child)) {
|
|
|
- deleteDirectory(new File(dataDir, child));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- Log.w("CacheCleaner", "===== All application data cleared! =====");
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- Log.e("CacheCleaner", "Error clearing application data: " + e.getMessage(), e);
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
}
|