Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 0 additions & 101 deletions catroid/src/main/java/org/catrobat/catroid/CatroidApplication.java
Original file line number Diff line number Diff line change
@@ -1,101 +0,0 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2025 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* An additional term exception under section 7 of the GNU Affero
* General Public License, version 3, is available at
* http://developer.catrobat.org/license_additional_term
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.catrobat.catroid;

import android.annotation.TargetApi;
import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.os.StrictMode;
import android.util.Log;

import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;
import com.huawei.agconnect.AGConnectInstance;
import com.huawei.agconnect.config.AGConnectServicesConfig;
import com.huawei.hms.mlsdk.common.MLApplication;

import org.catrobat.catroid.koin.CatroidKoinHelperKt;
import org.catrobat.catroid.utils.Utils;

import java.util.Locale;

public class CatroidApplication extends Application {

private static final String TAG = CatroidApplication.class.getSimpleName();

private static Context context;
public static String defaultSystemLanguage;

private static GoogleAnalytics googleAnalytics;
private static Tracker googleTracker;

@TargetApi(31)
@Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "CatroidApplication onCreate");
Log.d(TAG, "git commit info: " + BuildConfig.GIT_COMMIT_INFO);

if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectNonSdkApiUsage()
.penaltyLog()
.build());
}

context = getApplicationContext();

CatroidKoinHelperKt.start(this, CatroidKoinHelperKt.getMyModules());

Utils.fetchSpeechRecognitionSupportedLanguages(this);

defaultSystemLanguage = Locale.getDefault().toLanguageTag();

googleAnalytics = GoogleAnalytics.getInstance(this);
googleAnalytics.setDryRun(BuildConfig.DEBUG);

setupHuaweiMobileServices();
}

private void setupHuaweiMobileServices() {
if (AGConnectInstance.getInstance() == null) {
AGConnectInstance.initialize(this);
}

String apiKey = AGConnectServicesConfig.fromContext(this).getString("client/api_key");
MLApplication.getInstance().setApiKey(apiKey);
}

public synchronized Tracker getDefaultTracker() {
if (googleTracker == null) {
googleTracker = googleAnalytics.newTracker(R.xml.global_tracker);
}

return googleTracker;
}

public static Context getAppContext() {
return CatroidApplication.context;
}
}
107 changes: 107 additions & 0 deletions catroid/src/main/java/org/catrobat/catroid/CatroidApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2026 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* An additional term exception under section 7 of the GNU Affero
* General Public License, version 3, is available at
* http://developer.catrobat.org/license_additional_term
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.catrobat.catroid

import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import android.os.Build
import android.os.StrictMode
import android.util.Log
import androidx.annotation.VisibleForTesting
import com.google.android.gms.analytics.GoogleAnalytics
import com.google.android.gms.analytics.Tracker
import com.huawei.agconnect.AGConnectInstance
import com.huawei.agconnect.config.AGConnectServicesConfig
import com.huawei.hms.mlsdk.common.MLApplication
import org.catrobat.catroid.koin.myModules
import org.catrobat.catroid.koin.start
import org.catrobat.catroid.utils.Utils
import java.util.Locale

open class CatroidApplication : Application() {

@SuppressLint("VisibleForTests")
override fun onCreate() {
super.onCreate()
Log.d(TAG, "CatroidApplication onCreate")
Log.d(TAG, "git commit info: " + BuildConfig.GIT_COMMIT_INFO)

if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {

Check warning

Code scanning / Android Lint

Obsolete SDK_INT Version Check Warning

Unnecessary; SDK_INT is always >= 28
Comment thread
harshsomankar123-tech marked this conversation as resolved.
Dismissed
StrictMode.setVmPolicy(
StrictMode.VmPolicy.Builder()
.detectNonSdkApiUsage()
.penaltyLog()
.build()
)
}

appContext = applicationContext
start(this, myModules)

Utils.fetchSpeechRecognitionSupportedLanguages(this)
defaultSystemLanguage = Locale.getDefault().toLanguageTag()

googleAnalytics = GoogleAnalytics.getInstance(this)
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
googleAnalytics.setDryRun(BuildConfig.DEBUG)
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed

setupHuaweiMobileServices()
}

private fun setupHuaweiMobileServices() {
if (AGConnectInstance.getInstance() == null) {
AGConnectInstance.initialize(this)
}
val apiKey = AGConnectServicesConfig.fromContext(this).getString("client/api_key")
MLApplication.getInstance().apiKey = apiKey
}

@get:Synchronized
val defaultTracker: Tracker
@SuppressLint("VisibleForTests")
get() {
googleTracker = googleAnalytics.newTracker(R.xml.global_tracker)
return googleTracker
}

companion object {
private val TAG = CatroidApplication::class.java.simpleName
private var appContext: Context? = null
@JvmField
var defaultSystemLanguage: String? = null
@SuppressLint("VisibleForTests")
private lateinit var googleAnalytics: GoogleAnalytics
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
@SuppressLint("VisibleForTests")
private lateinit var googleTracker: Tracker

@VisibleForTesting
@JvmStatic
fun setAppContextForTesting(context: Context) {
Comment thread
harshsomankar123-tech marked this conversation as resolved.
appContext = context
}

@JvmStatic
fun getAppContext(): Context = appContext ?: throw IllegalStateException("CatroidApplication.appContext not initialized. Ensure onCreate() has been called.")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ abstract class BaseActivity : AppCompatActivity(), PermissionHandlingActivity {
surveyCampaign?.startAppTime(this)
}

protected fun googleAnalyticsTrackScreenResume() {
@SuppressLint("VisibleForTests")
private fun googleAnalyticsTrackScreenResume() {
val googleTracker = (application as CatroidApplication).defaultTracker
googleTracker.setScreenName(this.javaClass.name)
googleTracker.send(ScreenViewBuilder().build())
Expand Down Expand Up @@ -164,6 +165,7 @@ abstract class BaseActivity : AppCompatActivity(), PermissionHandlingActivity {
permissions: Array<String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
permissionRequestActivityExtension.onRequestPermissionsResult(
this,
requestCode,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2025 The Catrobat Team
* Copyright (C) 2010-2026 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -24,6 +24,7 @@
package org.catrobat.catroid.test

import android.content.Context
import org.catrobat.catroid.CatroidApplication
import org.catrobat.catroid.ProjectManager

/**
Expand All @@ -48,6 +49,8 @@ class StaticSingletonInitializer private constructor() {
if (ProjectManager.getInstance() == null) {
ProjectManager(contextMock)
}
// Initialize CatroidApplication.appContext for tests
CatroidApplication.setAppContextForTesting(contextMock)
}
}
}
Loading