TikTok.apk(点击下载) / C60807Nu8.java


package X;

import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.CalendarContract;
import android.text.TextUtils;
import android.util.Pair;
import com.bytedance.covode.number.Covode;
import com.bytedance.keva.Keva;
import com.kakao.usermgmt.StringSet;
import com.ss.android.vendorcamera.BuildConfig;
import java.util.TimeZone;
import kotlin.g.b.m;

/* renamed from: X.Nu8  reason: case insensitive filesystem */
public final class C60807Nu8 {
    public static final C60807Nu8 LIZ = new C60807Nu8();
    public static final Keva LIZIZ = Keva.getRepo("com.ss.android.ugc.aweme.specact.calendar.CalendarWriter");

    static {
        Covode.recordClassIndex(102967);
    }

    private final int LIZ(Context context) {
        int LIZIZ2 = LIZIZ(context);
        if (LIZIZ2 >= 0) {
            return LIZIZ2;
        }
        TimeZone timeZone = TimeZone.getDefault();
        m.LIZIZ(timeZone, "");
        ContentValues contentValues = new ContentValues();
        contentValues.put(StringSet.name, BuildConfig.REGION);
        contentValues.put("account_name", "tiktok@tiktok.com");
        contentValues.put("account_type", "com.tiktok");
        contentValues.put("calendar_displayName", "TikTok");
        contentValues.put("visible", (Integer) 1);
        contentValues.put("calendar_color", (Integer) -16776961);
        contentValues.put("calendar_access_level", (Integer) 700);
        contentValues.put("sync_events", (Integer) 1);
        contentValues.put("calendar_timezone", timeZone.getID());
        contentValues.put("ownerAccount", "tiktok@tiktok.com");
        contentValues.put("canOrganizerRespond", (Integer) 0);
        Uri parse = Uri.parse("content://com.android.calendar/calendars");
        m.LIZIZ(parse, "");
        Uri build = parse.buildUpon().appendQueryParameter("caller_is_syncadapter", "true").appendQueryParameter("account_name", "tiktok@tiktok.com").appendQueryParameter("account_type", "com.tiktok").build();
        m.LIZIZ(build, "");
        Uri insert = context.getContentResolver().insert(build, contentValues);
        if ((insert != null ? ContentUris.parseId(insert) : -1) >= 0) {
            return LIZIZ(context);
        }
        return -1;
    }

    public static Cursor LIZ(ContentResolver contentResolver, Uri uri, String[] strArr, String str, String[] strArr2) {
        Cursor query;
        Pair<Boolean, Object> LIZ2 = AnonymousClass0UU.LIZ(contentResolver, new Object[]{uri, strArr, str, strArr2, null}, 240004, "android.database.Cursor", false, null);
        if (((Boolean) LIZ2.first).booleanValue()) {
            query = (Cursor) LIZ2.second;
        } else {
            query = contentResolver.query(uri, strArr, str, strArr2, null);
            AnonymousClass0UU.LIZ(query, contentResolver, new Object[]{uri, strArr, str, strArr2, null}, 240004, "com_ss_android_ugc_aweme_specact_touchpoints_popup_calendar_CalendarWriter_android_content_ContentResolver_query(Landroid/content/ContentResolver;Landroid/net/Uri;[Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)Landroid/database/Cursor;");
        }
        return query;
    }

    private final Uri LIZ() {
        Uri build = CalendarContract.Events.CONTENT_URI.buildUpon().appendQueryParameter("caller_is_syncadapter", "true").appendQueryParameter("account_name", "com.tiktok").appendQueryParameter("account_type", "LOCAL").build();
        m.LIZIZ(build, "");
        return build;
    }

    private final boolean LIZ(C60811NuC nuC) {
        if (nuC.LIZ.length() == 0) {
            return false;
        }
        return (nuC.LIZIZ.length() <= 0 || ((!(m.LIZ(nuC.LIZIZ, "daily") ^ true) || !(m.LIZ(nuC.LIZIZ, "weekly") ^ true) || !(m.LIZ(nuC.LIZIZ, "monthly") ^ true) || !(m.LIZ(nuC.LIZIZ, "yearly") ^ true)) && nuC.LIZJ >= 0 && nuC.LIZLLL >= 0)) && nuC.LJ >= 0 && nuC.LJFF >= 0 && nuC.LJI >= 0 && nuC.LJIIIIZZ.length() != 0;
    }

    private final int LIZIZ(Context context) {
        Cursor LIZ2 = LIZ(context.getContentResolver(), Uri.parse("content://com.android.calendar/calendars"), null, null, null);
        int i2 = -1;
        int count = LIZ2 != null ? LIZ2.getCount() : -1;
        if (LIZ2 != null && count > 0) {
            LIZ2.moveToFirst();
            while (true) {
                if (LIZ2.getInt(LIZ2.getColumnIndex("calendar_access_level")) <= 200) {
                    if (!LIZ2.moveToNext()) {
                        break;
                    }
                } else {
                    i2 = LIZ2.getInt(LIZ2.getColumnIndex("_id"));
                    break;
                }
            }
        }
        if (LIZ2 != null) {
            LIZ2.close();
        }
        return i2;
    }

    private final void LIZIZ(String str) {
        LIZIZ.storeBoolean(str, true);
    }

    public final int LIZ(Context context, C60811NuC nuC) {
        C21090sc.LIZ(context, nuC);
        if (!LIZ(nuC)) {
            return -1;
        }
        if (LIZ(context, nuC.LIZ)) {
            return 5;
        }
        int LIZ2 = LIZ(context);
        if (LIZ2 < 0) {
            return 1000;
        }
        ContentValues contentValues = new ContentValues();
        contentValues.put("calendar_id", Integer.valueOf(LIZ2));
        contentValues.put("title", nuC.LJIIIIZZ);
        if (!TextUtils.isEmpty(nuC.LJIIIZ)) {
            contentValues.put("description", nuC.LJIIIZ);
        }
        contentValues.put("dtstart", Long.valueOf(nuC.LJ));
        contentValues.put("dtend", Long.valueOf(nuC.LJFF));
        TimeZone timeZone = TimeZone.getDefault();
        m.LIZIZ(timeZone, "");
        contentValues.put("eventTimezone", timeZone.getID());
        contentValues.put("allDay", Boolean.valueOf(nuC.LJII));
        contentValues.put(AnonymousClass3WB.LIZIZ, nuC.LIZ);
        if (nuC.LJI >= 0) {
            contentValues.put("hasAlarm", (Integer) 1);
        }
        if (!TextUtils.isEmpty(nuC.LIZIZ)) {
            contentValues.put("rrule", "FREQ=" + nuC.LIZIZ + ";INTERVAL=" + nuC.LIZJ + ";COUNT=" + nuC.LIZLLL);
        }
        Uri insert = context.getContentResolver().insert(LIZ(), contentValues);
        if (nuC.LJI >= 0) {
            ContentValues contentValues2 = new ContentValues();
            if (insert != null) {
                contentValues2.put("event_id", Long.valueOf(ContentUris.parseId(insert)));
            }
            contentValues2.put("minutes", Long.valueOf(nuC.LJI / 60000));
            contentValues2.put("method", (Integer) 1);
            context.getContentResolver().insert(Uri.parse("content://com.android.calendar/reminders"), contentValues2);
        }
        LIZIZ(nuC.LIZ);
        return 1;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:13:0x0049, code lost:
        r0 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:14:0x004a, code lost:
        X.C23290wA.LIZ(r2, r1);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:15:0x004d, code lost:
        throw r0;
     */
    public final boolean LIZ(Context context, String str) {
        C21090sc.LIZ(context, str);
        boolean z = true;
        Cursor LIZ2 = LIZ(context.getContentResolver(), CalendarContract.Events.CONTENT_URI, new String[]{AnonymousClass3WB.LIZIZ}, AnonymousClass1YG.LIZ(new String[]{"sync_data1=?"}, " and ", (CharSequence) null, (CharSequence) null, 0, (CharSequence) null, (AnonymousClass1IM) null, 62), new String[]{str});
        if (LIZ2 == null) {
            return false;
        }
        Cursor cursor = LIZ2;
        m.LIZIZ(cursor, "");
        if (cursor.getCount() <= 0) {
            z = false;
        }
        C23290wA.LIZ(LIZ2, null);
        return z;
    }

    public final boolean LIZ(String str) {
        C21090sc.LIZ(str);
        return LIZIZ.getBoolean(str, false);
    }
}