package com.example.justask;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    // FLAG 1: FLAG{Gutta_cavat_
    // FLAG 2: lapidem_non_vi
    // FLAG 3:
    // FLAG 4: _cadendo}

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // "com.example.victimapp/.PartOne"

        Intent callIntent1 = new Intent();
        callIntent1.setComponent(ComponentName.unflattenFromString("com.example.victimapp/.PartOne"));
        startActivityForResult(callIntent1, 1);


        Intent callIntent2 = new Intent("com.example.victimapp.intent.action.JUSTASK");
        startActivityForResult(callIntent2, 2);

        Intent callIntent3 = new Intent();
        callIntent3.setComponent(ComponentName.unflattenFromString("com.example.victimapp/.PartThree"));
        startActivityForResult(callIntent3, 1);

        Intent callIntent4 = new Intent("com.example.victimapp.intent.action.JUSTASKBUTNOTSOSIMPLE");
        startActivityForResult(callIntent4, 4);

        // Intent resultIntent = new Intent();
        // setResult(Activity.RESULT_OK, resultIntent);

        // String result = callIntent.getDataString();
        // Intent data = new Intent();
        // onActivityResult(0, RESULT_OK, data);
        // Log.d("MOBIOTSEC", "onCreate: " + data.getDataString());

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        Log.d("MOBIOTSEC", "> Part Code: "+ resultCode);

            Bundle extra = data.getExtras();

            /*
            for (String key: extra.keySet())
            {
                Log.d ("MOBIOTSEC", key + " is a key in the bundle");
            }*/

            if(resultCode == 4) {

                int count = 1;
                String currentVar = "follow";
                while(!currentVar.equals("never ending story")) {
                    extra = extra.getBundle(currentVar);
                    currentVar = extra.keySet().iterator().next();
                    count++;
                    Log.d ("MOBIOTSEC", currentVar + " is a key in the bundle "+count);
                }

                Log.d("MOBIOTSEC", ">> FLAG (follow the value... 6 TIMES RLY?): " + extra.getString("never ending story"));
            } else {
                Log.d("MOBIOTSEC", ">> FLAG: " + extra.getString("flag"));
            }
    }
}