Procházet zdrojové kódy

修复了二次启动花屏问题

zhunk před 6 měsíci
rodič
revize
812084e4e4

+ 2 - 242
app_bzy_armhf_7/android/src/com/yfkj/bzyv1/MyQtActivity.java

@@ -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);
-        }
-    }
+
+
 }

+ 11 - 78
app_bzy_armhf_7/main.cpp

@@ -280,13 +280,12 @@ QStringList m_permissions = {
 void clearAllCaches() {
 #ifndef WIN32
     QDir dir;
-    
     // ========== 1. 标准缓存位置 ==========
     QStringList cacheLocations = {
         QStandardPaths::writableLocation(QStandardPaths::CacheLocation),
         QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation),
-        QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation),
-        QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)
+        // QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation),
+        // QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)
     };
     
     // ========== 2. Android特定缓存位置 ==========
@@ -352,71 +351,8 @@ void clearAllCaches() {
 
 int main(int argc, char *argv[])
 {
-#if 0
-    // ========== 第一阶段:在任何Qt对象创建前先清理所有缓存 ==========
-    // 这是解决"第一次正常,第二次花屏"的关键!
-    clearAllCaches();
-    
-    // ========== 全志A133P ARM32渲染修复(终极版)==========
-    // 在QGuiApplication创建前设置环境变量
-    
-    // ========== 核心图形API配置 ==========
-    qputenv("QSG_RHI_BACKEND", "opengl");
-    qputenv("QSG_RENDERING_BACKEND", "opengl");
-    qputenv("QT_QUICK_BACKEND", "opengl");
-    
-    // ========== OpenGL ES版本强制配置(全志A133P关键)==========
-    qputenv("QT_OPENGL_FORCE_GLES2", "1");    // 强制使用OpenGL ES 2.0
-    qputenv("QT_OPENGL_NO_ES3", "1");         // 禁用OpenGL ES 3.0
-    qputenv("QT_OPENGL_NO_ES31", "1");        // 禁用OpenGL ES 3.1
-    qputenv("QT_OPENGL_NO_ES32", "1");        // 禁用OpenGL ES 3.2
-    
-    // ========== 渲染循环配置 ==========
-    qputenv("QSG_RENDER_LOOP", "basic");      // 使用basic渲染循环,ARM32更稳定
-    
-    // ========== 颜色格式配置(解决花屏关键)==========
-    qputenv("QT_OPENGL_NO_BGRA", "1");
-    qputenv("QT_QPA_EGLFS_FORCE888", "1");     // 强制24位色深
-    
-    // ========== 缓冲和缓存禁用(避免ARM32兼容性问题)==========
-    qputenv("QSG_DISABLE_DEPTH_BUFFER", "1");  // 禁用深度缓冲
-    qputenv("QSG_DISABLE_STENCIL_BUFFER", "1"); // 禁用模板缓冲
-    qputenv("QSG_DISABLE_ATLAS", "1");         // 禁用纹理图集
-    qputenv("QSG_DISABLE_MIPMAP", "1");        // 禁用MIP映射
-    
-    // ========== 所有类型的缓存完全禁用 ==========
-    qputenv("QML_DISABLE_DISK_CACHE", "1");   // 禁用QML磁盘缓存
-    qputenv("QML_FORCE_DISK_CACHE", "0");
-    qputenv("QSG_RHI_DISABLE_PIPELINE_CACHE", "1");  // 禁用RHI管线缓存
-    qputenv("QT_GL_USE_DISK_SHADER_CACHE", "0");     // 禁用磁盘着色器缓存
-    qputenv("QSG_DISTANCEFIELD_CACHE_SIZE", "0");    // 禁用距离场缓存
-    qputenv("QSG_TEXTURE_CACHE_SIZE", "0");          // 禁用纹理缓存
-    qputenv("QSG_SHADER_CACHE_SIZE", "0");           // 禁用着色器缓存
-    
-    // ========== 更多缓存禁用设置 ==========
-    qputenv("QT_DISABLE_SHADER_CACHE", "1");         // 禁用Qt着色器缓存
-    qputenv("QT_DISABLE_OPENGL_SHADER_CACHE", "1");  // 禁用OpenGL着色器缓存
-    qputenv("QSG_DISABLE_VBO_CACHE", "1");           // 禁用VBO缓存
-    
-    // ========== 渲染风格和质量(降低为最兼容级别)==========
-    qputenv("QSG_SIMPLE_STYLE", "1");         // 使用简单渲染风格
-    qputenv("QT_QUICK_CONTROLS_STYLE", "Basic");
-    qputenv("QSG_ANTIALIASING_METHOD", "disabled");  // 禁用抗锯齿
-    
-    // ========== 调试和信息输出 ==========
-    qputenv("QSG_INFO", "1");
-    qputenv("QSG_VISUALIZE", "0");
-    
-    // ========== 软件渲染器禁用(确保使用硬件加速)==========
-    qputenv("QSG_SOFTWARE_RENDERER", "0");
-    
-    // ========== EGL配置优化(全志A133P特定)==========
-    qputenv("QT_QPA_EGLFS_ALWAYS_SET_MODE", "1");
-    qputenv("QT_QPA_EGLFS_INTEGRATION", "none");
-#endif
     // ========== Android权限申请 ==========
     // 在应用启动时申请所有必要的权限
-
     // 使用正确的API逐个申请权限
     for (const QString &permission : m_permissions) {
         QtAndroidPrivate::checkPermission(permission);
@@ -426,20 +362,12 @@ int main(int argc, char *argv[])
 
     sendBroadcastFromQt("sleep");
     QGuiApplication app(argc, argv);
-
     // ========== 第二阶段:QGuiApplication创建后再次清理缓存 ==========
     // 有些缓存只有在QGuiApplication创建后才能正确访问
     clearAllCaches();
     LOG("Second cache clear completed!");
-    
-    // ========== 全志A133P窗口配置优化(关键) ==========
-    QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);
-    LOG("Graphics API forced: OpenGL");
-    QQuickWindow::setDefaultAlphaBuffer(false);  // 禁用透明缓冲
-    //QQuickWindow::setPersistentOpenGLContext(false);  // 不使用持久化GL上下文
-    QQuickWindow::setSceneGraphBackend("opengl");
 
-    
+
     MyCppClass myCppClass;
 
 #if WIN32
@@ -479,7 +407,12 @@ int main(int argc, char *argv[])
     if(param::imei.isEmpty()){
         sendBroadcastFromQt("imei");
         QTimer::singleShot(1000, [&]() {
-            sqlConfig->UpdateData(param::table_mqtt,"imei",param::imei);
+            sqlConfig->OpenDb();
+            if(sqlConfig->isTableExist(param::table_mqtt)){
+                LOG("Update imei:{}",param::imei.toStdString());
+                sqlConfig->UpdateData(param::table_mqtt,"imei",param::imei);
+            }
+            sqlConfig->CloseDb();
         });
     }
     if(!sqlConfig->isTableExist(param::table_mqtt_other))
@@ -656,12 +589,12 @@ int main(int argc, char *argv[])
             sqlConfig->UpdateData(param::table_camera,"stitch_photonum",QString::number(param::stitch_photonum));
         }
         sqlConfig->CloseDb();
-
     });
+
     QObject::connect(&mqttHandler,&MqttHandler::signal_imei_change,[&](QString NEW_IMEI){
         sqlConfig->OpenDb();
         if(sqlConfig->isTableExist(param::table_mqtt)){
-            qDebug() << "UpdateData imei !!!!!";
+            LOG("Update Data imei:{}",NEW_IMEI.toStdString());
             sqlConfig->UpdateData(param::table_mqtt,"imei",NEW_IMEI);
         }
         sqlConfig->CloseDb();

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 5 - 121
app_bzy_armhf_7/qml/Main.qml