// examples/inert-sample/InertNotificationRelay.java
//
// =========================================================================
// INERT TEACHING SAMPLE — chapter 69. THIS IS NOT MALWARE.
// A declared NotificationListenerService with an empty body. It reads no
// notification, cancels no notification, and relays nothing anywhere.
// =========================================================================
//
// WHY THIS CAPABILITY MATTERS MORE THAN IT LOOKS
//
// Notification access is the quiet one. It attracts far less attention than
// accessibility, and for a large class of fraud it is sufficient on its own.
//
// A bound NotificationListenerService receives onNotificationPosted() for
// EVERY notification posted by EVERY app on the device, with the posting
// package name, the notification's title and text, its actions, and its
// extras bundle. It can also CANCEL any notification.
//
// Put those two together against a single scenario — a bank sending a
// one-time passcode by SMS or push:
//
//   * The listener reads the code out of the notification. No SMS permission
//     is involved, so an app that never asked for READ_SMS still gets SMS
//     content, which defeats a detection rule built around SMS permissions.
//     Since API 19 this has been true; it is not new and it is not obscure.
//   * The listener then cancels the notification, so the user never sees the
//     code arrive and has no cue that a transaction is in progress.
//
// That is a complete second-factor interception with one capability, no
// exploit, and no accessibility service. The permission
// BIND_NOTIFICATION_LISTENER_SERVICE is held by the SYSTEM, not by the app —
// the app declares that only the system may bind it — and the actual grant is
// a per-app toggle in Settings > Notifications > Device & app notifications.
//
// PLATFORM MITIGATIONS, and their real strength
//
//   API 21   NotificationListenerService with rebind semantics; the system
//            restarts a bound listener, which is a persistence bonus.
//   API 24   requestRebind()/requestUnbind(), and the listener can be
//            re-enabled without a reboot.
//   API 26   Notification channels; importance is per-channel.
//   API 28   A listener no longer sees notifications from other users.
//   API 33   Restricted settings covers notification access for sideloaded
//            packages, exactly as it covers accessibility.
//   API 34+  Sensitive notifications can be redacted for listeners; support
//            is device- and configuration-dependent, so do not state it as a
//            universal protection without checking the specific build.
//
// The honest summary is the same as for accessibility: it is now harder to
// obtain by sideload and it still depends on a user toggling a switch after
// reading a warning.
//
// DETECTION — statically
//
//   * <service> with android:permission="android.permission.
//     BIND_NOTIFICATION_LISTENER_SERVICE"
//   * <intent-filter> for
//     android.service.notification.NotificationListenerService
//   * in the DEX: overrides of onNotificationPosted / onNotificationRemoved,
//     and calls to cancelNotification() or cancelAllNotifications() — the
//     CANCEL calls are the ones that turn "reads notifications" into
//     "suppresses evidence", and they are the line worth putting in a report.
//   * a string constant "android.settings.ACTION_NOTIFICATION_LISTENER_
//     SETTINGS", which is how the app drives the user to the toggle.
//
// DETECTION — dynamically, on an emulator
//
//   adb shell settings get secure enabled_notification_listeners
//   adb shell dumpsys notification --noredact | head -60
//
// This class overrides nothing. The two callbacks that carry the capability
// are not implemented at all, deliberately — not even as an empty override
// with a comment where the code would go.

package com.pentest.ch69.inert;

import android.service.notification.NotificationListenerService;
import android.util.Log;

public class InertNotificationRelay extends NotificationListenerService {

    @Override
    public void onListenerConnected() {
        super.onListenerConnected();
        Log.i(BootstrapProvider.TAG, "InertNotificationRelay connected — and "
                + "handles nothing. onNotificationPosted is not overridden in "
                + "this class, so the base implementation (a no-op) runs.");
    }

    @Override
    public void onListenerDisconnected() {
        super.onListenerDisconnected();
        Log.i(BootstrapProvider.TAG, "InertNotificationRelay disconnected. A "
                + "live sample calls requestRebind() here; this one does not.");
    }
}
