1

I'm trying to create a test app to test some code out for my main app, which creates ImageViews inside a ViewFlipper using an On-Click Button event. Every time I press the button, the code works as expected but Android gives me a Security Threat warning. Any answers as to why this is happening? And is there a better way to create dynamic image views, if that is whats causing the malware?

Here's the warning it gives me: Malware Warning

Here's the code for my Main program, including the On-Click event:

class MainActivity : AppCompatActivity() {
    private lateinit var binding: ActivityMainBinding
    private lateinit var vfProductImages: ViewFlipper

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)

        vfProductImages = binding.vfProductImages
        val btnAddImage = binding.btnAddImage
        var flip = false

        btnAddImage.setOnClickListener {
            val imageView = ImageView(this)
            imageView.layoutParams = LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT,
            )
            vfProductImages.addView(imageView)

            if (flip) imageView.setImageResource(R.drawable.ic_launcher_background)
            else imageView.setImageResource(R.drawable.ic_launcher_foreground)

            flip = flip.not()
        }
    }
}

Here's the XML Layout file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="10dp"
    tools:context=".MainActivity">

    <LinearLayout
        android:elevation="5dp"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ViewFlipper
            android:id="@+id/vfProductImages"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="330dp"
            android:elevation="16dp"
            android:flipInterval="1000">

        </ViewFlipper>

        <Space
            android:layout_width="match_parent"
            android:layout_height="20dp"/>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/btnAddImage"
            android:layout_gravity="center"
            android:text="Add Image"/>
    </LinearLayout>
</RelativeLayout>

Here's the build.gradle file:

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-kapt'
}

android {
    namespace 'com.example.xyz'
    compileSdk 33

    defaultConfig {
        applicationId "com.example.xyz"
        minSdk 26
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = '17'
    }
    viewBinding {
        enabled = true
    }
}

dependencies {
    def retrofit_version = "2.9.0"
    def coroutines_version = "1.7.2"
    def lifecycle_version = "2.6.1"
    def picasso_version = "2.8"

    //Picasso
    implementation "com.squareup.picasso:picasso:$picasso_version"

    // ViewModel
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
    // LiveData
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
    // Annotation processor
    kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"

    //Coroutines
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"

    //Retrofit
    implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
    implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"

    //Okhttp3
    implementation "com.squareup.okhttp3:logging-interceptor:4.10.0"

    implementation 'androidx.core:core-ktx:1.8.0'
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.5.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

1 Answers1

1

Alright so I went ahead and removed the Picasso dependency as I wasn't using it and for some reason, the malware error went away so I'm guessing picasso has something to do with it? If someone could let me know why that happened that would be great!

  • This is an addition to your question and not an answer. Please edit your question and not answer it in this way. – Philipp M Jul 23 '23 at 07:58