package com.android.systemui.secureline;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class SecureLineLockReceiver extends BroadcastReceiver {

    private static final String CHANNEL_ID = "secureline_lock";

    @Override
    public void onReceive(Context context, Intent intent) {

        String state = intent.getStringExtra("state");

        NotificationManager nm =
                context.getSystemService(NotificationManager.class);

        if (nm == null) {
            return;
        }

        NotificationChannel channel =
                new NotificationChannel(
                        CHANNEL_ID,
                        "LemenzoOS License",
                        NotificationManager.IMPORTANCE_HIGH
                );

        nm.createNotificationChannel(channel);

        String title;
        String text;

        /*
         * Grace period
         */
        if ("MID_LOCK".equals(state)) {

            title = "LemenzoOS License Expired";

            text = "Renew your license to avoid restrictions.";

        /*
         * Restricted mode
         */
        } else if ("HARD_LOCK".equals(state)) {

            title = "LemenzoOS Device Restricted";

            text = "Device is restricted. Renew your license.";

        /*
         * Fallback
         */
        } else {

            title = "LemenzoOS Warning";

            text = "LemenzoOS requires attention.";
        }

        Notification notification =
                new Notification.Builder(context, CHANNEL_ID)
                        .setSmallIcon(
                                com.android.internal.R.drawable.stat_sys_warning
                        )
                        .setContentTitle(title)
                        .setContentText(text)
                        .setPriority(Notification.PRIORITY_HIGH)
                        .setCategory(Notification.CATEGORY_SYSTEM)
                        .setOngoing(true)
                        .setAutoCancel(false)
                        .build();

        nm.notify(7002, notification);
    }
}
