avc: denied { read } fragment Android

Viewed 2411

I have a modal dialog that I've created with XML. Then, I show it in kotlin (it's not a real dialog view, more than an information popup).

See the XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    tools:context=".AlertsDialogRemi"
    android:id="@+id/alertLayoutRoot"
    android:orientation="vertical"
    >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:ignore="UselessParent"
        >

        <RelativeLayout
            android:id="@+id/layoutTopAlert"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="33dp"
            android:gravity="center"
            >

            <LinearLayout
                android:id="@+id/layoutAlert"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:background="@color/orange"
                >

                <TextView
                    android:id="@+id/alerte_title"
                    style="@style/titleActu"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="66dp"
                    android:text="@string/alertes"
                    android:textColor="@color/colorWhite" />


                <ViewFlipper
                    android:id="@+id/viewFlipperAlert"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/orange">
                </ViewFlipper>

                <LinearLayout
                    android:id="@+id/dotNavAlert"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:orientation="horizontal">

                </LinearLayout>

            </LinearLayout>
            <Button
                android:id="@+id/close_modal_alerte"
                style="@style/Base.Widget.AppCompat.Button.Borderless"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:background="@android:color/transparent"
                android:text="Fermer"
                android:layout_below="@id/layoutAlert"/>
        </RelativeLayout>
        <ImageView
            android:id="@+id/alert_logo"
            android:layout_width="66dp"
            android:layout_height="66dp"
            android:layout_centerHorizontal="true"
            android:src="@drawable/alertes" />


    </RelativeLayout>


</LinearLayout>

This function show the modal in MainActivity.kt (I'm using fragment and navigation drawer) :

lateinit var mydialog : Dialog
lateinit var txt : TextView

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        var fragment: Fragment? = null

        when (item.itemId) {
            R.id.action_alert -> {
                showDialog()
                return true
            }
            else -> return super.onOptionsItemSelected(item)
        }
    }

    fun showDialog(){
        mydialog = Dialog(this, R.style.DialogCustomTheme)
        mydialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
        mydialog.setContentView(R.layout.alerts_dialog_remi)

        txt = mydialog.findViewById(R.id.close_modal_alerte)
        txt.isEnabled = true
        txt.setOnClickListener{
            mydialog.cancel()
        }
        mydialog.show()
    }

And in AlertsDialogRemi.xml, I have this :

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)

    val alerts = arrayOf("AlertsDialogRemi 1", "AlertsDialogRemi 2", "AlertsDialogRemi 3")
    for(alert in alerts){
        Log.i(TAG, "Alert : $alert")
    }

I have this error in my logs when I'm trying to access alerts variable in AlertDialogRemi.kt:

W/RenderThread: type=1400 audit(0.0:6789172): avc: denied { read } for name="perf_ioctl" dev="proc" ino=4026533700 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:proc:s0 tclass=file permissive=0

It's weird because I do the same thing in another Fragment (Accueil.kt) but I have no problem at all.

EDIT : Apparently, this is due to the dialog, if I call the fragment without the dialog, I have my data. So what should I change ?

1 Answers

You should call mydialog.create() before calling the mydialog.show() method or trying to access its internal views.

fun showDialog(){
    mydialog = Dialog(this, R.style.DialogCustomTheme)
    mydialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
    mydialog.setContentView(R.layout.alerts_dialog_remi)

    mydialog.create()

    txt = mydialog.findViewById(R.id.close_modal_alerte)
    txt.isEnabled = true
    txt.setOnClickListener{
        mydialog.cancel()
    }
    mydialog.show()
}
Related