package com.intsig.camscanner.tsapp.sync; import android.app.Activity; import android.app.Notification; import android.app.PendingIntent; import android.content.ContentProviderOperation; import android.content.ContentResolver; import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.OperationApplicationException; import android.content.SharedPreferences; import android.database.Cursor; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.Uri; import android.os.RemoteException; import android.preference.PreferenceManager; import android.text.TextUtils; import android.util.LongSparseArray; import android.util.Pair; import androidx.annotation.Nullable; import androidx.exifinterface.media.ExifInterface; import com.efs.sdk.base.core.util.NetworkUtil; import com.facebook.GraphResponse; import com.facebook.ads.AdError; import com.facebook.appevents.AppEventsConstants; import com.facebook.appevents.UserDataStore; import com.facebook.internal.AnalyticsEvents; import com.google.android.gms.measurement.api.AppMeasurementSdk; import com.intsig.app.AlertDialog; import com.intsig.camscanner.R; import com.intsig.camscanner.app.AppSwitch; import com.intsig.camscanner.app.AppUtil; import com.intsig.camscanner.app.DBUtil; import com.intsig.camscanner.app.Verify; import com.intsig.camscanner.bitmap.BitmapUtils; import com.intsig.camscanner.data.dao.ShareDirDao; import com.intsig.camscanner.datastruct.WaterMarkInfo; import com.intsig.camscanner.eventbus.CsEventBus; import com.intsig.camscanner.eventbus.MessageEvent; import com.intsig.camscanner.fragment.TeamFragment; import com.intsig.camscanner.fundamental.net_tasks.DocShareLinkInfo; import com.intsig.camscanner.https.account.UserPropertyAPI; import com.intsig.camscanner.https.entity.CSQueryProperty; import com.intsig.camscanner.inkcore.InkUtils; import com.intsig.camscanner.launch.CsApplication; import com.intsig.camscanner.log.LogAgentData; import com.intsig.camscanner.mainmenu.MainPageRoute; import com.intsig.camscanner.pdfengine.PDF_Util; import com.intsig.camscanner.provider.Documents; import com.intsig.camscanner.purchase.entity.Function; import com.intsig.camscanner.purchase.track.FunctionEntrance; import com.intsig.camscanner.purchase.track.PurchaseScheme; import com.intsig.camscanner.purchase.track.PurchaseTracker; import com.intsig.camscanner.purchase.utils.PurchaseUtil; import com.intsig.camscanner.share.ShareRecorder; import com.intsig.camscanner.share.ShareSignatureLinkHelper; import com.intsig.camscanner.sharedir.ShareDirApiSync; import com.intsig.camscanner.sharedir.data.ShareDirDBData; import com.intsig.camscanner.signature.SignatureUtil; import com.intsig.camscanner.sync.SyncAccountUtil; import com.intsig.camscanner.tsapp.AccountListener; import com.intsig.camscanner.tsapp.AutoUploadThread; import com.intsig.camscanner.tsapp.SyncCallbackListener; import com.intsig.camscanner.tsapp.collaborate.CollaborateUtil; import com.intsig.camscanner.tsapp.sync.team.TeamCommitDirJson; import com.intsig.camscanner.tsapp.sync.team.TeamDirListJson; import com.intsig.camscanner.util.PreferenceHelper; import com.intsig.camscanner.util.SDStorageManager; import com.intsig.camscanner.util.Util; import com.intsig.camscanner.watermark.WaterMarkUtil; import com.intsig.camscanner.web.UrlUtil; import com.intsig.comm.account_data.AccountPreference; import com.intsig.comm.util.SyncUtilDelegate; import com.intsig.https.HttpsUtil; import com.intsig.log.LogAgentHelper; import com.intsig.log.LogUtils; import com.intsig.okgo.utils.GsonUtils; import com.intsig.owlery.TheOwlery; import com.intsig.scanner.ScannerEngine; import com.intsig.thread.ThreadPoolSingleton; import com.intsig.tianshu.TianShuAPI; import com.intsig.tianshu.UploadState; import com.intsig.tianshu.UserInfo; import com.intsig.tianshu.exception.TianShuException; import com.intsig.tianshu.parameter.LoginParameter; import com.intsig.tianshu.purchase.BalanceInfo; import com.intsig.tianshu.sync.SyncApi; import com.intsig.tianshu.sync.SyncState; import com.intsig.tianshu.sync.SyncTimeCount; import com.intsig.util.PhoneUtil; import com.intsig.utils.AESEncUtil; import com.intsig.utils.ApplicationHelper; import com.intsig.utils.CommonUtil; import com.intsig.utils.CustomExecutor; import com.intsig.utils.FileUtil; import com.intsig.utils.LanguageUtil; import com.intsig.utils.NotificationHelper; import com.intsig.utils.PendingIntentCompat; import com.intsig.utils.PreferenceUtil; import com.intsig.utils.SDStorageUtil; import com.microsoft.aad.adal.AuthenticationConstants; import com.microsoft.aad.adal.ClientMetricsEndpointType; import com.microsoft.services.msa.PreferencesConstants; import com.umeng.analytics.pro.ao; import com.umeng.analytics.pro.d; import com.vungle.warren.model.AdAssetDBAdapter; import com.vungle.warren.ui.JavascriptBridge; import io.netty.handler.codec.rtsp.RtspHeaders; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.text.DateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.Vector; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.concurrent.Semaphore; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import ra.a0; import ra.b0; import ra.c0; import ra.e0; import ra.y; import ra.z; public class SyncUtil { /* renamed from: a reason: collision with root package name */ public static boolean f35038a; /* renamed from: b reason: collision with root package name */ private static boolean f35039b; /* renamed from: c reason: collision with root package name */ private static String[] f35040c = {UserDataStore.PHONE, "id", "br", "co", "mx", "eg", "my", "tr", "ar", "pk"}; private static class DownloadImageFileCallable implements Callable<Boolean> { /* renamed from: a reason: collision with root package name */ private Context f35044a; /* renamed from: b reason: collision with root package name */ private String f35045b; /* renamed from: c reason: collision with root package name */ private DownloadImageInfo f35046c; /* renamed from: d reason: collision with root package name */ private Vector<SyncCallbackListener> f35047d; /* renamed from: e reason: collision with root package name */ private String f35048e; /* renamed from: f reason: collision with root package name */ private boolean f35049f; /* renamed from: g reason: collision with root package name */ private float f35050g; /* renamed from: h reason: collision with root package name */ private SyncApi.SyncProgress f35051h; /* renamed from: i reason: collision with root package name */ private SyncState f35052i; /* renamed from: j reason: collision with root package name */ private boolean[] f35053j; /* renamed from: k reason: collision with root package name */ private Semaphore f35054k; /* renamed from: l reason: collision with root package name */ private final boolean f35055l; DownloadImageFileCallable(boolean z10) { this.f35055l = z10; } private void l() { boolean[] zArr = this.f35053j; if (zArr == null || zArr.length < 1) { throw new IllegalArgumentException("pwdNotMatch is empty"); } else if (!TextUtils.isEmpty(this.f35048e)) { Objects.requireNonNull(this.f35046c, "downloadImageInfo == null"); Objects.requireNonNull(this.f35044a, "context == null"); Objects.requireNonNull(this.f35052i, "state == null"); Objects.requireNonNull(this.f35054k, "semaphore == null"); } else { throw new IllegalArgumentException("accountUid is empty"); } } /* JADX INFO: finally extract failed */ /* JADX WARNING: Removed duplicated region for block: B:26:0x00c7 A[Catch:{ TianShuException -> 0x00ff, all -> 0x00fd }] */ /* JADX WARNING: Removed duplicated region for block: B:27:0x00cb A[Catch:{ TianShuException -> 0x00ff, all -> 0x00fd }] */ /* JADX WARNING: Removed duplicated region for block: B:30:0x00d2 */ @Override // java.util.concurrent.Callable public Boolean call() throws InterruptedException { int i10; l(); if (SyncThread.f34994t) { LogUtils.a("SyncUtil", "DownloadImageFileCallable SyncThread.stopSync=true"); return Boolean.FALSE; } boolean z10 = false; if (this.f35053j[0]) { LogUtils.a("SyncUtil", "pwd change"); return Boolean.FALSE; } this.f35054k.acquire(); try { if (TextUtils.isEmpty(this.f35045b)) { String str = this.f35046c.f35058c; long j2 = this.f35046c.f35056a; Context context = this.f35044a; i10 = SyncUtil.I(str, j2, context, this.f35047d, !PreferenceHelper.l7(context), this.f35046c.f35064i); if (this.f35055l) { SyncTimeCount.f38937i0.b().g(1); boolean z11 = i10 <= 0; synchronized (this.f35052i) { try { if (this.f35051h != null) { this.f35052i.a(this.f35050g); this.f35051h.a(this.f35052i); } } catch (Throwable th) { throw th; } } this.f35054k.release(); z10 = z11; return Boolean.valueOf(z10); } } else { SyncUtil.D(this.f35044a, this.f35048e, this.f35045b, this.f35046c.f35058c, this.f35046c.f35056a, null, this.f35049f, null, !PreferenceHelper.l7(this.f35044a), this.f35047d); i10 = 1; } if (i10 <= 0) { } synchronized (this.f35052i) { } } catch (TianShuException e10) { LogUtils.e("SyncUtil", e10); if (SyncUtil.G1(e10.getErrorCode())) { this.f35053j[0] = true; } this.f35054k.release(); } catch (Throwable th2) { this.f35054k.release(); throw th2; } } } /* access modifiers changed from: private */ public static class DownloadImageInfo { /* renamed from: a reason: collision with root package name */ private long f35056a; /* renamed from: b reason: collision with root package name */ private String f35057b; /* renamed from: c reason: collision with root package name */ private String f35058c; /* renamed from: d reason: collision with root package name */ private long f35059d; /* renamed from: e reason: collision with root package name */ private long f35060e; /* renamed from: f reason: collision with root package name */ private String f35061f; /* renamed from: g reason: collision with root package name */ private int f35062g; /* renamed from: h reason: collision with root package name */ private int f35063h; /* renamed from: i reason: collision with root package name */ private boolean f35064i; private DownloadImageInfo() { } } /* access modifiers changed from: private */ public static class UploadImageFileCallable implements Callable<UploadImageResponse> { /* renamed from: a reason: collision with root package name */ private UploadLocalImageInfo f35065a; /* renamed from: b reason: collision with root package name */ private TianShuException[] f35066b; /* renamed from: c reason: collision with root package name */ private boolean[] f35067c; /* renamed from: d reason: collision with root package name */ private String f35068d; /* renamed from: e reason: collision with root package name */ private String f35069e; /* renamed from: f reason: collision with root package name */ private boolean f35070f; /* renamed from: g reason: collision with root package name */ private boolean f35071g; /* renamed from: h reason: collision with root package name */ private String f35072h; /* renamed from: i reason: collision with root package name */ private float f35073i; /* renamed from: j reason: collision with root package name */ private SyncApi.SyncProgress f35074j; /* renamed from: k reason: collision with root package name */ private SyncState f35075k; /* renamed from: l reason: collision with root package name */ private Context f35076l; /* renamed from: m reason: collision with root package name */ private Semaphore f35077m; /* renamed from: n reason: collision with root package name */ private ShareDirDBData f35078n; private UploadImageFileCallable() { } private void o() { Objects.requireNonNull(this.f35076l, "context == null"); Objects.requireNonNull(this.f35075k, "syncState == null"); Objects.requireNonNull(this.f35065a, "uploadLocalImageInfo == null"); Objects.requireNonNull(this.f35077m, "semaphore == null"); Objects.requireNonNull(this.f35078n, "shareDirDBData == null"); } /* JADX WARNING: Removed duplicated region for block: B:57:0x0138 */ @Override // java.util.concurrent.Callable public UploadImageResponse call() throws InterruptedException { boolean z10; boolean z11; boolean z12; TianShuException e10; TianShuException e11; o(); UploadImageResponse uploadImageResponse = new UploadImageResponse(); uploadImageResponse.f35149c = false; if (SyncThread.f34994t) { return uploadImageResponse; } if (!this.f35067c[0]) { return uploadImageResponse; } if (this.f35066b[0] != null) { return uploadImageResponse; } this.f35077m.acquire(); try { if (!FileUtil.C(this.f35065a.f35080b)) { try { LogUtils.a("SyncUtil", "hasMissedPage true imagePath=" + this.f35065a.f35080b); z11 = true; } catch (TianShuException e12) { e10 = e12; z12 = true; z10 = false; this.f35066b[0] = e10; uploadImageResponse.f35148b = e10.getErrorCode(); if (e10.getErrorCode() == 313) { } z11 = z12; uploadImageResponse.f35149c = z10; uploadImageResponse.f35150d = z11; this.f35077m.release(); return uploadImageResponse; } } else { z11 = false; } try { long currentTimeMillis = System.currentTimeMillis(); z10 = TextUtils.isEmpty(this.f35068d) ? SyncUtil.l3(this.f35076l, this.f35065a, this.f35071g, this.f35072h, this.f35067c, this.f35078n) : SyncUtil.m3(this.f35076l, this.f35065a, this.f35067c, this.f35068d, this.f35069e, this.f35070f); try { SyncUtil.E2("upload", System.currentTimeMillis() - currentTimeMillis, FileUtil.t(this.f35065a.f35080b), z10); if (TextUtils.isEmpty(this.f35068d)) { SyncTimeCount.f38937i0.b().x(1); } synchronized (this.f35075k) { try { if (this.f35074j != null) { this.f35075k.a(this.f35073i); this.f35074j.a(this.f35075k); } } finally { } } } catch (TianShuException e13) { e11 = e13; z12 = z11; e10 = e11; this.f35066b[0] = e10; uploadImageResponse.f35148b = e10.getErrorCode(); if (e10.getErrorCode() == 313) { } z11 = z12; uploadImageResponse.f35149c = z10; uploadImageResponse.f35150d = z11; this.f35077m.release(); return uploadImageResponse; } } catch (TianShuException e14) { e11 = e14; z10 = false; z12 = z11; e10 = e11; this.f35066b[0] = e10; uploadImageResponse.f35148b = e10.getErrorCode(); if (e10.getErrorCode() == 313) { uploadImageResponse.f35151e = true; } z11 = z12; uploadImageResponse.f35149c = z10; uploadImageResponse.f35150d = z11; this.f35077m.release(); return uploadImageResponse; } } catch (TianShuException e15) { e10 = e15; z12 = false; z10 = false; this.f35066b[0] = e10; uploadImageResponse.f35148b = e10.getErrorCode(); if (e10.getErrorCode() == 313) { } z11 = z12; uploadImageResponse.f35149c = z10; uploadImageResponse.f35150d = z11; this.f35077m.release(); return uploadImageResponse; } uploadImageResponse.f35149c = z10; uploadImageResponse.f35150d = z11; this.f35077m.release(); return uploadImageResponse; } } /* access modifiers changed from: private */ public static class UploadLocalImageInfo { /* renamed from: a reason: collision with root package name */ private long f35079a; /* renamed from: b reason: collision with root package name */ private String f35080b; /* renamed from: c reason: collision with root package name */ private long f35081c; /* renamed from: d reason: collision with root package name */ private int f35082d; /* renamed from: e reason: collision with root package name */ private int f35083e; /* renamed from: f reason: collision with root package name */ private int f35084f; /* renamed from: g reason: collision with root package name */ private String f35085g; /* renamed from: h reason: collision with root package name */ private String f35086h; /* renamed from: i reason: collision with root package name */ private int f35087i; private UploadLocalImageInfo() { } } private static class UploadRawImageCallable implements Callable<UploadImageResponse> { /* renamed from: a reason: collision with root package name */ private Context f35088a; /* renamed from: b reason: collision with root package name */ private float f35089b; /* renamed from: c reason: collision with root package name */ private boolean[] f35090c; /* renamed from: d reason: collision with root package name */ private TianShuException[] f35091d; /* renamed from: e reason: collision with root package name */ private String f35092e; /* renamed from: f reason: collision with root package name */ private boolean f35093f; /* renamed from: g reason: collision with root package name */ private volatile boolean[] f35094g; /* renamed from: h reason: collision with root package name */ private SyncState f35095h; /* renamed from: i reason: collision with root package name */ private SyncApi.SyncProgress f35096i; /* renamed from: j reason: collision with root package name */ private UploadRawImageInfo f35097j; /* renamed from: k reason: collision with root package name */ private Map<Long, TeamDirListJson.BaseTeamDoc> f35098k; /* renamed from: l reason: collision with root package name */ private LongSparseArray<String> f35099l; /* renamed from: m reason: collision with root package name */ private Semaphore f35100m; private UploadRawImageCallable() { } private void n() { Objects.requireNonNull(this.f35088a, "context == null"); Objects.requireNonNull(this.f35095h, "syncState == null"); Objects.requireNonNull(this.f35097j, "uploadRawImageInfo == null"); Objects.requireNonNull(this.f35100m, "semaphore == null"); } @Override // java.util.concurrent.Callable public UploadImageResponse call() throws Exception { n(); UploadImageResponse uploadImageResponse = new UploadImageResponse(); uploadImageResponse.f35149c = false; if (!SyncThread.f34994t) { if (SyncThread.Z()) { return uploadImageResponse; } if (!this.f35090c[0]) { return uploadImageResponse; } if (this.f35091d[0] != null) { return uploadImageResponse; } this.f35100m.acquire(); TianShuException e10 = null; boolean z10 = false; int i10 = 0; while (true) { try { uploadImageResponse.f35149c = p(); o(); e10 = null; } catch (TianShuException e11) { uploadImageResponse.f35148b = e11.getErrorCode(); if (e11.getErrorCode() == 313) { uploadImageResponse.f35151e = true; } if (this.f35094g[0]) { synchronized (this.f35094g) { if (this.f35094g[0]) { try { SyncUtil.w(); SyncUtil.u2(this.f35088a); this.f35094g[0] = false; } catch (TianShuException e12) { e10 = e12; } } z10 = true; } } else { e10 = e11; } } i10++; if (z10) { if (i10 >= 2) { break; } } else { break; } } if (e10 != null) { this.f35091d[0] = e10; } this.f35100m.release(); } return uploadImageResponse; } /* access modifiers changed from: package-private */ public void o() { if (this.f35096i != null) { synchronized (this.f35095h) { if (this.f35096i != null) { this.f35095h.a(this.f35089b); this.f35096i.a(this.f35095h); } } } } /* access modifiers changed from: package-private */ public boolean p() throws TianShuException { ShareDirDBData n10 = ShareDirDao.n(this.f35088a, this.f35097j.f35107g); if (!TextUtils.isEmpty(this.f35092e)) { return SyncUtil.s3(this.f35088a, this.f35097j.f35101a, this.f35097j.f35102b, this.f35097j.f35103c, this.f35097j.f35105e, this.f35090c, this.f35098k, this.f35099l, this.f35097j.f35107g, this.f35092e, this.f35093f); } boolean o32 = SyncUtil.o3(this.f35088a, this.f35097j.f35101a, this.f35097j.f35102b, this.f35097j.f35103c, this.f35097j.f35105e, this.f35097j.f35107g, this.f35097j.f35108h == 1, this.f35090c, this.f35094g, n10); SyncTimeCount.f38937i0.b().B(1); return o32; } } /* access modifiers changed from: private */ public static class UploadRawImageInfo { /* renamed from: a reason: collision with root package name */ private long f35101a; /* renamed from: b reason: collision with root package name */ private String f35102b; /* renamed from: c reason: collision with root package name */ private String f35103c; /* renamed from: d reason: collision with root package name */ private int f35104d; /* renamed from: e reason: collision with root package name */ private long f35105e; /* renamed from: f reason: collision with root package name */ private int f35106f; /* renamed from: g reason: collision with root package name */ private long f35107g; /* renamed from: h reason: collision with root package name */ private int f35108h; private UploadRawImageInfo() { } } public static void A(Context context, String str, boolean z10) { String str2; int i10; if (!z10) { str2 = BitmapUtils.D(str); } else if (FileUtil.C(str)) { str2 = str; } else { LogUtils.a("SyncUtil", "fileName is not exist"); str2 = null; } String R = Util.R(str); LogUtils.a("SyncUtil", "createThumbPage thumb=" + str2 + " fileName=" + str + " isThumb=" + z10 + " name=" + R); if (!TextUtils.isEmpty(R) && !TextUtils.isEmpty(str2)) { int lastIndexOf = R.lastIndexOf("."); if (lastIndexOf > 0) { ContentResolver contentResolver = context.getContentResolver(); if (!R.contains("_") || (i10 = R.lastIndexOf("_") + 1) > R.length()) { i10 = 0; } Cursor query = contentResolver.query(Documents.Image.f28706c, new String[]{"document_id", "page_num", ao.f45476d, "last_modified"}, "sync_image_id = ?", new String[]{R.substring(i10, lastIndexOf)}, null); if (query != null) { if (query.moveToFirst()) { LogUtils.a("SyncUtil", "pos=" + query.getInt(1)); long j2 = query.getLong(2); ContentValues contentValues = new ContentValues(); contentValues.put("thumb_data", str2); contentValues.put("last_modified", Long.valueOf(query.getLong(3))); contentResolver.update(ContentUris.withAppendedId(Documents.Image.f28706c, j2), contentValues, null, null); } query.close(); } } } else if (str2 == null) { LogUtils.c("SyncUtil", "createThumbPage file is damaged " + str); } } public static long A0() { return PreferenceUtil.f().h("woj87redsdwgaawdd90", 0) * 1000; } public static boolean A1() { return PreferenceHelper.h9() && S1() && !o1(); } public static void A2(Context context, Intent intent, String str, String str2) { try { Notification build = NotificationHelper.getInstance().getNotification(str, str2, PendingIntent.getActivity(context, 0, intent, PendingIntentCompat.a(false))).build(); if (intent != null && TextUtils.equals(intent.getAction(), "com.intsig.camscanner.keepnotification")) { build.flags |= 32; } NotificationHelper.getInstance().notify(R.layout.sync_progress, build); } catch (Exception e10) { LogUtils.d("SyncUtil", "showSyncNotification", e10); } } public static void B(Context context, long j2) { if (j2 > 0) { Cursor query = context.getContentResolver().query(Documents.Image.f28706c, new String[]{"_data", "raw_data", "ocr_border", "image_backup", "thumb_data"}, "document_id = " + j2, null, null); if (query != null) { while (query.moveToNext()) { FileUtil.k(query.getString(0)); FileUtil.k(query.getString(1)); FileUtil.k(query.getString(2)); FileUtil.k(query.getString(3)); FileUtil.k(query.getString(4)); } query.close(); } } } public static String B0() { return DateFormat.getDateInstance(1).format(new Date(A0())); } public static boolean B1() { return PreferenceHelper.h9() && !o1(); } public static void B2(Context context) { if (t1(context)) { SyncThread.f34994t = false; SyncClient.B().f0(null); } } public static void C() { ThreadPoolSingleton.e().c(z.f52808a); } public static long C0(Context context, long j2) { long j10; Cursor query = context.getContentResolver().query(ContentUris.withAppendedId(Documents.Image.f28704a, j2), new String[]{"last_modified"}, null, null, null); if (query != null) { j10 = query.moveToFirst() ? query.getLong(0) : 0; query.close(); } else { j10 = 0; } if (j10 <= 0) { j10 = System.currentTimeMillis(); } return j10; } public static boolean C1(Context context) { SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); return defaultSharedPreferences.getBoolean(context.getString(R.string.key_setting_open_raw_image_sync) + N0(), true); } public static void C2(Context context) { SyncClient.B().j0(); C(); } public static int D(Context context, String str, String str2, String str3, long j2, String str4, boolean z10, TianShuAPI.OnProgressListener onProgressListener, boolean z11, Vector<SyncCallbackListener> vector) throws TianShuException { String str5; FileNotFoundException e10; Exception e11; String str6 = "SyncUtil"; if (SDStorageManager.h0(context)) { SDStorageManager.q0(context, SDStorageUtil.c()); SDStorageManager.b0(); LogUtils.a(str6, "downloadImageFile ExternalStorageFullOrRemoved imageSyncId=" + str3 + " accountUid=" + str); } int i10 = 1; if (z11) { return E(context, str, str2, str3, j2, z10, onProgressListener, vector); } String[] C1 = DBUtil.C1(context, j2, new String[]{"image_backup"}); boolean z12 = false; FileUtil.k((C1 == null || C1.length != 1) ? null : C1[0]); String str7 = str + "_" + str3 + ".jpg"; String U = TextUtils.equals(str4, "ori") ? U(str7) : V(str7); try { P(str2, str3 + ".jpg", str4, z10, new FileOutputStream(U), onProgressListener, U); try { ContentValues contentValues = new ContentValues(); contentValues.put("_data", U); contentValues.put("cache_state", (Integer) 0); contentValues.put("sync_version", (Integer) 1); contentValues.put("sync_ui_state", (Integer) 0); Uri withAppendedId = ContentUris.withAppendedId(Documents.Image.f28706c, j2); contentValues.put("last_modified", Long.valueOf(C0(context, j2))); if (D1(context, j2)) { try { LogUtils.c(str6, "downloadImageFile page may be deleted by user when syncing imageSyncId=" + str3 + " imageId=" + j2); } catch (FileNotFoundException e12) { e10 = e12; str5 = str6; } } else { contentValues.put("sync_state", (Integer) 0); } context.getContentResolver().update(withAppendedId, contentValues, null, null); LogUtils.a(str6, "imageFile=" + U); LogUtils.a(str6, "imageFile exist=" + FileUtil.C(U)); p2(context, j2, -1, false, str); if (v1(j2, context)) { k(context, j2, str7); z12 = true; } if (w1(context, j2)) { m(context, j2, z12, str7); } if (x1(context, j2)) { SignatureUtil.a(U, SignatureUtil.l(context, j2)); } y(context, U, j2); if (vector != null) { try { Iterator<SyncCallbackListener> it = vector.iterator(); while (it.hasNext()) { str5 = str6; try { it.next().b(DBUtil.H0(context, str3), j2, -1, 3, true); str6 = str5; } catch (Exception e13) { e11 = e13; try { LogUtils.e(str5, e11); return 1; } catch (FileNotFoundException e14) { e10 = e14; } } } } catch (Exception e15) { e11 = e15; str5 = str6; LogUtils.e(str5, e11); return 1; } } return 1; } catch (FileNotFoundException e16) { e10 = e16; str5 = str6; i10 = 1; LogUtils.e(str5, e10); return i10; } } catch (FileNotFoundException e17) { e10 = e17; str5 = str6; i10 = 0; LogUtils.e(str5, e10); return i10; } } public static Vector D0(Context context) { return new DocSyncOperation(context, -1).I(); } public static boolean D1(Context context, long j2) { Cursor query; boolean z10 = true; if (!(context == null || j2 <= 0 || (query = context.getContentResolver().query(ContentUris.withAppendedId(Documents.Image.f28706c, j2), new String[]{"sync_state", "sync_jpage_state"}, null, null, null)) == null)) { if (!(!query.moveToFirst() || query.getInt(0) == 2 || query.getInt(1) == 2)) { z10 = false; } query.close(); } return z10; } private static void D2(boolean z10) { if (!z10 && !Q1() && !f35039b && S1()) { f35039b = true; LogAgentData.a("CSPiracyStaticsPage", "piracy_detected"); } } /* JADX WARNING: Removed duplicated region for block: B:26:0x012b A[SYNTHETIC, Splitter:B:26:0x012b] */ public static int E(Context context, String str, String str2, String str3, long j2, boolean z10, TianShuAPI.OnProgressListener onProgressListener, Vector<SyncCallbackListener> vector) throws TianShuException { String str4; String str5; String str6; FileNotFoundException e10; int i10; Exception e11; String str7 = "SyncUtil"; String[] C1 = DBUtil.C1(context, j2, new String[]{"thumb_data", "_data", "image_backup"}); int i11 = 1; if (C1 == null || C1.length != 3) { str5 = null; str4 = null; } else { String str8 = C1[0]; str4 = C1[1]; str5 = C1[2]; } String str9 = str + "_" + str3 + ".jpg"; String Y = Y(str9); try { int R = R(str2, str3 + ".jpg", BitmapUtils.y(), z10, new FileOutputStream(Y), onProgressListener, Y); LogUtils.a(str7, "downLoadTeamImageFile error=" + R); boolean z11 = R == 601; try { if (D1(context, j2)) { LogUtils.c(str7, "downloadImageFile page may be deleted by user when syncing imageSyncId=" + str3 + " id=" + j2); } else { ContentValues contentValues = new ContentValues(); if (z11) { String V = V(str9); if (FileUtil.h(Y, V)) { contentValues.put("_data", V); i10 = 0; contentValues.put("thumb_data", Y); contentValues.put("cache_state", Integer.valueOf(i10)); contentValues.put("sync_ui_state", (Integer) 0); contentValues.put("sync_version", (Integer) 1); Uri withAppendedId = ContentUris.withAppendedId(Documents.Image.f28706c, j2); contentValues.put("last_modified", Long.valueOf(C0(context, j2))); contentValues.put("sync_state", (Integer) 0); context.getContentResolver().update(withAppendedId, contentValues, null, null); p2(context, j2, -1, false, str); if (vector != null) { try { Iterator<SyncCallbackListener> it = vector.iterator(); while (it.hasNext()) { str6 = str7; try { it.next().b(DBUtil.H0(context, str3), j2, -1, 3, true); str7 = str6; } catch (Exception e12) { e11 = e12; try { LogUtils.e(str6, e11); } catch (FileNotFoundException e13) { e10 = e13; } return i11; } } } catch (Exception e14) { e11 = e14; str6 = str7; LogUtils.e(str6, e11); return i11; } } } } else { FileUtil.k(str4); FileUtil.k(str5); } i10 = 1; contentValues.put("thumb_data", Y); contentValues.put("cache_state", Integer.valueOf(i10)); contentValues.put("sync_ui_state", (Integer) 0); contentValues.put("sync_version", (Integer) 1); Uri withAppendedId2 = ContentUris.withAppendedId(Documents.Image.f28706c, j2); contentValues.put("last_modified", Long.valueOf(C0(context, j2))); contentValues.put("sync_state", (Integer) 0); context.getContentResolver().update(withAppendedId2, contentValues, null, null); p2(context, j2, -1, false, str); if (vector != null) { } } } catch (FileNotFoundException e15) { e10 = e15; str6 = str7; LogUtils.e(str6, e10); return i11; } } catch (FileNotFoundException e16) { e10 = e16; str6 = str7; i11 = 0; LogUtils.e(str6, e10); return i11; } return i11; } public static Vector E0(Context context) { return new TagSyncOperation(context, -1).G(); } public static boolean E1(Context context) { return z1(context) && CsApplication.X(); } /* access modifiers changed from: private */ public static void E2(String str, long j2, long j10, boolean z10) { if (CommonUtil.g().nextInt(100) <= 30) { if (System.currentTimeMillis() <= 1665763200000L) { if (e1()) { try { JSONObject jSONObject = new JSONObject(); Locale locale = Locale.US; int i10 = 1; jSONObject.put(RtspHeaders.Values.TIME, String.format(locale, "%.1f", Double.valueOf(((double) j2) / 1000.0d))); jSONObject.put(AdAssetDBAdapter.AdAssetColumns.COLUMN_FILE_SIZE, String.format(locale, "%.1f", Double.valueOf(((double) j10) / 1024.0d))); if (z10) { i10 = 0; } jSONObject.put(GraphResponse.SUCCESS_KEY, i10); LogAgentHelper.g("CSDevelopmentTool", str, jSONObject); } catch (Exception e10) { LogUtils.e("SyncUtil", e10); } } } } } public static int F(String str, String str2, String str3, OutputStream outputStream, TianShuAPI.OnProgressListener onProgressListener, int i10, String str4, boolean z10, String str5) throws TianShuException { int[] iArr = {0}; ShareDirDBData p10 = ShareDirDao.p(ApplicationHelper.f39908b, str); int U = (TextUtils.isEmpty(p10.a()) || p10.b() != 1) ? TianShuAPI.U(str2, str3, outputStream, onProgressListener, -1, -1, i10, str4, z10, iArr, p10.a()) : ShareDirApiSync.f32717a.h(p10.a(), str3, outputStream, ApplicationHelper.f39908b.getString(R.string.app_version), iArr, onProgressListener, str4, z10)[0]; if (iArr[0] > 0 && !TextUtils.isEmpty(str5)) { long t10 = FileUtil.t(str5); if (t10 > 0 && t10 < ((long) iArr[0])) { LogUtils.a("SyncUtil", "downloadFile Incomplete file, fileSize=" + t10 + " outputContentLength=" + iArr[0]); FileUtil.k(str5); return 0; } } return U; } public static Vector F0(Context context) { Vector vector = null; String C0 = DBUtil.C0(context, null, false); if (TextUtils.isEmpty(C0)) { return new Vector(); } String[] strArr = {"_data", "created_time", "image_backup", "sync_image_id", ao.f45476d}; Cursor query = context.getContentResolver().query(Documents.Image.f28706c, strArr, "sync_state = 7 AND belong_state != 1 AND document_id in " + C0, null, "document_id ASC"); if (query != null) { vector = new Vector(); while (query.moveToNext()) { String string = query.getString(2); String string2 = query.getString(3); if (!FileUtil.C(string)) { string = query.getString(0); } try { vector.add(new PageUploadAction(string2 + ".jpg", 0, "CamScanner_Page", query.getLong(1) / 1000, 3, string, query.getLong(4))); } catch (FileNotFoundException e10) { LogUtils.e("SyncUtil", e10); } } query.close(); } return vector; } public static boolean F1(Context context) { return P1(context, null); } public static void F2(Context context, DataRevertJson dataRevertJson) { JSONException e10; if (context == null || dataRevertJson == null) { LogUtils.a("SyncUtil", "updateDataRevertJson2Db context or revrtJson is null"); return; } LogUtils.a("SyncUtil", "updateDataRevertJson2Db"); ArrayList<ContentProviderOperation> arrayList = new ArrayList<>(); JSONArray a10 = dataRevertJson.a(); int i10 = 7; char c9 = 0; if (a10 != null) { int length = a10.length(); LogUtils.a("SyncUtil", "updateDataRevertJson2Db update jdoc num: " + length); for (int i11 = 0; i11 < length; i11++) { try { String string = a10.getString(i11); if (!TextUtils.isEmpty(string)) { String replace = string.replace(".jdoc", ""); ContentProviderOperation.Builder newUpdate = ContentProviderOperation.newUpdate(Documents.Document.f28695d); newUpdate.withValue("sync_state", 7); newUpdate.withSelection("sync_doc_id=?", new String[]{replace}); arrayList.add(newUpdate.build()); } } catch (JSONException e11) { LogUtils.e("SyncUtil", e11); } } } JSONArray c10 = dataRevertJson.c(); if (c10 != null) { int length2 = c10.length(); LogUtils.a("SyncUtil", "updateDataRevertJson2Db jpage and jtag num: " + length2); int i12 = 0; while (i12 < length2) { try { String string2 = c10.getString(i12); if (!TextUtils.isEmpty(string2)) { if (string2.endsWith(".jtag")) { String replace2 = string2.replace(".jtag", ""); ContentProviderOperation.Builder newUpdate2 = ContentProviderOperation.newUpdate(Documents.Tag.f28729b); newUpdate2.withValue("sync_state", Integer.valueOf(i10)); String[] strArr = new String[1]; strArr[c9] = replace2; newUpdate2.withSelection("sync_tag_id=?", strArr); arrayList.add(newUpdate2.build()); } else if (string2.endsWith(".jpage")) { String replace3 = string2.replace(".jpage", ""); ContentProviderOperation.Builder newUpdate3 = ContentProviderOperation.newUpdate(Documents.Image.f28706c); newUpdate3.withValue("sync_jpage_state", 7); newUpdate3.withSelection("sync_image_id=?", new String[]{replace3}); arrayList.add(newUpdate3.build()); } else { LogUtils.a("SyncUtil", "syncId error " + string2); } } } catch (JSONException e12) { LogUtils.e("SyncUtil", e12); } i12++; i10 = 7; c9 = 0; } } JSONArray b10 = dataRevertJson.b(); if (b10 != null) { int length3 = b10.length(); LogUtils.a("SyncUtil", "updateDataRevertJson2Db update jpg num: " + length3); for (int i13 = 0; i13 < length3; i13++) { try { String string3 = b10.getString(i13); if (!TextUtils.isEmpty(string3)) { String replace4 = string3.replace(".jpg", ""); ContentProviderOperation.Builder newUpdate4 = ContentProviderOperation.newUpdate(Documents.Image.f28706c); try { newUpdate4.withValue("sync_state", 7); String[] strArr2 = new String[1]; try { strArr2[0] = replace4; newUpdate4.withSelection("sync_image_id=?", strArr2); arrayList.add(newUpdate4.build()); } catch (JSONException e13) { e10 = e13; } } catch (JSONException e14) { e10 = e14; LogUtils.e("SyncUtil", e10); } } } catch (JSONException e15) { e10 = e15; LogUtils.e("SyncUtil", e10); } } } if (arrayList.size() > 0) { try { context.getContentResolver().applyBatch(Documents.f28683a, arrayList); } catch (Exception e16) { LogUtils.e("SyncUtil", e16); } } else { LogUtils.a("SyncUtil", "updateDataRevertJson2Db no ops"); } } public static int G(String str, long j2, Context context, Vector<SyncCallbackListener> vector, String str2, int i10, @Nullable TianShuAPI.OnProgressListener onProgressListener, boolean z10) throws TianShuException { return H(str, j2, context, vector, str2, i10, onProgressListener, z10, false); } public static Vector G0(Context context) { return new TagSyncOperation(context, -1).H(); } public static boolean G1(int i10) { return SyncUtilDelegate.c(i10); } public static void G2(Context context, ArrayList<String> arrayList, long j2) { if (arrayList == null || arrayList.size() == 0) { LogUtils.a("SyncUtil", "updateDirSyncStat dirSynds is empty"); return; } String O3 = DBUtil.O3(context); ArrayList arrayList2 = new ArrayList(); Iterator<String> it = arrayList.iterator(); while (it.hasNext()) { String next = it.next(); if (!TextUtils.isEmpty(next) && !TextUtils.equals(O3, next)) { ShareDirDBData m10 = ShareDirDao.m(context, next); long j10 = (TextUtils.isEmpty(m10.a()) || m10.b() != 1) ? j2 : ShareDirDao.j(context, m10.a()); ContentValues contentValues = new ContentValues(); contentValues.put("upload_time", Long.valueOf(1 + j10)); contentValues.put("sync_state", (Integer) 3); arrayList2.add(ContentProviderOperation.newUpdate(Documents.Dir.f28690c).withYieldAllowed(true).withSelection("sync_state =? and upload_time <= ? and sync_dir_id = ? ", new String[]{AppEventsConstants.EVENT_PARAM_VALUE_NO, j10 + "", next}).withValues(contentValues).build()); } } ArrayList<ContentProviderOperation> b02 = DBUtil.b0(ApplicationHelper.f39908b, arrayList2); if (b02.size() > 0) { try { ApplicationHelper.f39908b.getContentResolver().applyBatch(Documents.f28683a, b02); } catch (Exception e10) { LogUtils.e("SyncUtil", e10); } } } /* JADX DEBUG: Failed to insert an additional move for type inference into block B:198:0x036d */ /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Type inference failed for: r9v20 */ /* JADX WARN: Type inference failed for: r9v55 */ /* JADX WARNING: Code restructure failed: missing block: B:118:0x0363, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:119:0x0365, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:120:0x0366, code lost: r33 = r8; r15 = r9; */ /* JADX WARNING: Code restructure failed: missing block: B:122:?, code lost: com.intsig.log.LogUtils.e("SyncUtil", r0); */ /* JADX WARNING: Code restructure failed: missing block: B:124:0x0370, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:125:0x0371, code lost: r33 = r8; */ /* JADX WARNING: Code restructure failed: missing block: B:126:0x0374, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:127:0x0375, code lost: r33 = r8; */ /* JADX WARNING: Code restructure failed: missing block: B:137:0x038d, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:138:0x038e, code lost: r9 = r15; */ /* JADX WARNING: Code restructure failed: missing block: B:139:0x0390, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:140:0x0391, code lost: r9 = r15; */ /* JADX WARNING: Code restructure failed: missing block: B:141:0x0393, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:142:0x0394, code lost: r1 = r0; r15 = r16; */ /* JADX WARNING: Code restructure failed: missing block: B:143:0x0399, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:144:0x039a, code lost: r33 = r42; */ /* JADX WARNING: Code restructure failed: missing block: B:145:0x039c, code lost: r9 = r9; */ /* JADX WARNING: Code restructure failed: missing block: B:147:0x03a0, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:148:0x03a1, code lost: r33 = r42; */ /* JADX WARNING: Code restructure failed: missing block: B:149:0x03a3, code lost: r9 = r9; */ /* JADX WARNING: Code restructure failed: missing block: B:150:0x03a4, code lost: r1 = r16; r9 = r9; */ /* JADX WARNING: Code restructure failed: missing block: B:155:0x03af, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:156:0x03b0, code lost: r1 = r0; r15 = null; */ /* JADX WARNING: Code restructure failed: missing block: B:157:0x03b5, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:158:0x03b6, code lost: r33 = r5; */ /* JADX WARNING: Code restructure failed: missing block: B:165:?, code lost: r1.close(); r9 = r9; */ /* JADX WARNING: Code restructure failed: missing block: B:166:0x03c7, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:167:0x03c8, code lost: com.intsig.log.LogUtils.e("SyncUtil", r0); r9 = r9; */ /* JADX WARNING: Code restructure failed: missing block: B:169:0x03cf, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:170:0x03d0, code lost: r33 = r5; */ /* JADX WARNING: Code restructure failed: missing block: B:175:0x03e5, code lost: r15 = r0; */ /* JADX WARNING: Code restructure failed: missing block: B:176:0x03e7, code lost: r15 = null; */ /* JADX WARNING: Code restructure failed: missing block: B:179:0x03f3, code lost: com.intsig.camscanner.app.DBUtil.w4(r37, r35, 1); */ /* JADX WARNING: Code restructure failed: missing block: B:182:?, code lost: r1.close(); */ /* JADX WARNING: Code restructure failed: missing block: B:183:0x03fe, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:184:0x03ff, code lost: com.intsig.log.LogUtils.e("SyncUtil", r0); */ /* JADX WARNING: Code restructure failed: missing block: B:194:?, code lost: r15.close(); */ /* JADX WARNING: Code restructure failed: missing block: B:195:0x0434, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:196:0x0435, code lost: com.intsig.log.LogUtils.e("SyncUtil", r0); */ /* JADX WARNING: Code restructure failed: missing block: B:29:0x0100, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:30:0x0101, code lost: r33 = r5; r1 = null; */ /* JADX WARNING: Code restructure failed: missing block: B:31:0x0107, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:32:0x0108, code lost: r33 = r5; r1 = null; */ /* JADX WARNING: Code restructure failed: missing block: B:81:0x0248, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:82:0x0249, code lost: r33 = r8; r9 = r9; */ /* JADX WARNING: Code restructure failed: missing block: B:83:0x024d, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:84:0x024e, code lost: r33 = r8; r9 = r9; */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Removed duplicated region for block: B:103:0x0323 */ /* JADX WARNING: Removed duplicated region for block: B:106:0x032c */ /* JADX WARNING: Removed duplicated region for block: B:109:0x0338 A[SYNTHETIC, Splitter:B:109:0x0338] */ /* JADX WARNING: Removed duplicated region for block: B:132:0x0382 A[SYNTHETIC, Splitter:B:132:0x0382] */ /* JADX WARNING: Removed duplicated region for block: B:141:0x0393 A[ExcHandler: all (r0v25 'th' java.lang.Throwable A[CUSTOM_DECLARE]), Splitter:B:70:0x0205] */ /* JADX WARNING: Removed duplicated region for block: B:155:0x03af A[ExcHandler: all (r0v18 'th' java.lang.Throwable A[CUSTOM_DECLARE]), Splitter:B:22:0x00dc] */ /* JADX WARNING: Removed duplicated region for block: B:164:0x03c3 A[SYNTHETIC, Splitter:B:164:0x03c3] */ /* JADX WARNING: Removed duplicated region for block: B:175:0x03e5 */ /* JADX WARNING: Removed duplicated region for block: B:176:0x03e7 */ /* JADX WARNING: Removed duplicated region for block: B:179:0x03f3 */ /* JADX WARNING: Removed duplicated region for block: B:181:0x03fa A[SYNTHETIC, Splitter:B:181:0x03fa] */ /* JADX WARNING: Removed duplicated region for block: B:186:0x0405 */ /* JADX WARNING: Removed duplicated region for block: B:189:0x042a */ /* JADX WARNING: Removed duplicated region for block: B:193:0x0430 A[SYNTHETIC, Splitter:B:193:0x0430] */ /* JADX WARNING: Removed duplicated region for block: B:200:? A[RETURN, SYNTHETIC] */ /* JADX WARNING: Removed duplicated region for block: B:94:0x02b8 */ /* JADX WARNING: Removed duplicated region for block: B:95:0x02d3 */ public static int H(String str, long j2, Context context, Vector<SyncCallbackListener> vector, String str2, int i10, TianShuAPI.OnProgressListener onProgressListener, boolean z10, boolean z11) throws TianShuException { TianShuException tianShuException; int i11; String str3; String str4; String str5; String str6; FileOutputStream fileOutputStream; Throwable th; String str7; FileOutputStream fileOutputStream2; TianShuException e10; FileNotFoundException e11; String str8; int i12; String str9; String str10; FileOutputStream fileOutputStream3; int i13; int i14; boolean z12; int i15; String str11; String str12; boolean z13; String str13; int i16; String str14; LogUtils.a("SyncUtil", "downloadImageFile syncId=" + str + " id=" + j2 + " isResizeJpg=" + z10); if (z10) { return N(str, j2, context, vector, str2, i10, z11); } int i17 = 0; if (TextUtils.isEmpty(str)) { LogUtils.a("SyncUtil", "downloadImageFile syncId is empty"); i11 = 0; tianShuException = null; } else { String str15 = str + ".jpg"; String[] C1 = DBUtil.C1(context, j2, new String[]{"_data", "image_backup"}); if (C1 == null || C1.length != 2) { str4 = null; str3 = null; } else { str4 = C1[0]; str3 = C1[1]; } if (SDStorageManager.h0(context)) { SDStorageManager.q0(context, SDStorageUtil.c()); LogUtils.a("SyncUtil", "downloadImageFile ExternalStorageFullOrRemoved fileName=" + str15); str4 = null; } if (TextUtils.isEmpty(str4)) { str4 = V(str15); } boolean C = FileUtil.C(str4); if (C) { str5 = V(str + j2 + ".jpg"); str6 = str4; } else { str6 = V(str15); str5 = str6; } try { ContentResolver contentResolver = context.getContentResolver(); if (u1(j2, context)) { i14 = K(str, str5, onProgressListener); i13 = contentResolver; str10 = str6; str8 = str5; str9 = "_data"; i12 = 0; z12 = true; fileOutputStream3 = null; } else { long currentTimeMillis = System.currentTimeMillis(); if (TextUtils.isEmpty(str2)) { FileOutputStream fileOutputStream4 = new FileOutputStream(str5); i13 = contentResolver; str10 = str6; str8 = str5; str9 = "_data"; str13 = str15; i12 = 0; try { int F = F(str, "CamScanner_Page", str15, fileOutputStream4, onProgressListener, -1, null, z11, str8); fileOutputStream2 = fileOutputStream4; i16 = F; } catch (TianShuException e12) { e10 = e12; str7 = str8; fileOutputStream2 = fileOutputStream4; i17 = 0; LogUtils.e("SyncUtil", e10); if (G1(e10.getErrorCode())) { } if (e10.getErrorCode() == 304) { } if (fileOutputStream2 != null) { } if (i17 <= 0) { } int i18 = i17 == 1 ? 1 : 0; boolean z14 = i17 == 1 ? 1 : 0; boolean z15 = i17 == 1 ? 1 : 0; i11 = i18; if (tianShuException != null) { } } catch (FileNotFoundException e13) { e11 = e13; str7 = str8; fileOutputStream2 = fileOutputStream4; i17 = 0; try { LogUtils.e("SyncUtil", e11); i17 = i17; if (fileOutputStream2 != null) { } tianShuException = null; if (i17 <= 0) { } int i182 = i17 == 1 ? 1 : 0; boolean z142 = i17 == 1 ? 1 : 0; boolean z152 = i17 == 1 ? 1 : 0; i11 = i182; if (tianShuException != null) { } } catch (Throwable th2) { fileOutputStream = fileOutputStream2; th = th2; if (fileOutputStream != null) { } throw th; } } catch (Throwable th3) { th = th3; fileOutputStream = fileOutputStream4; if (fileOutputStream != null) { } throw th; } } else { i13 = contentResolver; str10 = str6; str8 = str5; str9 = "_data"; str13 = str15; i12 = 0; fileOutputStream2 = null; i16 = 0; } try { E2(JavascriptBridge.MraidHandler.DOWNLOAD_ACTION, System.currentTimeMillis() - currentTimeMillis, FileUtil.t(str8), i16 > 0); if (i16 > 0) { if (SDStorageManager.h0(context)) { SDStorageManager.q0(context, SDStorageUtil.c()); StringBuilder sb2 = new StringBuilder(); sb2.append("downloadImageFile 2 ExternalStorageFullOrRemoved fileName="); str14 = str13; sb2.append(str14); LogUtils.a("SyncUtil", sb2.toString()); str3 = null; } else { str14 = str13; } if (TextUtils.isEmpty(str3)) { str3 = W(str14); } File file = new File(str3); if (file.exists()) { file.delete(); } } fileOutputStream3 = fileOutputStream2; z12 = false; i14 = i16; } catch (TianShuException e14) { e10 = e14; str7 = str8; i17 = i16; LogUtils.e("SyncUtil", e10); if (G1(e10.getErrorCode())) { } if (e10.getErrorCode() == 304) { } if (fileOutputStream2 != null) { } if (i17 <= 0) { } int i1822 = i17 == 1 ? 1 : 0; boolean z1422 = i17 == 1 ? 1 : 0; boolean z1522 = i17 == 1 ? 1 : 0; i11 = i1822; if (tianShuException != null) { } } catch (FileNotFoundException e15) { e11 = e15; str7 = str8; i17 = i16; LogUtils.e("SyncUtil", e11); i17 = i17; if (fileOutputStream2 != null) { } tianShuException = null; if (i17 <= 0) { } int i18222 = i17 == 1 ? 1 : 0; boolean z14222 = i17 == 1 ? 1 : 0; boolean z15222 = i17 == 1 ? 1 : 0; i11 = i18222; if (tianShuException != null) { } } } try { StringBuilder sb3 = new StringBuilder(); sb3.append("downloadImageFile version ="); int i19 = i14 == true ? 1 : 0; int i20 = i14 == true ? 1 : 0; int i21 = i14 == true ? 1 : 0; sb3.append(i19); LogUtils.a("SyncUtil", sb3.toString()); if (i14 > 0) { if (C) { if (TextUtils.isEmpty(str2)) { str11 = str8; str12 = str10; LogUtils.a("SyncUtil", "downloadImageFile rename=" + FileUtil.K(str11, str12) + " imageFile=" + str12); ContentValues contentValues = new ContentValues(); contentValues.put(str9, str12); contentValues.put("sync_ui_state", Integer.valueOf(i12)); contentValues.put("sync_version", Integer.valueOf(i14)); Uri withAppendedId = ContentUris.withAppendedId(Documents.Image.f28706c, j2); contentValues.put("last_modified", Long.valueOf(C0(context, j2))); contentValues.put("cache_state", Integer.valueOf(i12)); if (!D1(context, j2)) { LogUtils.c("SyncUtil", "downloadImageFile page may be deleted by user when syncing syncId=" + str + " id=" + j2); } else { contentValues.put("sync_state", Integer.valueOf(i12)); } LogUtils.a("SyncUtil", "downloadImageFile uploadNumber:" + i13.update(withAppendedId, contentValues, null, null) + " syncId:" + str); p2(context, j2, -1, false, null); if (v1(j2, context) || z12) { z13 = false; } else { j(context, j2); z13 = true; } if (w1(context, j2)) { l(context, j2, z13); } if (x1(context, j2)) { SignatureUtil.a(str12, SignatureUtil.l(context, j2)); } y(context, str12, j2); if (vector != null) { Iterator<SyncCallbackListener> it = vector.iterator(); i14 = i14; while (it.hasNext()) { SyncCallbackListener next = it.next(); long H0 = DBUtil.H0(context, str); str7 = str11; ContentResolver contentResolver2 = i14 == 1 ? 1 : 0; boolean z16 = i14 == 1 ? 1 : 0; i13 = contentResolver2; next.b(H0, j2, -1, 3, true); i14 = i13; str11 = str7; } } str7 = str11; i15 = i14; } } str11 = str8; str12 = str10; LogUtils.a("SyncUtil", "downloadImageFile filePath=" + str11 + " imageFile=" + str12); ContentValues contentValues2 = new ContentValues(); contentValues2.put(str9, str12); contentValues2.put("sync_ui_state", Integer.valueOf(i12)); contentValues2.put("sync_version", Integer.valueOf(i14)); Uri withAppendedId2 = ContentUris.withAppendedId(Documents.Image.f28706c, j2); contentValues2.put("last_modified", Long.valueOf(C0(context, j2))); contentValues2.put("cache_state", Integer.valueOf(i12)); if (!D1(context, j2)) { } LogUtils.a("SyncUtil", "downloadImageFile uploadNumber:" + i13.update(withAppendedId2, contentValues2, null, null) + " syncId:" + str); p2(context, j2, -1, false, null); if (v1(j2, context)) { } z13 = false; if (w1(context, j2)) { } if (x1(context, j2)) { } y(context, str12, j2); if (vector != null) { } str7 = str11; i15 = i14; } else { str7 = str8; i15 = i14; } i13 = i15 == 1 ? 1 : 0; DBUtil.w4(context, j2, 0); if (fileOutputStream3 != null) { try { fileOutputStream3.close(); } catch (IOException e16) { LogUtils.e("SyncUtil", e16); } } i17 = i13; } catch (TianShuException e17) { e10 = e17; str7 = str8; ContentResolver contentResolver3 = i14; } catch (FileNotFoundException e18) { e11 = e18; str7 = str8; int i22 = i14; fileOutputStream2 = fileOutputStream3; i17 = i22; LogUtils.e("SyncUtil", e11); i17 = i17; if (fileOutputStream2 != null) { } tianShuException = null; if (i17 <= 0) { } int i182222 = i17 == 1 ? 1 : 0; boolean z142222 = i17 == 1 ? 1 : 0; boolean z152222 = i17 == 1 ? 1 : 0; i11 = i182222; if (tianShuException != null) { } } catch (Throwable th4) { } } catch (TianShuException e19) { e10 = e19; str7 = str5; fileOutputStream2 = null; i17 = 0; LogUtils.e("SyncUtil", e10); if (G1(e10.getErrorCode())) { } if (e10.getErrorCode() == 304) { } if (fileOutputStream2 != null) { } if (i17 <= 0) { } int i1822222 = i17 == 1 ? 1 : 0; boolean z1422222 = i17 == 1 ? 1 : 0; boolean z1522222 = i17 == 1 ? 1 : 0; i11 = i1822222; if (tianShuException != null) { } } catch (FileNotFoundException e20) { e11 = e20; str7 = str5; fileOutputStream2 = null; i17 = 0; LogUtils.e("SyncUtil", e11); i17 = i17; if (fileOutputStream2 != null) { } tianShuException = null; if (i17 <= 0) { } int i18222222 = i17 == 1 ? 1 : 0; boolean z14222222 = i17 == 1 ? 1 : 0; boolean z15222222 = i17 == 1 ? 1 : 0; i11 = i18222222; if (tianShuException != null) { } } catch (Throwable th5) { } tianShuException = null; if (i17 <= 0) { StringBuilder sb4 = new StringBuilder(); sb4.append("version="); int i23 = i17 == 1 ? 1 : 0; int i24 = i17 == 1 ? 1 : 0; int i25 = i17 == 1 ? 1 : 0; sb4.append(i23); sb4.append(" FileUtil.deleteOneFile filePath="); sb4.append(str7); LogUtils.a("SyncUtil", sb4.toString()); FileUtil.k(str7); } int i182222222 = i17 == 1 ? 1 : 0; boolean z142222222 = i17 == 1 ? 1 : 0; boolean z152222222 = i17 == 1 ? 1 : 0; i11 = i182222222; } if (tianShuException != null) { return i11; } throw tianShuException; } public static int H0() { AccountAttribute accountAttribute; String G0 = TianShuAPI.G0(); int i10 = 0; if (TextUtils.isEmpty(G0)) { LogUtils.a("SyncUtil", "getServerDocNumber token is empty"); return 0; } String e10 = AESEncUtil.e(ApplicationHelper.i()); HashMap hashMap = new HashMap(); hashMap.put(ClientMetricsEndpointType.TOKEN, G0); hashMap.put("platform", UrlUtil.C()); hashMap.put("cs_ept_d", e10); String str = null; try { str = TianShuAPI.z0("get_init_attribute", hashMap, false, 1); LogUtils.a("SyncUtil", "getServerDocNumber result:" + str); } catch (TianShuException e11) { LogUtils.e("SyncUtil", e11); } if (!(TextUtils.isEmpty(str) || (accountAttribute = (AccountAttribute) GsonUtils.b(str, AccountAttribute.class)) == null || accountAttribute.getAttribute() == null)) { i10 = accountAttribute.getAttribute().getDoc_count(); } return i10; } public static boolean H1() { return AccountPreference.M(); } public static void H2(Context context, ArrayList<Long> arrayList) { I2(context, arrayList, DirSyncFromServer.S().T(context)); } public static int I(String str, long j2, Context context, Vector<SyncCallbackListener> vector, boolean z10, boolean z11) throws TianShuException { return H(str, j2, context, vector, null, -1, null, z10, z11); } public static String I0(Context context) { return AccountPreference.r(); } public static boolean I1() { return "mounted".equals(SDStorageManager.G()); } public static void I2(Context context, ArrayList<Long> arrayList, long j2) { if (arrayList != null) { if (arrayList.size() != 0) { StringBuilder sb2 = new StringBuilder(); Iterator<Long> it = arrayList.iterator(); while (it.hasNext()) { long longValue = it.next().longValue(); if (longValue >= 0) { if (sb2.length() > 0) { sb2.append(PreferencesConstants.COOKIE_DELIMITER + longValue); } else { sb2.append("" + longValue); } } } if (sb2.length() > 0) { ContentResolver contentResolver = context.getContentResolver(); Uri uri = Documents.Document.f28695d; Cursor query = contentResolver.query(uri, new String[]{"sync_dir_id"}, "_id in " + ("(" + sb2.toString() + ")"), null, null); if (query != null) { ArrayList arrayList2 = new ArrayList(); while (query.moveToNext()) { String string = query.getString(0); if (!TextUtils.isEmpty(string)) { arrayList2.add(string); } } query.close(); G2(context, arrayList2, j2); } } return; } } LogUtils.a("SyncUtil", "updateDirSyncStatByDocId dirSynds is empty"); } public static Future<Boolean> J(Context context, long j2, SyncApi.SyncProgress syncProgress, Vector<SyncCallbackListener> vector, String str, boolean z10, boolean z11, Vector<Long> vector2) { boolean[] zArr = {true}; SyncState syncState = new SyncState(); List<DownloadImageInfo> w02 = w0(context, j2, s0(context, j2), zArr); if (syncProgress != null) { syncState.l(10.0f); syncProgress.a(syncState); } int size = w02.size(); float f10 = 90.0f / ((float) size); ExecutorService t02 = t0(TextUtils.isEmpty(str)); boolean[] zArr2 = {false}; ArrayList arrayList = new ArrayList(); Semaphore semaphore = new Semaphore(CustomExecutor.f39988a); int i10 = 0; while (true) { if (i10 >= size) { break; } DownloadImageInfo downloadImageInfo = w02.get(i10); LogUtils.a("SyncUtil", "downloadImageFromServer docId = " + j2 + " syncId = " + downloadImageInfo.f35058c); if (SyncThread.f34994t) { zArr[0] = false; break; } else if (zArr2[0]) { zArr[0] = false; LogUtils.a("SyncUtil", "pwd change"); break; } else { DownloadImageFileCallable downloadImageFileCallable = new DownloadImageFileCallable(z11); downloadImageFileCallable.f35048e = N0(); downloadImageFileCallable.f35044a = context; downloadImageFileCallable.f35046c = downloadImageInfo; downloadImageFileCallable.f35049f = z10; downloadImageFileCallable.f35050g = f10; downloadImageFileCallable.f35053j = zArr2; downloadImageFileCallable.f35052i = syncState; downloadImageFileCallable.f35051h = syncProgress; downloadImageFileCallable.f35045b = str; downloadImageFileCallable.f35047d = vector; downloadImageFileCallable.f35054k = semaphore; arrayList.add(t02.submit(downloadImageFileCallable)); i10++; w02 = w02; zArr2 = zArr2; } } return CustomExecutor.k().submit(new b0(arrayList, zArr, syncProgress, syncState, j2, context, vector2)); } public static long J0(Context context) { return SyncAccountUtil.a(context); } private static Pair<Boolean, String> J1(String[] strArr) { if (strArr != null) { if (strArr.length > 0) { String str = strArr[0]; if (strArr.length == 1) { return Pair.create(Boolean.TRUE, str); } for (int i10 = 1; i10 < strArr.length; i10++) { if (str == null) { if (strArr[i10] != null) { return Pair.create(Boolean.FALSE, null); } } else if (!str.equals(strArr[i10])) { return Pair.create(Boolean.FALSE, null); } } return Pair.create(Boolean.TRUE, str); } } return Pair.create(Boolean.TRUE, null); } /* JADX INFO: finally extract failed */ public static synchronized boolean J2(Context context, ArrayList<String> arrayList, int i10, String str, int i11) { boolean z10; synchronized (SyncUtil.class) { try { int v22 = v2(arrayList, i10, str, i11); z10 = false; if (v22 > 0 && arrayList != null && arrayList.size() > 0) { StringBuilder sb2 = new StringBuilder(); for (int i12 = 0; i12 < v22; i12++) { if (sb2.length() > 0) { sb2.append(",'" + arrayList.get(i12) + "'"); } else { sb2.append("'" + arrayList.get(i12) + "'"); } } if (sb2.length() > 0) { ContentValues contentValues = new ContentValues(); contentValues.put("permission", Integer.valueOf(i10)); LogUtils.a("SyncUtil", "update doc num:" + context.getContentResolver().update(Documents.Document.f28696e, contentValues, "sync_doc_id in " + ("(" + sb2.toString() + ")"), null)); o2(context); z10 = true; } } } catch (Throwable th) { throw th; } } return z10; } public static int K(String str, String str2, TianShuAPI.OnProgressListener onProgressListener) { try { FileOutputStream fileOutputStream = new FileOutputStream(str2); return F(str, "CamScanner_Page", str + ".jpg", fileOutputStream, onProgressListener, -1, "rendered", false, str2); } catch (Exception e10) { LogUtils.e("SyncUtil", e10); File file = new File(str2); if (file.exists()) { file.delete(); } return -1; } } public static String K0(Context context) { return PreferenceManager.getDefaultSharedPreferences(context).getString("Password", null); } public static boolean K1(UserInfo userInfo) { UserInfo.Feature feature; return (userInfo == null || (feature = userInfo.getFeature("CamScanner")) == null || !"Professional".equals(feature.getFeature())) ? false : true; } public static synchronized void K2(Context context, long j2, int i10, boolean z10) { synchronized (SyncUtil.class) { try { L2(context, j2, i10, z10, true); } finally { } } } public static int L(String str, long j2, String str2) { return M(str, j2, str2, null); } public static String L0(Context context) { long J0 = J0(context); String str = null; if (J0 > 0) { Cursor query = context.getContentResolver().query(Documents.SyncAccount.f28723a, new String[]{"account_sns_token"}, "_id =" + J0, null, null); if (query != null) { if (query.moveToFirst()) { str = query.getString(0); } query.close(); } } return str; } public static boolean L1() { return AppUtil.S() && AppSwitch.n(); } public static synchronized void L2(Context context, long j2, int i10, boolean z10, boolean z11) { synchronized (SyncUtil.class) { if (context == null || j2 < 1) { LogUtils.c("SyncUtil", "updateDocSyncStat invalid para id = " + j2); return; } ContentResolver contentResolver = context.getContentResolver(); Uri withAppendedId = ContentUris.withAppendedId(Documents.Document.f28695d, j2); ContentValues contentValues = new ContentValues(); if (z10) { Cursor query = contentResolver.query(withAppendedId, new String[]{"sync_state", "sync_extra_state", "modified", "sync_doc_id", "_data"}, null, null, null); if (query != null) { if (query.moveToFirst()) { int i11 = query.getInt(0); int i12 = query.getInt(1); if (i10 == 2) { Uri uri = Documents.Mtag.f28713a; contentResolver.delete(uri, "document_id = " + j2, null); FileUtil.k(query.getString(4)); T2(context, j2, i10); } LogUtils.a("SyncUtil", "updateDocSyncStat id:" + j2 + "localState:" + i11 + " state:" + i10 + "localExState:" + i12); if (i11 != 1 || i10 != 2 || i12 == 1) { if (i12 == 1) { contentValues.put("sync_extra_state", (Integer) 2); } contentValues.put("modified", Long.valueOf(query.getLong(2))); if ((i11 == 3 && i10 == 2) || ((i11 == -1 && i10 == 0) || ((i11 == 0 && (i10 == 2 || i10 == 3)) || ((i12 == 1 && i11 == 1 && i10 == 2) || i11 == 7)))) { contentValues.put("sync_state", Integer.valueOf(i10)); LogUtils.a("SyncUtil", "updateDocSyncStat succes id:" + j2 + "localState:" + i11 + " state:" + i10 + "localExState:" + i12); } if (i10 == 2) { contentValues.put(d.f45658t, (Integer) 0); contentResolver.update(withAppendedId, contentValues, null, null); LogUtils.a("SyncUtil", "updateDocSyncStat delete one doc locally sync doc id=" + query.getString(3)); } else { contentResolver.update(withAppendedId, contentValues, null, null); } } else if (i1(context, j2)) { B(context, j2); contentResolver.delete(withAppendedId, null, null); Uri uri2 = Documents.Image.f28704a; contentResolver.delete(uri2, "document_id = " + j2, null); } else { contentValues.put("sync_state", (Integer) 2); contentValues.put(d.f45658t, (Integer) 0); contentResolver.update(withAppendedId, contentValues, null, null); } } query.close(); if (z11) { o2(context); } } } else if (i10 == -1) { contentValues.put("modified", Long.valueOf(i0(context, j2))); contentValues.put("sync_extra_state", (Integer) 1); contentResolver.update(withAppendedId, contentValues, null, null); } else if (i10 != -2) { Cursor query2 = contentResolver.query(withAppendedId, new String[]{"sync_extra_state", "sync_state", "modified"}, null, null, null); if (query2 != null) { if (query2.moveToFirst()) { int i13 = query2.getInt(0); int i14 = query2.getInt(1); LogUtils.a("SyncUtil", "updateDocSyncStat server localExState:" + i13 + " localSyncState:" + i14 + " state=" + i10 + " docId=" + j2); if (!(i14 == 2 || i14 == 5 || i13 == 2)) { contentValues.put("sync_state", Integer.valueOf(i10)); } contentValues.put("sync_extra_state", (Integer) 0); contentValues.put("modified", Long.valueOf(query2.getLong(2))); contentResolver.update(withAppendedId, contentValues, null, null); } query2.close(); } } } } public static int M(String str, long j2, String str2, TianShuAPI.OnProgressListener onProgressListener) { int i10; try { FileUtil.k(str2); i10 = F(str, "CamScanner_Page", str + ".jpg", new FileOutputStream(str2), onProgressListener, -1, "ori", false, str2); if (i10 == 0 && FileUtil.G(str2)) { i10 = 100; } if (i10 <= 0) { FileUtil.k(str2); return i10; } } catch (Exception e10) { LogUtils.e("SyncUtil", e10); i10 = -1; FileUtil.k(str2); } return i10; } public static String M0(Context context) { long J0 = J0(context); String str = null; if (J0 > 0) { Cursor query = context.getContentResolver().query(Documents.SyncAccount.f28723a, new String[]{"account_type"}, "_id =" + J0, null, null); if (query != null) { if (query.moveToFirst()) { str = query.getString(0); } query.close(); } } return str; } public static boolean M1(Context context) { boolean z10 = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("keysetspecialaccount", false); if (!z10) { z10 = AccountPreference.D(); } return z10; } public static synchronized void M2(Context context, ArrayList<Long> arrayList, int i10) { Iterator<Long> it; synchronized (SyncUtil.class) { if (arrayList != null) { if (arrayList.size() > 0) { ContentResolver contentResolver = context.getContentResolver(); ArrayList arrayList2 = new ArrayList(); Iterator<Long> it2 = arrayList.iterator(); while (it2.hasNext()) { long longValue = it2.next().longValue(); if (longValue > 0) { Uri withAppendedId = ContentUris.withAppendedId(Documents.Document.f28695d, longValue); Cursor query = contentResolver.query(withAppendedId, new String[]{"sync_state", "sync_extra_state", "modified", "sync_doc_id"}, null, null, null); if (query != null) { if (query.moveToFirst()) { int i11 = query.getInt(0); int i12 = query.getInt(1); if (i10 == 2) { ContentProviderOperation.Builder newDelete = ContentProviderOperation.newDelete(Documents.Mtag.f28713a); StringBuilder sb2 = new StringBuilder(); sb2.append(longValue); it = it2; sb2.append(""); newDelete.withSelection("document_id =? ", new String[]{sb2.toString()}); arrayList2.add(newDelete.build()); T2(context, longValue, i10); } else { it = it2; } LogUtils.a("SyncUtil", "localState=" + i11 + " state=" + i10 + " localExState=" + i12 + " id=" + longValue); if (i11 != 1 || i10 != 2 || i12 == 1) { ContentProviderOperation.Builder newUpdate = ContentProviderOperation.newUpdate(withAppendedId); newUpdate.withValue("modified", Long.valueOf(query.getLong(2))); if (i12 == 1) { newUpdate.withValue("sync_extra_state", 2); } if ((i11 == 3 && i10 == 2) || ((i11 == -1 && i10 == 0) || ((i11 == 0 && (i10 == 2 || i10 == 3)) || ((i12 == 1 && i11 == 1 && i10 == 2) || i11 == 7)))) { newUpdate.withValue("sync_state", Integer.valueOf(i10)); LogUtils.a("SyncUtil", "updateDocSyncStat list succes id:" + longValue + "localState:" + i11 + " state:" + i10 + "localExState:" + i12); } if (i10 == 2) { newUpdate.withValue(d.f45658t, 0); LogUtils.a("SyncUtil", "updateDocSyncStat delete multi docs locally sync doc id=" + query.getString(3)); } arrayList2.add(newUpdate.build()); } else if (i1(context, longValue)) { B(context, longValue); arrayList2.add(ContentProviderOperation.newDelete(withAppendedId).build()); ContentProviderOperation.Builder newDelete2 = ContentProviderOperation.newDelete(Documents.Image.f28704a); newDelete2.withSelection("document_id =? ", new String[]{longValue + ""}); arrayList2.add(newDelete2.build()); } else { ContentProviderOperation.Builder newUpdate2 = ContentProviderOperation.newUpdate(withAppendedId); newUpdate2.withValue("sync_state", 2); newUpdate2.withValue(d.f45658t, 0); arrayList2.add(newUpdate2.build()); } } else { it = it2; } query.close(); it2 = it; } } it = it2; it2 = it; } if (arrayList2.size() > 0) { ArrayList<ContentProviderOperation> b02 = DBUtil.b0(context, arrayList2); if (b02.size() > 0) { try { contentResolver.applyBatch(Documents.f28683a, b02); } catch (Exception e10) { LogUtils.e("SyncUtil", e10); } } o2(context); } } } } } /* JADX DEBUG: Failed to insert an additional move for type inference into block B:31:0x0161 */ /* JADX DEBUG: Failed to insert an additional move for type inference into block B:158:0x03f2 */ /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Type inference failed for: r41v0, types: [boolean] */ /* JADX WARN: Type inference failed for: r19v2 */ /* JADX WARN: Type inference failed for: r4v10 */ /* JADX WARN: Type inference failed for: r19v15 */ /* JADX WARN: Type inference failed for: r8v31, types: [boolean] */ /* JADX WARN: Type inference failed for: r4v29, types: [java.lang.StringBuilder] */ /* JADX WARN: Type inference failed for: r8v33 */ /* JADX WARN: Type inference failed for: r8v36 */ /* JADX WARN: Type inference failed for: r41v3 */ /* JADX WARN: Type inference failed for: r41v4 */ /* JADX WARN: Type inference failed for: r19v54 */ /* JADX WARN: Type inference failed for: r41v5 */ /* JADX WARNING: Code restructure failed: missing block: B:164:0x040a, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:165:0x040b, code lost: r19 = null; */ /* JADX WARNING: Code restructure failed: missing block: B:167:0x0412, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:168:0x0413, code lost: r19 = null; */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Removed duplicated region for block: B:107:0x02e1 A[SYNTHETIC, Splitter:B:107:0x02e1] */ /* JADX WARNING: Removed duplicated region for block: B:128:0x0336 */ /* JADX WARNING: Removed duplicated region for block: B:129:0x033c */ /* JADX WARNING: Removed duplicated region for block: B:135:0x0365 */ /* JADX WARNING: Removed duplicated region for block: B:140:0x03b5 A[SYNTHETIC, Splitter:B:140:0x03b5] */ /* JADX WARNING: Removed duplicated region for block: B:177:0x042b A[SYNTHETIC, Splitter:B:177:0x042b] */ /* JADX WARNING: Removed duplicated region for block: B:203:0x0477 A[SYNTHETIC, Splitter:B:203:0x0477] */ /* JADX WARNING: Removed duplicated region for block: B:217:0x04a0 A[Catch:{ all -> 0x04e2 }] */ /* JADX WARNING: Removed duplicated region for block: B:220:0x04b0 */ /* JADX WARNING: Removed duplicated region for block: B:222:0x04b4 A[SYNTHETIC, Splitter:B:222:0x04b4] */ /* JADX WARNING: Removed duplicated region for block: B:227:0x04bf */ /* JADX WARNING: Removed duplicated region for block: B:230:0x04e1 */ /* JADX WARNING: Removed duplicated region for block: B:234:0x04e8 A[SYNTHETIC, Splitter:B:234:0x04e8] */ /* JADX WARNING: Unknown variable types count: 1 */ public static int N(String str, long j2, Context context, Vector<SyncCallbackListener> vector, String str2, int i10, boolean z10) throws TianShuException { String str3; String str4; int i11; int i12; String str5; String str6; String str7; FileOutputStream fileOutputStream; Throwable th; Throwable th2; String str8; TianShuException tianShuException; Object obj; Object obj2; Object obj3; Object obj4; int i13; IOException iOException; Object obj5; int i14; FileNotFoundException e10; Object obj6; int i15; String str9; Integer num; String str10; ContentResolver contentResolver; String str11; String str12; int i16; int[] iArr; int i17; int i18; boolean z11; Object obj7; int i19; TianShuException e11; Object obj8; int i20; Object obj9; int i21; int i22; String str13; Object obj10; TianShuException e12; Object obj11; Integer num2; Object obj12; Object obj13; Exception e13; int i23; String str14; ?? r82; int i24; int i25; String str15; LogUtils.a("SyncUtil", "downloadResizeImageFile syncId=" + str + " id=" + j2 + " coToken=" + str2 + " revision=" + i10); int i26 = 0; if (TextUtils.isEmpty(str)) { LogUtils.a("SyncUtil", "downloadResizeImageFile syncId is empty"); } else { long currentTimeMillis = System.currentTimeMillis(); String str16 = str + ".jpg"; int i27 = -1; FileOutputStream fileOutputStream2 = null; Cursor query = context.getContentResolver().query(ContentUris.withAppendedId(Documents.Image.f28704a, j2), new String[]{"thumb_data", "_data", "image_backup", "sync_version", "sync_state", "sync_ui_state"}, null, null, null); if (query != null) { if (query.moveToFirst()) { String string = query.getString(0); String string2 = query.getString(1); str4 = query.getString(2); int i28 = query.getInt(3); i12 = query.getInt(4); i11 = query.getInt(5); str5 = string; i27 = i28; str15 = string2; } else { str5 = null; i12 = 0; i11 = 0; str4 = null; str15 = null; } query.close(); str3 = str15; } else { str5 = null; i12 = 0; i11 = 0; str4 = null; str3 = null; } if (i27 <= 0 || i12 != 0 || i11 != 0 || !FileUtil.C(str5)) { if (SDStorageManager.h0(context)) { SDStorageManager.q0(context, SDStorageUtil.c()); LogUtils.a("SyncUtil", "downloadResizeImageFile ExternalStorageFullOrRemoved fileName=" + str16); str5 = null; } if (TextUtils.isEmpty(str5)) { str5 = Y(str16); } boolean C = FileUtil.C(str5); if (C) { str6 = Y(str + j2 + ".jpg"); str7 = str5; } else { str7 = Y(str16); str6 = str7; } try { ContentResolver contentResolver2 = context.getContentResolver(); if (TextUtils.isEmpty(str2)) { try { FileOutputStream fileOutputStream3 = new FileOutputStream(str6); try { fileOutputStream2 = fileOutputStream3; contentResolver = contentResolver2; str10 = str7; str12 = str16; num = 0; z10 = str6; str11 = ".jpg"; i16 = 0; try { iArr = O(str, "CamScanner_Page", str16, BitmapUtils.y(), fileOutputStream2, null, z10, str6); str9 = z10; } catch (TianShuException e14) { str8 = z10; tianShuException = e14; i15 = 0; obj = null; i26 = i15; try { LogUtils.e("SyncUtil", tianShuException); if (tianShuException.getErrorCode() == 304) { } if (!G1(tianShuException.getErrorCode())) { } if (fileOutputStream2 != null) { } if (i26 <= 0) { } if (tianShuException != null) { } return i26; } catch (Throwable th3) { th2 = th3; th = th2; fileOutputStream = fileOutputStream2; if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (IOException e15) { LogUtils.e("SyncUtil", e15); } } throw th; } } catch (FileNotFoundException e16) { e10 = e16; str8 = z10; fileOutputStream = fileOutputStream2; i25 = 0; obj5 = null; i14 = i25; try { LogUtils.e("SyncUtil", e10); i26 = i14; obj3 = obj5; if (fileOutputStream != null) { } tianShuException = obj3; if (i26 <= 0) { } if (tianShuException != null) { } return i26; } catch (Throwable th4) { th = th4; if (fileOutputStream != null) { } throw th; } } } catch (TianShuException e17) { fileOutputStream2 = fileOutputStream3; tianShuException = e17; str8 = str6; i15 = 0; obj = null; i26 = i15; LogUtils.e("SyncUtil", tianShuException); if (tianShuException.getErrorCode() == 304) { } if (!G1(tianShuException.getErrorCode())) { } if (fileOutputStream2 != null) { } if (i26 <= 0) { } if (tianShuException != null) { } return i26; } catch (FileNotFoundException e18) { e10 = e18; fileOutputStream2 = fileOutputStream3; str8 = str6; fileOutputStream = fileOutputStream2; i25 = 0; obj5 = null; i14 = i25; LogUtils.e("SyncUtil", e10); i26 = i14; obj3 = obj5; if (fileOutputStream != null) { } tianShuException = obj3; if (i26 <= 0) { } if (tianShuException != null) { } return i26; } catch (Throwable th5) { th2 = th5; fileOutputStream2 = fileOutputStream3; th = th2; fileOutputStream = fileOutputStream2; if (fileOutputStream != null) { } throw th; } } catch (TianShuException e19) { tianShuException = e19; str8 = str6; i26 = 0; obj = null; fileOutputStream2 = null; LogUtils.e("SyncUtil", tianShuException); if (tianShuException.getErrorCode() == 304) { } if (!G1(tianShuException.getErrorCode())) { } if (fileOutputStream2 != null) { } if (i26 <= 0) { } if (tianShuException != null) { } return i26; } catch (FileNotFoundException e20) { e10 = e20; str8 = str6; fileOutputStream = null; i25 = 0; obj5 = null; i14 = i25; LogUtils.e("SyncUtil", e10); i26 = i14; obj3 = obj5; if (fileOutputStream != null) { } tianShuException = obj3; if (i26 <= 0) { } if (tianShuException != null) { } return i26; } catch (Throwable th6) { th = th6; fileOutputStream = null; if (fileOutputStream != null) { } throw th; } } else { contentResolver = contentResolver2; str10 = str7; str12 = str16; str11 = ".jpg"; num = 0; str9 = str6; i16 = 0; iArr = null; fileOutputStream2 = null; } if (iArr == null || iArr.length != 2) { i18 = 1; try { LogUtils.a("SyncUtil", "downloadResizeImageFile ERROR"); z11 = false; i17 = 0; } catch (TianShuException e21) { str8 = str9; obj2 = null; tianShuException = e21; i26 = 0; obj = obj2; LogUtils.e("SyncUtil", tianShuException); if (tianShuException.getErrorCode() == 304) { } if (!G1(tianShuException.getErrorCode())) { } if (fileOutputStream2 != null) { } if (i26 <= 0) { } if (tianShuException != null) { } return i26; } catch (FileNotFoundException e22) { e10 = e22; str8 = str9; obj6 = null; fileOutputStream = fileOutputStream2; i14 = 0; obj5 = obj6; LogUtils.e("SyncUtil", e10); i26 = i14; obj3 = obj5; if (fileOutputStream != null) { } tianShuException = obj3; if (i26 <= 0) { } if (tianShuException != null) { } return i26; } } else { int i29 = iArr[i16]; i18 = 1; try { z11 = iArr[1] == 601; LogUtils.a("SyncUtil", "downloadResizeImageFile version=" + i29 + " results[1]=" + iArr[1]); i17 = i29; } catch (TianShuException e23) { e = e23; str8 = str9; i24 = i29; tianShuException = e; i15 = i24; obj = null; i26 = i15; LogUtils.e("SyncUtil", tianShuException); if (tianShuException.getErrorCode() == 304) { } if (!G1(tianShuException.getErrorCode())) { } if (fileOutputStream2 != null) { } if (i26 <= 0) { } if (tianShuException != null) { } return i26; } catch (FileNotFoundException e24) { e10 = e24; str8 = str9; i23 = i29; fileOutputStream = fileOutputStream2; i25 = i23; obj5 = null; i14 = i25; LogUtils.e("SyncUtil", e10); i26 = i14; obj3 = obj5; if (fileOutputStream != null) { } tianShuException = obj3; if (i26 <= 0) { } if (tianShuException != null) { } return i26; } } try { SyncTimeCount.f38937i0.b().k(System.currentTimeMillis() - currentTimeMillis); if (i17 > 0) { long currentTimeMillis2 = System.currentTimeMillis(); if (D1(context, j2)) { LogUtils.c("SyncUtil", "downloadImageFile page may be deleted by user when syncing syncId=" + str + " id=" + j2); str8 = str9; str3 = null; i17 = i17; } else { if (!C || !TextUtils.isEmpty(str2)) { str8 = str9; str13 = str10; try { LogUtils.a("SyncUtil", "downloadResizeImageFile filePath=" + str8 + " imageFile=" + str13); if (i17 < i10) { i22 = 0; ContentValues contentValues = new ContentValues(); if (!z11) { try { boolean isEmpty = TextUtils.isEmpty(str3); String str17 = str3; if (isEmpty) { str17 = V(str12); } boolean C2 = FileUtil.C(str17); if (C2) { str14 = V(str + j2 + str11); } else { str14 = str17; } if (FileUtil.h(str13, str14)) { if (!C2) { contentValues.put("_data", str14); } else if (FileUtil.K(str14, str17)) { contentValues.put("_data", str17); } else { LogUtils.a("SyncUtil", "downloadResizeImageFile rename FAILED"); } r82 = 1; if (r82 == 0) { num2 = num; contentValues.put("cache_state", num2); } else { num2 = num; contentValues.put("cache_state", Integer.valueOf(i18)); } LogUtils.a("SyncUtil", "downloadResizeImageFile download not resize jpg, set cache state to normal successAddImageData=" + r82); i17 = r82; str3 = str17; } else { LogUtils.a("SyncUtil", "downloadResizeImageFile COPY FAILED"); } r82 = 0; if (r82 == 0) { } LogUtils.a("SyncUtil", "downloadResizeImageFile download not resize jpg, set cache state to normal successAddImageData=" + r82); i17 = r82; str3 = str17; } catch (TianShuException e25) { tianShuException = e25; i15 = i22; obj = null; i26 = i15; LogUtils.e("SyncUtil", tianShuException); if (tianShuException.getErrorCode() == 304) { } if (!G1(tianShuException.getErrorCode())) { } if (fileOutputStream2 != null) { } if (i26 <= 0) { } if (tianShuException != null) { } return i26; } catch (FileNotFoundException e26) { e10 = e26; i23 = i22; fileOutputStream = fileOutputStream2; i25 = i23; obj5 = null; i14 = i25; LogUtils.e("SyncUtil", e10); i26 = i14; obj3 = obj5; if (fileOutputStream != null) { } tianShuException = obj3; if (i26 <= 0) { } if (tianShuException != null) { } return i26; } } else { num2 = num; FileUtil.k(str3); FileUtil.k(str4); contentValues.put("cache_state", Integer.valueOf(i18)); i17 = i17; str3 = str3; } contentValues.put("thumb_data", str13); contentValues.put("sync_ui_state", num2); contentValues.put("sync_version", Integer.valueOf(i22)); Uri withAppendedId = ContentUris.withAppendedId(Documents.Image.f28706c, j2); contentValues.put("last_modified", Long.valueOf(C0(context, j2))); contentValues.put("sync_state", num2); String str18 = null; contentResolver.update(withAppendedId, contentValues, null, null); p2(context, j2, -1, false, null); if (vector != null) { try { Iterator<SyncCallbackListener> it = vector.iterator(); while (it.hasNext()) { String str19 = str18; try { it.next().b(DBUtil.H0(context, str), j2, -1, 3, true); str18 = str19; } catch (Exception e27) { e13 = e27; obj13 = str19; try { LogUtils.e("SyncUtil", e13); obj12 = obj13; i17 = i22; str3 = obj12; SyncTimeCount.f38937i0.b().p(System.currentTimeMillis() - currentTimeMillis2); i21 = i17; obj9 = str3; DBUtil.w4(context, j2, i16); i26 = i21; obj3 = obj9; if (fileOutputStream2 != null) { } } catch (TianShuException e28) { e12 = e28; obj10 = obj13; } catch (FileNotFoundException e29) { e10 = e29; obj11 = obj13; i20 = i22; obj8 = obj11; fileOutputStream = fileOutputStream2; i14 = i20; obj5 = obj8; LogUtils.e("SyncUtil", e10); i26 = i14; obj3 = obj5; if (fileOutputStream != null) { } tianShuException = obj3; if (i26 <= 0) { } if (tianShuException != null) { } return i26; } tianShuException = obj3; if (i26 <= 0) { } if (tianShuException != null) { } return i26; } } } catch (Exception e30) { e13 = e30; obj13 = null; LogUtils.e("SyncUtil", e13); obj12 = obj13; i17 = i22; str3 = obj12; SyncTimeCount.f38937i0.b().p(System.currentTimeMillis() - currentTimeMillis2); i21 = i17; obj9 = str3; DBUtil.w4(context, j2, i16); i26 = i21; obj3 = obj9; if (fileOutputStream2 != null) { } tianShuException = obj3; if (i26 <= 0) { } if (tianShuException != null) { } return i26; } } obj12 = str18; i17 = i22; str3 = obj12; } } catch (TianShuException e31) { e11 = e31; obj7 = null; i19 = i17; tianShuException = e11; i26 = i19; obj = obj7; LogUtils.e("SyncUtil", tianShuException); if (tianShuException.getErrorCode() == 304) { } if (!G1(tianShuException.getErrorCode())) { } if (fileOutputStream2 != null) { } if (i26 <= 0) { } if (tianShuException != null) { } return i26; } catch (FileNotFoundException e32) { e10 = e32; obj8 = null; i20 = i17; fileOutputStream = fileOutputStream2; i14 = i20; obj5 = obj8; LogUtils.e("SyncUtil", e10); i26 = i14; obj3 = obj5; if (fileOutputStream != null) { } tianShuException = obj3; if (i26 <= 0) { } if (tianShuException != null) { } return i26; } } else { str8 = str9; str13 = str10; try { LogUtils.a("SyncUtil", "downloadResizeImageFile rename=" + FileUtil.K(str8, str13) + " imageFile=" + str13); } catch (TianShuException e33) { e = e33; i24 = i17; } catch (FileNotFoundException e34) { e10 = e34; i23 = i17; fileOutputStream = fileOutputStream2; i25 = i23; obj5 = null; i14 = i25; LogUtils.e("SyncUtil", e10); i26 = i14; obj3 = obj5; if (fileOutputStream != null) { } tianShuException = obj3; if (i26 <= 0) { } if (tianShuException != null) { } return i26; } } i22 = i17; try { ContentValues contentValues2 = new ContentValues(); if (!z11) { } contentValues2.put("thumb_data", str13); contentValues2.put("sync_ui_state", num2); contentValues2.put("sync_version", Integer.valueOf(i22)); Uri withAppendedId2 = ContentUris.withAppendedId(Documents.Image.f28706c, j2); contentValues2.put("last_modified", Long.valueOf(C0(context, j2))); contentValues2.put("sync_state", num2); String str182 = null; } catch (TianShuException e35) { e11 = e35; i19 = i17; obj7 = str3; tianShuException = e11; i26 = i19; obj = obj7; LogUtils.e("SyncUtil", tianShuException); if (tianShuException.getErrorCode() == 304) { } if (!G1(tianShuException.getErrorCode())) { } if (fileOutputStream2 != null) { } if (i26 <= 0) { } if (tianShuException != null) { } return i26; } catch (FileNotFoundException e36) { e10 = e36; i20 = i17; obj8 = str3; fileOutputStream = fileOutputStream2; i14 = i20; obj5 = obj8; LogUtils.e("SyncUtil", e10); i26 = i14; obj3 = obj5; if (fileOutputStream != null) { } tianShuException = obj3; if (i26 <= 0) { } if (tianShuException != null) { } return i26; } try { contentResolver.update(withAppendedId2, contentValues2, null, null); p2(context, j2, -1, false, null); if (vector != null) { } obj12 = str182; i17 = i22; str3 = obj12; } catch (TianShuException e37) { e12 = e37; obj10 = null; tianShuException = e12; i26 = i22; obj = obj10; LogUtils.e("SyncUtil", tianShuException); if (tianShuException.getErrorCode() == 304) { } if (!G1(tianShuException.getErrorCode())) { } if (fileOutputStream2 != null) { } if (i26 <= 0) { } if (tianShuException != null) { } return i26; } catch (FileNotFoundException e38) { e10 = e38; obj11 = null; i20 = i22; obj8 = obj11; fileOutputStream = fileOutputStream2; i14 = i20; obj5 = obj8; LogUtils.e("SyncUtil", e10); i26 = i14; obj3 = obj5; if (fileOutputStream != null) { } tianShuException = obj3; if (i26 <= 0) { } if (tianShuException != null) { } return i26; } } SyncTimeCount.f38937i0.b().p(System.currentTimeMillis() - currentTimeMillis2); i21 = i17; obj9 = str3; } else { str8 = str9; obj9 = null; i21 = i17; } DBUtil.w4(context, j2, i16); i26 = i21; obj3 = obj9; if (fileOutputStream2 != null) { try { fileOutputStream2.close(); i26 = i21; obj3 = obj9; } catch (IOException e39) { iOException = e39; i13 = i21; obj4 = obj9; } } } catch (TianShuException e40) { e11 = e40; str8 = str9; obj7 = null; i19 = i17; tianShuException = e11; i26 = i19; obj = obj7; LogUtils.e("SyncUtil", tianShuException); if (tianShuException.getErrorCode() == 304) { } if (!G1(tianShuException.getErrorCode())) { } if (fileOutputStream2 != null) { } if (i26 <= 0) { } if (tianShuException != null) { } return i26; } catch (FileNotFoundException e41) { e10 = e41; str8 = str9; obj8 = null; i20 = i17; fileOutputStream = fileOutputStream2; i14 = i20; obj5 = obj8; LogUtils.e("SyncUtil", e10); i26 = i14; obj3 = obj5; if (fileOutputStream != null) { } tianShuException = obj3; if (i26 <= 0) { } if (tianShuException != null) { } return i26; } } catch (TianShuException e42) { str8 = str6; obj2 = null; tianShuException = e42; fileOutputStream2 = null; i26 = 0; obj = obj2; LogUtils.e("SyncUtil", tianShuException); if (tianShuException.getErrorCode() == 304) { DBUtil.w4(context, j2, 1); } if (!G1(tianShuException.getErrorCode())) { tianShuException = obj; } if (fileOutputStream2 != null) { try { fileOutputStream2.close(); } catch (IOException e43) { LogUtils.e("SyncUtil", e43); } } if (i26 <= 0) { } if (tianShuException != null) { } return i26; } catch (FileNotFoundException e44) { e10 = e44; str8 = str6; obj6 = null; fileOutputStream = null; i14 = 0; obj5 = obj6; LogUtils.e("SyncUtil", e10); i26 = i14; obj3 = obj5; if (fileOutputStream != null) { try { fileOutputStream.close(); i26 = i14; obj3 = obj5; } catch (IOException e45) { iOException = e45; i13 = i14; obj4 = obj5; } } tianShuException = obj3; if (i26 <= 0) { } if (tianShuException != null) { } return i26; } catch (Throwable th7) { th = th7; fileOutputStream = null; if (fileOutputStream != null) { } throw th; } tianShuException = obj3; if (i26 <= 0) { FileUtil.k(str8); StringBuilder sb2 = new StringBuilder(); sb2.append("downloadResizeImageFile FileUtil.deleteOneFile version="); int i30 = i26 == 1 ? 1 : 0; int i31 = i26 == 1 ? 1 : 0; int i32 = i26 == 1 ? 1 : 0; int i33 = i26 == 1 ? 1 : 0; int i34 = i26 == 1 ? 1 : 0; int i35 = i26 == 1 ? 1 : 0; int i36 = i26 == 1 ? 1 : 0; int i37 = i26 == 1 ? 1 : 0; sb2.append(i30); sb2.append(" filePath="); sb2.append(str8); LogUtils.a("SyncUtil", sb2.toString()); } if (tianShuException != null) { throw tianShuException; } } else { LogUtils.a("SyncUtil", "jpgVersion=" + i27 + " imageThumb=" + str5); return i27; } } return i26; LogUtils.e("SyncUtil", iOException); i26 = i13; obj3 = obj4; tianShuException = obj3; if (i26 <= 0) { } if (tianShuException != null) { } return i26; } public static String N0() { return PreferenceHelper.x5(); } public static boolean N1(Context context) { return AccountPreference.O(); } private static void N2(Context context, long j2, String str, String str2) { boolean z10; if (InkUtils.g(InkUtils.j(context, j2), str2, str)) { z10 = true; x(context, str); } else { z10 = false; } if (!z10) { FileUtil.h(str2, str); x(context, str); } } public static int[] O(String str, String str2, String str3, int i10, OutputStream outputStream, TianShuAPI.OnProgressListener onProgressListener, boolean z10, String str4) throws TianShuException { int[] iArr = {0}; ShareDirDBData p10 = ShareDirDao.p(ApplicationHelper.f39908b, str); int[] W = (TextUtils.isEmpty(p10.a()) || p10.b() != 1) ? TianShuAPI.W(str2, str3, i10, outputStream, onProgressListener, z10, iArr, p10.a()) : ShareDirApiSync.f32717a.i(p10.a(), str3, outputStream, ApplicationHelper.f39908b.getString(R.string.app_version), iArr, onProgressListener, BitmapUtils.y(), z10); if (iArr[0] > 0) { long t10 = FileUtil.t(str4); if (t10 > 0 && t10 < ((long) iArr[0])) { LogUtils.a("SyncUtil", "downloadResizeJpg Incomplete file, fileSize=" + t10 + " outputContentLength=" + iArr[0]); FileUtil.k(str4); W[0] = 0; } } return W; } public static String O0() { return AccountPreference.t(); } public static boolean O1() { boolean z10 = true; if (!S1()) { return true; } boolean z11 = 1 == AccountPreference.y(); long Z5 = PreferenceHelper.Z5(); Calendar instance = Calendar.getInstance(); instance.set(AdError.BROKEN_MEDIA_ERROR_CODE, 1, 1); long timeInMillis = instance.getTimeInMillis() / 1000; if (z11 && Z5 > timeInMillis) { z10 = true; } return z10; } public static synchronized void O2(Context context, long j2, int i10, boolean z10) { synchronized (SyncUtil.class) { try { P2(context, j2, i10, z10, false); } finally { } } } public static void P(String str, String str2, String str3, boolean z10, OutputStream outputStream, TianShuAPI.OnProgressListener onProgressListener, String str4) throws TianShuException { int[] iArr = {0}; TianShuAPI.X(str, str2, str3, z10, outputStream, onProgressListener, iArr); if (iArr[0] > 0 && !TextUtils.isEmpty(str4)) { long t10 = FileUtil.t(str4); if (t10 > 0 && t10 < ((long) iArr[0])) { LogUtils.a("SyncUtil", "downloadFile Incomplete file, fileSize=" + t10 + " outputContentLength=" + iArr[0]); FileUtil.k(str4); throw new TianShuException(-305, "fileSize=" + t10 + " outputContentLength=" + iArr[0]); } } } public static String P0(Context context) { return PreferenceManager.getDefaultSharedPreferences(context).getString("token_Password", null); } public static boolean P1(Context context, String str) { boolean z10 = false; if (context != null) { String C0 = DBUtil.C0(context, str, false); if (TextUtils.isEmpty(C0)) { z10 = true; } else { Cursor query = context.getContentResolver().query(Documents.Image.f28704a, new String[]{"count(_id)"}, "sync_state = -1 AND document_id in " + C0, null, null); if (query != null) { if (query.moveToFirst() && query.getInt(0) <= 0) { z10 = true; } query.close(); } } LogUtils.a("SyncUtil", "isTeamAllDocsImageJpgComplete result=" + z10 + " teamToken=" + str); return z10; } LogUtils.a("SyncUtil", "context = null"); LogUtils.a("SyncUtil", "isTeamAllDocsImageJpgComplete result=" + z10 + " teamToken=" + str); return z10; } public static synchronized void P2(Context context, long j2, int i10, boolean z10, boolean z11) { synchronized (SyncUtil.class) { try { Q2(context, j2, i10, z10, z11, true); } finally { } } } public static void Q(String str, String str2, boolean z10, String str3, TianShuAPI.OnProgressListener onProgressListener) throws TianShuException { FileOutputStream fileOutputStream; try { fileOutputStream = new FileOutputStream(str3); } catch (FileNotFoundException unused) { fileOutputStream = null; } P(str, str2 + ".jpg", "ori", z10, fileOutputStream, onProgressListener, str3); } public static long Q0(Context context, long j2) { long j10; Cursor query = context.getContentResolver().query(ContentUris.withAppendedId(Documents.Tag.f28728a, j2), new String[]{"last_modified"}, null, null, null); if (query != null) { j10 = query.moveToFirst() ? query.getLong(0) : 0; query.close(); } else { j10 = 0; } if (j10 <= 0) { j10 = System.currentTimeMillis(); } return j10; } public static boolean Q1() { return 0 == AccountPreference.u(); } public static synchronized void Q2(Context context, long j2, int i10, boolean z10, boolean z11, boolean z12) { synchronized (SyncUtil.class) { ContentResolver contentResolver = context.getContentResolver(); Uri withAppendedId = ContentUris.withAppendedId(Documents.Image.f28706c, j2); ContentValues contentValues = new ContentValues(); if (z10) { Cursor query = contentResolver.query(withAppendedId, new String[]{"sync_jpage_state", "sync_jpage_extra_state", "last_modified"}, null, null, null); if (query != null) { if (query.moveToFirst()) { int i11 = query.getInt(0); int i12 = query.getInt(1); if (i11 == 1 && i10 == 2 && i12 != 1) { List<String> h02 = h0(context, j2); if (contentResolver.delete(withAppendedId, null, null) > 0) { FileUtil.i(h02); } } else { if (i12 == 1) { contentValues.put("sync_jpage_extra_state", (Integer) 2); } if (!z11) { contentValues.put("last_modified", Long.valueOf(query.getLong(2))); } if ((i11 == 3 && i10 == 2) || ((i11 == -1 && i10 == 2) || ((i11 == 0 && (i10 == 2 || i10 == 3)) || ((i12 == 1 && i11 == 1 && i10 == 2) || i11 == 7)))) { contentValues.put("sync_jpage_state", Integer.valueOf(i10)); } contentResolver.update(withAppendedId, contentValues, null, null); } } query.close(); if (z12) { o2(context); } } } else if (i10 == -1) { contentValues.put("last_modified", Long.valueOf(C0(context, j2))); contentValues.put("sync_jpage_extra_state", (Integer) 1); contentResolver.update(withAppendedId, contentValues, null, null); } else if (i10 != -2) { Cursor query2 = contentResolver.query(withAppendedId, new String[]{"sync_jpage_extra_state", "last_modified"}, null, null, null); if (query2 != null) { if (query2.moveToFirst()) { if (query2.getInt(0) != 2) { contentValues.put("sync_jpage_state", Integer.valueOf(i10)); } contentValues.put("sync_jpage_extra_state", (Integer) 0); contentValues.put("last_modified", Long.valueOf(query2.getLong(1))); contentResolver.update(withAppendedId, contentValues, null, null); } query2.close(); } } } } public static int R(String str, String str2, int i10, boolean z10, OutputStream outputStream, TianShuAPI.OnProgressListener onProgressListener, String str3) throws TianShuException { int[] iArr = {0}; int Y = TianShuAPI.Y(str, str2, i10, z10, outputStream, onProgressListener, iArr); if (iArr[0] > 0 && !TextUtils.isEmpty(str3)) { long t10 = FileUtil.t(str3); if (t10 > 0 && t10 < ((long) iArr[0])) { LogUtils.a("SyncUtil", "downloadFile Incomplete file, fileSize=" + t10 + " outputContentLength=" + iArr[0]); FileUtil.k(str3); throw new TianShuException(-305, "fileSize=" + t10 + " outputContentLength=" + iArr[0]); } } return Y; } public static long[] R0(Context context) { SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); return new long[]{defaultSharedPreferences.getLong("tafdseddfeasfeafaewf", -1), defaultSharedPreferences.getLong("t121212121sffewdfweefe", -1), defaultSharedPreferences.getLong("33xd5adju9elexedadsxln", -1)}; } public static boolean R1(Context context) { return -1 == PreferenceManager.getDefaultSharedPreferences(context).getLong("tafdseddfeasfeafaewf", -1); } public static synchronized void R2(Context context, ArrayList<Long> arrayList, int i10) { synchronized (SyncUtil.class) { if (arrayList != null) { if (arrayList.size() > 0) { ContentResolver contentResolver = context.getContentResolver(); ArrayList<ContentProviderOperation> arrayList2 = new ArrayList<>(); Iterator<Long> it = arrayList.iterator(); List<String> list = null; while (it.hasNext()) { long longValue = it.next().longValue(); if (longValue > 0) { Uri withAppendedId = ContentUris.withAppendedId(Documents.Image.f28706c, longValue); Cursor query = contentResolver.query(withAppendedId, new String[]{"sync_jpage_state", "sync_jpage_extra_state", "last_modified"}, null, null, null); if (query != null) { if (query.moveToFirst()) { int i11 = query.getInt(0); int i12 = query.getInt(1); if (i11 == 1 && i10 == 2 && i12 != 1) { list = h0(context, longValue); arrayList2.add(ContentProviderOperation.newDelete(withAppendedId).build()); } else { ContentProviderOperation.Builder newUpdate = ContentProviderOperation.newUpdate(withAppendedId); newUpdate.withValue("last_modified", Long.valueOf(query.getLong(2))); if (i12 == 1) { newUpdate.withValue("sync_jpage_extra_state", 2); } if ((i11 == 3 && i10 == 2) || ((i11 == -1 && i10 == 2) || ((i11 == 0 && (i10 == 2 || i10 == 3)) || ((i12 == 1 && i11 == 1 && i10 == 2) || i11 == 7)))) { newUpdate.withValue("sync_jpage_state", Integer.valueOf(i10)); } arrayList2.add(newUpdate.build()); } } query.close(); } } } if (arrayList2.size() > 0) { try { contentResolver.applyBatch(Documents.f28683a, arrayList2); FileUtil.i(list); } catch (Exception e10) { LogUtils.e("SyncUtil", e10); } } } } } } private static List<UploadRawImageInfo> S(List<UploadRawImageInfo> list, boolean[] zArr) { ArrayList arrayList = new ArrayList(); for (UploadRawImageInfo uploadRawImageInfo : list) { if (!n1(uploadRawImageInfo.f35102b)) { LogUtils.h("SyncUtil", uploadRawImageInfo.f35103c + "'s ' raw image " + uploadRawImageInfo.f35102b + " has lost"); } else if (uploadRawImageInfo.f35104d != 0) { zArr[0] = false; LogUtils.c("SyncUtil", "uploadLocalRawImage2Server batchState is not normal but " + uploadRawImageInfo.f35104d + " imageId=" + uploadRawImageInfo.f35101a); } else { arrayList.add(uploadRawImageInfo); } } return arrayList; } public static String S0() { return TianShuAPI.G0(); } public static boolean S1() { return AccountPreference.R(); } public static void S2(Context context, ContentResolver contentResolver, long j2, String str, String str2, boolean z10) { Cursor query = contentResolver.query(ContentUris.withAppendedId(Documents.PageMark.f28717b, j2), new String[]{"mark_text", "mark_x", "mark_y", "mark_rect_height", "mark_rect_width", "mark_rotate", "mark_text_font_size", "mark_text_color"}, null, null, null); boolean z11 = false; if (query != null) { if (query.moveToFirst()) { if (!z10) { FileUtil.h(str2, str); } if (WaterMarkUtil.b(str, new WaterMarkInfo(InkUtils.b(query.getInt(7)), (float) query.getInt(5), query.getFloat(1), query.getFloat(2), query.getFloat(4), query.getFloat(3), query.getString(0)))) { LogUtils.a("SyncUtil", "addWaterMark() true"); x(context, str); z11 = true; } else { LogUtils.a("SyncUtil", "addWaterMark() false"); } } query.close(); } if (!z11 && !z10) { FileUtil.h(str2, str); x(context, str); } } public static String T(String str) { return str != null ? str.replace("\"{", "{").replace("}\"", "}").replace("\"[", "[").replace("]\"", "]") : ""; } private static List<UploadLocalImageInfo> T0(Context context, long j2) { ArrayList arrayList = new ArrayList(); Cursor query = context.getContentResolver().query(ContentUris.withAppendedId(Documents.Image.f28705b, j2), new String[]{ao.f45476d, "raw_data", "_data", "created_time", "detail_index", "sync_state", "status", "image_backup", "sync_image_id", "image_confirm_state"}, "sync_state = 1 OR sync_state = 3", null, null); if (query != null) { while (query.moveToNext()) { UploadLocalImageInfo uploadLocalImageInfo = new UploadLocalImageInfo(); uploadLocalImageInfo.f35079a = query.getLong(0); uploadLocalImageInfo.f35080b = query.getString(2); uploadLocalImageInfo.f35081c = query.getLong(3) / 1000; uploadLocalImageInfo.f35082d = query.getInt(4); uploadLocalImageInfo.f35083e = query.getInt(5); uploadLocalImageInfo.f35084f = query.getInt(6); uploadLocalImageInfo.f35085g = query.getString(7); uploadLocalImageInfo.f35086h = query.getString(8); uploadLocalImageInfo.f35087i = query.getInt(9); arrayList.add(uploadLocalImageInfo); } query.close(); } return arrayList; } public static boolean T1(Context context) { NetworkInfo activeNetworkInfo; boolean z10 = true; if (context == null || (activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo()) == null || !activeNetworkInfo.isConnected() || activeNetworkInfo.getType() != 1) { z10 = false; } LogUtils.a("SyncUtil", "isWifiConnected result=" + z10); return z10; } public static void T2(Context context, long j2, int i10) { Cursor query = context.getContentResolver().query(ContentUris.withAppendedId(Documents.Image.f28705b, j2), new String[]{ao.f45476d}, null, null, null); if (query != null) { ArrayList arrayList = new ArrayList(); while (query.moveToNext()) { arrayList.add(Long.valueOf(query.getLong(0))); } query.close(); R2(context, arrayList, i10); W2(context, arrayList, i10); } } public static String U(String str) { return SDStorageManager.o() + str; } private static List<UploadRawImageInfo> U0(Context context, String str) { ArrayList arrayList = new ArrayList(); Cursor query = context.getContentResolver().query(Documents.Image.f28706c, new String[]{ao.f45476d, "raw_data", "sync_image_id", "status", "created_time", "sync_state", "document_id", "belong_state"}, "sync_raw_jpg_state = 1 AND sync_state = 0 AND folder_type = 0 AND raw_data IS NOT NULL " + (" AND document_id in " + str), null, "document_id"); if (query != null) { while (query.moveToNext()) { UploadRawImageInfo uploadRawImageInfo = new UploadRawImageInfo(); uploadRawImageInfo.f35101a = query.getLong(0); uploadRawImageInfo.f35102b = query.getString(1); uploadRawImageInfo.f35103c = query.getString(2); uploadRawImageInfo.f35104d = query.getInt(3); uploadRawImageInfo.f35105e = query.getLong(4) / 1000; uploadRawImageInfo.f35106f = query.getInt(5); uploadRawImageInfo.f35107g = query.getLong(6); uploadRawImageInfo.f35108h = query.getInt(7); arrayList.add(uploadRawImageInfo); } query.close(); } return arrayList; } /* access modifiers changed from: private */ public static /* synthetic */ void U1() { long[] f22 = f2(); if (f22 != null && f22[0] > f22[1]) { CsEventBus.b(new MessageEvent("intsig_message_cloud_storage_limit")); } } public static synchronized void U2(Context context, long j2, int i10, boolean z10) { synchronized (SyncUtil.class) { try { V2(context, j2, i10, z10, true); } finally { } } } public static String V(String str) { return SDStorageManager.Q() + str; } private static ExecutorService V0(boolean z10) { return z10 ? CustomExecutor.i() : CustomExecutor.o(); } public static synchronized void V2(Context context, long j2, int i10, boolean z10, boolean z11) { synchronized (SyncUtil.class) { ContentResolver contentResolver = context.getContentResolver(); Uri withAppendedId = ContentUris.withAppendedId(Documents.Image.f28706c, j2); ContentValues contentValues = new ContentValues(); if (z10) { Cursor query = contentResolver.query(withAppendedId, new String[]{"sync_state", "sync_extra_state", "last_modified"}, null, null, null); if (query != null) { if (query.moveToFirst()) { int i11 = query.getInt(0); int i12 = query.getInt(1); if (i11 == 1 && i10 == 2 && i12 != 1) { List<String> h02 = h0(context, j2); if (contentResolver.delete(withAppendedId, null, null) > 0) { FileUtil.i(h02); } } else { if (i12 == 1) { contentValues.put("sync_extra_state", (Integer) 2); } contentValues.put("last_modified", Long.valueOf(query.getLong(2))); if ((i11 == 3 && i10 == 2) || ((i11 == -1 && i10 == 2) || ((i11 == 0 && (i10 == 2 || i10 == 3)) || ((i12 == 1 && i11 == 1 && i10 == 2) || ((i11 == 6 && (i10 == 2 || i10 == 3)) || i11 == 7))))) { contentValues.put("sync_state", Integer.valueOf(i10)); } contentResolver.update(withAppendedId, contentValues, null, null); } } query.close(); if (z11) { o2(context); } } } else if (i10 == -1) { contentValues.put("last_modified", Long.valueOf(C0(context, j2))); contentValues.put("sync_extra_state", (Integer) 1); contentResolver.update(withAppendedId, contentValues, null, null); } else if (i10 != -2) { Cursor query2 = contentResolver.query(withAppendedId, new String[]{"sync_extra_state", "last_modified"}, null, null, null); if (query2 != null) { if (query2.moveToFirst()) { if (query2.getInt(0) != 2) { contentValues.put("sync_state", Integer.valueOf(i10)); } contentValues.put("sync_extra_state", (Integer) 0); contentValues.put("last_modified", Long.valueOf(query2.getLong(1))); contentResolver.update(withAppendedId, contentValues, null, null); } query2.close(); } } } } public static String W(String str) { return SDStorageManager.s() + str; } public static String W0(String str) { String G0 = TianShuAPI.G0(); String str2 = null; if (TextUtils.isEmpty(G0)) { LogUtils.a("SyncUtil", "getUserAttribute token is emtpy"); return null; } HashMap hashMap = new HashMap(); hashMap.put("client", AccountPreference.c()); hashMap.put("client_id", AccountPreference.e()); hashMap.put("client_app", AccountPreference.d()); hashMap.put("cs_ept_d", AESEncUtil.e(ApplicationHelper.i())); hashMap.put("attribute", str); hashMap.put(ClientMetricsEndpointType.TOKEN, G0); hashMap.put("timestamp", System.currentTimeMillis() + ""); try { str2 = TianShuAPI.z0("get_user_attribute", hashMap, true, 0); LogUtils.a("SyncUtil", "getUserAttribute result:" + str2); return str2; } catch (TianShuException e10) { LogUtils.e("SyncUtil", e10); return str2; } } /* access modifiers changed from: private */ public static /* synthetic */ Boolean W1(List list, boolean[] zArr, SyncApi.SyncProgress syncProgress, SyncState syncState, long j2, Context context, Vector vector) throws Exception { Iterator it = list.iterator(); loop0: while (true) { while (true) { if (!it.hasNext()) { break loop0; } try { if (!((Boolean) ((Future) it.next()).get()).booleanValue()) { zArr[0] = false; } } catch (InterruptedException e10) { LogUtils.e("SyncUtil", e10); Thread.currentThread().interrupt(); } catch (Exception e11) { LogUtils.e("SyncUtil", e11); } } } if (syncProgress != null) { syncState.l(100.0f); syncProgress.a(syncState); } LogUtils.a("SyncUtil", "downloadImageFromServer doc id=" + j2 + " result=" + zArr[0]); if (zArr[0]) { q2(context, j2, 0); } if (vector != null) { vector.remove(Long.valueOf(j2)); } return Boolean.valueOf(zArr[0]); } public static synchronized void W2(Context context, List<Long> list, int i10) { synchronized (SyncUtil.class) { if (list != null) { if (list.size() > 0) { ContentResolver contentResolver = context.getContentResolver(); ArrayList<ContentProviderOperation> arrayList = new ArrayList<>(); List<String> list2 = null; for (Long l10 : list) { long longValue = l10.longValue(); if (longValue > 0) { Uri withAppendedId = ContentUris.withAppendedId(Documents.Image.f28706c, longValue); Cursor query = contentResolver.query(withAppendedId, new String[]{"sync_state", "sync_extra_state", "last_modified"}, null, null, null); if (query != null) { if (query.moveToFirst()) { int i11 = query.getInt(0); int i12 = query.getInt(1); if (i11 == 1 && i10 == 2 && i12 != 1) { list2 = h0(context, longValue); arrayList.add(ContentProviderOperation.newDelete(withAppendedId).build()); } else { ContentProviderOperation.Builder newUpdate = ContentProviderOperation.newUpdate(withAppendedId); newUpdate.withValue("last_modified", Long.valueOf(query.getLong(2))); if (i12 == 1) { newUpdate.withValue("sync_extra_state", 2); } if ((i11 == 3 && i10 == 2) || ((i11 == -1 && i10 == 2) || ((i11 == 0 && (i10 == 2 || i10 == 3)) || ((i12 == 1 && i11 == 1 && i10 == 2) || ((i11 == 6 && (i10 == 2 || i10 == 3)) || i11 == 7))))) { newUpdate.withValue("sync_state", Integer.valueOf(i10)); } arrayList.add(newUpdate.build()); } } query.close(); } } } if (arrayList.size() > 0) { try { contentResolver.applyBatch(Documents.f28683a, arrayList); FileUtil.i(list2); } catch (RemoteException e10) { LogUtils.e("SyncUtil", e10); } catch (OperationApplicationException e11) { LogUtils.e("SyncUtil", e11); } } } } } } public static String X(String str) { return SDStorageManager.t() + str; } public static String X0(Context context) { return AccountPreference.v(context); } /* access modifiers changed from: private */ public static /* synthetic */ UploadImageResponse X1(List list, TianShuException[] tianShuExceptionArr, SyncApi.SyncProgress syncProgress, SyncState syncState, boolean[] zArr) throws Exception { UploadImageResponse uploadImageResponse = new UploadImageResponse(); Iterator it = list.iterator(); loop0: while (true) { while (true) { if (!it.hasNext()) { break loop0; } try { UploadImageResponse uploadImageResponse2 = (UploadImageResponse) ((Future) it.next()).get(); uploadImageResponse.f35148b = uploadImageResponse2.f35148b; if (!uploadImageResponse2.f35149c) { uploadImageResponse.f35149c = false; } if (uploadImageResponse2.f35150d) { uploadImageResponse.f35150d = true; } if (uploadImageResponse2.f35151e) { uploadImageResponse.f35151e = true; } } catch (InterruptedException e10) { LogUtils.e("SyncUtil", e10); Thread.currentThread().interrupt(); } catch (Exception e11) { LogUtils.e("SyncUtil", e11); } } } if (tianShuExceptionArr[0] == null) { if (syncProgress != null) { syncState.l(100.0f); syncProgress.a(syncState); } if (!zArr[0]) { uploadImageResponse.f35149c = false; } return uploadImageResponse; } throw tianShuExceptionArr[0]; } public static void X2(Context context, boolean z10) { SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); if (z10) { defaultSharedPreferences.edit().putBoolean("keysetspecialaccount", true).apply(); } else { defaultSharedPreferences.edit().remove("keysetspecialaccount").apply(); } } public static String Y(String str) { return SDStorageManager.W() + str; } public static long Y0() { return ((PreferenceUtil.f().h("tkreds3sdvv22ccsx3xd3", 0) - PreferenceUtil.f().h("33xd5adju9elexedadsxln", 0)) / 24) / 3600; } private static void Y1(Context context, String str, Map<Long, TeamDirListJson.BaseTeamDoc> map) { if (!TextUtils.isEmpty(str)) { HashMap hashMap = new HashMap(); String[] strArr = {str, ExifInterface.GPS_MEASUREMENT_2D, "5"}; Cursor query = context.getContentResolver().query(Documents.Dir.f28688a, new String[]{"sync_dir_id", "last_upload_time"}, "team_token=? AND sync_state !=? AND sync_state !=? ", strArr, null); if (query != null) { while (query.moveToNext()) { hashMap.put(query.getString(0), Long.valueOf(query.getLong(1))); } query.close(); } Cursor query2 = context.getContentResolver().query(Documents.Document.f28695d, new String[]{ao.f45476d, "sync_doc_id", "sync_dir_id", "last_upload_time"}, "team_token=? AND sync_state !=? AND sync_state !=? ", new String[]{str, ExifInterface.GPS_MEASUREMENT_2D, "5"}, null); if (query2 != null) { while (query2.moveToNext()) { String string = query2.getString(2); if (!TextUtils.isEmpty(string)) { TeamDirListJson.BaseTeamDoc baseTeamDoc = new TeamDirListJson.BaseTeamDoc(); baseTeamDoc.doc_id = query2.getString(1); if (hashMap.containsKey(string)) { baseTeamDoc.setDirId(string); baseTeamDoc.setLastDirUploadTime(((Long) hashMap.get(string)).longValue()); } baseTeamDoc.setLastDocUploadTime(query2.getLong(3)); map.put(Long.valueOf(query2.getLong(0)), baseTeamDoc); } } query2.close(); } } } public static void Y2() { String W0 = W0("personal_sync"); if (!TextUtils.isEmpty(W0)) { try { PersonalSyncAttribute personalSyncAttribute = (PersonalSyncAttribute) GsonUtils.b(W0, PersonalSyncAttribute.class); if (!(personalSyncAttribute == null || personalSyncAttribute.getData() == null)) { if (personalSyncAttribute.getData().getPersonal_sync() == 3) { LogUtils.a("SyncUtil", "updateSyncSettingFromServer close"); Context context = ApplicationHelper.f39908b; AppUtil.j0(context, context.getString(R.string.set_sync_close)); } else if (personalSyncAttribute.getData().getPersonal_sync() == 2) { if (AppUtil.M(ApplicationHelper.f39908b)) { LogUtils.a("SyncUtil", "updateSyncSettingFromServer wifi"); Context context2 = ApplicationHelper.f39908b; AppUtil.j0(context2, context2.getString(R.string.set_sync_wifi)); return; } LogUtils.a("SyncUtil", "updateSyncSettingFromServer keep"); } } } catch (Exception e10) { LogUtils.e("SyncUtil", e10); } } } public static long[] Z(Context context) { return a0(context, true); } public static long Z0() { return PreferenceUtil.f().h("tkreds3sdvv22ccsx3xd3", 0) * 1000; } public static void Z1(LoginParameter loginParameter) throws TianShuException { SyncUtilDelegate.d(loginParameter); } public static synchronized void Z2(Context context, long j2, int i10, boolean z10) { synchronized (SyncUtil.class) { ContentResolver contentResolver = context.getContentResolver(); Uri withAppendedId = ContentUris.withAppendedId(Documents.Tag.f28729b, j2); ContentValues contentValues = new ContentValues(); if (z10) { Cursor query = contentResolver.query(withAppendedId, new String[]{"sync_state", "sync_extra_state", "last_modified"}, null, null, null); if (query != null) { if (query.moveToFirst()) { int i11 = query.getInt(0); int i12 = query.getInt(1); if (i11 == 1 && i10 == 2 && i12 != 1) { contentResolver.delete(withAppendedId, null, null); Uri uri = Documents.Mtag.f28713a; contentResolver.delete(uri, "tag_id = " + j2, null); } else { if (i12 == 1) { contentValues.put("sync_extra_state", (Integer) 2); } contentValues.put("last_modified", Long.valueOf(query.getLong(2))); if ((i11 == 3 && i10 == 2) || ((i11 == 0 && (i10 == 2 || i10 == 3)) || ((i12 == 1 && i11 == 1 && i10 == 2) || i11 == 7))) { contentValues.put("sync_state", Integer.valueOf(i10)); } contentResolver.update(withAppendedId, contentValues, null, null); } } query.close(); o2(context); } } else if (i10 == -1) { contentValues.put("last_modified", Long.valueOf(Q0(context, j2))); contentValues.put("sync_extra_state", (Integer) 1); contentResolver.update(withAppendedId, contentValues, null, null); } else if (i10 != -2) { Cursor query2 = contentResolver.query(withAppendedId, new String[]{"sync_extra_state", "last_modified"}, null, null, null); if (query2 != null) { if (query2.moveToFirst()) { if (query2.getInt(0) != 2) { contentValues.put("sync_state", Integer.valueOf(i10)); } contentValues.put("sync_extra_state", (Integer) 0); contentValues.put("last_modified", Long.valueOf(query2.getLong(1))); contentResolver.update(withAppendedId, contentValues, null, null); } query2.close(); } } } } public static long[] a0(Context context, boolean z10) { String[] split; if (context == null) { LogUtils.a("SyncUtil", "context == null"); return null; } long[] f22 = f2(); if (z10 && f22 == null) { String w10 = AppUtil.w(); if (!TextUtils.isEmpty(w10) && (split = w10.split("/")) != null && split.length == 2) { f22 = new long[]{Long.valueOf(split[0]).longValue(), Long.valueOf(split[1]).longValue()}; } } return f22; } public static String a1() { return DateFormat.getDateInstance(1).format(new Date(Z0())); } public static HashSet<Long> a2(Context context, String str) { long currentTimeMillis = System.currentTimeMillis(); HashSet<Long> hashSet = new HashSet<>(); String C0 = DBUtil.C0(context, str, false); if (TextUtils.isEmpty(C0)) { return hashSet; } ContentResolver contentResolver = context.getContentResolver(); Uri uri = Documents.Image.f28704a; String[] strArr = {ao.f45476d, "_data", "thumb_data", "sync_image_id", "sync_state", "sync_timestamp", "document_id", "sync_version", "sync_ui_state"}; Cursor query = contentResolver.query(uri, strArr, "status = 0 AND belong_state != 1" + (" AND document_id in " + C0), null, "document_id ASC"); if (query != null) { while (query.moveToNext() && !SyncThread.f34994t && !SyncThread.Z()) { try { int i10 = query.getInt(4); if (!(i10 == 1 || i10 == 2)) { if (i10 != 5) { if (query.getLong(5) <= 0) { LogUtils.a("SyncUtil", "downloadMissedJpg no jpage downloaded from server, don't download jpg, id=" + query.getLong(0) + " sync id=" + query.getString(3)); } else { long j2 = query.getLong(6); if (j2 > 0) { if (!FileUtil.C(PreferenceHelper.l7(context) ? query.getString(1) : query.getString(2))) { hashSet.add(Long.valueOf(j2)); } else if (query.getInt(7) <= 0 && query.getInt(8) == 1) { hashSet.add(Long.valueOf(j2)); } } } } } } catch (Exception e10) { LogUtils.c("SyncUtil", "needDownloadMissedDocIds exception >>> " + e10); } } query.close(); } LogUtils.a("SyncUtil", "needDownloadMissedDocIds size=" + hashSet.size() + " costtime=" + (System.currentTimeMillis() - currentTimeMillis)); return hashSet; } public static synchronized void a3(Context context, ArrayList<Long> arrayList, int i10) { synchronized (SyncUtil.class) { if (arrayList != null) { try { if (arrayList.size() > 0) { ContentResolver contentResolver = context.getContentResolver(); ArrayList<ContentProviderOperation> arrayList2 = new ArrayList<>(); Iterator<Long> it = arrayList.iterator(); loop0: while (true) { while (it.hasNext()) { long longValue = it.next().longValue(); if (longValue > 0) { Uri withAppendedId = ContentUris.withAppendedId(Documents.Tag.f28729b, longValue); Cursor query = contentResolver.query(withAppendedId, new String[]{"sync_state", "sync_extra_state", "last_modified"}, null, null, null); if (query != null) { if (query.moveToFirst()) { int i11 = query.getInt(0); int i12 = query.getInt(1); if (i11 == 1 && i10 == 2 && i12 != 1) { arrayList2.add(ContentProviderOperation.newDelete(withAppendedId).build()); query.close(); } else { ContentProviderOperation.Builder newUpdate = ContentProviderOperation.newUpdate(withAppendedId); if (i12 == 1) { newUpdate.withValue("sync_extra_state", 2); } newUpdate.withValue("last_modified", Long.valueOf(query.getLong(2))); if (i11 == 3) { if (i10 != 2) { } newUpdate.withValue("sync_state", Integer.valueOf(i10)); arrayList2.add(newUpdate.build()); } if (i11 == 0) { if (!(i10 == 2 || i10 == 3)) { } newUpdate.withValue("sync_state", Integer.valueOf(i10)); arrayList2.add(newUpdate.build()); } if (i12 == 1 && i11 == 1) { if (i10 != 2) { } newUpdate.withValue("sync_state", Integer.valueOf(i10)); arrayList2.add(newUpdate.build()); } if (i11 == 7) { newUpdate.withValue("sync_state", Integer.valueOf(i10)); } arrayList2.add(newUpdate.build()); } } query.close(); } } } break loop0; } if (arrayList2.size() > 0) { try { contentResolver.applyBatch(Documents.f28683a, arrayList2); } catch (RemoteException e10) { LogUtils.e("SyncUtil", e10); } catch (OperationApplicationException e11) { LogUtils.e("SyncUtil", e11); } } } } finally { } } } } public static float b0(long[] jArr) { if (jArr == null || jArr.length != 2) { return 0.0f; } if (jArr[1] == 0 || jArr[1] <= jArr[0]) { return 100.0f; } return (((float) jArr[0]) * 100.0f) / ((float) jArr[1]); } public static long[] b1(Context context) { SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); return new long[]{defaultSharedPreferences.getLong("qp3sdjd79xhdas02sd", 2), defaultSharedPreferences.getLong("tkreds3sdvv22ccsx3xd3", -1), defaultSharedPreferences.getLong("33xd5adju9elexedadsxln", -1)}; } public static boolean b2(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity"); boolean z10 = false; if (connectivityManager != null) { NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); if (activeNetworkInfo == null) { LogUtils.a("SyncUtil", "info == null"); } else if (!activeNetworkInfo.isConnected()) { LogUtils.a("SyncUtil", NetworkUtil.NETWORK_CLASS_DISCONNECTED); } else if (activeNetworkInfo.getType() == 0) { z10 = AppUtil.F(context).equals(context.getString(R.string.set_sync_wifi)); } LogUtils.a("SyncUtil", "needed tips for sync on mobile network =" + z10); return z10; } LogUtils.a("SyncUtil", "cm == null"); LogUtils.a("SyncUtil", "needed tips for sync on mobile network =" + z10); return z10; } public static boolean b3() { return c3(true); } public static String c0(Context context) { StringBuilder sb2 = new StringBuilder(); if (context != null) { Cursor query = context.getContentResolver().query(Documents.Image.f28704a, new String[]{ao.f45476d, "sync_image_id"}, "sync_state = -1 AND document_id >0 ", null, null); if (query != null) { while (query.moveToNext()) { if (sb2.length() > 0) { sb2.append(AuthenticationConstants.Broker.CHALLENGE_REQUEST_CERT_AUTH_DELIMETER); } sb2.append("id="); sb2.append(query.getLong(0)); sb2.append(",imageSyncId="); sb2.append(query.getString(1)); } query.close(); return sb2.toString(); } } else { LogUtils.a("SyncUtil", "context = null"); } return sb2.toString(); } public static boolean c1(long[] jArr) { if (jArr == null || jArr.length != 2) { return false; } return jArr[1] == 0 || jArr[1] <= jArr[0]; } public static int c2(Context context) { NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo(); if (activeNetworkInfo != null) { if (activeNetworkInfo.isConnected()) { if (activeNetworkInfo.getType() == 7) { return -1; } return activeNetworkInfo.getType(); } } return -1; } public static boolean c3(boolean z10) { return d3(UserPropertyAPI.b(), z10); } public static String d0(Context context) { return AccountPreference.b(context); } public static boolean d1(Context context) { boolean z10 = false; if (context != null) { Cursor query = context.getContentResolver().query(Documents.Image.f28704a, new String[]{"count(_id)"}, "sync_state = -1 AND document_id >0 ", null, null); if (query != null) { if (query.moveToFirst() && query.getInt(0) <= 0) { z10 = true; } query.close(); LogUtils.a("SyncUtil", "isAllDocsImageJpgComplete result=" + z10); return z10; } } else { LogUtils.a("SyncUtil", "context = null"); } LogUtils.a("SyncUtil", "isAllDocsImageJpgComplete result=" + z10); return z10; } public static String d2(String str) { int indexOf; if (!TextUtils.isEmpty(str) && (indexOf = str.indexOf(AuthenticationConstants.Broker.CHALLENGE_REQUEST_CERT_AUTH_DELIMETER)) > 0) { try { long longValue = Long.valueOf(str.substring(indexOf + 1)).longValue(); if (System.currentTimeMillis() - longValue <= 432000000) { return str.substring(0, indexOf); } LogUtils.a("SyncUtil", "parseAndCheckPdfLink expire t=" + longValue + " current time=" + System.currentTimeMillis()); return null; } catch (NumberFormatException e10) { LogUtils.e("SyncUtil", e10); } } return null; } /* JADX WARNING: Removed duplicated region for block: B:21:0x0205 */ /* JADX WARNING: Removed duplicated region for block: B:22:0x020c */ /* JADX WARNING: Removed duplicated region for block: B:24:0x0212 */ /* JADX WARNING: Removed duplicated region for block: B:27:0x0251 */ /* JADX WARNING: Removed duplicated region for block: B:28:0x0255 */ /* JADX WARNING: Removed duplicated region for block: B:31:0x0267 */ /* JADX WARNING: Removed duplicated region for block: B:32:0x026b */ /* JADX WARNING: Removed duplicated region for block: B:35:0x027d */ public static boolean d3(long[] jArr, boolean z10) { boolean z11; LogUtils.a("SyncUtil", "updateVipInfo() "); boolean z12 = false; if (jArr == null) { LogUtils.a("SyncUtil", "updateVipInfo() info = null"); return false; } if (jArr[0] != -101) { if (jArr[0] == 200) { jArr[0] = 1; if (jArr[3] == 1) { TheOwlery.t(true); z11 = true; HashMap hashMap = new HashMap(); hashMap.put("qp3sdjd79xhdas02sd", Long.valueOf(jArr[0])); hashMap.put("tkreds3sdvv22ccsx3xd3", Long.valueOf(jArr[1])); LogUtils.c("SyncUtil", "KEY_VIP_EXPIRE time " + jArr[1]); hashMap.put("woj87redsdwgaawdd90", Long.valueOf(jArr[1])); hashMap.put("33xd5adju9elexedadsxln", Long.valueOf(jArr[2])); hashMap.put("qp3sdjd30renew02sd", Long.valueOf(jArr[4])); hashMap.put("qp3sdjd30renewmethod02sd", Long.valueOf(jArr[5])); hashMap.put("qp3sdnex3rwmethod02sd", Long.valueOf(jArr[6])); hashMap.put("qp3sdnex3initial2time02sd", Long.valueOf(jArr[7])); hashMap.put("qp3sdfsdesdfwsvvs20161108", Long.valueOf(jArr[8])); hashMap.put("qp3sdfsdesdfwsvvs20200312", Long.valueOf(jArr[17])); hashMap.put("qp3sdfsdehorizonwsvvs2020032014", Long.valueOf(jArr[18])); hashMap.put("qp3sdfsdehorizonwsvvs2020032813", Long.valueOf(jArr[19])); hashMap.put("t43543fgdfsfdfweweffsfsdfe", Long.valueOf(jArr[9])); hashMap.put("t121212121sffewdfweefe", Long.valueOf(jArr[10])); hashMap.put("tafdseddfeasfeafaewf", Long.valueOf(jArr[11])); hashMap.put("qp3sddfa0renewergw", Long.valueOf(jArr[12])); hashMap.put("qp3sdjd79s7hrdbdcm", Long.valueOf(jArr[20])); hashMap.put("qpfcgdfggdfgdfgdx", Long.valueOf(jArr[21])); hashMap.put("sdfdnsjnfjdjkefbnb", Long.valueOf(jArr[22])); hashMap.put("KEY_REMOVE_AD", Long.valueOf(jArr[23])); hashMap.put("fagagiolnglangnae", Long.valueOf(jArr[24])); r(jArr[0]); PreferenceUtil.f().r(hashMap); String i10 = !Verify.d() ? ApplicationHelper.i() : "NOT AGREED PROTOCOL YET"; if (z10) { i10 = N0(); } LogUtils.a("SyncUtil", "updateVipInfo isLogin=" + z10 + " usrId=" + i10 + " info=" + Arrays.toString(jArr)); D2(jArr[0] == 1); PreferenceHelper.cd(jArr[15] == 1); if (jArr[16] == 1) { z12 = true; } PreferenceHelper.zh(z12); LogUtils.a("SyncUtil", "updateVipInfo is_trial_guide = " + jArr[16]); z12 = z11; } } else if (jArr[0] == -402) { jArr[0] = 2; z11 = false; HashMap hashMap2 = new HashMap(); hashMap2.put("qp3sdjd79xhdas02sd", Long.valueOf(jArr[0])); hashMap2.put("tkreds3sdvv22ccsx3xd3", Long.valueOf(jArr[1])); LogUtils.c("SyncUtil", "KEY_VIP_EXPIRE time " + jArr[1]); hashMap2.put("woj87redsdwgaawdd90", Long.valueOf(jArr[1])); hashMap2.put("33xd5adju9elexedadsxln", Long.valueOf(jArr[2])); hashMap2.put("qp3sdjd30renew02sd", Long.valueOf(jArr[4])); hashMap2.put("qp3sdjd30renewmethod02sd", Long.valueOf(jArr[5])); hashMap2.put("qp3sdnex3rwmethod02sd", Long.valueOf(jArr[6])); hashMap2.put("qp3sdnex3initial2time02sd", Long.valueOf(jArr[7])); hashMap2.put("qp3sdfsdesdfwsvvs20161108", Long.valueOf(jArr[8])); hashMap2.put("qp3sdfsdesdfwsvvs20200312", Long.valueOf(jArr[17])); hashMap2.put("qp3sdfsdehorizonwsvvs2020032014", Long.valueOf(jArr[18])); hashMap2.put("qp3sdfsdehorizonwsvvs2020032813", Long.valueOf(jArr[19])); hashMap2.put("t43543fgdfsfdfweweffsfsdfe", Long.valueOf(jArr[9])); hashMap2.put("t121212121sffewdfweefe", Long.valueOf(jArr[10])); hashMap2.put("tafdseddfeasfeafaewf", Long.valueOf(jArr[11])); hashMap2.put("qp3sddfa0renewergw", Long.valueOf(jArr[12])); hashMap2.put("qp3sdjd79s7hrdbdcm", Long.valueOf(jArr[20])); hashMap2.put("qpfcgdfggdfgdfgdx", Long.valueOf(jArr[21])); hashMap2.put("sdfdnsjnfjdjkefbnb", Long.valueOf(jArr[22])); hashMap2.put("KEY_REMOVE_AD", Long.valueOf(jArr[23])); hashMap2.put("fagagiolnglangnae", Long.valueOf(jArr[24])); r(jArr[0]); PreferenceUtil.f().r(hashMap2); if (!Verify.d()) { } if (z10) { } LogUtils.a("SyncUtil", "updateVipInfo isLogin=" + z10 + " usrId=" + i10 + " info=" + Arrays.toString(jArr)); D2(jArr[0] == 1); PreferenceHelper.cd(jArr[15] == 1); if (jArr[16] == 1) { } PreferenceHelper.zh(z12); LogUtils.a("SyncUtil", "updateVipInfo is_trial_guide = " + jArr[16]); z12 = z11; } else if (jArr[0] == -400) { jArr[0] = 3; } z11 = false; HashMap hashMap22 = new HashMap(); hashMap22.put("qp3sdjd79xhdas02sd", Long.valueOf(jArr[0])); hashMap22.put("tkreds3sdvv22ccsx3xd3", Long.valueOf(jArr[1])); LogUtils.c("SyncUtil", "KEY_VIP_EXPIRE time " + jArr[1]); hashMap22.put("woj87redsdwgaawdd90", Long.valueOf(jArr[1])); hashMap22.put("33xd5adju9elexedadsxln", Long.valueOf(jArr[2])); hashMap22.put("qp3sdjd30renew02sd", Long.valueOf(jArr[4])); hashMap22.put("qp3sdjd30renewmethod02sd", Long.valueOf(jArr[5])); hashMap22.put("qp3sdnex3rwmethod02sd", Long.valueOf(jArr[6])); hashMap22.put("qp3sdnex3initial2time02sd", Long.valueOf(jArr[7])); hashMap22.put("qp3sdfsdesdfwsvvs20161108", Long.valueOf(jArr[8])); hashMap22.put("qp3sdfsdesdfwsvvs20200312", Long.valueOf(jArr[17])); hashMap22.put("qp3sdfsdehorizonwsvvs2020032014", Long.valueOf(jArr[18])); hashMap22.put("qp3sdfsdehorizonwsvvs2020032813", Long.valueOf(jArr[19])); hashMap22.put("t43543fgdfsfdfweweffsfsdfe", Long.valueOf(jArr[9])); hashMap22.put("t121212121sffewdfweefe", Long.valueOf(jArr[10])); hashMap22.put("tafdseddfeasfeafaewf", Long.valueOf(jArr[11])); hashMap22.put("qp3sddfa0renewergw", Long.valueOf(jArr[12])); hashMap22.put("qp3sdjd79s7hrdbdcm", Long.valueOf(jArr[20])); hashMap22.put("qpfcgdfggdfgdfgdx", Long.valueOf(jArr[21])); hashMap22.put("sdfdnsjnfjdjkefbnb", Long.valueOf(jArr[22])); hashMap22.put("KEY_REMOVE_AD", Long.valueOf(jArr[23])); hashMap22.put("fagagiolnglangnae", Long.valueOf(jArr[24])); r(jArr[0]); PreferenceUtil.f().r(hashMap22); if (!Verify.d()) { } if (z10) { } LogUtils.a("SyncUtil", "updateVipInfo isLogin=" + z10 + " usrId=" + i10 + " info=" + Arrays.toString(jArr)); D2(jArr[0] == 1); PreferenceHelper.cd(jArr[15] == 1); if (jArr[16] == 1) { } PreferenceHelper.zh(z12); LogUtils.a("SyncUtil", "updateVipInfo is_trial_guide = " + jArr[16]); z12 = z11; } return z12; } public static String e0() { return AccountPreference.c(); } private static boolean e1() { String d10 = LanguageUtil.d(); if (TextUtils.isEmpty(d10)) { return false; } String lowerCase = d10.toLowerCase(); for (String str : f35040c) { if (TextUtils.equals(str.toLowerCase(), lowerCase)) { return true; } } return false; } public static String e2(String str) { if (!TextUtils.isEmpty(str)) { String[] split = str.split(".+(www\\.camcard\\.|w12013\\.camcard\\.|www\\.camscanner\\.|w12013\\.camscanner\\.|www-sandbox\\.camscanner\\.).+/l/"); if (split.length == 2) { return split[1]; } } return null; } /* JADX WARNING: Removed duplicated region for block: B:19:0x00ef */ public static boolean e3(String str, String str2) { boolean z10 = false; if (FileUtil.C(str2)) { HttpURLConnection httpURLConnection = null; try { File file = new File(str2); if (file.length() > 0) { String str3 = "https://d2100.intsig.net:5443/sync/upload_bug?" + str; httpURLConnection = HttpsUtil.a(new URL(str3)); LogUtils.a("SyncUtil", "uploadBug2Server url =" + str3); FileInputStream fileInputStream = new FileInputStream(file); httpURLConnection.setUseCaches(false); httpURLConnection.setDoInput(true); httpURLConnection.setDoOutput(true); httpURLConnection.setConnectTimeout(6000); httpURLConnection.setReadTimeout(6000); httpURLConnection.setRequestMethod("POST"); httpURLConnection.setRequestProperty("Content-Type", "application/x-gzip"); OutputStream outputStream = httpURLConnection.getOutputStream(); byte[] bArr = new byte[4096]; while (true) { int read = fileInputStream.read(bArr); if (read == -1) { break; } outputStream.write(bArr, 0, read); } outputStream.flush(); outputStream.close(); fileInputStream.close(); int responseCode = httpURLConnection.getResponseCode(); LogUtils.a("SyncUtil", "uploadBug2Server response code=" + responseCode); if (responseCode != 200) { if (responseCode == 413) { } } z10 = true; if (httpURLConnection != null) { httpURLConnection.disconnect(); LogUtils.a("SyncUtil", "uploadBug2Server result=" + z10); return z10; } } else { LogUtils.a("SyncUtil", "uploadBug2Server File size = 0"); } if (httpURLConnection != null) { } } catch (MalformedURLException e10) { LogUtils.e("SyncUtil", e10); if (0 != 0) { } } catch (Exception e11) { LogUtils.d("SyncUtil", "Exception", e11); if (0 != 0) { } } catch (Throwable th) { if (0 != 0) { httpURLConnection.disconnect(); } throw th; } } else { LogUtils.a("SyncUtil", "uploadBug2Server filePath is not exist"); } LogUtils.a("SyncUtil", "uploadBug2Server result=" + z10); return z10; } public static String f0(Context context) { return AccountPreference.d(); } public static boolean f1(Context context) { return !AppSwitch.i() && N1(context) && PreferenceHelper.v7(); } public static long[] f2() { try { long[] I1 = TianShuAPI.I1(); if (I1 != null && I1.length == 2 && I1[1] > 0) { LogUtils.a("SyncUtil", "queryAccountStorage storage[0]=" + I1[0] + " storage[1]=" + I1[1]); StringBuilder sb2 = new StringBuilder(); sb2.append(I1[0]); sb2.append("/"); sb2.append(I1[1]); AppUtil.g0(sb2.toString()); return I1; } } catch (TianShuException e10) { LogUtils.c("SyncUtil", "queryAccountStorage = " + e10); } catch (NumberFormatException e11) { LogUtils.c("SyncUtil", "queryAccountStorage = " + e11); return null; } return null; } public static boolean f3(Vector vector) { boolean z10 = true; try { TianShuAPI.r(vector); } catch (TianShuException unused) { try { TianShuAPI.r(vector); } catch (TianShuException e10) { LogUtils.e("SyncUtil", e10); z10 = false; } } LogUtils.a("SyncUtil", "uploadDataLost2Server result=" + z10); return z10; } public static String g0(Context context) { return AccountPreference.e(); } public static boolean g1(Context context, ArrayList<Long> arrayList) { boolean z10 = false; if (arrayList != null) { if (arrayList.size() == 0) { return z10; } Cursor query = context.getContentResolver().query(Documents.Signature.f28721a, new String[]{"signature_path"}, "image_id in (" + DBUtil.h(arrayList) + ")", null, null); if (query != null && query.getCount() > 0) { z10 = true; } if (query != null) { query.close(); } } return z10; } public static DataRevertJson g2() { try { return DataRevertJson.d(TianShuAPI.N()); } catch (TianShuException e10) { LogUtils.e("SyncUtil", e10); try { return DataRevertJson.d(TianShuAPI.N()); } catch (TianShuException e11) { LogUtils.e("SyncUtil", e11); return null; } } } public static UploadState g3(Vector vector, String str, TianShuAPI.OnProgressListener onProgressListener, String str2, boolean z10, boolean z11) throws TianShuException { return TianShuAPI.G2(vector, str, onProgressListener, false, str2, z10, z11); } public static List<String> h0(Context context, long j2) { Cursor query; ArrayList arrayList = new ArrayList(); if (j2 > 0 && (query = context.getContentResolver().query(ContentUris.withAppendedId(Documents.Image.f28706c, j2), new String[]{"_data", "raw_data", "ocr_border", "image_backup", "thumb_data"}, null, null, null)) != null) { if (query.moveToFirst()) { for (int i10 = 0; i10 < 5; i10++) { arrayList.add(query.getString(i10)); } } query.close(); } return arrayList; } /* JADX WARNING: Removed duplicated region for block: B:18:0x004a */ public static boolean h1(long j2) { Cursor query = ApplicationHelper.f39908b.getContentResolver().query(Documents.Image.a(j2), new String[]{"count(_id)"}, "sync_jpage_state<>0 and sync_jpage_state<>5 and sync_state<>0 and sync_state<>5", null, null); boolean z10 = false; if (query != null) { try { if (query.moveToFirst() && query.getInt(0) <= 0) { z10 = true; if (query != null) { query.close(); } LogUtils.a("SyncUtil", "isDocAllPageSynced=" + z10 + " docId=" + j2); return z10; } } catch (Throwable th) { th.addSuppressed(th); } } if (query != null) { } LogUtils.a("SyncUtil", "isDocAllPageSynced=" + z10 + " docId=" + j2); return z10; throw th; } public static void h2() { BalanceInfo balanceInfo; BalanceInfo.UserDirInfo userDirInfo; CSQueryProperty q10 = UserPropertyAPI.q("CamScanner_DirNum"); if (!(q10 == null || (balanceInfo = q10.data) == null || (userDirInfo = balanceInfo.dir) == null)) { PreferenceHelper.Ee(userDirInfo.user_total_num); } } public static Future<UploadImageResponse> h3(Context context, long j2, SyncApi.SyncProgress syncProgress, String str, String str2, boolean z10, ShareDirDBData shareDirDBData) { return j3(context, j2, syncProgress, false, false, null, str, str2, z10, shareDirDBData); } public static long i0(Context context, long j2) { long j10; Cursor query = context.getContentResolver().query(ContentUris.withAppendedId(Documents.Document.f28692a, j2), new String[]{"modified"}, null, null, null); if (query != null) { j10 = query.moveToFirst() ? query.getLong(0) : 0; query.close(); } else { j10 = 0; } if (j10 <= 0) { j10 = System.currentTimeMillis(); } return j10; } public static boolean i1(Context context, long j2) { boolean z10 = false; if (j2 <= 0) { return false; } Cursor query = context.getContentResolver().query(Documents.Image.f28706c, new String[]{ao.f45476d}, "document_id = " + j2, null, null); if (query != null) { int count = query.getCount(); if (count == 0) { z10 = true; } query.close(); LogUtils.a("SyncUtil", "deleteDoc docId=" + j2 + " image count=" + count); } if (z10 || J0(context) >= 0) { return z10; } return true; } public static String i2(Context context, String str, String str2) throws TianShuException { String str3 = null; if (!TextUtils.isEmpty(str2)) { long J0 = J0(context); if (str2.equals(I0(context)) && J0 > 0) { Cursor query = context.getContentResolver().query(Documents.SyncAccount.f28723a, new String[]{"account_uid"}, "_id=" + J0, null, null); if (query != null) { if (query.moveToFirst()) { str3 = query.getString(0); } query.close(); } } if (TextUtils.isEmpty(str3)) { String str4 = !str2.contains("@") ? "mobile" : "email"; if (TextUtils.isEmpty(str)) { str = PhoneUtil.b(context); } str3 = TianShuAPI.N1(str4, str2, str, f0(context)); } } LogUtils.a("SyncUtil", "queryUserId uid=" + str3); return str3; } public static Future<UploadImageResponse> i3(Context context, long j2, SyncApi.SyncProgress syncProgress, boolean z10, boolean z11, String str, ShareDirDBData shareDirDBData) { return j3(context, j2, syncProgress, z10, z11, str, null, null, false, shareDirDBData); } public static void j(Context context, long j2) { k(context, j2, null); } /* JADX WARNING: Code restructure failed: missing block: B:24:0x00bc, code lost: r1 = null; */ public static String j0(Context context, ArrayList<Long> arrayList) { String str = null; if (arrayList != null && arrayList.size() > 0) { StringBuilder sb2 = new StringBuilder(); Iterator<Long> it = arrayList.iterator(); while (true) { if (it.hasNext()) { Cursor query = context.getContentResolver().query(ContentUris.withAppendedId(Documents.Document.f28692a, it.next().longValue()), new String[]{"sync_extra_data2", "title"}, null, null, null); if (query != null) { if (!query.moveToFirst()) { query.close(); break; } String d22 = d2(query.getString(0)); if (TextUtils.isEmpty(d22)) { query.close(); break; } if (sb2.length() > 0) { sb2.append("\n"); } if (arrayList.size() == 1) { sb2.append(d22); } else { sb2.append(query.getString(1) + "\n" + d22); } query.close(); } else { break; } } else { break; } } if (sb2 != null) { str = sb2.toString(); } } LogUtils.a("SyncUtil", "getDocPdfShareLink pdfLink=" + str); return str; } public static boolean j1(Context context, long j2, String str, boolean z10) { String str2; long currentTimeMillis = System.currentTimeMillis(); boolean z11 = false; if (context != null && j2 > 0) { Uri a10 = Documents.Image.a(j2); String str3 = ""; if (TextUtils.isEmpty(str)) { str2 = str3; } else { str2 = " and _id in " + str; } if (z10) { str3 = " and sync_jpg_error_type = 0"; } Cursor query = context.getContentResolver().query(a10, new String[]{"count(_id)"}, "sync_timestamp < 0" + str2 + str3, null, null); if (query != null) { if (query.moveToFirst() && query.getInt(0) <= 0) { z11 = true; } query.close(); } } LogUtils.a("SyncUtil", "isDocImageJpgComplete result=" + z11 + " doc id=" + j2 + " costTime=" + (System.currentTimeMillis() - currentTimeMillis)); return z11; } public static void j2(Context context, long j2) { if (context != null && j2 > 0) { ContentResolver contentResolver = context.getContentResolver(); Uri uri = Documents.Graphics.f28702a; int delete = contentResolver.delete(uri, "image_id=?", new String[]{j2 + ""}); LogUtils.a("SyncUtil", "removeInk result = " + delete + ", pageId = " + j2); } } public static Future<UploadImageResponse> j3(Context context, long j2, SyncApi.SyncProgress syncProgress, boolean z10, boolean z11, String str, String str2, String str3, boolean z12, ShareDirDBData shareDirDBData) { Context context2 = context; SyncState syncState = new SyncState(); ContentResolver contentResolver = context.getContentResolver(); ContentValues contentValues = new ContentValues(); contentValues.put("sync_ui_state", (Integer) 2); e0 e0Var = null; int update = contentResolver.update(ContentUris.withAppendedId(Documents.Image.f28705b, j2), contentValues, "sync_state = 1 OR sync_state = 3", null); float f10 = 100.0f; if (update < 1) { if (syncProgress != null) { syncState.l(100.0f); syncProgress.a(syncState); } return CustomExecutor.k().submit(c0.f52746a); } char c9 = 0; boolean[] zArr = {true}; List<UploadLocalImageInfo> y02 = y0(context2, j2, T0(context, j2), zArr); if (y02.size() == 0) { if (syncProgress != null) { syncState.l(100.0f); syncProgress.a(syncState); } return CustomExecutor.k().submit(c0.f52746a); } float f11 = 0.0f; if (z10) { f10 = 40.0f; f11 = 60.0f; } float size = f10 / ((float) y02.size()); if (syncProgress != null) { syncState.l(f11); syncProgress.a(syncState); } TianShuException[] tianShuExceptionArr = {null}; boolean[] zArr2 = {true}; ExecutorService V0 = V0(TextUtils.isEmpty(str2)); ArrayList arrayList = new ArrayList(); Semaphore semaphore = new Semaphore(10); Iterator<UploadLocalImageInfo> it = y02.iterator(); while (true) { if (!it.hasNext()) { break; } UploadLocalImageInfo next = it.next(); if (SyncThread.f34994t) { break; } else if (!zArr2[c9]) { LogUtils.a("SyncUtil", "storage is low"); break; } else if (tianShuExceptionArr[c9] != null) { LogUtils.a("SyncUtil", "hasExceptions"); break; } else { UploadImageFileCallable uploadImageFileCallable = new UploadImageFileCallable(); uploadImageFileCallable.f35078n = shareDirDBData; uploadImageFileCallable.f35076l = context2; uploadImageFileCallable.f35072h = str; uploadImageFileCallable.f35066b = tianShuExceptionArr; uploadImageFileCallable.f35067c = zArr2; uploadImageFileCallable.f35071g = z11; uploadImageFileCallable.f35070f = z12; uploadImageFileCallable.f35068d = str2; uploadImageFileCallable.f35069e = str3; uploadImageFileCallable.f35073i = size; uploadImageFileCallable.f35074j = syncProgress; uploadImageFileCallable.f35075k = syncState; uploadImageFileCallable.f35065a = next; uploadImageFileCallable.f35077m = semaphore; arrayList.add(V0.submit(uploadImageFileCallable)); c9 = 0; e0Var = null; context2 = context; } } return CustomExecutor.k().submit(new a0(arrayList, tianShuExceptionArr, syncProgress, syncState, zArr)); } public static void k(Context context, long j2, String str) { String str2; ContentResolver contentResolver = context.getContentResolver(); Cursor query = contentResolver.query(ContentUris.withAppendedId(Documents.Image.f28704a, j2), new String[]{ao.f45476d, "_data", "image_backup", "sync_image_id", "last_modified"}, null, null, null); if (query != null) { if (query.moveToFirst()) { boolean z10 = false; query.getLong(0); String string = query.getString(1); String string2 = query.getString(2); String string3 = query.getString(3); if (!TextUtils.isEmpty(string2) && new File(string2).exists()) { z10 = true; } if (!z10) { if (TextUtils.isEmpty(str)) { str2 = W(string3 + ".jpg"); } else { str2 = W(str); } string2 = str2; LogUtils.a("SyncUtil", "addInk2Image copyNoInkImage=" + FileUtil.h(string, string2) + ", noInkImagePath=" + string2 + ", from " + string); } ContentValues contentValues = new ContentValues(); contentValues.put("image_backup", string2); contentValues.put("last_modified", Long.valueOf(query.getLong(4))); contentResolver.update(ContentUris.withAppendedId(Documents.Image.f28704a, j2), contentValues, null, null); N2(context, j2, string, string2); } query.close(); } } public static ArrayList<DocShareLinkInfo> k0(Context context, ArrayList<String> arrayList, ArrayList<String> arrayList2, String str, int i10, String str2, long j2, int i11) { Pair<Boolean, String> J1; Object obj; boolean c9 = ShareSignatureLinkHelper.c(context, arrayList, arrayList2); if (arrayList2 != null && !arrayList2.isEmpty()) { return (arrayList == null || arrayList.size() <= 0 || arrayList2.size() <= 1) ? p0(arrayList2, true, str, i10, str2, j2, i11, c9, context) : o0(arrayList.get(0), arrayList2, str, i10, str2, j2, i11, c9, context); } if (arrayList.size() > 1) { String[] B0 = DBUtil.B0(context, arrayList); if (B0.length == arrayList.size() && (obj = (J1 = J1(B0)).first) != null && ((Boolean) obj).booleanValue()) { return n0(arrayList, str, i10, str2, j2, (String) J1.second, i11, c9, context); } } return p0(arrayList, false, str, i10, str2, j2, i11, c9, context); } public static boolean k1(Context context, long j2) { return l1(context, j2, null, false); } public static void k2(int i10) { NotificationHelper.getInstance().cancelNotification(i10); } /* JADX WARNING: Code restructure failed: missing block: B:28:0x0130, code lost: r20 = r8; */ /* JADX WARNING: Code restructure failed: missing block: B:41:0x0151, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:42:0x0152, code lost: r5 = r20; */ /* JADX WARNING: Code restructure failed: missing block: B:55:0x016f, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:59:0x0178, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:60:0x0179, code lost: r5 = r20; */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Removed duplicated region for block: B:55:0x016f A[ExcHandler: Exception (e java.lang.Exception), Splitter:B:33:0x0142] */ /* JADX WARNING: Removed duplicated region for block: B:59:0x0178 A[ExcHandler: InterruptedException (e java.lang.InterruptedException), Splitter:B:33:0x0142] */ public static UploadImageResponse k3(Context context, SyncApi.SyncProgress syncProgress, String str, LongSparseArray<String> longSparseArray, boolean z10, ShareDirDBData shareDirDBData) throws TianShuException { String str2; InterruptedException e10; Context context2 = context; HashMap hashMap = new HashMap(); Y1(context2, str, hashMap); SyncState syncState = new SyncState(); String D0 = DBUtil.D0(context2, str, false, shareDirDBData.a(), shareDirDBData.b()); String str3 = "SyncUtil"; LogUtils.a(str3, "uploadLocalRawImage2Server teamToken=" + str + " allDocIdString=" + D0 + " duuid=" + shareDirDBData.a()); UploadImageResponse uploadImageResponse = new UploadImageResponse(); if (TextUtils.isEmpty(D0)) { return uploadImageResponse; } boolean[] zArr = {true}; List<UploadRawImageInfo> S = S(U0(context2, D0), zArr); if (S.size() == 0) { LogUtils.a(str3, "uploadRawImageInfoList is empty"); return uploadImageResponse; } if (syncProgress != null) { syncState.l(0.0f); syncProgress.a(syncState); } float size = 100.0f / ((float) S.size()); boolean[] zArr2 = {true}; TianShuException[] tianShuExceptionArr = new TianShuException[1]; boolean[] zArr3 = {false}; ExecutorService V0 = V0(TextUtils.isEmpty(str)); ArrayList<Future> arrayList = new ArrayList(); Semaphore semaphore = new Semaphore(10); Iterator<UploadRawImageInfo> it = S.iterator(); while (true) { if (!it.hasNext()) { break; } UploadRawImageInfo next = it.next(); if (SyncThread.f34994t || SyncThread.Z()) { String str4 = str3; uploadImageResponse.f35149c = false; } else if (!zArr2[0]) { LogUtils.a(str3, "hasStorages false"); break; } else if (tianShuExceptionArr[0] != null) { LogUtils.a(str3, "hasExceptiolns"); break; } else if (!C1(context)) { LogUtils.a(str3, "uploadLocalRawImage2Server close raw jpg sync"); uploadImageResponse.f35149c = false; break; } else { UploadRawImageCallable uploadRawImageCallable = new UploadRawImageCallable(); uploadRawImageCallable.f35088a = context2; uploadRawImageCallable.f35089b = size; uploadRawImageCallable.f35091d = tianShuExceptionArr; uploadRawImageCallable.f35090c = zArr2; uploadRawImageCallable.f35094g = zArr3; uploadRawImageCallable.f35096i = syncProgress; uploadRawImageCallable.f35095h = syncState; uploadRawImageCallable.f35092e = str; uploadRawImageCallable.f35093f = z10; uploadRawImageCallable.f35098k = hashMap; uploadRawImageCallable.f35099l = longSparseArray; uploadRawImageCallable.f35097j = next; uploadRawImageCallable.f35100m = semaphore; arrayList.add(V0.submit(uploadRawImageCallable)); context2 = context; it = it; str3 = str3; } } String str42 = str3; uploadImageResponse.f35149c = false; for (Future future : arrayList) { try { UploadImageResponse uploadImageResponse2 = (UploadImageResponse) future.get(); if (!uploadImageResponse2.f35149c) { uploadImageResponse.f35149c = false; } if (uploadImageResponse2.f35151e) { try { uploadImageResponse.f35151e = true; } catch (InterruptedException e11) { e10 = e11; } catch (Exception e12) { Exception e13 = e12; str2 = str42; LogUtils.e(str2, e13); str42 = str2; } } str2 = str42; } catch (InterruptedException e14) { e10 = e14; str2 = str42; LogUtils.e(str2, e10); Thread.currentThread().interrupt(); str42 = str2; } catch (Exception e15) { } str42 = str2; } if (syncProgress != null) { syncState.l(100.0f); syncProgress.a(syncState); } if (!zArr[0]) { uploadImageResponse.f35149c = false; } return uploadImageResponse; } public static void l(Context context, long j2, boolean z10) { m(context, j2, z10, null); } private static ArrayList<DocShareLinkInfo> l0(String str, String str2, long j2, int i10, boolean z10, int i11, Context context) { String str3; JSONArray jSONArray; ArrayList<DocShareLinkInfo> arrayList = new ArrayList<>(); if (TextUtils.isEmpty(str)) { LogUtils.c("SyncUtil", "getDocShareLink invalid paras token = " + str2); str3 = null; } else { StringBuilder sb2 = new StringBuilder(); LogUtils.a("SyncUtil", "add_share postBody = " + str); try { String n12 = TianShuAPI.n1(str, z10); LogUtils.a("SyncUtil", "personAddShare = " + n12); int i12 = 1; if (n12 != null) { JSONObject jSONObject = new JSONObject(n12); JSONArray optJSONArray = jSONObject.optJSONArray("link_list"); int i13 = 0; if (optJSONArray != null && optJSONArray.length() > 0) { i12 = 0; } ShareRecorder.c(i10, i12, z10, i11, context); String optString = jSONObject.optString("dl_url"); if (optJSONArray != null) { while (i13 < optJSONArray.length()) { if (i13 > 0) { sb2.append("\n"); } JSONObject jSONObject2 = optJSONArray.getJSONObject(i13); DocShareLinkInfo docShareLinkInfo = new DocShareLinkInfo(); docShareLinkInfo.s(jSONObject2.optString("encrypt_id")); docShareLinkInfo.o(jSONObject2.optString("device_id")); docShareLinkInfo.x(jSONObject2.optInt("snapshot")); String optString2 = jSONObject2.optString("sid"); if (TextUtils.isEmpty(docShareLinkInfo.i())) { docShareLinkInfo.w(optString2); } String optString3 = jSONObject2.optString("encrypt"); if (!TextUtils.isEmpty(optString3)) { String a10 = AESEncUtil.a(optString3, AESEncUtil.EncType.SharePwd); StringBuilder sb3 = new StringBuilder(); jSONArray = optJSONArray; sb3.append("AES ori = "); sb3.append(optString3); sb3.append(" decrypt = "); sb3.append(a10); LogUtils.a("SyncUtil", sb3.toString()); docShareLinkInfo.n(a10); } else { jSONArray = optJSONArray; } String optString4 = jSONObject2.optString("link"); if (!TextUtils.isEmpty(optString4)) { docShareLinkInfo.A("1".equals(Uri.parse(optString4).getQueryParameter(AnalyticsEvents.PARAMETER_LIKE_VIEW_STYLE))); optString4 = optString4 + "&share_link_style=" + AppConfigJsonUtils.e().share_link_style; } docShareLinkInfo.p(optString); docShareLinkInfo.q(optString4); sb2.append(optString4); if (j2 > 0) { docShareLinkInfo.t(1000 * j2); } sb2.append("\n"); arrayList.add(docShareLinkInfo); i13++; optJSONArray = jSONArray; } } else { LogUtils.a("SyncUtil", "linkList is null"); } } else { ShareRecorder.c(i10, 1, z10, i11, context); } } catch (TianShuException e10) { ShareRecorder.c(i10, e10.getErrorCode(), z10, i11, context); } catch (JSONException e11) { LogUtils.e("SyncUtil", e11); ShareRecorder.c(i10, 2, z10, i11, context); } str3 = sb2.toString(); } LogUtils.a("SyncUtil", "getDocShareLink() " + str3); Iterator<DocShareLinkInfo> it = arrayList.iterator(); while (it.hasNext()) { it.next().r(str3); } return arrayList; } public static boolean l1(Context context, long j2, String str, boolean z10) { String str2; long currentTimeMillis = System.currentTimeMillis(); boolean z11 = false; if (context != null && j2 > 0) { Uri a10 = Documents.Image.a(j2); String str3 = ""; if (TextUtils.isEmpty(str)) { str2 = str3; } else { str2 = " and _id in " + str; } if (z10) { str3 = " and sync_jpg_error_type = 0"; } Cursor query = context.getContentResolver().query(a10, new String[]{"count(_id)"}, "sync_state = -1" + str2 + str3, null, null); if (query != null) { if (query.moveToFirst() && query.getInt(0) <= 0) { z11 = true; } query.close(); } } LogUtils.a("SyncUtil", "isDocImageJpgComplete result=" + z11 + " doc id=" + j2 + " costTime=" + (System.currentTimeMillis() - currentTimeMillis)); return z11; } public static boolean l2(Context context, long j2) { ContentResolver contentResolver = context.getContentResolver(); Uri uri = Documents.Signature.f28721a; StringBuilder sb2 = new StringBuilder(); sb2.append("image_id ="); sb2.append(j2); return contentResolver.delete(uri, sb2.toString(), null) > 0; } /* access modifiers changed from: private */ /* JADX WARNING: Code restructure failed: missing block: B:14:0x006c, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:15:0x006d, code lost: com.intsig.log.LogUtils.e("SyncUtil", r0); r0 = com.intsig.tianshu.TianShuAPI.I(r25, "CamScanner_Page", r13, null); */ /* JADX WARNING: Code restructure failed: missing block: B:35:0x00da, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:36:0x00db, code lost: com.intsig.log.LogUtils.e("SyncUtil", r0); */ /* JADX WARNING: Code restructure failed: missing block: B:37:0x00e6, code lost: if (r0.getErrorCode() == 302) goto L_0x00e8; */ /* JADX WARNING: Code restructure failed: missing block: B:39:?, code lost: w(); */ /* JADX WARNING: Code restructure failed: missing block: B:40:0x00ec, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:42:0x00f6, code lost: if (r0.getErrorCode() != 301) goto L_0x01c7; */ /* JADX WARNING: Code restructure failed: missing block: B:43:0x00f8, code lost: u2(r22); r0 = g3(r13, "CamScanner_Page", null, r27.a(), r2, false); */ /* JADX WARNING: Code restructure failed: missing block: B:60:0x01c7, code lost: throw r0; */ /* JADX WARNING: Code restructure failed: missing block: B:61:0x01c8, code lost: throw r0; */ /* JADX WARNING: Code restructure failed: missing block: B:65:0x01f4, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:66:0x01f5, code lost: r2 = com.intsig.camscanner.util.SDStorageManager.Z(); com.intsig.log.LogUtils.d("SyncUtil", "sync state=" + r23.f35083e + " sd card is " + r2 + " ", r0); */ /* JADX WARNING: Code restructure failed: missing block: B:67:0x021e, code lost: if (r2 == false) goto L_0x0220; */ /* JADX WARNING: Code restructure failed: missing block: B:68:0x0220, code lost: r26[0] = false; */ /* JADX WARNING: Code restructure failed: missing block: B:69:0x0223, code lost: r6 = true; */ /* JADX WARNING: Code restructure failed: missing block: B:71:?, code lost: return r6; */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Removed duplicated region for block: B:65:0x01f4 A[ExcHandler: FileNotFoundException (r0v0 'e' java.io.FileNotFoundException A[CUSTOM_DECLARE]), Splitter:B:1:0x000c] */ public static boolean l3(Context context, UploadLocalImageInfo uploadLocalImageInfo, boolean z10, String str, boolean[] zArr, ShareDirDBData shareDirDBData) throws TianShuException { int i10; boolean z11 = true; boolean z12 = false; try { if (!FileUtil.C(uploadLocalImageInfo.f35080b) || FileUtil.t(uploadLocalImageInfo.f35080b) <= 0) { LogUtils.a("SyncUtil", "uploadOneJpg2Server is not exists imagePath=" + uploadLocalImageInfo.f35080b + " size=" + FileUtil.t(uploadLocalImageInfo.f35080b)); return true; } String str2 = uploadLocalImageInfo.f35086h; if (z10) { str2 = CollaborateUtil.b(uploadLocalImageInfo.f35086h); } Vector vector = new Vector(); vector.add(new PageUploadAction(str2 + ".jpg", 0, "CamScanner_Page", uploadLocalImageInfo.f35081c, uploadLocalImageInfo.f35083e, uploadLocalImageInfo.f35080b)); if (z10) { int[] iArr = TianShuAPI.I(str, "CamScanner_Page", vector, null); if (iArr == null || iArr.length != 2) { LogUtils.a("SyncUtil", "uploadLocalImage2Server result is error"); } else if (iArr[0] <= 0) { LogUtils.a("SyncUtil", "uploadLocalImage2Server revision is error " + iArr[0]); } else if (iArr[1] > 0) { i10 = iArr[0]; } else { LogUtils.a("SyncUtil", "uploadLocalImage2Server results[1] =" + iArr[1]); } i10 = 0; } else { boolean z13 = shareDirDBData.b() == 1; UploadState uploadState = g3(vector, "CamScanner_Page", null, shareDirDBData.a(), z13, false); i10 = uploadState.c(); } if (i10 > 0) { ContentValues contentValues = new ContentValues(); Uri withAppendedId = ContentUris.withAppendedId(Documents.Image.f28706c, uploadLocalImageInfo.f35079a); if (z10) { contentValues.put("sync_state", (Integer) 0); } else { contentValues.put("sync_state", (Integer) 6); } if (uploadLocalImageInfo.f35083e == 3) { if (uploadLocalImageInfo.f35082d < 100) { uploadLocalImageInfo.f35082d++; } else { uploadLocalImageInfo.f35082d--; } contentValues.put("detail_index", Integer.valueOf(uploadLocalImageInfo.f35082d)); } contentValues.put("sync_ui_state", (Integer) 0); contentValues.put("sync_timestamp", Long.valueOf(System.currentTimeMillis())); contentValues.put("sync_version", Integer.valueOf(i10)); contentValues.put("cache_state", (Integer) 0); context.getContentResolver().update(withAppendedId, contentValues, null, null); } else { FileUtil.t(uploadLocalImageInfo.f35080b); z11 = false; } LogUtils.a("SyncUtil", "version=" + i10 + " result=" + z11 + " shareDirDBData:" + shareDirDBData.toString()); return z11; } catch (FileNotFoundException e10) { } catch (TianShuException e11) { throw e11; } } public static void m(Context context, long j2, boolean z10, String str) { String str2; String str3; ContentResolver contentResolver = context.getContentResolver(); Cursor query = contentResolver.query(ContentUris.withAppendedId(Documents.Image.f28704a, j2), new String[]{ao.f45476d, "_data", "image_backup", "sync_image_id", "last_modified"}, null, null, null); if (query != null) { if (query.moveToFirst()) { boolean z11 = false; long j10 = query.getLong(0); String string = query.getString(1); String string2 = query.getString(2); String string3 = query.getString(3); if (!TextUtils.isEmpty(string2) && new File(string2).exists()) { z11 = true; } if (!z11) { if (TextUtils.isEmpty(str)) { str3 = W(string3 + ".jpg"); } else { str3 = W(str); } FileUtil.h(string, str3); str2 = str3; } else { str2 = string2; } ContentValues contentValues = new ContentValues(); contentValues.put("image_backup", str2); contentValues.put("last_modified", Long.valueOf(query.getLong(4))); contentResolver.update(ContentUris.withAppendedId(Documents.Image.f28704a, j2), contentValues, null, null); S2(context, contentResolver, j10, string, str2, z10); } query.close(); } } /* JADX WARNING: Removed duplicated region for block: B:17:0x006f */ /* JADX WARNING: Removed duplicated region for block: B:38:0x00d0 */ /* JADX WARNING: Removed duplicated region for block: B:42:0x00f7 A[Catch:{ TianShuException | JSONException -> 0x0199 }] */ /* JADX WARNING: Removed duplicated region for block: B:56:0x0193 */ /* JADX WARNING: Removed duplicated region for block: B:66:0x00b1 A[EDGE_INSN: B:66:0x00b1->B:36:0x00b1 ?: BREAK , SYNTHETIC] */ public static ArrayList<DocShareLinkInfo> m0(Context context, ArrayList<String> arrayList, boolean z10, String str, String str2, int i10, String str3, long j2) { String str4; String str5; Iterator<String> it; String str6; String str7; JSONArray optJSONArray; String str8; String str9; JSONException e10; ArrayList<DocShareLinkInfo> arrayList2 = new ArrayList<>(); if (arrayList == null || TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) { LogUtils.c("SyncUtil", "getDocShareLinkForTeam invalid paras token = " + str + "teamToken =" + str2); str4 = null; } else { StringBuilder sb2 = new StringBuilder(); boolean z11 = true; if (i10 == 1 && !TextUtils.isEmpty(str3)) { String d10 = AppUtil.d(str3 + "_IntSig_Share"); if (!TextUtils.isEmpty(d10)) { str5 = d10.substring(0, d10.length() / 2); JSONArray jSONArray = new JSONArray(); it = arrayList.iterator(); long j10 = j2; while (true) { str6 = "encrypt"; str7 = "doc_id"; if (it.hasNext()) { break; } String next = it.next(); JSONObject jSONObject = new JSONObject(); if (z10) { str7 = "page_id"; } try { jSONObject.put(str7, next); if (i10 == 2 && PreferenceHelper.di()) { try { jSONObject.put("need_encrypt", 1); j10 = v(); } catch (JSONException e11) { e10 = e11; LogUtils.e("SyncUtil", e10); z11 = true; } } jSONObject.put(str6, str5); jSONObject.put("dead_time", j10); jSONArray.put(jSONObject); } catch (JSONException e12) { e10 = e12; LogUtils.e("SyncUtil", e10); z11 = true; } z11 = true; } String jSONArray2 = jSONArray.toString(); LogUtils.a("SyncUtil", " postBody = " + jSONArray2); if (DBUtil.b2(context, str2) != 2) { z11 = false; } String p22 = TianShuAPI.p2(str2, jSONArray2, z11); LogUtils.a("SyncUtil", " teamAddShare = " + p22); optJSONArray = new JSONObject(p22).optJSONArray("link_list"); if (optJSONArray == null) { int i11 = 0; while (i11 < optJSONArray.length()) { if (i11 > 0) { sb2.append("\n"); } String optString = optJSONArray.getJSONObject(i11).optString(str7); DocShareLinkInfo docShareLinkInfo = new DocShareLinkInfo(); String optString2 = optJSONArray.getJSONObject(i11).optString(str6); if (!TextUtils.isEmpty(optString2)) { String a10 = AESEncUtil.a(optString2, AESEncUtil.EncType.SharePwd); str9 = str7; StringBuilder sb3 = new StringBuilder(); str8 = str6; sb3.append("AES ori = "); sb3.append(optString2); sb3.append(" decrypt = "); sb3.append(a10); LogUtils.a("SyncUtil", sb3.toString()); docShareLinkInfo.n(a10); } else { str9 = str7; str8 = str6; } docShareLinkInfo.u(z11); String Y0 = DBUtil.Y0(context, optString); String optString3 = optJSONArray.getJSONObject(i11).optString("link"); docShareLinkInfo.q(optString3); sb2.append(Y0 + "\n" + optString3); if (j10 > 0) { docShareLinkInfo.t(1000 * j10); } sb2.append("\n"); arrayList2.add(docShareLinkInfo); i11++; str7 = str9; str6 = str8; } } else { LogUtils.a("SyncUtil", "linkList is null"); } str4 = sb2.toString(); } } str5 = ""; JSONArray jSONArray3 = new JSONArray(); it = arrayList.iterator(); long j102 = j2; while (true) { str6 = "encrypt"; str7 = "doc_id"; if (it.hasNext()) { } z11 = true; } String jSONArray22 = jSONArray3.toString(); LogUtils.a("SyncUtil", " postBody = " + jSONArray22); if (DBUtil.b2(context, str2) != 2) { } try { String p222 = TianShuAPI.p2(str2, jSONArray22, z11); LogUtils.a("SyncUtil", " teamAddShare = " + p222); optJSONArray = new JSONObject(p222).optJSONArray("link_list"); if (optJSONArray == null) { } } catch (TianShuException | JSONException e13) { LogUtils.e("SyncUtil", e13); } str4 = sb2.toString(); } LogUtils.a("SyncUtil", "getDocShareLinkForTeam() " + str4); Iterator<DocShareLinkInfo> it2 = arrayList2.iterator(); while (it2.hasNext()) { it2.next().r(str4); } return arrayList2; } public static boolean m1(Context context) { return AccountPreference.G(); } public static void m2(Context context, long j2) { if (context != null && j2 > 0) { int delete = context.getContentResolver().delete(ContentUris.withAppendedId(Documents.PageMark.f28717b, j2), null, null); LogUtils.a("SyncUtil", "deleteWarterMark: " + delete + ", pageid = " + j2); } } /* access modifiers changed from: private */ /* JADX WARNING: Code restructure failed: missing block: B:21:0x0100, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:22:0x0101, code lost: com.intsig.log.LogUtils.e("SyncUtil", r0); */ /* JADX WARNING: Code restructure failed: missing block: B:23:0x0105, code lost: throw r0; */ /* JADX WARNING: Code restructure failed: missing block: B:27:0x0131, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:28:0x0132, code lost: r5 = com.intsig.camscanner.util.SDStorageManager.Z(); com.intsig.log.LogUtils.d("SyncUtil", "sync state=" + r15.f35083e + " sd card is " + r5, r0); */ /* JADX WARNING: Code restructure failed: missing block: B:29:0x0156, code lost: if (r5 == false) goto L_0x0158; */ /* JADX WARNING: Code restructure failed: missing block: B:30:0x0158, code lost: r16[0] = false; */ /* JADX WARNING: Code restructure failed: missing block: B:31:0x015b, code lost: r4 = true; */ /* JADX WARNING: Code restructure failed: missing block: B:33:?, code lost: return r4; */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Removed duplicated region for block: B:27:0x0131 A[ExcHandler: FileNotFoundException (r0v0 'e' java.io.FileNotFoundException A[CUSTOM_DECLARE]), Splitter:B:1:0x0007] */ public static boolean m3(Context context, UploadLocalImageInfo uploadLocalImageInfo, boolean[] zArr, String str, String str2, boolean z10) throws TianShuException { boolean z11 = true; boolean z12 = false; try { if (!FileUtil.C(uploadLocalImageInfo.f35080b) || FileUtil.t(uploadLocalImageInfo.f35080b) <= 0) { LogUtils.a("SyncUtil", "uploadOneTeamJpg2Server is not exists imagePath=" + uploadLocalImageInfo.f35080b + " size=" + FileUtil.t(uploadLocalImageInfo.f35080b)); return true; } Vector vector = new Vector(); vector.add(new PageUploadAction(uploadLocalImageInfo.f35086h + ".jpg", 0, "CamScanner_Page", uploadLocalImageInfo.f35081c, uploadLocalImageInfo.f35083e, uploadLocalImageInfo.f35080b)); int r32 = r3(vector, null, str, str2, z10); if (r32 > 0) { ContentValues contentValues = new ContentValues(); Uri withAppendedId = ContentUris.withAppendedId(Documents.Image.f28706c, uploadLocalImageInfo.f35079a); contentValues.put("sync_state", (Integer) 6); if (uploadLocalImageInfo.f35083e == 3) { if (uploadLocalImageInfo.f35082d < 100) { uploadLocalImageInfo.f35082d++; } else { uploadLocalImageInfo.f35082d--; } contentValues.put("detail_index", Integer.valueOf(uploadLocalImageInfo.f35082d)); } contentValues.put("sync_ui_state", (Integer) 0); contentValues.put("sync_timestamp", Long.valueOf(System.currentTimeMillis())); contentValues.put("sync_version", Integer.valueOf(r32)); contentValues.put("cache_state", (Integer) 0); context.getContentResolver().update(withAppendedId, contentValues, null, null); } else { FileUtil.t(uploadLocalImageInfo.f35080b); z11 = false; } LogUtils.a("SyncUtil", "version=" + r32 + " result=" + z11); return z11; } catch (FileNotFoundException e10) { } catch (TianShuException e11) { throw e11; } } public static boolean n(String str) { boolean z10 = true; try { TianShuAPI.o(str); } catch (TianShuException e10) { if (e10.getErrorCode() != 350) { z10 = false; } LogUtils.e("SyncUtil", e10); } return z10; } /* JADX WARNING: Removed duplicated region for block: B:14:0x0053 A[SYNTHETIC, Splitter:B:14:0x0053] */ /* JADX WARNING: Removed duplicated region for block: B:24:0x0088 */ /* JADX WARNING: Removed duplicated region for block: B:25:0x008c */ /* JADX WARNING: Removed duplicated region for block: B:28:0x009f */ /* JADX WARNING: Removed duplicated region for block: B:32:0x00b7 */ /* JADX WARNING: Removed duplicated region for block: B:38:0x00e5 */ private static ArrayList<DocShareLinkInfo> n0(ArrayList<String> arrayList, String str, int i10, String str2, long j2, String str3, int i11, boolean z10, Context context) { int i12; long j10; String str4; long j11; JSONException e10; String str5; ShareDirDBData m10; Iterator<String> it; int i13 = 0; if (arrayList == null) { LogUtils.c("SyncUtil", "getDocShareLink invalid paras token = " + str); j10 = j2; str4 = null; i12 = 0; } else { JSONArray jSONArray = new JSONArray(); JSONObject jSONObject = new JSONObject(); if (i10 == 2) { try { if (PreferenceHelper.di()) { jSONObject.put("need_encrypt", 1); j11 = v(); if (i10 == 1) { try { if (!TextUtils.isEmpty(str2)) { String d10 = AppUtil.d(str2 + "_IntSig_Share"); if (!TextUtils.isEmpty(d10)) { str5 = d10.substring(0, d10.length() / 2); if (TextUtils.isEmpty(str3)) { jSONObject.put("dir_id", ""); } else { jSONObject.put("dir_id", str3); } m10 = ShareDirDao.m(ApplicationHelper.f39908b, str3); if (!TextUtils.isEmpty(m10.a())) { jSONObject.put("duuid", m10.a()); } StringBuilder sb2 = new StringBuilder(); it = arrayList.iterator(); while (it.hasNext()) { String next = it.next(); i13 += DBUtil.L0(next); if (sb2.length() > 0) { sb2.append(PreferencesConstants.COOKIE_DELIMITER); } sb2.append(next); } jSONObject.put("docs", sb2.toString()); jSONObject.put("encrypt", str5); if (!TextUtils.isEmpty(str)) { jSONObject.put("dead_time", j11); } jSONArray.put(jSONObject); str4 = jSONArray.toString(); j10 = j11; i12 = i13; } } } catch (JSONException e11) { e10 = e11; LogUtils.e("SyncUtil", e10); str4 = jSONArray.toString(); j10 = j11; i12 = i13; return l0(str4, str, j10, i11, z10, i12, context); } } str5 = ""; if (TextUtils.isEmpty(str3)) { } m10 = ShareDirDao.m(ApplicationHelper.f39908b, str3); if (!TextUtils.isEmpty(m10.a())) { } StringBuilder sb22 = new StringBuilder(); it = arrayList.iterator(); while (it.hasNext()) { } jSONObject.put("docs", sb22.toString()); jSONObject.put("encrypt", str5); if (!TextUtils.isEmpty(str)) { } jSONArray.put(jSONObject); str4 = jSONArray.toString(); j10 = j11; i12 = i13; } } catch (JSONException e12) { e10 = e12; j11 = j2; LogUtils.e("SyncUtil", e10); str4 = jSONArray.toString(); j10 = j11; i12 = i13; return l0(str4, str, j10, i11, z10, i12, context); } } j11 = j2; if (i10 == 1) { } str5 = ""; if (TextUtils.isEmpty(str3)) { } m10 = ShareDirDao.m(ApplicationHelper.f39908b, str3); if (!TextUtils.isEmpty(m10.a())) { } StringBuilder sb222 = new StringBuilder(); it = arrayList.iterator(); while (it.hasNext()) { } jSONObject.put("docs", sb222.toString()); jSONObject.put("encrypt", str5); if (!TextUtils.isEmpty(str)) { } jSONArray.put(jSONObject); str4 = jSONArray.toString(); j10 = j11; i12 = i13; } return l0(str4, str, j10, i11, z10, i12, context); } public static boolean n1(String str) { if (!TextUtils.isEmpty(str)) { return new File(str).exists(); } return false; } public static String n2(String str) { String str2 = str; if (str2 != null) { while (str2.indexOf("\\") != -1) { int indexOf = str2.indexOf("\\"); str2 = str2.substring(0, indexOf) + str2.substring(indexOf + 1, str2.length()); } } return str2; } public static int n3(String str, String str2, String str3, String str4, int i10) { int i11 = 1; try { TianShuAPI.J2(new FileInputStream(str), str2, i10, str3, str4, null); } catch (FileNotFoundException e10) { try { LogUtils.e("SyncUtil", e10); i11 = -1; } catch (TianShuException e11) { LogUtils.e("SyncUtil", e11); try { TianShuAPI.J2(new FileInputStream(str), str2, i10, str3, str4, null); } catch (FileNotFoundException e12) { try { LogUtils.e("SyncUtil", e12); i11 = -1; } catch (TianShuException unused) { i11 = e11.getErrorCode(); } } } } LogUtils.a("SyncUtil", "uploadPDF2Server size=" + i10); LogUtils.a("SyncUtil", "uploadPDF2Server result=" + i11 + "\n" + str); return i11; } /* JADX WARNING: Code restructure failed: missing block: B:15:0x0069, code lost: if (r12.moveToFirst() == false) goto L_0x00b7; */ /* JADX WARNING: Code restructure failed: missing block: B:17:0x0071, code lost: if (r12.getInt(1) != 1) goto L_0x0076; */ /* JADX WARNING: Code restructure failed: missing block: B:19:0x0074, code lost: r2 = r12; */ /* JADX WARNING: Code restructure failed: missing block: B:21:0x007c, code lost: if (r12.getInt(0) == 0) goto L_0x0080; */ /* JADX WARNING: Code restructure failed: missing block: B:23:0x0080, code lost: r12 = r12.query(android.content.ContentUris.withAppendedId(com.intsig.camscanner.provider.Documents.Image.f28705b, r10.longValue()), new java.lang.String[]{"sync_jpage_state"}, "sync_state != 0", null, null); */ /* JADX WARNING: Code restructure failed: missing block: B:24:0x00a2, code lost: if (r12 == null) goto L_0x00b7; */ /* JADX WARNING: Code restructure failed: missing block: B:26:0x00aa, code lost: if (r12.getCount() <= 0) goto L_0x00b2; */ /* JADX WARNING: Code restructure failed: missing block: B:27:0x00ac, code lost: r12.close(); */ /* JADX WARNING: Code restructure failed: missing block: B:28:0x00b2, code lost: r12.close(); */ /* JADX WARNING: Code restructure failed: missing block: B:42:0x00b7, code lost: continue; */ public static boolean o(Context context, ArrayList<Long> arrayList) { Cursor cursor; Cursor query; boolean z10 = false; if (t1(context) && Util.t0(context) && arrayList != null && !arrayList.isEmpty()) { ContentResolver contentResolver = context.getContentResolver(); String[] strArr = {"sync_state", "belong_state"}; Iterator<Long> it = arrayList.iterator(); loop0: while (true) { cursor = null; while (true) { if (!it.hasNext()) { z10 = true; break loop0; } Long next = it.next(); query = contentResolver.query(ContentUris.withAppendedId(Documents.Document.f28692a, next.longValue()), strArr, null, null, null); if (query != null) { break; } cursor = query; } query.close(); } if (cursor != null) { cursor.close(); } } LogUtils.a("SyncUtil", "isDocsInServer result=" + z10); return z10; } /* JADX WARNING: Removed duplicated region for block: B:14:0x005c A[LOOP:0: B:12:0x0056->B:14:0x005c, LOOP_END] */ /* JADX WARNING: Removed duplicated region for block: B:17:0x0071 */ /* JADX WARNING: Removed duplicated region for block: B:29:0x00ab A[Catch:{ JSONException -> 0x00d2 }] */ /* JADX WARNING: Removed duplicated region for block: B:32:0x00c9 A[Catch:{ JSONException -> 0x00d2 }] */ /* JADX WARNING: Removed duplicated region for block: B:37:0x00f2 */ private static ArrayList<DocShareLinkInfo> o0(String str, ArrayList<String> arrayList, String str2, int i10, String str3, long j2, int i11, boolean z10, Context context) { long j10; String str4; String str5; StringBuilder sb2; Iterator<String> it; long j11; JSONException e10; ShareDirDBData o10; if (TextUtils.isEmpty(str) || arrayList == null) { LogUtils.c("SyncUtil", "getDocShareLinkMultiPage invalid paras token = " + str2); } else { if (i10 == 1 && !TextUtils.isEmpty(str3)) { String d10 = AppUtil.d(str3 + "_IntSig_Share"); if (!TextUtils.isEmpty(d10)) { str5 = d10.substring(0, d10.length() / 2); JSONArray jSONArray = new JSONArray(); sb2 = new StringBuilder(); it = arrayList.iterator(); while (it.hasNext()) { sb2.append(it.next()); sb2.append(PreferencesConstants.COOKIE_DELIMITER); } if (sb2.length() <= 0) { String str6 = sb2.substring(0, sb2.length() - 1).toString(); JSONObject jSONObject = new JSONObject(); if (i10 == 2) { try { if (PreferenceHelper.di()) { jSONObject.put("need_encrypt", 1); j11 = v(); o10 = ShareDirDao.o(ApplicationHelper.f39908b, str); if (!TextUtils.isEmpty(o10.a())) { jSONObject.put("duuid", o10.a()); } jSONObject.put(d.f45658t, str6); jSONObject.put("doc_id", str); jSONObject.put("encrypt", str5); if (!TextUtils.isEmpty(str2)) { jSONObject.put("dead_time", j11); } jSONArray.put(jSONObject); String jSONArray2 = jSONArray.toString(); LogUtils.c("SyncUtil", "getDocShareLinkMultiPage postBody = " + jSONArray2); j10 = j11; str4 = jSONArray2; return l0(str4, str2, j10, i11, z10, arrayList.size(), context); } } catch (JSONException e11) { e10 = e11; j11 = j2; LogUtils.e("SyncUtil", e10); String jSONArray22 = jSONArray.toString(); LogUtils.c("SyncUtil", "getDocShareLinkMultiPage postBody = " + jSONArray22); j10 = j11; str4 = jSONArray22; return l0(str4, str2, j10, i11, z10, arrayList.size(), context); } } j11 = j2; try { o10 = ShareDirDao.o(ApplicationHelper.f39908b, str); if (!TextUtils.isEmpty(o10.a())) { } jSONObject.put(d.f45658t, str6); jSONObject.put("doc_id", str); jSONObject.put("encrypt", str5); if (!TextUtils.isEmpty(str2)) { } jSONArray.put(jSONObject); } catch (JSONException e12) { e10 = e12; LogUtils.e("SyncUtil", e10); String jSONArray222 = jSONArray.toString(); LogUtils.c("SyncUtil", "getDocShareLinkMultiPage postBody = " + jSONArray222); j10 = j11; str4 = jSONArray222; return l0(str4, str2, j10, i11, z10, arrayList.size(), context); } String jSONArray2222 = jSONArray.toString(); LogUtils.c("SyncUtil", "getDocShareLinkMultiPage postBody = " + jSONArray2222); j10 = j11; str4 = jSONArray2222; return l0(str4, str2, j10, i11, z10, arrayList.size(), context); } } } str5 = ""; JSONArray jSONArray3 = new JSONArray(); sb2 = new StringBuilder(); it = arrayList.iterator(); while (it.hasNext()) { } if (sb2.length() <= 0) { } } j10 = j2; str4 = null; return l0(str4, str2, j10, i11, z10, arrayList.size(), context); } public static boolean o1() { return AccountPreference.J(); } public static void o2(Context context) { if (!t1(context)) { AutoUploadThread.o(context).s(); LogUtils.a("SyncUtil", "requestSync no account login"); } else if (TeamFragment.f19365a5) { TeamFragment.f19365a5 = false; SyncClient.B().h0(null); } else { SyncClient.B().f0(null); } } /* access modifiers changed from: private */ /* JADX WARNING: Code restructure failed: missing block: B:34:0x0150, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:35:0x0152, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:37:0x0155, code lost: r7 = true; */ /* JADX WARNING: Code restructure failed: missing block: B:39:0x0162, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:40:0x0164, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:44:0x0171, code lost: r29[0] = true; */ /* JADX WARNING: Code restructure failed: missing block: B:46:0x0182, code lost: throw new com.intsig.tianshu.exception.TianShuException(r0.getErrorCode(), r0.getErrorMsg()); */ /* JADX WARNING: Code restructure failed: missing block: B:49:0x0188, code lost: com.intsig.log.LogUtils.d("SyncUtil", "sync raw image sd card is " + com.intsig.camscanner.util.SDStorageManager.Z(), r0); */ /* JADX WARNING: Code restructure failed: missing block: B:50:0x01a4, code lost: if (com.intsig.camscanner.util.SDStorageManager.Z() != false) goto L_0x01a9; */ /* JADX WARNING: Code restructure failed: missing block: B:51:0x01a6, code lost: r28[0] = false; */ /* JADX WARNING: Code restructure failed: missing block: B:52:0x01a9, code lost: r0 = new android.content.ContentValues(); r1 = android.content.ContentUris.withAppendedId(com.intsig.camscanner.provider.Documents.Image.f28706c, r19); r0.put("sync_raw_jpg_state", (java.lang.Integer) 0); r18.getContentResolver().update(r1, r0, null, null); r8 = r7; */ /* JADX WARNING: Code restructure failed: missing block: B:54:?, code lost: return r8; */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Removed duplicated region for block: B:40:0x0164 A[ExcHandler: TianShuException (r0v5 'e' com.intsig.tianshu.exception.TianShuException A[CUSTOM_DECLARE]), Splitter:B:1:0x000e] */ /* JADX WARNING: Removed duplicated region for block: B:51:0x01a6 */ /* JADX WARNING: Removed duplicated region for block: B:52:0x01a9 */ public static boolean o3(Context context, long j2, String str, String str2, long j10, long j11, boolean z10, boolean[] zArr, boolean[] zArr2, ShareDirDBData shareDirDBData) throws TianShuException { boolean z11; int i10; boolean z12 = false; try { if (!TextUtils.isEmpty(str)) { Vector vector = new Vector(); PageUploadAction pageUploadAction = new PageUploadAction(str2 + ".ori.jpg", 0, "CamScanner_Page", j10, 1, str); LogUtils.a("SyncUtil", "uploadLocalRawImage2Server action = " + str2 + ".ori.jpg" + ", time = " + j10 + ", path = " + str); vector.add(pageUploadAction); if (z10) { String b10 = CollaborateUtil.b(str2); String f10 = CollaborateUtil.f(context, j11); LogUtils.a("SyncUtil", "uploadLocalRawImage2Server collaborateBatchUpload syncid = " + b10 + " coToken " + f10); int[] I = TianShuAPI.I(f10, "CamScanner_Page", vector, null); if (I == null || I.length != 2) { LogUtils.a("SyncUtil", "uploadLocalRawImage2Server result is error"); } else if (I[0] <= 0) { LogUtils.a("SyncUtil", "uploadLocalRawImage2Server revision is error " + I[0]); } else if (I[1] > 0) { i10 = I[0]; } else { LogUtils.a("SyncUtil", "uploadLocalRawImage2Server results[1] =" + I[1]); } i10 = 0; } else { i10 = g3(vector, "CamScanner_Page", null, shareDirDBData.a(), shareDirDBData.b() == 1, true).c(); } if (i10 > 0) { ContentValues contentValues = new ContentValues(); Uri withAppendedId = ContentUris.withAppendedId(Documents.Image.f28706c, j2); contentValues.put("sync_raw_jpg_state", (Integer) 0); context.getContentResolver().update(withAppendedId, contentValues, null, null); z11 = true; } else { z11 = false; } LogUtils.a("SyncUtil", "uploadLocalRawImage2Server version=" + i10 + " result=" + z11); return z11; } LogUtils.a("SyncUtil", "uploadLocalRawImage2Server image path is null"); return true; } catch (FileNotFoundException e10) { FileNotFoundException e11 = e10; z11 = true; } catch (TianShuException e12) { } } public static void p(Context context) { SyncClient.B().f34963a = true; C2(context); } private static ArrayList<DocShareLinkInfo> p0(ArrayList<String> arrayList, boolean z10, String str, int i10, String str2, long j2, int i11, boolean z11, Context context) { int i12; long j10; String str3; JSONException e10; if (arrayList == null) { LogUtils.c("SyncUtil", "getDocShareLink invalid paras token = " + str); j10 = j2; str3 = null; i12 = 0; } else { JSONArray jSONArray = new JSONArray(); Iterator<String> it = arrayList.iterator(); long j11 = j2; int i13 = 0; while (it.hasNext()) { String next = it.next(); int L0 = z10 ? i13 + 1 : i13 + DBUtil.L0(next); JSONObject jSONObject = new JSONObject(); if (i10 == 2) { try { if (PreferenceHelper.di()) { jSONObject.put("need_encrypt", 1); j11 = v(); } } catch (JSONException e11) { e10 = e11; LogUtils.e("SyncUtil", e10); i13 = L0; } } String str4 = ""; if (i10 == 1 && !TextUtils.isEmpty(str2)) { StringBuilder sb2 = new StringBuilder(); try { sb2.append(str2); sb2.append("_IntSig_Share"); String d10 = AppUtil.d(sb2.toString()); if (!TextUtils.isEmpty(d10)) { str4 = d10.substring(0, d10.length() / 2); } } catch (JSONException e12) { e10 = e12; LogUtils.e("SyncUtil", e10); i13 = L0; } } String str5 = z10 ? "page_id" : "doc_id"; ShareDirDBData p10 = z10 ? ShareDirDao.p(ApplicationHelper.f39908b, next) : ShareDirDao.o(ApplicationHelper.f39908b, next); if (!TextUtils.isEmpty(p10.a())) { jSONObject.put("duuid", p10.a()); } jSONObject.put(str5, next); jSONObject.put("encrypt", str4); if (!TextUtils.isEmpty(str)) { jSONObject.put("dead_time", j11); } jSONArray.put(jSONObject); i13 = L0; } i12 = i13; str3 = jSONArray.toString(); j10 = j11; } return l0(str3, str, j10, i11, z11, i12, context); } public static boolean p1() { if (PreferenceHelper.h9()) { return o1(); } if (!S1()) { if (!s1()) { return false; } } return true; } /* JADX WARNING: Removed duplicated region for block: B:28:0x00cf */ /* JADX WARNING: Removed duplicated region for block: B:40:0x0148 */ /* JADX WARNING: Removed duplicated region for block: B:44:0x0156 */ public static void p2(Context context, long j2, int i10, boolean z10, String str) { int i11; boolean C; boolean C2; int i12; String str2; String str3; Cursor query = context.getContentResolver().query(ContentUris.withAppendedId(Documents.Image.f28704a, j2), new String[]{"image_rotation", "_data", "image_backup", "sync_image_id", "thumb_data"}, null, null, null); if (query != null) { if (query.moveToFirst()) { boolean z11 = false; int i13 = query.getInt(0); if (i10 >= 0 && (i13 = i13 - i10) < 0) { i13 += 360; } if (BitmapUtils.C(j2)) { LogUtils.a("SyncUtil", "isImageEditing true"); BitmapUtils.F(j2); query.close(); return; } if (i13 % 360 != 0) { String string = query.getString(2); int i14 = 80; if (string == null) { LogUtils.a("SyncUtil", "rotateImage has not been inked before, no ink"); } else if (new File(string).exists()) { int scaleImage = ScannerEngine.scaleImage(string, i13, 1.0f, 80, null); if (scaleImage >= 0) { LogUtils.c("SyncUtil", "rotateImage noInkImage oldRotate=" + i10 + " rotate=" + i13); } i11 = scaleImage; z11 = true; LogUtils.a("SyncUtil", "rotateImage has inked image is =" + z11); String string2 = query.getString(1); String string3 = query.getString(4); C = FileUtil.C(string2); C2 = FileUtil.C(string3); int i15 = -1; if (!z10) { if (z11 || !C) { LogUtils.a("SyncUtil", "rotateImage exist image =" + C); } else { if (TextUtils.isEmpty(string)) { if (TextUtils.isEmpty(str)) { string = W(query.getString(3) + ".jpg"); } else { string = W(str + "_" + query.getString(3) + ".jpg"); str3 = null; i14 = 80; i11 = ScannerEngine.scaleImage(string2, i13, 1.0f, i14, str3); FileUtil.h(string2, string); } } str3 = null; i11 = ScannerEngine.scaleImage(string2, i13, 1.0f, i14, str3); FileUtil.h(string2, string); } str2 = null; i12 = 80; } else { str2 = null; i12 = 80; if (C) { i11 = ScannerEngine.scaleImage(string2, i13, 1.0f, 80, null); } } if (C2) { i15 = ScannerEngine.scaleImage(string3, i13, 1.0f, i12, str2); } if (i11 >= 0 || i15 >= 0) { LogUtils.a("SyncUtil", "rotateImage oldRotate=" + i10 + " rotate=" + i13 + " imageExist=" + C + " thumbExist=" + C2); } } else { LogUtils.a("SyncUtil", "rotateImage has not been inked before"); } i11 = 0; LogUtils.a("SyncUtil", "rotateImage has inked image is =" + z11); String string22 = query.getString(1); String string32 = query.getString(4); C = FileUtil.C(string22); C2 = FileUtil.C(string32); int i152 = -1; if (!z10) { } if (C2) { } LogUtils.a("SyncUtil", "rotateImage oldRotate=" + i10 + " rotate=" + i13 + " imageExist=" + C + " thumbExist=" + C2); } BitmapUtils.F(j2); } query.close(); } } /* JADX WARNING: Code restructure failed: missing block: B:11:0x00c5, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:13:0x00cf, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:15:0x00dd, code lost: throw new com.intsig.tianshu.exception.TianShuException(r0.getErrorCode(), r0.getErrorMsg()); */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Removed duplicated region for block: B:13:0x00cf A[ExcHandler: TianShuException (r0v5 'e' com.intsig.tianshu.exception.TianShuException A[CUSTOM_DECLARE]), Splitter:B:1:0x000e] */ private static boolean p3(Context context, long j2, String str, String str2, long j10, boolean[] zArr, String str3, String str4, boolean z10) throws TianShuException { boolean z11; FileNotFoundException e10; boolean z12 = false; try { if (!TextUtils.isEmpty(str)) { Vector vector = new Vector(); PageUploadAction pageUploadAction = new PageUploadAction(str2 + ".ori.jpg", 0, "CamScanner_Page", j10, 1, str); LogUtils.a("SyncUtil", "uploadRawJpg2Server action = " + str2 + ".ori.jpg" + ", time = " + j10 + ", path = " + str); vector.add(pageUploadAction); int r32 = r3(vector, null, str3, str4, z10); if (r32 > 0) { ContentValues contentValues = new ContentValues(); Uri withAppendedId = ContentUris.withAppendedId(Documents.Image.f28706c, j2); contentValues.put("sync_raw_jpg_state", (Integer) 0); int update = context.getContentResolver().update(withAppendedId, contentValues, null, null); LogUtils.a("SyncUtil", "uploadRawJpg2Server resolver.update num=" + update); z11 = true; } else { z11 = false; } LogUtils.a("SyncUtil", "uploadRawJpg2Server version=" + r32 + " result=" + z11); return z11; } LogUtils.a("SyncUtil", "uploadRawJpg2Server image path is null"); return true; } catch (FileNotFoundException e11) { e10 = e11; z11 = true; } catch (TianShuException e12) { } LogUtils.d("SyncUtil", "sync raw image sd card is " + SDStorageManager.Z(), e10); if (!SDStorageManager.Z()) { zArr[0] = false; } else { ContentValues contentValues2 = new ContentValues(); Uri withAppendedId2 = ContentUris.withAppendedId(Documents.Image.f28706c, j2); contentValues2.put("sync_raw_jpg_state", (Integer) 0); context.getContentResolver().update(withAppendedId2, contentValues2, null, null); z12 = z11; } return z12; } public static void q() { SyncClient.B().f34963a = false; SyncThread.f34994t = false; } public static int q0(long j2) { try { Cursor query = ApplicationHelper.f39908b.getContentResolver().query(ContentUris.withAppendedId(Documents.Document.f28695d, j2), new String[]{"sync_ui_state"}, null, null, null); if (query != null) { try { if (query.moveToFirst()) { int i10 = query.getInt(0); query.close(); return i10; } } catch (Throwable th) { th.addSuppressed(th); } } if (query != null) { query.close(); return -1; } } catch (Exception e10) { LogUtils.e("SyncUtil", e10); } return -1; throw th; } public static boolean q1() { return PreferenceHelper.h9() && o1(); } public static void q2(Context context, long j2, int i10) { r2(context, j2, i10, i0(context, j2)); } public static void q3(Context context) { Vector F0 = F0(context); if (F0 != null && F0.size() > 0) { LogUtils.a("SyncUtil", "uploadRevertData2Server jpg size:" + F0.size()); Vector vector = new Vector(); Iterator it = F0.iterator(); while (it.hasNext()) { PageUploadAction pageUploadAction = (PageUploadAction) it.next(); vector.clear(); vector.add(pageUploadAction); if (f3(vector)) { U2(context, pageUploadAction.j(), 0, true); } else { LogUtils.a("SyncUtil", "uploadRevertData2Server jpg failed " + pageUploadAction.f()); } } } Vector E0 = E0(context); if (E0 != null && E0.size() > 0) { LogUtils.a("SyncUtil", "uploadRevertData2Server jpage size:" + E0.size()); if (f3(E0)) { Iterator it2 = E0.iterator(); while (it2.hasNext()) { O2(context, ((JsonUploadAction) it2.next()).j(), 0, true); } } else { LogUtils.a("SyncUtil", "uploadRevertData2Server jpage failed "); } } Vector G0 = G0(context); if (G0 != null && G0.size() > 0) { LogUtils.a("SyncUtil", "uploadRevertData2Server jtag size:" + G0.size()); if (f3(G0)) { Iterator it3 = G0.iterator(); while (it3.hasNext()) { Z2(context, ((JsonUploadAction) it3.next()).j(), 0, true); } } else { LogUtils.a("SyncUtil", "uploadRevertData2Server jtag failed "); } } Vector D0 = D0(context); if (D0 != null && D0.size() > 0) { LogUtils.a("SyncUtil", "uploadRevertData2Server jdoc size:" + D0.size()); if (f3(D0)) { Iterator it4 = D0.iterator(); while (it4.hasNext()) { K2(context, ((JsonUploadAction) it4.next()).j(), 0, true); } } else { LogUtils.a("SyncUtil", "uploadRevertData2Server jdoc failed "); } } } private static void r(long j2) { long y6 = AccountPreference.y(); if (y6 != j2 && j2 == 1) { LogUtils.a("SyncUtil", "updateVipInfo changed,clear pdf oldState =" + y6 + ", nowSate=" + j2); PDF_Util.clearNormalPdf(); } } public static String r0(Context context, String str) { Cursor query; String str2 = null; if (!TextUtils.isEmpty(str) && (query = context.getContentResolver().query(Documents.Document.f28692a, new String[]{"title"}, "sync_doc_id =?", new String[]{str}, null)) != null) { if (query.moveToFirst()) { str2 = query.getString(0); } query.close(); } LogUtils.a("SyncUtil", "getDocTitle title=" + str2); return str2; } public static boolean r1(Context context, long j2) { Cursor query; boolean z10 = false; if (!(context == null || j2 <= 0 || (query = context.getContentResolver().query(ContentUris.withAppendedId(Documents.Image.f28704a, j2), new String[]{ao.f45476d}, "sync_state = -1", null, null)) == null)) { if (query.getCount() <= 0) { z10 = true; } query.close(); } LogUtils.a("SyncUtil", "isImageJpgComplete result=" + z10 + " imageId=" + j2); return z10; } public static void r2(Context context, long j2, int i10, long j10) { ContentValues contentValues = new ContentValues(); contentValues.put("sync_ui_state", Integer.valueOf(i10)); Uri withAppendedId = ContentUris.withAppendedId(Documents.Document.f28695d, j2); contentValues.put("modified", Long.valueOf(j10)); int update = context.getContentResolver().update(withAppendedId, contentValues, null, null); LogUtils.a("SyncUtil", "updateDocImages docId=" + j2 + " result=" + update + " uiState=" + i10); } public static int r3(Vector vector, TianShuAPI.OnProgressListener onProgressListener, String str, String str2, boolean z10) throws TianShuException { if (vector != null && vector.size() > 0) { UploadState w10 = TianShuAPI.w(vector, 0, onProgressListener, false, str, str2, z10); LogUtils.a("SyncUtil", "state.getSuccessNum()" + w10.d() + " actions.size()=" + vector.size()); if (w10.d() == vector.size()) { return 1; } } return 0; } public static String s(Context context, String str) { return null; } private static List<DownloadImageInfo> s0(Context context, long j2) { ArrayList arrayList = new ArrayList(); Cursor query = context.getContentResolver().query(ContentUris.withAppendedId(Documents.Image.f28705b, j2), new String[]{ao.f45476d, "_data", "sync_image_id", "sync_version", "sync_timestamp", "thumb_data", "cache_state", "sync_jpage_state"}, "sync_state <> 1 AND sync_state <> 2 AND sync_state <> 5", null, "page_num ASC"); if (query != null) { while (query.moveToNext()) { DownloadImageInfo downloadImageInfo = new DownloadImageInfo(); downloadImageInfo.f35056a = query.getLong(0); downloadImageInfo.f35057b = query.getString(1); downloadImageInfo.f35058c = query.getString(2); downloadImageInfo.f35059d = query.getLong(3); downloadImageInfo.f35060e = query.getLong(4); downloadImageInfo.f35061f = query.getString(5); downloadImageInfo.f35062g = query.getInt(6); downloadImageInfo.f35063h = query.getInt(7); arrayList.add(downloadImageInfo); } query.close(); } return arrayList; } public static boolean s1() { return AccountPreference.K(); } public static void s2(Context context, boolean z10) { AccountPreference.T(context, z10); } /* access modifiers changed from: private */ /* JADX WARNING: Removed duplicated region for block: B:29:0x0088 */ /* JADX WARNING: Removed duplicated region for block: B:31:0x0094 */ public static boolean s3(Context context, long j2, String str, String str2, long j10, boolean[] zArr, Map<Long, TeamDirListJson.BaseTeamDoc> map, LongSparseArray<String> longSparseArray, long j11, String str3, boolean z10) throws TianShuException { String str4 = null; boolean z11 = true; int i10 = 0; boolean z12 = false; while (z11 && i10 < 2) { i10++; if (longSparseArray != null && longSparseArray.indexOfKey(j11) >= 0) { str4 = longSparseArray.get(j11); } else if (map.containsKey(Long.valueOf(j11))) { TeamDirListJson.BaseTeamDoc baseTeamDoc = map.get(Long.valueOf(j11)); long lastDirUploadTime = baseTeamDoc.getLastDirUploadTime(); long c22 = DBUtil.c2(context, str3, baseTeamDoc.getDirId()); String r22 = TianShuAPI.r2(str3, baseTeamDoc.getDirId(), null, c22 > lastDirUploadTime ? c22 : lastDirUploadTime, z10); if (!TextUtils.isEmpty(r22)) { try { str4 = new TeamCommitDirJson(r22).upload_token; if (longSparseArray != null) { try { longSparseArray.put(j11, str4); } catch (JSONException unused) { } if (TextUtils.isEmpty(str4)) { LogUtils.a("SyncUtil", "uploadToken is empty"); } else { try { z12 = p3(context, j2, str, str2, j10, zArr, str3, str4, z10); } catch (TianShuException e10) { if (e10.getErrorCode() == 106) { longSparseArray.remove(j11); str4 = str4; z11 = true; } else { throw e10; } } } str4 = str4; z11 = false; } } catch (JSONException unused2) { } } if (TextUtils.isEmpty(str4)) { } str4 = str4; z11 = false; } if (TextUtils.isEmpty(str4)) { } str4 = str4; z11 = false; } return z12; } public static void t(Context context) { ThreadPoolSingleton.e().c(y.f52807a); } public static ExecutorService t0(boolean z10) { return z10 ? CustomExecutor.g() : CustomExecutor.n(); } public static boolean t1(Context context) { return AccountPreference.L(context); } public static void t2(Context context, boolean z10) { LogUtils.a("SyncUtil", "setOpenRawJpgSync open=" + z10); SharedPreferences.Editor edit = PreferenceManager.getDefaultSharedPreferences(context).edit(); edit.putBoolean(context.getString(R.string.key_setting_open_raw_image_sync) + N0(), z10).apply(); } public static void u() { SyncUtilDelegate.a(); } public static long[] u0(Context context) { String[] split; long[] jArr = null; if (context == null) { LogUtils.a("SyncUtil", "getLastStorage context == null"); return null; } String w10 = AppUtil.w(); if (!TextUtils.isEmpty(w10) && (split = w10.split("/")) != null && split.length == 2) { jArr = new long[]{Long.valueOf(split[0]).longValue(), Long.valueOf(split[1]).longValue()}; } return jArr; } public static boolean u1(long j2, Context context) { Cursor query = context.getContentResolver().query(ContentUris.withAppendedId(Documents.Image.f28704a, j2), new String[]{"min_version"}, null, null, null); boolean z10 = false; if (query != null) { if (query.moveToFirst() && 1.0f < ((float) query.getInt(0))) { z10 = true; } query.close(); } return z10; } public static void u2(Context context) { ContentValues contentValues = new ContentValues(); contentValues.put("sync_jpage_state", (Integer) 1); contentValues.put("sync_state", (Integer) 1); context.getContentResolver().update(Documents.Image.f28708e, contentValues, null, null); } public static long v() { int j32 = t1(ApplicationHelper.f39908b) ? PreferenceHelper.j3() : 2; Calendar instance = Calendar.getInstance(); instance.add(5, j32); return instance.getTimeInMillis() / 1000; } public static String v0() { return LanguageUtil.f(); } public static boolean v1(long j2, Context context) { ContentResolver contentResolver = context.getContentResolver(); Cursor query = contentResolver.query(Documents.Graphics.f28702a, new String[]{ao.f45476d}, "image_id = " + j2, null, null); boolean z10 = false; if (query != null) { if (query.moveToFirst()) { long j10 = query.getLong(0); Cursor query2 = contentResolver.query(Documents.NotePath.f28714a, new String[]{ao.f45476d}, "graphics_id = " + j10, null, null); if (query2 != null) { if (query2.getCount() > 0) { z10 = true; } query2.close(); } } query.close(); } return z10; } public static int v2(ArrayList<String> arrayList, int i10, String str, int i11) { try { JSONArray jSONArray = new JSONArray(); Iterator<String> it = arrayList.iterator(); while (it.hasNext()) { JSONObject jSONObject = new JSONObject(); jSONObject.put("doc_id", it.next()); jSONObject.put("permission", i10); jSONArray.put(jSONObject); } String jSONArray2 = jSONArray.toString(); LogUtils.a("SyncUtil", "setServerDocPermission postBody:" + jSONArray2 + " , teamArea:" + i11); String j2 = TianShuAPI.j2(str, jSONArray2, i11 == 2); LogUtils.a("SyncUtil", "setServerDocPermission response:" + j2); if (!TextUtils.isEmpty(j2)) { return new JSONObject(j2).getInt("success_num"); } } catch (JSONException e10) { LogUtils.c("SyncUtil", "updateDocPermission :" + e10); } catch (TianShuException e11) { LogUtils.c("SyncUtil", "updateDocPermission : " + e11); return 0; } return 0; } public static void w() throws TianShuException { try { TianShuAPI.L("CamScanner_Page"); } catch (TianShuException unused) { TianShuAPI.L("CamScanner_Page"); } } /* JADX WARNING: Code restructure failed: missing block: B:29:0x00f9, code lost: if (r5.f35062g == 1) goto L_0x00fe; */ /* JADX WARNING: Removed duplicated region for block: B:32:0x0100 */ /* JADX WARNING: Removed duplicated region for block: B:45:0x0032 A[SYNTHETIC] */ private static List<DownloadImageInfo> w0(Context context, long j2, List<DownloadImageInfo> list, boolean[] zArr) { boolean z10; ArrayList arrayList = new ArrayList(); ContentResolver contentResolver = context.getContentResolver(); StringBuilder sb2 = new StringBuilder(); sb2.append("docId=" + j2); sb2.append(" forbid download image:\n"); ArrayList arrayList2 = new ArrayList(); Iterator<DownloadImageInfo> it = list.iterator(); while (it.hasNext()) { DownloadImageInfo next = it.next(); boolean z11 = false; if (next.f35060e <= 0) { zArr[0] = false; sb2.append(" imageSyncId="); sb2.append(next.f35058c); sb2.append(" jpgTime="); sb2.append(next.f35060e); sb2.append(" jpage not download from server\n"); } else if (next.f35063h == 1 || next.f35063h == 2 || next.f35063h == 5) { sb2.append(" imageSyncId="); sb2.append(next.f35058c); sb2.append(" jpageSyncState="); sb2.append(next.f35063h); sb2.append(" jpage Sync State is not normal\n"); } else { if (next.f35059d > 0) { if (TextUtils.isEmpty(next.f35057b)) { z10 = false; } else { z10 = new File(next.f35057b).exists(); next.f35064i = !z10; } if (z10) { if (!FileUtil.C(next.f35061f)) { LogUtils.a("SyncUtil", "downloadImageFromServer create thumbPath"); FileUtil.K(BitmapUtils.D(next.f35057b), next.f35061f); } } else if (!PreferenceHelper.l7(context) && !TextUtils.isEmpty(next.f35061f)) { File file = new File(next.f35061f); next.f35064i = !file.exists(); if (file.exists()) { } } if (!z11) { arrayList.add(next); ContentValues contentValues = new ContentValues(); contentValues.put("sync_ui_state", (Integer) 1); arrayList2.add(ContentProviderOperation.newUpdate(ContentUris.withAppendedId(Documents.Image.f28704a, next.f35056a)).withValues(contentValues).build()); } } z11 = true; if (!z11) { } } } ArrayList<ContentProviderOperation> b02 = DBUtil.b0(context, arrayList2); if (b02.size() > 0) { try { contentResolver.applyBatch(Documents.f28683a, b02); } catch (Exception e10) { LogUtils.e("SyncUtil", e10); } } LogUtils.a("SyncUtil", sb2.toString()); return arrayList; } public static boolean w1(Context context, long j2) { Cursor query; boolean z10 = false; if (j2 > 0 && (query = context.getContentResolver().query(ContentUris.withAppendedId(Documents.PageMark.f28717b, j2), new String[]{"mark_text"}, null, null, null)) != null) { if (query.moveToFirst() && !TextUtils.isEmpty(query.getString(0))) { z10 = true; } query.close(); } LogUtils.a("SyncUtil", "isNeedMarkImage imageId=" + j2 + " result=" + z10); return z10; } public static void w2(final Context context) { AnonymousClass1 r02 = new AccountListener() { /* class com.intsig.camscanner.tsapp.sync.SyncUtil.AnonymousClass1 */ @Override // com.intsig.camscanner.tsapp.AccountListener public boolean a() { return !SDStorageManager.e(context); } @Override // com.intsig.camscanner.tsapp.AccountListener public String b() { return SyncUtil.g0(context); } @Override // com.intsig.camscanner.tsapp.AccountListener public void c(SyncApi.SyncProgress syncProgress, Vector<SyncCallbackListener> vector) { LogUtils.a("SyncUtil", "doWorkAfterSync"); } @Override // com.intsig.camscanner.tsapp.AccountListener public String d() { return SyncUtil.L0(context); } @Override // com.intsig.camscanner.tsapp.AccountListener public String e() { return SyncUtil.I0(context); } @Override // com.intsig.camscanner.tsapp.AccountListener public void f(long j2) { int i10; long J0 = SyncUtil.J0(context); if (J0 > 0) { Uri withAppendedId = ContentUris.withAppendedId(Documents.SyncAccount.f28723a, J0); ContentValues contentValues = new ContentValues(); contentValues.put("sync_time", Long.valueOf(j2)); try { i10 = context.getContentResolver().update(withAppendedId, contentValues, null, null); } catch (RuntimeException e10) { LogUtils.e("SyncUtil", e10); } LogUtils.a("SyncUtil", "updateAccountSyncTime id=" + J0 + " time=" + j2 + " uploadCount=" + i10); } i10 = -1; LogUtils.a("SyncUtil", "updateAccountSyncTime id=" + J0 + " time=" + j2 + " uploadCount=" + i10); } @Override // com.intsig.camscanner.tsapp.AccountListener public boolean g() { return AppUtil.F(context).equals(context.getString(R.string.set_sync_wifi)); } @Override // com.intsig.camscanner.tsapp.AccountListener public String getAccountType() { return SyncUtil.M0(context); } @Override // com.intsig.camscanner.tsapp.AccountListener public String getTokenPwd() { return SyncUtil.P0(context); } @Override // com.intsig.camscanner.tsapp.AccountListener public String h() { return SyncUtil.f0(context); } @Override // com.intsig.camscanner.tsapp.AccountListener public String i() { return SyncUtil.K0(context); } @Override // com.intsig.camscanner.tsapp.AccountListener public String j() { return SyncUtil.O0(); } @Override // com.intsig.camscanner.tsapp.AccountListener public boolean k() { return AppUtil.E(context) && AppUtil.v(); } }; SyncClient B = SyncClient.B(); B.Y(r02); B.z(); long J0 = J0(context); B.w(new TagSyncOperation(context, J0)); B.w(new DocSyncOperation(context, J0)); } public static void x(Context context, String str) { A(context, str, false); } public static ArrayList<Long> x0(Context context, boolean z10, String str, HashSet<Long> hashSet) { String str2; Iterator<Long> it; if (hashSet == null) { hashSet = new HashSet<>(); } int i10 = z10 ? 1 : 2; String[] strArr = {i10 + "", str}; if (TextUtils.isEmpty(str)) { strArr[1] = "1"; str2 = "sync_ui_state = ? AND belong_state != ? "; } else { str2 = "sync_ui_state = ? AND team_token=?"; } List<String> i11 = ShareDirDao.i(); if (i11.size() > 0) { StringBuilder sb2 = new StringBuilder(); for (String str3 : i11) { if (sb2.length() > 0) { sb2.append(PreferencesConstants.COOKIE_DELIMITER); } sb2.append("'"); sb2.append(str3); sb2.append("'"); } str2 = str2 + " and ( " + "sync_dir_id" + " not in (" + ((Object) sb2) + ") or " + "sync_dir_id" + " IS NULL )"; } StringBuilder sb3 = new StringBuilder(); ArrayList<Long> arrayList = new ArrayList<>(); Cursor query = context.getContentResolver().query(Documents.Document.f28695d, new String[]{ao.f45476d}, str2, strArr, null); if (query != null) { while (query.moveToNext()) { long j2 = query.getLong(0); if (hashSet.contains(Long.valueOf(j2))) { if (sb3.length() > 0) { sb3.append(",'" + j2 + "'"); } else { sb3.append("'" + j2 + "'"); } hashSet.remove(Long.valueOf(j2)); } arrayList.add(Long.valueOf(j2)); } query.close(); } if (hashSet.size() > 0 && (it = hashSet.iterator()) != null) { while (it.hasNext()) { long longValue = it.next().longValue(); arrayList.add(Long.valueOf(longValue)); if (sb3.length() > 0) { sb3.append(",'" + longValue + "'"); } else { sb3.append("'" + longValue + "'"); } } } if (sb3.length() > 0) { ContentValues contentValues = new ContentValues(); contentValues.put("sync_ui_state", Integer.valueOf(i10)); LogUtils.a("SyncUtil", "getNeedUpdateDocIds num=" + context.getContentResolver().update(Documents.Document.f28695d, contentValues, "_id in (" + ((Object) sb3) + ") and " + "sync_ui_state" + " !=? ", new String[]{i10 + ""}) + " download=" + z10); } return arrayList; } public static boolean x1(Context context, long j2) { Cursor query = context.getContentResolver().query(ContentUris.withAppendedId(Documents.Signature.f28722b, j2), new String[]{ao.f45476d}, null, null, null); boolean z10 = query != null && query.getCount() > 0; if (query != null) { query.close(); } return z10; } public static String x2(String str, String str2) { String G0 = TianShuAPI.G0(); String str3 = null; if (TextUtils.isEmpty(G0)) { LogUtils.a("SyncUtil", ""); return null; } HashMap hashMap = new HashMap(); hashMap.put("client", AccountPreference.c()); hashMap.put("client_id", AccountPreference.e()); hashMap.put("client_app", AccountPreference.d()); hashMap.put("cs_ept_d", AESEncUtil.e(ApplicationHelper.i())); hashMap.put("attribute", str); hashMap.put(ClientMetricsEndpointType.TOKEN, G0); hashMap.put(AppMeasurementSdk.ConditionalUserProperty.VALUE, str2); try { str3 = TianShuAPI.z0("set_user_attribute", hashMap, true, 0); LogUtils.a("SyncUtil", "setUserAttribute result:" + str3); return str3; } catch (TianShuException e10) { LogUtils.e("SyncUtil", e10); return str3; } } public static void y(Context context, String str, long j2) { z(context, str, j2, null); } private static List<UploadLocalImageInfo> y0(Context context, long j2, List<UploadLocalImageInfo> list, boolean[] zArr) { ArrayList arrayList = new ArrayList(); for (UploadLocalImageInfo uploadLocalImageInfo : list) { if (!TextUtils.isEmpty(uploadLocalImageInfo.f35080b)) { if (uploadLocalImageInfo.f35083e != 6) { if (uploadLocalImageInfo.f35084f == 0) { if (uploadLocalImageInfo.f35087i == 0) { if (!v1(uploadLocalImageInfo.f35079a, context) && !w1(context, uploadLocalImageInfo.f35079a)) { if (!x1(context, uploadLocalImageInfo.f35079a)) { if (!FileUtil.C(uploadLocalImageInfo.f35080b) && FileUtil.C(uploadLocalImageInfo.f35085g)) { uploadLocalImageInfo.f35080b = uploadLocalImageInfo.f35085g; LogUtils.a("SyncUtil", "image not exist, used no ink image to upload"); arrayList.add(uploadLocalImageInfo); } arrayList.add(uploadLocalImageInfo); } } if (FileUtil.C(uploadLocalImageInfo.f35085g)) { uploadLocalImageInfo.f35080b = uploadLocalImageInfo.f35085g; arrayList.add(uploadLocalImageInfo); } else { LogUtils.a("SyncUtil", "image not exist, used no ink image to upload"); arrayList.add(uploadLocalImageInfo); } } } LogUtils.c("SyncUtil", "uploadLocalImage2Server batchState is not normal but batchState=" + uploadLocalImageInfo.f35084f + " confirmState=" + uploadLocalImageInfo.f35087i + " doc id:" + j2 + " imageId=" + uploadLocalImageInfo.f35079a + " " + uploadLocalImageInfo.f35086h); if (FileUtil.t(uploadLocalImageInfo.f35080b) > 0 || FileUtil.t(uploadLocalImageInfo.f35085g) > 0) { zArr[0] = false; } else { LogUtils.a("SyncUtil", "jpg file not exists"); } } } } return arrayList; } /* JADX WARNING: Removed duplicated region for block: B:24:0x00b1 */ /* JADX WARNING: Removed duplicated region for block: B:25:0x00b3 */ public static boolean y1(Context context) { boolean z10; Cursor query; Cursor query2 = context.getContentResolver().query(Documents.Document.f28695d, new String[]{ao.f45476d}, "sync_state = 7 AND belong_state != 1", null, null); boolean z11 = true; if (query2 != null) { z10 = query2.getCount() > 0; query2.close(); } else { z10 = false; } if (!z10) { String C0 = DBUtil.C0(context, null, false); if (TextUtils.isEmpty(C0)) { if (!z10 && (query = context.getContentResolver().query(Documents.Tag.f28729b, new String[]{ao.f45476d}, "sync_state = 7", null, null)) != null) { if (query.getCount() > 0) { z11 = z10; } query.close(); z10 = z11; } return z10; } Cursor query3 = context.getContentResolver().query(Documents.Image.f28706c, new String[]{ao.f45476d}, "(sync_state = 7 OR sync_jpage_state = 7) AND belong_state != 1 AND document_id in " + C0, null, null); if (query3 != null) { if (query3.getCount() > 0) { z10 = true; } query3.close(); } } if (query.getCount() > 0) { } query.close(); z10 = z11; return z10; } public static void y2(Context context, Intent intent, String str, String str2, int i10) { NotificationHelper.getInstance().notify(i10, NotificationHelper.getInstance().getNotification(str, str2, PendingIntent.getActivity(context, 0, intent, PendingIntentCompat.a(false)))); } public static void z(Context context, String str, long j2, String str2) { String str3; LogUtils.a("SyncUtil", "createThumbPage fileName=" + str); ContentResolver contentResolver = context.getContentResolver(); String D = BitmapUtils.D(str); String R = Util.R(str); LogUtils.a("SyncUtil", "createThumbPage thumb=" + D + " name=" + R); if (!TextUtils.isEmpty(R) && !TextUtils.isEmpty(D)) { int lastIndexOf = R.lastIndexOf("."); if (lastIndexOf > 0) { if (TextUtils.isEmpty(str2)) { str2 = R.substring(0, lastIndexOf); } if (j2 > 0) { str3 = "_id = " + j2; } else { str3 = "sync_image_id = " + str2; } Cursor query = contentResolver.query(Documents.Image.f28706c, new String[]{"document_id", "page_num", ao.f45476d, "last_modified"}, str3, null, null); if (query != null) { if (query.moveToFirst()) { LogUtils.a("SyncUtil", "pos=" + query.getInt(1)); long j10 = query.getLong(2); ContentValues contentValues = new ContentValues(); contentValues.put("thumb_data", D); contentValues.put("last_modified", Long.valueOf(query.getLong(3))); contentResolver.update(ContentUris.withAppendedId(Documents.Image.f28706c, j10), contentValues, null, null); } query.close(); } } } else if (D == null) { LogUtils.c("SyncUtil", "createThumbPage file is damaged " + str + " size " + FileUtil.t(str)); } } public static String z0(Context context) { if (T1(context)) { return "&net=" + NetworkUtil.NETWORK_TYPE_WIFI; } return "&net=" + "mobile"; } public static boolean z1(Context context) { return t1(context) && !M1(context) && !S1(); } public static void z2(final Context context) { try { new AlertDialog.Builder(context).K(R.string.a_msg_storage_limit_title).p(context.getString(R.string.a_msg_storage_limit_message)).r(R.string.cancel, new DialogInterface.OnClickListener() { /* class com.intsig.camscanner.tsapp.sync.SyncUtil.AnonymousClass3 */ public void onClick(DialogInterface dialogInterface, int i10) { Context context = context; context.startActivity(MainPageRoute.t(context)); ((Activity) context).finish(); } }).A(R.string.a_global_label_upgrade, new DialogInterface.OnClickListener() { /* class com.intsig.camscanner.tsapp.sync.SyncUtil.AnonymousClass2 */ public void onClick(DialogInterface dialogInterface, int i10) { PurchaseUtil.T((Activity) context, new PurchaseTracker().entrance(FunctionEntrance.FROM_SYNC_CLOUD_STORAGE_LIMIT).function(Function.SYNC_CLOUD_STORAGE_LIMIT).scheme(PurchaseScheme.MAIN_NORMAL)); ((Activity) context).finish(); } }).a().show(); } catch (Exception e10) { LogUtils.e("SyncUtil", e10); } } }