// examples/inert-sample/MainActivity.java
//
// =========================================================================
// INERT TEACHING SAMPLE — chapter 69. THIS IS NOT MALWARE.
// One TextView. It asks for nothing, grants nothing, and starts nothing.
// =========================================================================
//
// WHY A DROPPER HAS A LAUNCHER ACTIVITY AT ALL
//
// It looks like a mistake. A component with no user-facing purpose should
// hide, and Android gives it several ways to: android:excludeFromRecents,
// no launcher intent-filter at all, or a launcher activity-alias that is
// disabled with setComponentEnabledSetting() after the first run so the icon
// disappears from the drawer. All three are used in the wild.
//
// But a sample almost always has ONE launcher Activity anyway, because of a
// platform rule that has nothing to do with UI: since API 26, an app that has
// never been launched is in the STOPPED state, and **an app in the stopped
// state receives no broadcasts at all** — not BOOT_COMPLETED, not
// MY_PACKAGE_REPLACED, nothing. The only way out of the stopped state is an
// explicit user action, which in practice means one tap on an icon.
//
// So the shape you should recognise is:
//
//   * a launcher Activity with a trivial or absent layout,
//   * which requests a capability or shows a "device is not compatible"
//     message and calls finish(),
//   * followed, on many samples, by the icon disappearing.
//
// The icon disappearing is the classic and it is worth naming exactly: an
// <activity-alias> declared android:enabled="true" carries the LAUNCHER
// filter; after the first run the app calls
//
//     pm.setComponentEnabledSetting(aliasComponent,
//         COMPONENT_ENABLED_STATE_DISABLED, DONT_KILL_APP)
//
// and the launcher removes the icon. The app is still installed, still holds
// every permission, and is now much harder for a non-technical user to find.
// You can detect it after the fact, on a device, with:
//
//     adb shell cmd package resolve-activity --brief <pkg>
//
// which returns nothing for a package whose only launcher entry is disabled,
// and with `adb shell dumpsys package <pkg>` whose "disabledComponents" list
// names the alias. Statically, the tell is an <activity-alias> in the
// manifest plus a setComponentEnabledSetting call in the DEX; the triage tool
// in ../../scripts/apk-triage.py reports both.
//
// This sample does none of that. Its icon stays where it is.

package com.pentest.ch69.inert;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.widget.TextView;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Log.i(BootstrapProvider.TAG, "MainActivity.onCreate  pid="
                + android.os.Process.myPid());

        long providerAt = BootstrapProvider.providerOnCreateNanos;
        if (providerAt != 0L) {
            long deltaMs = (System.nanoTime() - providerAt) / 1000000L;
            Log.i(BootstrapProvider.TAG, "ordering proof: BootstrapProvider."
                    + "onCreate ran " + deltaMs + " ms before this Activity, "
                    + "and before Application.onCreate. See chapter 09 "
                    + "section 3.14 for the AOSP path that guarantees it.");
        }

        ConfigVault.describe();

        TextView tv = new TextView(this);
        tv.setGravity(Gravity.CENTER);
        tv.setTextColor(Color.BLACK);
        tv.setBackgroundColor(Color.WHITE);
        tv.setText("INERT TEACHING SAMPLE\n"
                + "chapter 69 — Malware Analysis\n\n"
                + "This app has no payload, no network code,\n"
                + "and no capability request.\n"
                + "It exists to be analysed, not run.\n\n"
                + "Read logcat with:  adb logcat -s CH69-INERT");
        setContentView(tv);
    }
}
