package com.ss.android.ugc.aweme.tile;

import X.0Gp;
import X.0HH;
import X.2HX;
import X.2UX;
import X.2nK;
import X.8cV;
import X.9EH;
import X.C2789S9h;
import X.C2791S9j;
import X.C2793S9l;
import X.C2794S9m;
import X.C3829SfZ;
import android.content.Intent;
import android.net.Uri;
import android.os.SystemClock;
import android.service.quicksettings.Tile;
import android.service.quicksettings.TileService;
import com.bytedance.covode.number.Covode;
import com.bytedance.helios.sdk.utils.ServiceLifecycle;
import com.ss.android.ugc.aweme.deeplink.DeepLinkServiceImpl;
import com.ss.android.ugc.aweme.deeplink.IDeepLinkService;

public final class PublishTileService extends TileService {
    public static final long LIZIZ = 2500;
    public static final C2793S9l LIZJ = new C2793S9l((byte) 0);
    public volatile boolean LIZ;

    public final int onStartCommand(Intent intent, int i, int i2) {
        ServiceLifecycle.onStartCommand(this, intent, i, i2);
        return super.onStartCommand(intent, i, i2);
    }

    public final void onStartListening() {
        super.onStartListening();
        LIZ();
    }

    static {
        Covode.recordClassIndex(118861);
    }

    private final void LIZ() {
        Tile qsTile = getQsTile();
        if (qsTile != null) {
            qsTile.setState(1);
            qsTile.setLabel(getString(C2794S9m.LIZ));
            qsTile.updateTile();
        }
    }

    public final void onTileAdded() {
        super.onTileAdded();
        2UX r2 = new 2UX();
        r2.LIZ("features", "record_video");
        2nK.LIZ("add_to_notificationbar", r2.LIZ);
    }

    public final void onTileRemoved() {
        super.onTileRemoved();
        2UX r2 = new 2UX();
        r2.LIZ("features", "record_video");
        2nK.LIZ("delete_from_notificationbar", r2.LIZ);
    }

    public final void onCreate() {
        super.onCreate();
        long uptimeMillis = SystemClock.uptimeMillis() - 2HX.LIZ.LJII;
        if (uptimeMillis <= 1000) {
            2UX r2 = new 2UX();
            r2.LIZ("time", uptimeMillis);
            r2.LIZ("features", "record_video");
            2nK.LIZ("active_in_notificationbar", r2.LIZ);
        }
        LIZ();
    }

    public final void onClick() {
        Class LJFF;
        super.onClick();
        IDeepLinkService LJIIJ = DeepLinkServiceImpl.LJIIJ();
        if (LJIIJ != null && (LJFF = LJIIJ.LJFF()) != null) {
            if (!C3829SfZ.LJIIJJI) {
                Intent intent = new Intent("android.intent.action.VIEW");
                intent.setClass(this, LJFF);
                intent.putExtra("from_tile_service", true);
                intent.addFlags(268435456);
                startActivityAndCollapse(intent);
                return;
            }
            int i = 9EH.LJIILJJIL;
            if (i <= 0) {
                i = 1233;
            }
            Intent intent2 = new Intent("android.intent.action.VIEW");
            intent2.setClass(this, LJFF);
            intent2.setData(Uri.parse("snssdk" + i + "://openRecord?recordParam=withStickerPanel&_t=" + System.currentTimeMillis()));
            try {
                intent2.addFlags(268435456);
                intent2.putExtra("from_tile_service", true);
                startActivityAndCollapse(intent2);
                this.LIZ = false;
                C3829SfZ.LJIJ.LIZJ().LIZLLL(new C2791S9j(this));
                0Gp.LIZ(LIZIZ).LIZIZ(new C2789S9h(this), 0Gp.LIZIZ);
            } catch (Exception e) {
                0HH.LIZ(e);
                8cV.LIZ(e);
            }
            2UX r2 = new 2UX();
            r2.LIZ("features", "record_video");
            2nK.LIZ("click_notificationbar", r2.LIZ);
        }
    }
}
