CarrotChat v2.8.80.240429版本的 MD5 值为:fdf98761f01e715a89df24b85b0d206e
以下内容为反编译后的 FileUtil.java 源代码,内容仅作参考
package ak.im.utils;
import ak.application.AKApplication;
import ak.im.BuildConfig;
import ak.im.module.AKCDiscoverGlobal;
import ak.im.module.AKStrException;
import ak.im.module.Attachment;
import ak.im.module.BaseWorkflow;
import ak.im.module.ChatMessage;
import ak.im.module.Emoticon;
import ak.im.module.EnterpriseInfo;
import ak.im.module.IMMessage;
import ak.im.module.Server;
import ak.im.module.StrangerUserTable;
import ak.im.module.UploadFileResult;
import ak.im.module.User;
import ak.im.sdk.manager.AKeyManager;
import ak.im.sdk.manager.TokenManager;
import ak.im.sdk.manager.bf;
import ak.im.uitls.AKCAppConfiguration;
import ak.im.uitls.AKCCheckPoint;
import ak.im.utils.HttpURLTools;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.LocaleList;
import android.os.StatFs;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.support.v4.media.session.PlaybackStateCompat;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import com.alibaba.fastjson.JSON;
import com.asim.protobuf.Akeychat;
import com.kinggrid.iapppdf.droids.mupdf.codec.cosobject.PdfBoolean;
import com.mobile.auth.gatewayauth.Constant;
import g.w7;
import g.y7;
import j.u0;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.ByteBuffer;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import okhttp3.HttpUrl;
import okhttp3.m;
import org.apache.commons.httpclient.cookie.CookieSpec;
import org.cryptomator.cryptolib.common.DecryptingReadableByteChannel;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.bookmarks.Bookmarks;
import org.json.JSONException;
import org.json.JSONObject;
import retrofit2.k;
import ye.l;
public class FileUtil {
public static String f10117d;
public static m0.a f10114a = m0.a.getInstance();
private static User f10115b = new User();
public static String f10116c = null;
private static final String[][] f10118e = {new String[]{".3gp", "video/3gpp"}, new String[]{".3gpp", "video/3gpp"}, new String[]{".aac", "audio/x-mpeg"}, new String[]{".amr", "audio/x-mpeg"}, new String[]{".apk", "application/vnd.android.package-archive"}, new String[]{".avi", "video/x-msvideo"}, new String[]{".aab", "application/x-authoware-bin"}, new String[]{".aam", "application/x-authoware-map"}, new String[]{".aas", "application/x-authoware-seg"}, new String[]{".ai", "application/postscript"}, new String[]{".aif", "audio/x-aiff"}, new String[]{".aifc", "audio/x-aiff"}, new String[]{".aiff", "audio/x-aiff"}, new String[]{".als", "audio/X-Alpha5"}, new String[]{".amc", "application/x-mpeg"}, new String[]{".ani", "application/octet-stream"}, new String[]{".asc", "text/plain"}, new String[]{".asd", "application/astound"}, new String[]{".asf", "video/x-ms-asf"}, new String[]{".asn", "application/astound"}, new String[]{".asp", "application/x-asap"}, new String[]{".asx", " video/x-ms-asf"}, new String[]{".au", "audio/basic"}, new String[]{".avb", "application/octet-stream"}, new String[]{".awb", "audio/amr-wb"}, new String[]{".bcpio", "application/x-bcpio"}, new String[]{".bld", "application/bld"}, new String[]{".bld2", "application/bld2"}, new String[]{".bpk", "application/octet-stream"}, new String[]{".bz2", "application/x-bzip2"}, new String[]{".bin", "application/octet-stream"}, new String[]{".bmp", "image/bmp"}, new String[]{".c", "text/plain"}, new String[]{".class", "application/octet-stream"}, new String[]{".conf", "text/plain"}, new String[]{".cpp", "text/plain"}, new String[]{".cal", "image/x-cals"}, new String[]{".ccn", "application/x-cnc"}, new String[]{".cco", "application/x-cocoa"}, new String[]{".cdf", "application/x-netcdf"}, new String[]{".cgi", "magnus-internal/cgi"}, new String[]{".chat", "application/x-chat"}, new String[]{".chm", "application/x-chm"}, new String[]{".clp", "application/x-msclip"}, new String[]{".cmx", "application/x-cmx"}, new String[]{".co", "application/x-cult3d-object"}, new String[]{".cod", "image/cis-cod"}, new String[]{".cpio", "application/x-cpio"}, new String[]{".cpt", "application/mac-compactpro"}, new String[]{".crd", "application/x-mscardfile"}, new String[]{".csh", "application/x-csh"}, new String[]{".csm", "chemical/x-csml"}, new String[]{".csml", "chemical/x-csml"}, new String[]{".csv", "text/csv"}, new String[]{".css", "text/css"}, new String[]{".cur", "application/octet-stream"}, new String[]{".doc", "application/msword"}, new String[]{".docx", "application/msword"}, new String[]{".dotx", "application/msword"}, new String[]{".dotm", "application/msword"}, new String[]{".dcm", "x-lml/x-evm"}, new String[]{".dcr", "application/x-director"}, new String[]{".dcx", "image/x-dcx"}, new String[]{".dhtml", "text/html"}, new String[]{".dir", "application/x-director"}, new String[]{".dll", "application/octet-stream"}, new String[]{".dmg", "application/octet-stream"}, new String[]{".dms", "application/octet-stream"}, new String[]{".dot", "application/x-dot"}, new String[]{".dvi", "application/x-dvi"}, new String[]{".dwf", "drawing/x-dwf"}, new String[]{".dwg", "application/x-autocad"}, new String[]{".dxf", "application/x-autocad"}, new String[]{".dxr", "application/x-director"}, new String[]{".ebk", "application/x-expandedbook"}, new String[]{".emb", "chemical/x-embl-dl-nucleotide"}, new String[]{".embl", "chemical/x-embl-dl-nucleotide"}, new String[]{".eps", "application/postscript"}, new String[]{".epub", "application/epub+zip"}, new String[]{".eri", "image/x-eri"}, new String[]{".es", "audio/echospeech"}, new String[]{".esl", "audio/echospeech"}, new String[]{".etc", "application/x-earthtime"}, new String[]{".etx", "text/x-setext"}, new String[]{".evm", "x-lml/x-evm"}, new String[]{".evy", "application/x-envoy"}, new String[]{".exe", "application/octet-stream"}, new String[]{".fh4", "image/x-freehand"}, new String[]{".fh5", "image/x-freehand"}, new String[]{".fhc", "image/x-freehand"}, new String[]{".fif", "image/fif"}, new String[]{".fm", "application/x-maker"}, new String[]{".fpx", "image/x-fpx"}, new String[]{".fvi", "video/isivideo"}, new String[]{".flv", "video/x-msvideo"}, new String[]{".gau", "chemical/x-gaussian-input"}, new String[]{".gca", "application/x-gca-compressed"}, new String[]{".gdb", "x-lml/x-gdb"}, new String[]{".gif", Attachment.GIF}, new String[]{".gps", "application/x-gps"}, new String[]{".gtar", "application/x-gtar"}, new String[]{".gz", "application/x-gzip"}, new String[]{".gif", Attachment.GIF}, new String[]{".gtar", "application/x-gtar"}, new String[]{".gz", "application/x-gzip"}, new String[]{".h", "text/plain"}, new String[]{".hdf", "application/x-hdf"}, new String[]{".hdm", "text/x-hdml"}, new String[]{".hdml", "text/x-hdml"}, new String[]{".htm", "text/html"}, new String[]{".html", "text/html"}, new String[]{".hlp", "application/winhlp"}, new String[]{".hqx", "application/mac-binhex40"}, new String[]{".hts", "text/html"}, new String[]{".ice", "x-conference/x-cooltalk"}, new String[]{".ico", "application/octet-stream"}, new String[]{".ief", "image/ief"}, new String[]{".ifm", Attachment.GIF}, new String[]{".ifs", "image/ifs"}, new String[]{".imy", "audio/melody"}, new String[]{".ins", "application/x-NET-Install"}, new String[]{".ips", "application/x-ipscript"}, new String[]{".ipx", "application/x-ipix"}, new String[]{".it", "audio/x-mod"}, new String[]{".itz", "audio/x-mod"}, new String[]{".ivr", "i-world/i-vrml"}, new String[]{".j2k", "image/j2k"}, new String[]{".jad", "text/vnd.sun.j2me.app-descriptor"}, new String[]{".jam", "application/x-jam"}, new String[]{".jnlp", "application/x-java-jnlp-file"}, new String[]{".jpe", "image/jpeg"}, new String[]{".jpz", "image/jpeg"}, new String[]{".jwc", "application/jwc"}, new String[]{".jar", "application/java-archive"}, new String[]{".java", "text/plain"}, new String[]{".jpeg", "image/jpeg"}, new String[]{".jpg", "image/jpeg"}, new String[]{".js", "application/x-javascript"}, new String[]{".kjx", "application/x-kjx"}, new String[]{".lak", "x-lml/x-lak"}, new String[]{".latex", "application/x-latex"}, new String[]{".lcc", "application/fastman"}, new String[]{".lcl", "application/x-digitalloca"}, new String[]{".lcr", "application/x-digitalloca"}, new String[]{".lgh", "application/lgh"}, new String[]{".lha", "application/octet-stream"}, new String[]{".lml", "x-lml/x-lml"}, new String[]{".lmlpack", "x-lml/x-lmlpack"}, new String[]{".log", "text/plain"}, new String[]{".lsf", "video/x-ms-asf"}, new String[]{".lsx", "video/x-ms-asf"}, new String[]{".lzh", "application/x-lzh "}, new String[]{".m13", "application/x-msmediaview"}, new String[]{".m14", "application/x-msmediaview"}, new String[]{".m15", "audio/x-mod"}, new String[]{".m3u", "audio/x-mpegurl"}, new String[]{".m3url", "audio/x-mpegurl"}, new String[]{".ma1", "audio/ma1"}, new String[]{".ma2", "audio/ma2"}, new String[]{".ma3", "audio/ma3"}, new String[]{".ma5", "audio/ma5"}, new String[]{".man", "application/x-troff-man"}, new String[]{".map", "magnus-internal/imagemap"}, new String[]{".mbd", "application/mbedlet"}, new String[]{".mct", "application/x-mascot"}, new String[]{".mdb", "application/x-msaccess"}, new String[]{".mdz", "audio/x-mod"}, new String[]{".me", "application/x-troff-me"}, new String[]{".mel", "text/x-vmel"}, new String[]{".mi", "application/x-mif"}, new String[]{".mid", "audio/midi"}, new String[]{".midi", "audio/midi"}, new String[]{".m4a", "audio/mp4a-latm"}, new String[]{".m4b", "audio/mp4a-latm"}, new String[]{".m4p", "audio/mp4a-latm"}, new String[]{".m4u", "video/vnd.mpegurl"}, new String[]{".m4v", "video/x-m4v"}, new String[]{".mov", "video/quicktime"}, new String[]{".mp2", "audio/x-mpeg"}, new String[]{".mp3", "audio/x-mpeg"}, new String[]{".mp4", "video/mp4"}, new String[]{".mpc", "application/vnd.mpohun.certificate"}, new String[]{".mpe", "video/mpeg"}, new String[]{".mpeg", "video/mpeg"}, new String[]{".mpg", "video/mpeg"}, new String[]{".mpg4", "video/mp4"}, new String[]{".mpga", "audio/mpeg"}, new String[]{".msg", "application/vnd.ms-outlook"}, new String[]{".mif", "application/x-mif"}, new String[]{".mil", "image/x-cals"}, new String[]{".mio", "audio/x-mio"}, new String[]{".mmf", "application/x-skt-lbs"}, new String[]{".mng", "video/x-mng"}, new String[]{".mny", "application/x-msmoney"}, new String[]{".moc", "application/x-mocha"}, new String[]{".mocha", "application/x-mocha"}, new String[]{".mod", "audio/x-mod"}, new String[]{".mof", "application/x-yumekara"}, new String[]{".mol", "chemical/x-mdl-molfile"}, new String[]{".mop", "chemical/x-mopac-input"}, new String[]{".movie", "video/x-sgi-movie"}, new String[]{".mpn", "application/vnd.mophun.application"}, new String[]{".mpp", "application/vnd.ms-project"}, new String[]{".mps", "application/x-mapserver"}, new String[]{".mrl", "text/x-mrml"}, new String[]{".mrm", "application/x-mrm"}, new String[]{".ms", "application/x-troff-ms"}, new String[]{".mts", "application/metastream"}, new String[]{".mtx", "application/metastream"}, new String[]{".mtz", "application/metastream"}, new String[]{".mzv", "application/metastream"}, new String[]{".nar", "application/zip"}, new String[]{".nbmp", "image/nbmp"}, new String[]{".nc", "application/x-netcdf"}, new String[]{".ndb", "x-lml/x-ndb"}, new String[]{".ndwn", "application/ndwn"}, new String[]{".nif", "application/x-nif"}, new String[]{".nmz", "application/x-scream"}, new String[]{".nokia-op-logo", "image/vnd.nok-oplogo-color"}, new String[]{".npx", "application/x-netfpx"}, new String[]{".nsnd", "audio/nsnd"}, new String[]{".nva", "application/x-neva1"}, new String[]{".oda", "application/oda"}, new String[]{".oom", "application/x-AtlasMate-Plugin"}, new String[]{".ogg", "audio/ogg"}, new String[]{".pac", "audio/x-pac"}, new String[]{".pae", "audio/x-epac"}, new String[]{".pan", "application/x-pan"}, new String[]{".pbm", "image/x-portable-bitmap"}, new String[]{".pcx", "image/x-pcx"}, new String[]{".pda", "image/x-pda"}, new String[]{".pdb", "chemical/x-pdb"}, new String[]{".pdf", "application/pdf"}, new String[]{".pfr", "application/font-tdpfr"}, new String[]{".pgm", "image/x-portable-graymap"}, new String[]{".pict", "image/x-pict"}, new String[]{".pm", "application/x-perl"}, new String[]{".pmd", "application/x-pmd"}, new String[]{".png", "image/png"}, new String[]{".pnm", "image/x-portable-anymap"}, new String[]{".pnz", "image/png"}, new String[]{".pot", "application/vnd.ms-powerpoint"}, new String[]{".potm", "application/vnd.ms-powerpoint"}, new String[]{".potx", "application/vnd.ms-powerpoint"}, new String[]{".ppam", "application/vnd.ms-powerpoint"}, new String[]{".ppm", "image/x-portable-pixmap"}, new String[]{".pps", "application/vnd.ms-powerpoint"}, new String[]{".ppsx", "application/vnd.ms-powerpoint"}, new String[]{".ppt", "application/vnd.ms-powerpoint"}, new String[]{".pptm", "application/vnd.ms-powerpoint"}, new String[]{".pptx", "application/vnd.ms-powerpoint"}, new String[]{".pqf", "application/x-cprplayer"}, new String[]{".pqi", "application/cprplayer"}, new String[]{".prc", "application/x-prc"}, new String[]{".proxy", "application/x-ns-proxy-autoconfig"}, new String[]{".prop", "text/plain"}, new String[]{".ps", "application/postscript"}, new String[]{".ptlk", "application/listenup"}, new String[]{".pub", "application/x-mspublisher"}, new String[]{".pvx", "video/x-pv-pvx"}, new String[]{".qcp", "audio/vnd.qcelp"}, new String[]{".qt", "video/quicktime"}, new String[]{".qti", "image/x-quicktime"}, new String[]{".qtif", "image/x-quicktime"}, new String[]{".r3t", "text/vnd.rn-realtext3d"}, new String[]{".ra", "audio/x-pn-realaudio"}, new String[]{".ram", "audio/x-pn-realaudio"}, new String[]{".ras", "image/x-cmu-raster"}, new String[]{".rdf", "application/rdf+xml"}, new String[]{".rf", "image/vnd.rn-realflash"}, new String[]{".rgb", "image/x-rgb"}, new String[]{".rlf", "application/x-richlink"}, new String[]{".rm", "audio/x-pn-realaudio"}, new String[]{".rmf", "audio/x-rmf"}, new String[]{".rmm", "audio/x-pn-realaudio"}, new String[]{".rnx", "application/vnd.rn-realplayer"}, new String[]{".roff", "application/x-troff"}, new String[]{".rp", "image/vnd.rn-realpix"}, new String[]{".rpm", "audio/x-pn-realaudio-plugin"}, new String[]{".rt", "text/vnd.rn-realtext"}, new String[]{".rte", "x-lml/x-gps"}, new String[]{".rtf", "application/rtf"}, new String[]{".rtg", "application/metastream"}, new String[]{".rtx", "text/richtext"}, new String[]{".rv", "video/vnd.rn-realvideo"}, new String[]{".rwc", "application/x-rogerwilco"}, new String[]{".rar", "application/x-rar-compressed"}, new String[]{".rc", "text/plain"}, new String[]{".rmvb", "audio/x-pn-realaudio"}, new String[]{".s3m", "audio/x-mod"}, new String[]{".s3z", "audio/x-mod"}, new String[]{".sca", "application/x-supercard"}, new String[]{".scd", "application/x-msschedule"}, new String[]{".sdf", "application/e-score"}, new String[]{".sdp", "application/sdp"}, new String[]{".sea", "application/x-stuffit"}, new String[]{".sgm", "text/x-sgml"}, new String[]{".sgml", "text/x-sgml"}, new String[]{".shar", "application/x-shar"}, new String[]{".shtml", "magnus-internal/parsed-html"}, new String[]{".shw", "application/presentations"}, new String[]{".si6", "image/si6"}, new String[]{".si7", "image/vnd.stiwap.sis"}, new String[]{".si9", "image/vnd.lgtwap.sis"}, new String[]{".sis", "application/vnd.symbian.install"}, new String[]{".sit", "application/x-stuffit"}, new String[]{".skd", "application/x-Koan"}, new String[]{".skm", "application/x-Koan"}, new String[]{".skp", "application/x-Koan"}, new String[]{".skt", "application/x-Koan"}, new String[]{".slc", "application/x-salsa"}, new String[]{".smd", "audio/x-smd"}, new String[]{".smi", "application/smil"}, new String[]{".smil", "application/smil"}, new String[]{".smp", "application/studiom"}, new String[]{".smz", "audio/x-smd"}, new String[]{".sh", "application/x-sh"}, new String[]{".snd", "audio/basic"}, new String[]{".spc", "text/x-speech"}, new String[]{".spl", "application/futuresplash"}, new String[]{".spr", "application/x-sprite"}, new String[]{".sprite", "application/x-sprite"}, new String[]{".spt", "application/x-spt"}, new String[]{".sql", "application/sql"}, new String[]{".src", "application/x-wais-source"}, new String[]{".stk", "application/hyperstudio"}, new String[]{".stm", "audio/x-mod"}, new String[]{".sv4cpio", "application/x-sv4cpio"}, new String[]{".sv4crc", "application/x-sv4crc"}, new String[]{".svf", "image/vnd"}, new String[]{".svg", "image/svg-xml"}, new String[]{".svh", "image/svh"}, new String[]{".svr", "x-world/x-svr"}, new String[]{".swf", "application/x-shockwave-flash"}, new String[]{".swfl", "application/x-shockwave-flash"}, new String[]{".t", "application/x-troff"}, new String[]{".tad", "application/octet-stream"}, new String[]{".talk", "text/x-speech"}, new String[]{".tar", "application/x-tar"}, new String[]{".taz", "application/x-tar"}, new String[]{".tbp", "application/x-timbuktu"}, new String[]{".tbt", "application/x-timbuktu"}, new String[]{".tcl", "application/x-tcl"}, new String[]{".tex", "application/x-tex"}, new String[]{".texi", "application/x-texinfo"}, new String[]{".texinfo", "application/x-texinfo"}, new String[]{".tgz", "application/x-tar"}, new String[]{".thm", "application/vnd.eri.thm"}, new String[]{".tif", "image/tiff"}, new String[]{".tiff", "image/tiff"}, new String[]{".tki", "application/x-tkined"}, new String[]{".tkined", "application/x-tkined"}, new String[]{".toc", "application/toc"}, new String[]{".toy", "image/toy"}, new String[]{".tr", "application/x-troff"}, new String[]{".trk", "x-lml/x-gps"}, new String[]{".trm", "application/x-msterminal"}, new String[]{".tsi", "audio/tsplayer"}, new String[]{".tsp", "application/dsptype"}, new String[]{".tsv", "text/tab-separated-values"}, new String[]{".ttf", "application/octet-stream"}, new String[]{".ttz", "application/t-time"}, new String[]{".txt", "text/plain"}, new String[]{".ult", "audio/x-mod"}, new String[]{".ustar", "application/x-ustar"}, new String[]{".uu", "application/x-uuencode"}, new String[]{".uue", "application/x-uuencode"}, new String[]{".vcd", "application/x-cdlink"}, new String[]{".vcf", "text/x-vcard"}, new String[]{".vdo", "video/vdo"}, new String[]{".vib", "audio/vib"}, new String[]{".viv", "video/vivo"}, new String[]{".vivo", "video/vivo"}, new String[]{".vmd", "application/vocaltec-media-desc"}, new String[]{".vmf", "application/vocaltec-media-file"}, new String[]{".vmi", "application/x-dreamcast-vms-info"}, new String[]{".vms", "application/x-dreamcast-vms"}, new String[]{".vox", "audio/voxware"}, new String[]{".vqe", "audio/x-twinvq-plugin"}, new String[]{".vqf", "audio/x-twinvq"}, new String[]{".vql", "audio/x-twinvq"}, new String[]{".vre", "x-world/x-vream"}, new String[]{".vrml", "x-world/x-vrml"}, new String[]{".vrt", "x-world/x-vrt"}, new String[]{".vrw", "x-world/x-vream"}, new String[]{".vts", "workbook/formulaone"}, new String[]{".wax", "audio/x-ms-wax"}, new String[]{".wbmp", "image/vnd.wap.wbmp"}, new String[]{".web", "application/vnd.xara"}, new String[]{".wav", "audio/x-wav"}, new String[]{".wma", "audio/x-ms-wma"}, new String[]{".wmv", "audio/x-ms-wmv"}, new String[]{".wi", "image/wavelet"}, new String[]{".wis", "application/x-InstallShield"}, new String[]{".wm", "video/x-ms-wm"}, new String[]{".wmd", "application/x-ms-wmd"}, new String[]{".wmf", "application/x-msmetafile"}, new String[]{".wml", "text/vnd.wap.wml"}, new String[]{".wmlc", "application/vnd.wap.wmlc"}, new String[]{".wmls", "text/vnd.wap.wmlscript"}, new String[]{".wmlsc", "application/vnd.wap.wmlscriptc"}, new String[]{".wmlscript", "text/vnd.wap.wmlscript"}, new String[]{".wmv", "video/x-ms-wmv"}, new String[]{".wmx", "video/x-ms-wmx"}, new String[]{".wmz", "application/x-ms-wmz"}, new String[]{".wpng", "image/x-up-wpng"}, new String[]{".wps", "application/vnd.ms-works"}, new String[]{".wpt", "x-lml/x-gps"}, new String[]{".wri", "application/x-mswrite"}, new String[]{".wrl", "x-world/x-vrml"}, new String[]{".wrz", "x-world/x-vrml"}, new String[]{".ws", "text/vnd.wap.wmlscript"}, new String[]{".wsc", "application/vnd.wap.wmlscriptc"}, new String[]{".wv", "video/wavelet"}, new String[]{".wvx", "video/x-ms-wvx"}, new String[]{".wxl", "application/x-wxl"}, new String[]{".x-gzip", "application/x-gzip"}, new String[]{".xar", "application/vnd.xara"}, new String[]{".xbm", "image/x-xbitmap"}, new String[]{".xdm", "application/x-xdma"}, new String[]{".xdma", "application/x-xdma"}, new String[]{".xdw", "application/vnd.fujixerox.docuworks"}, new String[]{".xht", "application/xhtml+xml"}, new String[]{".xhtm", "application/xhtml+xml"}, new String[]{".xhtml", "application/xhtml+xml"}, new String[]{".xla", "application/vnd.ms-excel"}, new String[]{".xlam", "application/vnd.ms-excel"}, new String[]{".xlc", "application/vnd.ms-excel"}, new String[]{".xll", "application/x-excel"}, new String[]{".xlm", "application/vnd.ms-excel"}, new String[]{".xls", "application/vnd.ms-excel"}, new String[]{".xlsm", "application/vnd.ms-excel"}, new String[]{".xlsx", "application/vnd.ms-excel"}, new String[]{".xlsb", "application/vnd.ms-excel"}, new String[]{".xlt", "application/vnd.ms-excel"}, new String[]{".xltx", "application/vnd.ms-excel"}, new String[]{".xlw", "application/vnd.ms-excel"}, new String[]{".xm", "audio/x-mod"}, new String[]{".xml", "text/xml"}, new String[]{".xmz", "audio/x-mod"}, new String[]{".xpi", "application/x-xpinstall"}, new String[]{".xpm", "image/x-xpixmap"}, new String[]{".xsit", "text/xml"}, new String[]{".xsl", "text/xml"}, new String[]{".xul", "text/xul"}, new String[]{".xwd", "image/x-xwindowdump"}, new String[]{".xyz", "chemical/x-pdb"}, new String[]{".yz1", "application/x-yz1"}, new String[]{".z", "application/x-compress"}, new String[]{".zac", "application/x-zaurus-zac"}, new String[]{".zip", "application/zip"}, new String[]{"", "*/*"}};
class a extends v0.a<String> {
a() {
}
@Override
public void onNext(String str) {
}
}
class b implements MediaScannerConnection.OnScanCompletedListener {
b() {
}
@Override
public void onScanCompleted(String str, Uri uri) {
Log.d("FileUtil", "==== insert to MediaStore.Uri:" + uri);
}
}
class c implements MediaScannerConnection.OnScanCompletedListener {
c() {
}
@Override
public void onScanCompleted(String str, Uri uri) {
Log.d("FileUtil", "==== insert to MediaStore.Uri:" + uri);
}
}
public class d extends v0.a<UploadFileResult> {
final f f10126a;
d(f fVar) {
this.f10126a = fVar;
}
@Override
public void onError(Throwable th) {
AkeyChatUtils.logException(th);
Log.w("FileUtil", "upload file failed:" + th.getMessage());
this.f10126a.f10130a = false;
}
@Override
public void onNext(UploadFileResult uploadFileResult) {
}
}
class e extends r0.b {
final String f10127b;
final Activity f10128c;
final Boolean f10129d;
e(String str, Activity activity, Boolean bool) {
this.f10127b = str;
this.f10128c = activity;
this.f10129d = bool;
}
@Override
public void onFailure(Exception exc) {
if ("auto".equals(this.f10127b) || "beep_manual".equals(this.f10127b)) {
Log.d("FileUtil", "upload failed");
}
new a1.c1(this.f10128c, 1, this.f10129d.booleanValue()).start();
}
@Override
public void onSuccess(JSONObject jSONObject) {
try {
jSONObject.getString("key");
} catch (JSONException e10) {
Log.d("FileUtil", "parse the uploadlog failed " + e10.getMessage());
e10.printStackTrace();
}
if ("auto".equals(this.f10127b) || "beep_manual".equals(this.f10127b)) {
Log.d("FileUtil", "upload Log success");
}
new a1.c1(this.f10128c, 1, this.f10129d.booleanValue()).start();
}
}
public static class f {
boolean f10130a = true;
}
public static void A(Akeychat.RecordType recordType, long j10, fc.b0 b0Var) throws Exception {
try {
b0Var.onNext(TokenManager.getSingleton().getFreeSeaweedUploadTokenFromServer(recordType, j10));
b0Var.onComplete();
} catch (Throwable th) {
b0Var.onError(th);
}
}
public static void B(String str, long j10, String str2, Akeychat.RecordType recordType, String str3, Akeychat.ChatType chatType, long j11, int i10, fc.b0 b0Var) throws Exception {
try {
b0Var.onNext(TokenManager.getSingleton().getS3UploadTokenFromServer(str, j10, str2, recordType, str3, chatType, j11, i10));
b0Var.onComplete();
} catch (Throwable th) {
b0Var.onError(th);
}
}
public static void C(String str, long j10, String str2, Akeychat.RecordType recordType, String str3, Akeychat.ChatType chatType, long j11, fc.b0 b0Var) throws Exception {
try {
b0Var.onNext(TokenManager.getSingleton().getS3UploadTokenFromServer(str, j10, str2, recordType, str3, chatType, j11, -1));
b0Var.onComplete();
} catch (Throwable th) {
b0Var.onError(th);
}
}
public static void D(String str, long j10, Akeychat.ChatType chatType, int i10, fc.b0 b0Var) throws Exception {
try {
b0Var.onNext(TokenManager.getSingleton().getSeaweedUploadTokenFromServer(str, j10, chatType, i10));
b0Var.onComplete();
} catch (Throwable th) {
b0Var.onError(th);
}
}
public static UploadFileResult E(String str, File file, retrofit2.j jVar) throws Exception {
UploadFileResult uploadFileResult = new UploadFileResult();
if (jVar.isSuccessful() && jVar.code() == 200) {
uploadFileResult.setmName(str);
uploadFileResult.setmSize(file.length());
return uploadFileResult;
}
Log.w("FileUtil", "Response is " + jVar.toString());
return null;
}
public static void F(Akeychat.GetSeaweedfsUploadTokenResponse getSeaweedfsUploadTokenResponse, File file, u0.e0 e0Var, okhttp3.m mVar, StringBuilder sb2, fc.b0 b0Var) throws Exception {
List<l.b> splitFileToMultipartBodies = u0.f0.splitFileToMultipartBodies(getSeaweedfsUploadTokenResponse, file, e0Var);
l.b bVar = splitFileToMultipartBodies.get(splitFileToMultipartBodies.size() - 1);
splitFileToMultipartBodies.remove(bVar);
f fVar = new f();
for (int i10 = 0; i10 < getSeaweedfsUploadTokenResponse.getChunkfidListCount(); i10++) {
l.b bVar2 = splitFileToMultipartBodies.get(i10);
u0.l0 l0Var = (u0.l0) u(mVar, sb2.toString()).create(u0.l0.class);
if (!fVar.f10130a) {
b0Var.onError(new AKStrException("upload file failed"));
return;
}
Log.i("FileUtil", "upload file:" + i10);
l0Var.uploadFiles(getSeaweedfsUploadTokenResponse.getChunkfidList(i10), bVar2).subscribe(new d(fVar));
}
b0Var.onNext(bVar);
b0Var.onComplete();
}
public static UploadFileResult G(File file, UploadFileResult uploadFileResult) throws Exception {
uploadFileResult.setmSize(file.length());
return uploadFileResult;
}
public static fc.e0 H(okhttp3.m mVar, StringBuilder sb2, Akeychat.GetSeaweedfsUploadTokenResponse getSeaweedfsUploadTokenResponse, final File file, l.b bVar) throws Exception {
return ((u0.m0) u(mVar, sb2.toString()).create(u0.m0.class)).uploadManifest(getSeaweedfsUploadTokenResponse.getFid(), bVar, PdfBoolean.TRUE).map(new mc.o() {
@Override
public final Object apply(Object obj) {
UploadFileResult G;
G = FileUtil.G(file, (UploadFileResult) obj);
return G;
}
});
}
@RequiresApi(api = 17)
private static void I(Context context, String str) {
Resources resources = context.getResources();
Locale locale = new Locale(str);
Locale.setDefault(locale);
Configuration configuration = resources.getConfiguration();
configuration.setLocale(locale);
resources.updateConfiguration(configuration, resources.getDisplayMetrics());
}
public static boolean checkFileValid(String str, String str2) {
if (checkPathValid(str)) {
return e.j.calculateMD5(new File(str)).equals(str2);
}
return false;
}
public static boolean checkPathValid(String str) {
Log.i("FileUtil", "test valid path is " + str);
if (TextUtils.isEmpty(str)) {
return false;
}
if (isVaultPath(str)) {
String path = f10114a.getPath(str);
Log.i("FileUtil", "test valid path vaultPath is " + path);
boolean isFileExist = isFileExist(path);
if (isFileExist) {
Log.debug("FileUtil", "file size is " + getFileSize(path));
}
return isFileExist;
}
try {
if (new StatFs(str).getTotalBytes() == 0) {
return false;
}
return true;
} catch (Exception unused) {
return false;
}
}
public static boolean checkSdcardCapability() {
String sDCardRootDirectory = getSDCardRootDirectory();
if (sDCardRootDirectory == null) {
return false;
}
File file = new File(sDCardRootDirectory);
if (file.getUsableSpace() < 40960) {
Log.d("FileUtil", "check sdcard capacity,availabe space:" + file.getUsableSpace() + ",IMConstant.LOW_CAPACITY_THRESHOLD:40960");
return false;
}
Log.d("FileUtil", "enought sdcard capability.");
return true;
}
public static void clearOutTimeFile() {
try {
ArrayList arrayList = new ArrayList();
arrayList.add(getGlobalCachePath());
arrayList.add(getUserRootPath());
arrayList.add(getSandBoxPath());
Iterator it = arrayList.iterator();
while (it.hasNext()) {
m((String) it.next());
}
} catch (Exception e10) {
e10.printStackTrace();
}
}
public static void copyFile(File file, String str) throws IOException {
FileInputStream fileInputStream = null;
try {
FileInputStream fileInputStream2 = new FileInputStream(file);
try {
copyFile(fileInputStream2, str);
try {
fileInputStream2.close();
} catch (IOException e10) {
Log.w("FileUtil", "", e10);
}
} catch (Throwable th) {
th = th;
fileInputStream = fileInputStream2;
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (IOException e11) {
Log.w("FileUtil", "", e11);
}
}
throw th;
}
} catch (Throwable th2) {
th = th2;
}
}
public static void copyFileNew(String str, String str2) {
if (isVaultPath(str)) {
str = f10114a.getPath(getVaultPath(str));
}
File file = new File(str);
if (isVaultPath(str2)) {
str2 = f10114a.getPath(getVaultPath(str2));
}
File file2 = new File(str2);
if (file2.exists()) {
file2.delete();
}
Log.i("FileUtil", "copy file " + str + " to " + str2);
try {
copyFile(file, str2);
} catch (IOException e10) {
e10.printStackTrace();
}
}
public static void copyFileWithLen(File file, String str, long j10) {
FileOutputStream fileOutputStream;
FileInputStream fileInputStream;
FileInputStream fileInputStream2 = null;
try {
try {
fileInputStream = new FileInputStream(file);
try {
fileOutputStream = new FileOutputStream(str);
} catch (IOException e10) {
e = e10;
fileOutputStream = null;
} catch (Throwable th) {
th = th;
fileOutputStream = null;
}
} catch (IOException e11) {
Log.e("FileUtil", "", e11);
}
} catch (IOException e12) {
e = e12;
fileOutputStream = null;
} catch (Throwable th2) {
th = th2;
fileOutputStream = null;
}
try {
byte[] bArr = new byte[1024];
long j11 = 0;
while (true) {
int read = fileInputStream.read(bArr);
if (read != -1) {
long j12 = read;
j11 += j12;
if (j11 > j10) {
break;
} else {
fileOutputStream.write(bArr, 0, read);
}
}
}
} catch (IOException e13) {
e = e13;
fileInputStream2 = fileInputStream;
try {
e.printStackTrace();
if (fileInputStream2 != null) {
try {
fileInputStream2.close();
} catch (IOException e14) {
Log.e("FileUtil", "", e14);
}
}
if (fileOutputStream != null) {
fileOutputStream.close();
}
return;
} catch (Throwable th3) {
th = th3;
if (fileInputStream2 != null) {
try {
fileInputStream2.close();
} catch (IOException e15) {
Log.e("FileUtil", "", e15);
}
}
if (fileOutputStream == null) {
try {
fileOutputStream.close();
throw th;
} catch (IOException e16) {
Log.e("FileUtil", "", e16);
throw th;
}
}
throw th;
}
} catch (Throwable th4) {
th = th4;
fileInputStream2 = fileInputStream;
if (fileInputStream2 != null) {
}
if (fileOutputStream == null) {
}
}
fileOutputStream.close();
}
public static File copyVaultFileToTemp(String str) {
try {
String vaultPath = getVaultPath(str);
String str2 = ".gif";
if (vaultPath.startsWith("/image")) {
if (!str.endsWith(".gif")) {
str2 = ".jpeg";
}
} else {
str2 = "_" + vaultPath.substring(vaultPath.lastIndexOf(47) + 1);
}
Log.i("FileUtil", str2 + " temp file name is " + vaultPath);
File createTempFile = File.createTempFile("vft", str2, j.a.get().getCacheDir());
f10114a.decryptFile(str, createTempFile.getAbsolutePath(), null);
if (createTempFile.length() <= 0) {
deleteFile(str);
return null;
}
return createTempFile;
} catch (Exception e10) {
Log.e("FileUtil", "copy origin file to temp failed");
deleteFile(str);
AkeyChatUtils.logException(e10);
return null;
}
}
public static File copyVaultFileToTempForAndroid6(String str) {
try {
String vaultPath = getVaultPath(str);
String str2 = ".gif";
if (vaultPath.startsWith("/image")) {
if (!str.endsWith(".gif")) {
str2 = ".jpeg";
}
} else {
str2 = "_" + vaultPath.substring(vaultPath.lastIndexOf(47) + 1);
}
Log.i("FileUtil", str2 + " temp file name is " + vaultPath);
String globalCacheVftPath = getGlobalCacheVftPath();
createDir(new File(globalCacheVftPath));
String str3 = globalCacheVftPath + File.separator + "vft" + str2;
f10114a.decryptFile(str, str3, null);
return new File(str3);
} catch (Exception e10) {
Log.e("FileUtil", "copy origin file to temp failed");
AkeyChatUtils.logException(e10);
return null;
}
}
public static File creatSDDir(String str) {
File file = new File(str);
file.mkdir();
return file;
}
public static boolean createDir(File file) {
String path;
if (isVaultPath(file.getPath())) {
path = f10114a.getPath(file.getPath());
} else {
path = file.getPath();
}
File file2 = new File(path);
try {
if (!file2.exists()) {
return file2.mkdirs();
}
return true;
} catch (Exception e10) {
Log.e("FileUtil", "create dir error", e10);
return false;
}
}
public static void createFileIfNotExistByName(String str) {
File file = new File(str);
if (!file.exists()) {
createDir(file);
Log.i("FileUtil", "create success , file is " + file.exists() + ",path is " + file.getAbsolutePath());
}
}
public static File createNewFile(File file) {
try {
if (file.exists()) {
return file;
}
File parentFile = file.getParentFile();
if (!parentFile.exists()) {
parentFile.mkdirs();
}
if (!file.exists()) {
file.createNewFile();
}
return file;
} catch (IOException e10) {
Log.e("FileUtil", "", e10);
return null;
}
}
public static void createVaultDirByFilePath(String str) {
if (f10114a != null && !TextUtils.isEmpty(str)) {
String vaultPath = getVaultPath(str);
System.out.println("absolute path " + str + ", vault path " + vaultPath);
File file = new File(f10114a.getPath(vaultPath));
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
}
}
public static boolean currentLanguageIsChinese(Context context) {
String language;
LocaleList locales;
if (Build.VERSION.SDK_INT >= 24) {
locales = context.getResources().getConfiguration().getLocales();
language = locales.get(0).getLanguage();
} else {
language = context.getResources().getConfiguration().locale.getLanguage();
}
Log.e("LanguageUtil", "language = " + language);
return TextUtils.equals("zh", language);
}
public static void deleteFile(String str) {
if (str == null) {
return;
}
if (isVaultPath(str)) {
str = f10114a.getPath(str);
}
deleteFile(new File(str));
}
public static void deleteFileByMediaStore(String str) {
try {
ContentResolver contentResolver = j.a.get().getContentResolver();
Uri contentUri = MediaStore.Files.getContentUri("external");
new ContentValues();
Log.i("FileUtil", "deleteFileByMediaStore is " + contentResolver.delete(contentUri, "_data=?", new String[]{str}) + ",path is " + str);
} catch (Exception e10) {
e10.printStackTrace();
}
}
public static void downloadAudioAttachment(ChatMessage chatMessage) {
User userMe;
if (chatMessage == null) {
Log.w("FileUtil", "msg is null do not download audio attachment");
return;
}
String type = chatMessage.getType();
if (!ChatMessage.CHAT_AUDIO.equals(type)) {
Log.w("FileUtil", "msg type is not audio:" + type + ",cancel download attachment");
return;
}
Attachment attachment = chatMessage.getAttachment();
if (attachment == null) {
Log.w("FileUtil", "attachment is null cancel download audio attachment");
return;
}
String key = attachment.getKey();
if (checkPathValid(attachment.getSrcUri())) {
Log.w("FileUtil", "audio attchment file has exist,cancel download");
return;
}
String downloadUrlByKey = getDownloadUrlByKey(key);
long parseLong = Long.parseLong(attachment.getSize());
String audioPathByWith = getAudioPathByWith(chatMessage.getWith());
createDir(new File(audioPathByWith));
String str = audioPathByWith + h4.getLocalSrcImageNameByKey(key);
byte[] bytesFromHttpsUrl = HttpURLTools.getBytesFromHttpsUrl(downloadUrlByKey, 5000, ak.im.sdk.manager.f1.getInstance().getAccessToken(), ak.im.sdk.manager.f1.getInstance().getServerIdFromChatMessage(chatMessage));
if (bytesFromHttpsUrl == null) {
Log.w("FileUtil", "bytes is null download failed");
return;
}
if ("encryption".equals(chatMessage.getSecurity())) {
h4.saveFile(bytesFromHttpsUrl, str);
if (!chatMessage.getFrom().contains(ak.im.sdk.manager.f1.getInstance().getUsername())) {
userMe = bf.getInstance().getUserInfoByName(chatMessage.getFrom().split("@")[0], false, true);
} else {
userMe = bf.getInstance().getUserMe();
}
User user = userMe;
if (user != null) {
String str2 = str + ".decr";
Log.i("FileUtil", "decrypt audio file:" + str + " start on " + o3.getCurDateStr());
try {
AKeyManager.getInstance().decryptNewAndOldEncryptedFile(user, parseLong, str, str2, chatMessage);
} catch (Exception e10) {
e10.printStackTrace();
}
Log.i("FileUtil", "decrypt audio file:" + str2 + " end on " + o3.getCurDateStr());
deleteFile(str);
str = str2;
} else {
Log.w("FileUtil", "error happend meesage can not decrypt,null user");
}
} else if (IMMessage.PLAIN.equals(chatMessage.getSecurity())) {
h4.saveFile(bytesFromHttpsUrl, str);
} else {
Log.w("FileUtil", "other security");
}
attachment.setSrcUri(str);
}
public static boolean downloadEmoticon(Emoticon emoticon) {
String str;
if (emoticon != null && !TextUtils.isEmpty(emoticon.getUrl())) {
String emoticonPath = getEmoticonPath();
String str2 = emoticonPath + h4.decreaseFileNameLength(emoticon.getUrl());
Log.d("FileUtil", "emoticon path is " + str2);
if (new File(str2).exists()) {
Log.e("FileUtil", "emoticon is exist");
return false;
}
createDir(new File(emoticonPath));
byte[] bytesFromHttpsUrl = HttpURLTools.getBytesFromHttpsUrl(emoticon.getLocalUrl(), AKCDiscoverGlobal.AKCDiscoverError_BNOffline, ak.im.sdk.manager.f1.getInstance().getAccessToken(), null);
if (bytesFromHttpsUrl != null && bytesFromHttpsUrl.length != 0) {
if (!str2.endsWith("_enc")) {
str2 = str2 + "_enc";
}
h4.saveFile(bytesFromHttpsUrl, str2);
Log.i("FileUtil", "decrypt file " + str2 + " start on " + o3.getCurDateStr());
if (str2.endsWith("_enc")) {
str = str2.substring(0, str2.length() - 4);
} else {
str = str2;
}
com.google.protobuf.e privateKey = AKeyManager.getInstance().getMyKeyBundle().getIdentityKey().getPrivateKey();
Log.d("FileUtil", "key string is " + privateKey.toString());
byte[] byteArray = privateKey.toByteArray();
byte[] bArr = new byte[16];
byte[] bArr2 = new byte[16];
System.arraycopy(byteArray, 0, bArr, 0, 16);
System.arraycopy(byteArray, 16, bArr2, 0, 16);
try {
AKeyManager.getInstance().newDecryptFile(str2, str, bArr, bArr2);
} catch (AKeyManager.NoUser e10) {
e10.printStackTrace();
Log.d("FileUtil", e10.getMessage());
}
Log.i("FileUtil", "decrypt file " + str2 + " end on " + o3.getCurDateStr() + ",decrypt path:" + str);
if (!TextUtils.isEmpty(str2)) {
File file = new File(str2);
if (file.exists()) {
file.delete();
}
}
return true;
}
Log.e("FileUtil", "download image failed! downloadUrl is " + emoticon.getLocalUrl());
return false;
}
Log.e("FileUtil", "emoticon is null");
return true;
}
public static boolean downloadImageSource(ChatMessage chatMessage) {
String replaceAll;
String str;
User userInfoByName;
if (chatMessage != null && chatMessage.getAttachment() != null) {
if (!q5.isEmptyString(chatMessage.getAttachment().getSrcUri()) && checkPathValid(chatMessage.getAttachment().getSrcUri())) {
return true;
}
if (!q5.isEmptyString(chatMessage.getAttachment().getOriginUri()) && checkPathValid(chatMessage.getAttachment().getOriginUri())) {
return true;
}
try {
if (chatMessage.getAttachment().getAntiShot() == 1) {
replaceAll = URLEncoder.encode(chatMessage.getAttachment().getOriginKey(), "UTF-8").replaceAll("\\+", "%20");
} else {
replaceAll = URLEncoder.encode(chatMessage.getAttachment().getKey(), "UTF-8").replaceAll("\\+", "%20");
}
String downloadUrlByKey = getDownloadUrlByKey(replaceAll);
long parseLong = Long.parseLong(chatMessage.getAttachment().getSize());
if (chatMessage.getAttachment().getAntiShot() == 1) {
parseLong = Long.parseLong(chatMessage.getAttachment().getOriginSize());
}
long j10 = parseLong;
String imagePathByWith = getImagePathByWith(chatMessage.getWith(), chatMessage.getAttachment().isReadOnly());
String imgPath = getImgPath(chatMessage);
createDir(new File(imagePathByWith));
byte[] bytesFromHttpsUrl = HttpURLTools.getBytesFromHttpsUrl(downloadUrlByKey, AKCDiscoverGlobal.AKCDiscoverError_BNOffline, ak.im.sdk.manager.f1.getInstance().getAccessToken(), ak.im.sdk.manager.f1.getInstance().getServerIdFromChatMessage(chatMessage));
if (bytesFromHttpsUrl != null && bytesFromHttpsUrl.length != 0) {
if ("encryption".equals(chatMessage.getSecurity())) {
if (!imgPath.endsWith(".encr")) {
imgPath = imgPath + ".encr";
}
h4.saveFile(bytesFromHttpsUrl, imgPath);
if (chatMessage.getAKeyType() != null && (chatMessage.getAKeyType() == null || !chatMessage.getAKeyType().contains("null"))) {
Log.i("FileUtil", "decrypt file " + imgPath + " start on " + o3.getCurDateStr());
if (imgPath.endsWith(".encr")) {
str = imgPath.substring(0, imgPath.length() - 5);
} else {
str = imgPath;
}
if (!"group".equals(chatMessage.getChatType())) {
userInfoByName = bf.getInstance().getUserMe();
if (!userInfoByName.getJID().equals(chatMessage.getFrom())) {
userInfoByName = bf.getInstance().getUserIncontacters(chatMessage.getFrom());
}
} else {
userInfoByName = bf.getInstance().getUserInfoByName(chatMessage.getFrom().split("@")[0], false, true);
}
try {
AKeyManager.getInstance().decryptNewAndOldEncryptedFile(userInfoByName, j10, imgPath, str, chatMessage);
Log.i("FileUtil", "decrypt file " + imgPath + " end on " + o3.getCurDateStr() + ",decrypt path:" + str);
if (TextUtils.isEmpty(imgPath)) {
File file = new File(imgPath);
if (file.exists()) {
file.delete();
}
}
} catch (AKeyManager.NoUser e10) {
e10.printStackTrace();
return false;
} catch (AKeyManager.NoWorkingAKey e11) {
e11.printStackTrace();
return false;
}
} else {
Log.e("FileUtil", "");
return false;
}
} else {
h4.saveFile(bytesFromHttpsUrl, imgPath);
if (TextUtils.isEmpty(imgPath)) {
File file2 = new File(imgPath);
if (file2.exists()) {
file2.delete();
}
}
}
return true;
}
Log.e("FileUtil", "download image failed! downloadUrl is " + downloadUrlByKey);
return false;
} catch (UnsupportedEncodingException e12) {
e12.printStackTrace();
return false;
}
}
Log.d("FileUtil", "message attachment is empty");
return true;
}
public static String downloadImageThumb(ChatMessage chatMessage) {
String userFilePath;
String str;
User userMe;
if (chatMessage == null) {
Log.w("FileUtil", "message is null");
return null;
}
String thumbKey = chatMessage.getAttachment().getThumbKey();
if (TextUtils.isEmpty(thumbKey)) {
Log.w("FileUtil", "thumb key is null do not download it");
return null;
}
try {
String replaceAll = URLEncoder.encode(thumbKey, "UTF-8").replaceAll("\\+", "%20");
String type = chatMessage.getType();
if ("video".equals(type)) {
userFilePath = getVideoPathByWith(chatMessage.getWith(), false);
} else if (ChatMessage.CHAT_IMAGE.equals(type)) {
userFilePath = getImagePathByWith(chatMessage.getWith(), false);
} else if (ChatMessage.CHAT_FILE.equals(type)) {
userFilePath = getUserFilePath();
} else {
Log.w("FileUtil", "other message type:" + type);
return null;
}
Attachment attachment = chatMessage.getAttachment();
String downloadUrlByKey = getDownloadUrlByKey(replaceAll);
Log.i("FileUtil", "downloading image from url:" + downloadUrlByKey);
long j10 = 0;
try {
j10 = Long.parseLong(attachment.getThumbSize());
} catch (NumberFormatException e10) {
e10.printStackTrace();
Log.w("FileUtil", "parse file size error:" + attachment.getThumbSize());
}
createDir(new File(userFilePath));
boolean equals = "encryption".equals(chatMessage.getSecurity());
String str2 = userFilePath + h4.getLocalSrcImageNameByKey(thumbKey);
if (equals) {
str = userFilePath + o3.getRightTime() + h4.getLocalSrcImageNameByKey(thumbKey);
} else {
str = str2;
}
if (equals) {
str = str + ".encr";
}
String str3 = str;
byte[] bytesFromHttpsUrl = HttpURLTools.getBytesFromHttpsUrl(downloadUrlByKey, AKCDiscoverGlobal.AKCDiscoverError_BNOffline, ak.im.sdk.manager.f1.getInstance().getAccessToken(), ak.im.sdk.manager.f1.getInstance().getServerIdFromChatMessage(chatMessage));
if (bytesFromHttpsUrl == null) {
Log.w("FileUtil", "download thumbnail failed:" + chatMessage);
return null;
}
Log.i("FileUtil", "get thumbBm");
h4.saveFile(bytesFromHttpsUrl, str3);
if (equals) {
if (!chatMessage.getFrom().contains(ak.im.sdk.manager.f1.getInstance().getUsername())) {
userMe = bf.getInstance().getUserInfoByName(chatMessage.getFrom().split("@")[0], false, true);
} else {
userMe = bf.getInstance().getUserMe();
}
User user = userMe;
if (user != null) {
try {
AKeyManager.getInstance().decryptNewAndOldEncryptedFile(user, j10, str3, str2, chatMessage);
} catch (Exception e11) {
e11.printStackTrace();
}
Log.i("FileUtil", "decrypt thumb file " + str3);
deleteFile(str3);
}
}
return str2;
} catch (UnsupportedEncodingException e12) {
e12.printStackTrace();
return null;
}
}
public static String downloadMessageAttachment(ChatMessage chatMessage) {
if (chatMessage == null) {
Log.w("FileUtil", "msg is null do not need download its attachment");
return null;
}
String type = chatMessage.getType();
if (ChatMessage.CHAT_AUDIO.equals(type)) {
downloadAudioAttachment(chatMessage);
return null;
}
if (!"video".equals(type) && !ChatMessage.CHAT_IMAGE.equals(type)) {
if (!ChatMessage.CHAT_FILE.equals(type) || TextUtils.isEmpty(chatMessage.getAttachment().getThumbKey()) || TextUtils.isEmpty(chatMessage.getAttachment().getThumbSize())) {
return null;
}
return downloadImageThumb(chatMessage);
}
downloadImageThumb(chatMessage);
return null;
}
public static void downloadMessageAttachmentSync(final ChatMessage chatMessage) {
if (chatMessage == null) {
Log.w("FileUtil", "msg is null do not need download its attachment");
} else {
fc.z.just(chatMessage.getType()).map(new mc.o() {
@Override
public final Object apply(Object obj) {
String w10;
w10 = FileUtil.w(ChatMessage.this, (String) obj);
return w10;
}
}).subscribeOn(gd.b.io()).observeOn(ic.a.mainThread()).subscribe(new a());
}
}
public static String downloadReferenceMsgAttach(ChatMessage chatMessage, boolean z10) {
String key;
String filePathByWith;
String str;
String str2;
User userMe;
if (chatMessage == null) {
Log.w("FileUtil", "message is null");
return null;
}
Attachment attachment = chatMessage.getAttachment();
if (attachment == null) {
Log.w("FileUtil", "your attachment is null");
return null;
}
Attachment loadRefAttachment = AkeyChatUtils.loadRefAttachment(attachment);
try {
if (z10) {
key = loadRefAttachment.getThumbKey();
} else {
key = loadRefAttachment.getKey();
}
String downloadUrlByKey = getDownloadUrlByKey(URLEncoder.encode(key, "UTF-8").replaceAll("\\+", "%20"));
Log.i("FileUtil", "downloading image from url:" + downloadUrlByKey);
long parseLong = Long.parseLong(loadRefAttachment.getThumbSize());
String refMsgType = chatMessage.getAttachment().getRefMsgType();
if ("video".equals(refMsgType)) {
filePathByWith = getVideoPathByWith(chatMessage.getWith(), loadRefAttachment.isReadOnly());
} else if (ChatMessage.CHAT_IMAGE.equals(refMsgType)) {
filePathByWith = getImagePathByWith(chatMessage.getWith(), loadRefAttachment.isReadOnly());
} else if (ChatMessage.CHAT_FILE.equals(refMsgType)) {
filePathByWith = getFilePathByWith(chatMessage.getWith(), loadRefAttachment.isReadOnly());
} else {
Log.w("FileUtil", "other message type:" + refMsgType);
return null;
}
createDir(new File(filePathByWith));
if (z10) {
str = filePathByWith + h4.getLocalSrcImageNameByKey(loadRefAttachment.getThumbKey());
} else {
str = filePathByWith + h4.getLocalSrcImageNameByKey(loadRefAttachment.getKey());
}
boolean equals = "encryption".equals(chatMessage.getSecurity());
if (equals) {
str2 = str + ".encr";
} else {
str2 = str;
}
byte[] bytesFromHttpsUrl = HttpURLTools.getBytesFromHttpsUrl(downloadUrlByKey, AKCDiscoverGlobal.AKCDiscoverError_BNOffline, ak.im.sdk.manager.f1.getInstance().getAccessToken(), ak.im.sdk.manager.f1.getInstance().getServerIdFromChatMessage(chatMessage));
if (bytesFromHttpsUrl == null) {
Log.w("FileUtil", "download thumbnail failed:" + chatMessage);
return null;
}
h4.saveFile(bytesFromHttpsUrl, str2);
String str3 = chatMessage.getAttachment().getRefSrc().split("@")[0];
if (equals) {
boolean equals2 = str3.equals(ak.im.sdk.manager.f1.getInstance().getUsername());
if (!equals2) {
userMe = bf.getInstance().getUserInfoByName(str3);
} else {
userMe = bf.getInstance().getUserMe();
}
User user = userMe;
if (user != null) {
Log.i("FileUtil", "decrypt thumb file " + str2 + ",refersrc:" + str3 + "," + chatMessage.getAttachment().getRefSrc());
try {
ChatMessage chatMessage2 = new ChatMessage();
chatMessage2.setUniqueId(loadRefAttachment.getRefUid());
chatMessage2.setFrom(loadRefAttachment.getRefSrc());
chatMessage2.setWith(chatMessage.getWith());
chatMessage2.setChatType(chatMessage.getChatType());
chatMessage2.setAKeyType(chatMessage.getAKeyType());
if (equals2) {
chatMessage2.setDir(IMMessage.SEND);
} else {
chatMessage2.setDir(IMMessage.RECV);
}
chatMessage2.setEncryptVer(chatMessage.getEncryptVer());
chatMessage2.setAttachment(loadRefAttachment);
try {
chatMessage2.setE2EHead(Akeychat.E2EMessageHead.parseFrom(loadRefAttachment.getRefMsgHead()));
} catch (Exception e10) {
e10.printStackTrace();
}
if (TextUtils.isEmpty(loadRefAttachment.getRefUid())) {
Log.w("FileUtil", "check illegal ref msg:" + chatMessage);
}
AKeyManager.getInstance().decryptNewAndOldEncryptedFile(user, parseLong, str2, str, chatMessage2);
} catch (Exception e11) {
e11.printStackTrace();
}
Log.i("FileUtil", "decrypt thumb file " + str2 + " end on " + o3.getCurDateStr());
deleteFile(str2);
}
}
return str;
} catch (UnsupportedEncodingException e12) {
e12.printStackTrace();
return null;
}
}
public static boolean fileExist(File file) {
if (file == null) {
return false;
}
String path = file.getPath();
if (isVaultPath(path)) {
return new File(f10114a.getPath(path)).exists();
}
return file.exists();
}
public static boolean fileSupportedPreview(String str) {
return "other".equals(str);
}
public static String genCaptureAudioName() {
return "audio-" + String.valueOf(Calendar.getInstance().getTimeInMillis()) + ".src";
}
public static String genCaptureImageName() {
return "image-" + String.valueOf(Calendar.getInstance().getTimeInMillis()) + ".src";
}
public static String genFirmwareSavePath(String str) {
return r() + str;
}
public static String genSipRecordFilePath() {
return getGlobalLogPath() + BaseWorkflow.TEMPLATE_TYPE_NORMAL + "-" + o3.getCurDateStr("yyyy-MM-dd-HH-mm-ss") + ".wav";
}
public static String genTempFilePath(String str) {
File file;
try {
file = File.createTempFile("vft", str, j.a.get().getCacheDir());
} catch (IOException e10) {
e10.printStackTrace();
file = null;
}
if (file != null) {
return file.getPath();
}
return "";
}
public static String generateAFileWithoutRepeatName(String str) {
File file;
if (str != null && str.contains(CookieSpec.PATH_DELIM)) {
if (!checkPathValid(str)) {
return str;
}
String[] split = str.split(CookieSpec.PATH_DELIM);
String str2 = split[split.length - 1];
String substring = str.substring(0, str.lastIndexOf(CookieSpec.PATH_DELIM) + 1);
int lastIndexOf = str2.lastIndexOf(".");
String substring2 = str2.substring(0, lastIndexOf);
String substring3 = str2.substring(lastIndexOf);
int i10 = 1;
do {
file = new File(substring, substring2 + "(" + i10 + ")" + substring3);
i10++;
} while (checkPathValid(file.getAbsolutePath()));
return file.getAbsolutePath();
}
Log.w("FileUtil", "illegal path:" + str);
return str;
}
public static String generateLogZipUri(long j10, long j11, String str) {
File[] listFiles = new File(getGlobalLogPath()).listFiles();
if (listFiles != null && listFiles.length != 0) {
ArrayList arrayList = new ArrayList();
for (File file : listFiles) {
if (file.getName().startsWith(BaseWorkflow.TEMPLATE_TYPE_NORMAL)) {
long str2Long = o3.str2Long(getNameFromFilename(file.getName()).substring(7), "yyyy-MM-dd-HH-mm-ss");
if (str2Long >= j10 && str2Long <= j11) {
arrayList.add(file.getAbsolutePath());
}
}
}
if (arrayList.size() == 0) {
return null;
}
String str2 = getGlobalCachePath() + p(str);
deleteFile(str2);
createNewFile(str2);
try {
x5.writeByApacheZipOutputStream(arrayList, str2, "");
return str2;
} catch (FileNotFoundException e10) {
e10.printStackTrace();
} catch (IOException e11) {
e11.printStackTrace();
return null;
}
}
return null;
}
public static String generateShotImageNameInWebView() {
String str = j.u0.f40392d + getAppRootPath() + File.separator + ChatMessage.CHAT_IMAGE + "-web_shot" + System.nanoTime() + ".jpg";
f10117d = str;
return str;
}
public static String getAKCachePath(Context context) {
String str;
if (Build.VERSION.SDK_INT >= 24) {
str = context.getCacheDir().getAbsolutePath();
} else {
File externalCacheDir = context.getExternalCacheDir();
if (externalCacheDir != null) {
str = externalCacheDir.getAbsolutePath();
} else {
str = null;
}
if (str == null) {
String absolutePath = Environment.getExternalStorageDirectory().getAbsolutePath();
if (!absolutePath.endsWith(CookieSpec.PATH_DELIM)) {
absolutePath = absolutePath + CookieSpec.PATH_DELIM;
}
str = absolutePath + "AKeyChat/.cache/";
}
}
if (!str.equals(CookieSpec.PATH_DELIM)) {
return str + CookieSpec.PATH_DELIM;
}
return str;
}
public static String getAKeyDeviceInfo() {
Log.d("FileUtil", "cat /proc/bus/usb/devices");
try {
Process exec = Runtime.getRuntime().exec("cat /proc/bus/usb/devices");
BufferedInputStream bufferedInputStream = new BufferedInputStream(exec.getInputStream());
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(bufferedInputStream));
while (true) {
String readLine = bufferedReader.readLine();
if (readLine != null) {
Log.d("FileUtil", readLine);
if (exec.waitFor() != 0 && exec.exitValue() == 1) {
Log.e("FileUtil", "check mount info failed");
return null;
}
} else {
bufferedReader.close();
bufferedInputStream.close();
return null;
}
}
} catch (Exception e10) {
e10.printStackTrace();
return null;
}
}
public static String getAKeyPath() {
Log.d("FileUtil", "cat /proc/mounts");
try {
Process exec = Runtime.getRuntime().exec("cat /proc/mounts");
BufferedInputStream bufferedInputStream = new BufferedInputStream(exec.getInputStream());
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(bufferedInputStream));
while (true) {
String readLine = bufferedReader.readLine();
if (readLine != null) {
Log.d("FileUtil", readLine);
if (readLine.toLowerCase().contains("usb") || readLine.toLowerCase().contains("udisk")) {
String[] split = readLine.split(" ");
if (split.length >= 3) {
return split[1].trim();
}
}
if (exec.waitFor() != 0 && exec.exitValue() == 1) {
Log.e("FileUtil", "check mount info failed");
return null;
}
} else {
bufferedReader.close();
bufferedInputStream.close();
return null;
}
}
} catch (Exception e10) {
e10.printStackTrace();
return null;
}
}
public static fc.z<Akeychat.GetAliyunfsUploadTokenResponse> getAliyunFsUploadResource(final String str, final long j10, final String str2, final Akeychat.RecordType recordType, final String str3, final Akeychat.ChatType chatType, final long j11, final int i10) {
return fc.z.create(new fc.c0() {
@Override
public final void subscribe(fc.b0 b0Var) {
FileUtil.y(str, j10, str2, recordType, str3, chatType, j11, i10, b0Var);
}
});
}
public static String getAppDataPath() {
String str = getAppRootPath() + "/data";
EnterpriseInfo currentEnterpriseInfo = ak.im.sdk.manager.f1.getInstance().getmEnterpriseCfg().getCurrentEnterpriseInfo();
if (currentEnterpriseInfo != null) {
str = str + "/enterprise-" + e.j.MD5Encode(currentEnterpriseInfo.enterpriseID);
Log.w("FileUtil", "enterprise info is not null:" + str);
} else {
Log.w("FileUtil", "enterprise info is null");
new RuntimeException("has not choose enterprise,do your job after choosing a enterprise--OF");
}
Log.i("FileUtil", "we get enterprise version app data path:" + str);
return str;
}
public static String getAppRootPath() {
return j.u0.f40394e;
}
public static String getArticleUrlByKey(String str) {
return ak.im.sdk.manager.f1.getInstance().getArticleUrlPrefix(str);
}
public static String getAudioPathByWith(String str) {
if (j.u0.f40392d != null && ak.im.sdk.manager.f1.getInstance().getUsername() != null && str != null) {
return getUserAudioPath() + q5.getUserNameByJid(str) + File.separator;
}
return null;
}
public static String getAvatarTempImageName(String str) {
return getUserTempPath() + ChatMessage.CHAT_IMAGE + "-" + e.j.MD5Encode(str) + System.nanoTime() + ".jpg";
}
public static String getAvatarTempImageNameBeforeSignUp() {
return j.u0.f40392d + getAppRootPath() + ChatMessage.CHAT_IMAGE + "-shot-out-" + f10115b.hashCode();
}
public static String getAvatarTempImageNameForThumb() {
return getUserTempPath() + ChatMessage.CHAT_IMAGE + "-" + o3.getCurDateStr("yyyy-MM-dd-HH-mm-ss") + "_thumb_" + System.nanoTime() + ".jpg";
}
public static String getAvatarTempImageNameForThumbBeforeSignUp() {
return j.u0.f40392d + getAppRootPath() + ChatMessage.CHAT_IMAGE + "-shot-out" + f10115b.hashCode() + "_thumb";
}
public static String getBackupDeviceFilePath() {
return getBackupPath() + "/device.dat";
}
public static String getBackupFilePath() {
return getBackupPath() + "/bk.dat";
}
public static String getBackupPath() {
return getSDCardRootDirectory() + "/Android/data/." + BuildConfig.PRODUCT_PKG_NAME + "/kv";
}
public static String getCacheFileByWith(String str) {
if (TextUtils.isEmpty(str)) {
return null;
}
String str2 = j.a.get().getCacheDir() + CookieSpec.PATH_DELIM + q5.getUserNameByJid(str) + File.separator;
createFileIfNotExistByName(str2);
return str2;
}
public static String getDataColumn(Context context, Uri uri, String str, String[] strArr) {
Cursor cursor;
Cursor cursor2 = null;
try {
if (Build.VERSION.SDK_INT >= 24 && "com.miui.gallery.open".equals(uri.getAuthority())) {
context.grantUriPermission("com.miui.gallery.provider.GalleryOpenProvider", uri, 3);
}
Cursor query = context.getContentResolver().query(uri, null, str, strArr, null);
if (query != null) {
try {
query.moveToFirst();
Log.i("FileUtil", "cursor count:" + query.getColumnCount());
String[] columnNames = query.getColumnNames();
if (columnNames != null) {
for (String str2 : columnNames) {
Log.i("FileUtil", "check column name:" + str2 + ",c:" + query.getString(query.getColumnIndex(str2)));
}
}
} catch (Exception e10) {
cursor = query;
e = e10;
try {
AkeyChatUtils.logException(e);
if (cursor != null) {
cursor.close();
}
return null;
} catch (Throwable th) {
th = th;
cursor2 = cursor;
if (cursor2 != null) {
cursor2.close();
}
throw th;
}
} catch (Throwable th2) {
cursor2 = query;
th = th2;
if (cursor2 != null) {
}
throw th;
}
}
int columnIndexOrThrow = query.getColumnIndexOrThrow("_data");
int columnIndexOrThrow2 = query.getColumnIndexOrThrow("_data");
String string = query.getString(columnIndexOrThrow);
String string2 = query.getString(columnIndexOrThrow2);
Log.i("FileUtil", "check dn:" + string2 + ",path:" + string);
String uri2 = uri.toString();
if (uri2.startsWith("content://cn.wps.moffice_eng.fileprovider/external")) {
string = getSDCardRootDirectory() + uri2.substring(50, uri2.lastIndexOf(CookieSpec.PATH_DELIM) + 1) + string2;
}
Log.i("FileUtil", "check final path:" + string);
query.close();
return string;
} catch (Exception e11) {
e = e11;
cursor = null;
} catch (Throwable th3) {
th = th3;
}
}
public static String getDataColumnForNogut(Context context, Uri uri) {
Cursor cursor;
String str;
String str2;
String str3;
String str4;
?? r12 = 0;
try {
try {
cursor = context.getContentResolver().query(uri, null, null, null, null);
if (cursor != null) {
try {
if (cursor.moveToFirst()) {
int columnCount = cursor.getColumnCount();
for (int i10 = 0; i10 < columnCount; i10++) {
try {
Log.i("FileUtil", "check column-" + i10 + ",c-name:" + cursor.getColumnName(i10) + ":" + cursor.getString(i10));
} catch (Exception e10) {
e10.printStackTrace();
}
}
int columnIndex = cursor.getColumnIndex("_data");
int columnIndex2 = cursor.getColumnIndex("_display_name");
int columnIndex3 = cursor.getColumnIndex("document_id:raw");
if (columnIndex3 != -1) {
str = cursor.getString(columnIndex3);
} else {
str = null;
}
if (!TextUtils.isEmpty(str)) {
Log.i("FileUtil", "we get raw path:" + str);
cursor.close();
return str;
}
if (columnIndex != -1) {
str2 = cursor.getString(columnIndex);
} else {
str2 = null;
}
if (columnIndex2 != -1) {
str3 = cursor.getString(columnIndex2);
} else {
str3 = null;
}
Log.i("FileUtil", "check dn:" + str3 + ",path:" + str2);
String path = uri.getPath();
Log.i("FileUtil", "check path:" + path + "," + uri.getEncodedPath() + "," + uri.getLastPathSegment());
if (TextUtils.isEmpty(str2)) {
String authority = uri.getAuthority();
if (path.startsWith("content://com.huawei.hidisk.fileprovider/root")) {
str4 = path.substring(45);
} else if (path.startsWith("content://cn.wps.moffice_eng.fileprovider/external")) {
str4 = getSDCardRootDirectory() + path.substring(50, path.lastIndexOf(CookieSpec.PATH_DELIM) + 1) + str3;
} else {
if ("cn.wps.moffice_eng.fileprovider".equals(authority)) {
if (path.startsWith("/external")) {
path = getSDCardRootDirectory() + path.substring(9);
}
} else {
if ("com.huawei.hidisk.fileprovider".equals(authority)) {
if (path.startsWith("/root")) {
str2 = path.substring(5);
}
} else if ("com.android.browser.fileprovider".equals(authority)) {
if (path.startsWith("//")) {
str2 = path.substring(2);
}
} else if ("com.example.android.notepad.files".equals(authority)) {
if (path.startsWith("/my_external")) {
path = getSDCardRootDirectory() + path.substring(12);
}
} else if (path.startsWith("/document/raw:/storage/emulated/0")) {
str4 = path.substring(14);
} else if ("com.android.providers.downloads.documents".equals(authority)) {
str4 = getSystemDownloadPath() + str3;
Log.w("FileUtil", "we get path from qi pa:" + str4);
} else if ("com.tencent.mtt.fileprovider".equals(authority)) {
String absolutePath = Environment.getExternalStorageDirectory().getAbsolutePath();
if (path.startsWith("/QQBrowser")) {
path = path.substring(10);
}
if (path != null && !path.startsWith(absolutePath)) {
path = absolutePath + path;
}
Log.w("FileUtil", "we get path from qq browser:" + path);
}
Log.i("FileUtil", "check path,we modify path:" + str2);
}
str2 = path;
Log.i("FileUtil", "check path,we modify path:" + str2);
}
str2 = str4;
Log.i("FileUtil", "check path,we modify path:" + str2);
}
cursor.close();
return str2;
}
} catch (Exception e11) {
e = e11;
e.printStackTrace();
}
}
} catch (Throwable th) {
th = th;
r12 = context;
if (r12 != 0) {
r12.close();
}
throw th;
}
} catch (Exception e12) {
e = e12;
cursor = null;
} catch (Throwable th2) {
th = th2;
if (r12 != 0) {
}
throw th;
}
}
public static int getDirs(String str) {
File[] listFiles;
File file = new File(str);
if (!file.exists() || (listFiles = file.listFiles()) == null) {
return 0;
}
int i10 = 0;
for (File file2 : listFiles) {
if (file2.isHidden()) {
i10++;
}
}
return listFiles.length - i10;
}
public static String getDiscoverInstancePath() {
return getNewBackupPath() + "discover.dat";
}
public static String getDownloadFileSaveName(@NonNull String str, @NonNull String str2) {
if (!TextUtils.isEmpty(str) && !TextUtils.isEmpty(str2)) {
if (str.endsWith(CookieSpec.PATH_DELIM) && !str2.startsWith(CookieSpec.PATH_DELIM)) {
int lastIndexOf = str2.lastIndexOf(".");
int i10 = 1;
String str3 = str2;
while (true) {
if (checkPathValid(str + str3)) {
if (lastIndexOf == -1) {
str3 = str3 + "-" + i10;
} else {
str3 = str2.substring(0, lastIndexOf) + "(" + i10 + ")" + str2.substring(lastIndexOf);
}
i10++;
} else {
return str + str3;
}
}
} else {
Log.w("FileUtil", "illegal file path:" + str + ",name:" + str2);
}
}
return null;
}
public static String getDownloadPath(@NonNull Context context) {
String globalCachePath;
if (Build.VERSION.SDK_INT >= 24) {
globalCachePath = context.getFilesDir().getAbsolutePath();
} else {
globalCachePath = getGlobalCachePath();
}
File file = new File(globalCachePath, "745d816a45cae554");
if (!file.exists()) {
file.mkdirs();
}
return file.getAbsolutePath() + CookieSpec.PATH_DELIM;
}
public static String getDownloadUrlByKey(String str) {
return ak.im.sdk.manager.f1.getInstance().getDownloadUrl() + str.replace("%2C", ",");
}
public static List<String> getEmojiList() {
try {
ArrayList arrayList = new ArrayList();
Context context = j.a.get();
if (context == null) {
return null;
}
InputStream open = context.getResources().getAssets().open("emotion_list");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(open, "UTF-8"));
while (true) {
String readLine = bufferedReader.readLine();
if (readLine != null) {
arrayList.add(readLine);
} else {
open.close();
bufferedReader.close();
return arrayList;
}
}
} catch (Exception e10) {
e10.printStackTrace();
return null;
}
}
public static String getEmoticonPath() {
if (j.u0.f40392d == null || ak.im.sdk.manager.f1.getInstance().getUsername() == null) {
return null;
}
return getUserRootPath() + "emoticon" + File.separator;
}
public static String getExternalSDCardRootDirectory() {
Runtime runtime = Runtime.getRuntime();
ArrayList arrayList = new ArrayList();
try {
Process exec = runtime.exec("cat /proc/mounts");
BufferedInputStream bufferedInputStream = new BufferedInputStream(exec.getInputStream());
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(bufferedInputStream));
while (true) {
String readLine = bufferedReader.readLine();
if (readLine != null) {
Log.d("FileUtil", readLine);
if (readLine.toLowerCase().contains("sdcard") || readLine.toLowerCase().contains("ext")) {
String[] split = readLine.split(" ");
if (split.length >= 3 && !split[1].contains("/system") && !split[1].contains("/data") && !split[1].contains("/cache") && !split[1].contains("/persist")) {
String trim = split[1].trim();
if ((trim.contains("ext") || trim.contains("1")) && trim.contains(Bookmarks.ELEMENT)) {
arrayList.add(trim);
}
}
}
if (exec.waitFor() != 0 && exec.exitValue() == 1) {
Log.e("FileUtil", "check mount info failed");
return null;
}
} else {
bufferedReader.close();
bufferedInputStream.close();
if (arrayList.size() <= 0) {
return null;
}
return (String) arrayList.get(0);
}
}
} catch (Exception e10) {
e10.printStackTrace();
return null;
}
}
public static List<String> getFileEachRow(InputStream inputStream) {
ArrayList arrayList = new ArrayList();
if (inputStream == null) {
Log.e("FileUtil", "getFileEachRow the param inputStream is null");
return arrayList;
}
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
while (true) {
try {
try {
try {
String readLine = bufferedReader.readLine();
if (readLine == null) {
break;
}
arrayList.add(readLine);
} catch (IOException e10) {
e10.printStackTrace();
Log.e("FileUtil", "getFileEachRow() IOException!");
}
} catch (Throwable th) {
try {
bufferedReader.close();
} catch (IOException e11) {
e11.printStackTrace();
Log.e("FileUtil", "getFileEachRow() IOException!");
}
throw th;
}
} catch (IOException e12) {
e12.printStackTrace();
Log.e("FileUtil", "getFileEachRow() IOException!");
bufferedReader.close();
}
}
bufferedReader.close();
return arrayList;
}
public static byte[] getFileHead(int i10, String str) {
FileInputStream fileInputStream;
long j10;
if (isFileExist(str)) {
try {
long j11 = 0;
if (isVaultPath(str)) {
File file = new File(f10114a.getPath(str));
if (file.exists()) {
j11 = file.length();
}
DecryptingReadableByteChannel decryptChannel = f10114a.getDecryptChannel(file);
ByteBuffer allocate = ByteBuffer.allocate((int) Math.min(i10, j11));
allocate.flip();
decryptChannel.read(allocate);
byte[] array = allocate.array();
decryptChannel.close();
return array;
}
File file2 = new File(str);
if (file2.exists()) {
fileInputStream = new FileInputStream(file2);
j10 = file2.length();
} else {
fileInputStream = null;
j10 = 0;
}
if (fileInputStream != null && j10 > 0) {
int min = (int) Math.min(i10, j10);
byte[] bArr = new byte[min];
fileInputStream.read(bArr, 0, min);
fileInputStream.close();
return bArr;
}
} catch (Exception e10) {
e10.printStackTrace();
}
}
return null;
}
public static String getFileName(String str) {
if (q5.empty(str)) {
return null;
}
String name = new File(str).getName();
return (!TextUtils.isEmpty(name) && name.startsWith("vft") && name.contains("_")) ? name.substring(name.indexOf(95) + 1) : name;
}
public static String getFileNameByPath(String str) {
if (!TextUtils.isEmpty(str)) {
String str2 = File.separator;
if (str.contains(str2)) {
return str.substring(str.lastIndexOf(str2) + 1);
}
}
Log.w("FileUtil", "path is null get null name" + str);
return str;
}
public static String getFileNameWithoutPostfix(String str) {
if (str == null) {
return str;
}
int lastIndexOf = str.lastIndexOf(".");
if (lastIndexOf >= 0) {
return str.substring(0, lastIndexOf);
}
return str;
}
public static String getFileOriginSimpleNameByPath(String str, String str2) {
String str3 = null;
if (TextUtils.isEmpty(str)) {
Log.w("FileUtil", "path is null.");
return null;
}
String str4 = File.separator;
if (str.contains(str4)) {
String substring = str.substring(str.lastIndexOf(str4) + 1);
if (substring.startsWith(User.NAME_PREFIX) && '_' == substring.charAt(12) && '_' == substring.charAt(26)) {
substring = substring.substring(27, substring.length());
}
if (substring.startsWith("small_")) {
substring = substring.substring(6, substring.length());
}
if (substring.endsWith(".decr")) {
substring = substring.substring(0, substring.length() - 5);
}
if (substring.endsWith(".encr")) {
substring = substring.substring(0, substring.length() - 5);
}
if (substring.endsWith(".thumb")) {
substring = substring.substring(0, substring.length() - 6);
}
str3 = substring;
if (str3.endsWith(".tmp")) {
str3 = str3.substring(0, str3.length() - 4);
}
}
Log.d("FileUtil", "real simple fileName:" + str3);
return str3;
}
public static String getFilePathByWith(String str) {
if (j.u0.f40392d == null || ak.im.sdk.manager.f1.getInstance().getUsername() == null || str == null) {
return null;
}
return getUserFilePath() + q5.getUserNameByJid(str) + File.separator;
}
public static long getFileSize(String str) {
File file = new File(str);
if (file.exists()) {
return file.length();
}
return 0L;
}
public static String getFileType(String str, boolean z10) {
String lowerCase = str.toLowerCase();
if (z10) {
return "folder";
}
if (!lowerCase.endsWith(".jpg") && !lowerCase.endsWith(".png") && !lowerCase.endsWith(".bmp") && !lowerCase.endsWith(".jpeg") && !lowerCase.endsWith(".webp") && !lowerCase.endsWith(".gif")) {
if (lowerCase.endsWith(".pdf")) {
return "pdf";
}
if (lowerCase.endsWith(".xps")) {
return "xps";
}
if (lowerCase.endsWith(".epub")) {
return "epub";
}
if (!lowerCase.endsWith(".doc") && !lowerCase.endsWith(".docx") && !lowerCase.endsWith(".dotx") && !lowerCase.endsWith(".dotm")) {
if (!lowerCase.endsWith(".rtf") && !lowerCase.endsWith(".sxw")) {
if (lowerCase.endsWith(".form")) {
return "form";
}
if (!lowerCase.endsWith(".txt") && !lowerCase.endsWith(".xml") && !lowerCase.endsWith(".log")) {
if (!lowerCase.endsWith(".html") && !lowerCase.endsWith(".htm") && !lowerCase.endsWith(".css") && !lowerCase.endsWith(".js") && !lowerCase.endsWith(".svg") && !lowerCase.endsWith(".json") && !lowerCase.endsWith(".ini")) {
if (!lowerCase.endsWith(".xls") && !lowerCase.endsWith(".xlsx") && !lowerCase.endsWith(".xltx")) {
if (lowerCase.endsWith(".exe")) {
return "other";
}
if (lowerCase.endsWith(".apk")) {
return "apk";
}
if (!lowerCase.endsWith(".cbz") && !lowerCase.endsWith(".ar") && !lowerCase.endsWith(".gz") && !lowerCase.endsWith(".tar") && !lowerCase.endsWith(".jar") && !lowerCase.endsWith(".bz2") && !lowerCase.endsWith(".lzma") && !lowerCase.endsWith(".7z")) {
if (lowerCase.endsWith(".zip")) {
return "zip";
}
if (!lowerCase.endsWith(".vai") && !lowerCase.endsWith(".mp4") && !lowerCase.endsWith(".m4v") && !lowerCase.endsWith(".dat") && !lowerCase.endsWith(".mkv") && !lowerCase.endsWith(".flv") && !lowerCase.endsWith(".vob") && !lowerCase.endsWith(".mov") && !lowerCase.endsWith(".3gp") && !lowerCase.endsWith(".mpg") && !lowerCase.endsWith(".mpeg") && !lowerCase.endsWith(".mpe") && !lowerCase.endsWith(".rm") && !lowerCase.endsWith(".rmvb") && !lowerCase.endsWith(".wmv") && !lowerCase.endsWith(".asf") && !lowerCase.endsWith(".asx") && !lowerCase.endsWith(".avi")) {
if (!lowerCase.endsWith(".mp3") && !lowerCase.endsWith(".wma") && !lowerCase.endsWith(".aac") && !lowerCase.endsWith(".flac") && !lowerCase.endsWith(".ape") && !lowerCase.endsWith(".m4a") && !lowerCase.endsWith(".amr") && !lowerCase.endsWith(".pcm") && !lowerCase.endsWith(".mka") && !lowerCase.endsWith(".cda") && !lowerCase.endsWith(".voc") && !lowerCase.endsWith(".wav")) {
if (!lowerCase.endsWith(".pptx") && !lowerCase.endsWith(".ppt") && !lowerCase.endsWith(".pot") && !lowerCase.endsWith(".pps") && !lowerCase.endsWith(".pots") && !lowerCase.endsWith(".ppsx")) {
return "other";
}
return "ppt";
}
return ChatMessage.CHAT_AUDIO;
}
return "video";
}
return "archiver";
}
return "excel";
}
return "web";
}
return "txt";
}
return "document";
}
return "word";
}
return "picture";
}
public static fc.z<Akeychat.GetSeaweedfsUploadTokenResponse> getFreeSeaWeedUploadResource(final Akeychat.RecordType recordType, final long j10) {
return fc.z.create(new fc.c0() {
@Override
public final void subscribe(fc.b0 b0Var) {
FileUtil.A(Akeychat.RecordType.this, j10, b0Var);
}
});
}
public static String getGlobalCachePath() {
if (j.u0.f40392d == null) {
return null;
}
return j.u0.f40392d + j.u0.f40394e + j.u0.f40396f + File.separator;
}
public static String getGlobalCacheVftPath() {
if (j.u0.f40392d == null) {
return null;
}
return j.u0.f40392d + j.u0.f40394e + j.u0.f40396f + File.separator + "vft";
}
public static String getGlobalLogPath() {
if (j.u0.f40392d == null) {
return null;
}
return j.u0.f40392d + j.u0.f40394e + j.u0.f40398g + File.separator;
}
public static String getGlobalZTPath() {
if (j.u0.f40392d == null) {
return null;
}
return j.u0.f40392d + j.u0.f40394e + j.u0.f40400h + File.separator;
}
public static String getImageFileType(String str) {
if (TextUtils.isEmpty(str)) {
return "*/*";
}
File file = new File(str);
if (file.exists()) {
try {
FileInputStream fileInputStream = new FileInputStream(file);
byte[] bArr = new byte[8];
fileInputStream.read(bArr, 0, 8);
fileInputStream.close();
String upperCase = q5.bytesToHexString(bArr).toUpperCase();
if (upperCase.startsWith("FFD8")) {
return "jpg";
}
if (upperCase.startsWith("89504E470D0A1A0A")) {
return "png";
}
if (upperCase.startsWith("474946")) {
return "gif";
}
if (upperCase.startsWith("424D")) {
return "bmp";
}
if (upperCase.startsWith("384250")) {
return "psd";
}
if (upperCase.startsWith("0A") && !upperCase.startsWith("0A2D2D2D2D")) {
return "pcx";
}
if (!upperCase.startsWith("4D4D") && !upperCase.startsWith("4949")) {
if (!upperCase.startsWith("52494646")) {
return "*/*";
}
return "webp";
}
return "tif";
} catch (Exception e10) {
e10.printStackTrace();
}
}
return "*/*";
}
public static String getImagePathByWith(String str) {
if (j.u0.f40392d == null || ak.im.sdk.manager.f1.getInstance().getUsername() == null || str == null) {
return null;
}
return getUserImagePath() + q5.getUserNameByJid(str) + File.separator;
}
public static String getImagePickCropAndroidR() {
return getGlobalCachePath() + BuildConfig.FLAVOR_akProduct + "_c.jpg";
}
public static int getImageResId(String str) {
if ("folder".equalsIgnoreCase(str)) {
return j.s1.icon_file_folder;
}
if ("picture".equalsIgnoreCase(str)) {
return j.s1.icon_file_picture;
}
if ("pdf".equalsIgnoreCase(str)) {
return j.s1.icon_file_pdf;
}
if ("word".equalsIgnoreCase(str)) {
return j.s1.icon_file_word;
}
if ("document".equalsIgnoreCase(str)) {
return j.s1.icon_file_docu;
}
if ("excel".equalsIgnoreCase(str)) {
return j.s1.icon_file_xls;
}
if ("other".equalsIgnoreCase(str)) {
return j.s1.icon_file_other;
}
if ("apk".equalsIgnoreCase(str)) {
return j.s1.icon_file_apk;
}
if ("archiver".equalsIgnoreCase(str)) {
return j.s1.icon_file_rar;
}
if ("video".equalsIgnoreCase(str)) {
return j.s1.icon_file_video;
}
if (ChatMessage.CHAT_AUDIO.equalsIgnoreCase(str)) {
return j.s1.icon_file_music;
}
if ("ppt".equalsIgnoreCase(str)) {
return j.s1.icon_file_ppt;
}
return j.s1.icon_file_other;
}
public static String getImgPath(ChatMessage chatMessage) {
String str;
if (chatMessage.getAttachment() == null) {
Log.d("FileUtil", "msg attachment is empty");
return "";
}
String imagePathByWith = getImagePathByWith(chatMessage.getWith(), chatMessage.getAttachment().isReadOnly());
if (chatMessage.getAttachment().getAntiShot() == 1) {
str = imagePathByWith + h4.decreaseFileNameLength(chatMessage.getAttachment().getOriginKey());
} else {
str = imagePathByWith + h4.decreaseFileNameLength(chatMessage.getAttachment().getKey());
}
Log.d("FileUtil", "saveName is " + str);
return str;
}
public static String getMIMEType(String str) {
int lastIndexOf = str.lastIndexOf(".");
String str2 = "*/*";
if (lastIndexOf < 0) {
return "*/*";
}
String lowerCase = str.substring(lastIndexOf, str.length()).toLowerCase();
if ("".equals(lowerCase)) {
return "*/*";
}
for (String[] strArr : f10118e) {
if (lowerCase.equals(strArr[0])) {
str2 = strArr[1];
}
}
return str2;
}
public static String getNameFromFilename(String str) {
int lastIndexOf = str.lastIndexOf(46);
if (lastIndexOf != -1) {
return str.substring(0, lastIndexOf);
}
return str;
}
public static String getNewBackupDeviceFilePath() {
if (Build.VERSION.SDK_INT >= 30) {
return getNewBackupPath() + "/device.amr";
}
return getNewBackupPath() + "/device.dat";
}
public static String getNewBackupFilePath() {
long currentTimeMillis = System.currentTimeMillis();
if (Build.VERSION.SDK_INT >= 30) {
return getNewBackupPath() + CookieSpec.PATH_DELIM + currentTimeMillis + "bk.amr";
}
return getNewBackupPath() + CookieSpec.PATH_DELIM + currentTimeMillis + "bk.dat";
}
public static String getNewBackupPath() {
if (Build.VERSION.SDK_INT >= 30) {
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + CookieSpec.PATH_DELIM + BuildConfig.FLAVOR_akProduct + "/kv";
}
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/." + BuildConfig.PRODUCT_PKG_NAME + "/kv";
}
public static String getNodeFilePath() {
return getNewBackupPath() + "/node.dat";
}
public static String getPath(Context context, Uri uri) {
String dataColumnForNogut;
String path;
Log.i("FileUtil", "uri scheme:" + uri.getScheme());
String authority = uri.getAuthority();
Log.i("FileUtil", "uri authority:" + authority);
int i10 = Build.VERSION.SDK_INT;
String str = null;
if (DocumentsContract.isDocumentUri(context, uri)) {
Iterator<String> it = uri.getPathSegments().iterator();
int i11 = 0;
while (it.hasNext()) {
Log.i("FileUtil", "uri path:" + it.next() + " - " + i11);
i11++;
}
if (isExternalStorageDocument(authority)) {
String[] split = DocumentsContract.getDocumentId(uri).split(":");
String str2 = split[0];
if ("primary".equalsIgnoreCase(str2)) {
str = Environment.getExternalStorageDirectory() + CookieSpec.PATH_DELIM + split[1];
} else if (!TextUtils.isEmpty(str2)) {
str = getExternalSDCardRootDirectory() + CookieSpec.PATH_DELIM + split[1];
}
} else if (isDownloadsDocument(authority)) {
String documentId = DocumentsContract.getDocumentId(uri);
try {
Log.i("FileUtil", "check id:" + documentId);
if (documentId.startsWith("raw:")) {
String substring = documentId.substring(4);
if (checkPathValid(substring)) {
return substring;
}
}
Uri withAppendedId = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(documentId).longValue());
String dataColumn = getDataColumn(context, withAppendedId, null, null);
if (dataColumn == null) {
Log.w("FileUtil", "get path from uri" + withAppendedId + " failed try original uri:" + uri);
dataColumn = getDataColumnForNogut(context, uri);
}
str = dataColumn;
} catch (NumberFormatException e10) {
AkeyChatUtils.logException(e10);
return getDataColumnForNogut(context, uri);
}
} else if (isMediaDocument(uri)) {
dataColumnForNogut = v(context, uri);
str = dataColumnForNogut;
} else {
Log.w("FileUtil", "other branch:" + authority + ",len:" + authority.length());
}
} else if (i10 >= 24 && "content".equalsIgnoreCase(uri.getScheme())) {
List<String> pathSegments = uri.getPathSegments();
if (pathSegments.size() > 0 && "external_files".equals(pathSegments.get(0))) {
StringBuilder sb2 = new StringBuilder();
sb2.append(getSDCardRootDirectory());
for (int i12 = 1; i12 < pathSegments.size(); i12++) {
sb2.append(File.separator);
sb2.append(pathSegments.get(i12));
}
dataColumnForNogut = sb2.toString();
} else {
dataColumnForNogut = getDataColumnForNogut(context, uri);
}
str = dataColumnForNogut;
} else if ("content".equalsIgnoreCase(uri.getScheme())) {
str = getDataColumn(context, uri, null, null);
} else if (ChatMessage.CHAT_FILE.equalsIgnoreCase(uri.getScheme())) {
str = uri.getPath();
}
if (TextUtils.isEmpty(str) || !isFileExist(str)) {
String uri2 = uri.toString();
if (!TextUtils.isEmpty(uri2) && (uri2.contains("#") || uri2.contains("?"))) {
path = uri2;
} else {
path = uri.getPath();
}
if (checkPathValid(path)) {
return path;
}
return uri2;
}
return str;
}
public static String getPrefix(boolean z10, String str) {
boolean z11;
String sandBoxPath;
if (j.u0.f40392d != null && ak.im.sdk.manager.f1.getInstance().getUsername() != null) {
if (Build.VERSION.SDK_INT >= j.u0.f40411m0) {
z11 = true;
} else {
z11 = false;
}
if (z10) {
return getUserRootPath();
}
StringBuilder sb2 = new StringBuilder();
if (z11) {
sandBoxPath = "cryptomator://";
} else {
sandBoxPath = getSandBoxPath();
}
sb2.append(sandBoxPath);
sb2.append(str);
return sb2.toString();
}
return null;
}
public static String getRandomFileNameForAliyun(String str) {
return UUID.randomUUID().toString();
}
public static fc.z<Akeychat.GetAWSUploadUrlResponse> getS3UploadResource(final String str, final long j10, final String str2, final Akeychat.RecordType recordType, final String str3, final Akeychat.ChatType chatType, final long j11, final int i10) {
return fc.z.create(new fc.c0() {
@Override
public final void subscribe(fc.b0 b0Var) {
FileUtil.B(str, j10, str2, recordType, str3, chatType, j11, i10, b0Var);
}
});
}
public static String getSDCardRootDirectory() {
if ("mounted".equals(Environment.getExternalStorageState())) {
return Environment.getExternalStorageDirectory().getAbsolutePath();
}
try {
Process exec = Runtime.getRuntime().exec("cat /proc/mounts");
BufferedInputStream bufferedInputStream = new BufferedInputStream(exec.getInputStream());
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(bufferedInputStream));
while (true) {
String readLine = bufferedReader.readLine();
if (readLine != null) {
Log.d("FileUtil", readLine);
if (readLine.contains("sdcard")) {
String[] split = readLine.split(" ");
if (split.length >= 3) {
return split[1].trim();
}
}
if (exec.waitFor() != 0 && exec.exitValue() == 1) {
Log.e("FileUtil", "check mount info failed");
return null;
}
} else {
bufferedReader.close();
bufferedInputStream.close();
return null;
}
}
} catch (Exception e10) {
e10.printStackTrace();
return null;
}
}
public static String getSandBoxPath() {
String absolutePath = AKApplication.f780g.getFilesDir().getAbsolutePath();
if (TextUtils.isEmpty(absolutePath)) {
return getUserRootPath();
}
String MD5Hash = e.j.MD5Hash(q5.getJidByName(ak.im.sdk.manager.f1.getInstance().getUsername()) + "");
Log.i("FileUtil", "current sand box path is " + absolutePath);
EnterpriseInfo currentEnterpriseInfo = ak.im.sdk.manager.f1.getInstance().getmEnterpriseCfg().getCurrentEnterpriseInfo();
if (currentEnterpriseInfo == null) {
Log.i("FileUtil", "enterprise info is null");
return "";
}
Log.i("FileUtil", "enterprise id is " + currentEnterpriseInfo.enterpriseID);
return absolutePath + "/enterprise-" + e.j.MD5Encode(currentEnterpriseInfo.enterpriseID) + CookieSpec.PATH_DELIM + MD5Hash;
}
public static String getSaveAttachAudioPath() {
return getSaveAttachRootPath() + "/audio" + File.separator;
}
public static String getSaveAttachFilePath() {
return getSaveAttachRootPath() + "/file" + File.separator;
}
public static String getSaveAttachImagePath() {
return getSaveAttachRootPath() + "/image" + File.separator;
}
public static String getSaveAttachRootPath() {
return getSystemDownloadPath() + BuildConfig.FLAVOR_akProduct;
}
public static String getSaveAttachVideoPath() {
return getSaveAttachRootPath() + "/video" + File.separator;
}
public static String getServerLogoPath(String str) {
if (TextUtils.isEmpty(str)) {
return "";
}
return getGlobalCachePath() + e.j.MD5Encode(str);
}
public static String getShotAvatarImageNameBeforeSignUp() {
return j.u0.f40392d + getAppRootPath() + ChatMessage.CHAT_IMAGE + "-shot-for-sign-up";
}
public static String getShotAvatarTempImageName(String str) {
if (f10116c == null) {
f10116c = getUserTempPath() + ChatMessage.CHAT_IMAGE + "-shot-" + e.j.MD5Encode(str) + System.nanoTime() + ".jpg";
}
return f10116c;
}
public static String getStampPath(Context context, String str) {
return getAKCachePath(context) + str;
}
public static String getSystemDownloadPath() {
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + File.separator;
}
public static String getTempUserAudioPath() {
return getSandBoxPath() + "/audio" + File.separator;
}
public static String getTestFile() {
if (j.u0.f40392d == null) {
return null;
}
return j.u0.f40392d + j.u0.f40394e + "/test.txt";
}
public static String getTestNodeFilePath() {
return j.u0.f40392d + j.u0.f40394e + "/node.txt";
}
public static fc.z<Akeychat.GetSeaweedfsUploadTokenResponse> getUploadResource(final String str, final long j10, final Akeychat.ChatType chatType, final int i10) {
return fc.z.create(new fc.c0() {
@Override
public final void subscribe(fc.b0 b0Var) {
FileUtil.D(str, j10, chatType, i10, b0Var);
}
});
}
public static String getUserAudioPath() {
if (j.u0.f40392d != null && ak.im.sdk.manager.f1.getInstance().getUsername() != null) {
return getPrefix(false, "/audio" + File.separator);
}
return null;
}
public static String getUserDBPath() {
if (j.u0.f40392d != null && ak.im.sdk.manager.f1.getInstance().getUsername() != null) {
return getUserRootPath() + "/database" + File.separator;
}
return null;
}
public static String getUserFilePath() {
if (j.u0.f40392d != null && ak.im.sdk.manager.f1.getInstance().getUsername() != null) {
return getPrefix(false, "/file" + File.separator);
}
return null;
}
public static String getUserImagePath() {
if (j.u0.f40392d != null && ak.im.sdk.manager.f1.getInstance().getUsername() != null) {
return getPrefix(false, "/image" + File.separator);
}
return null;
}
public static String getUserRootPath() {
if (ak.im.sdk.manager.f1.getInstance().getUsername() == null) {
return null;
}
String jidByName = q5.getJidByName(ak.im.sdk.manager.f1.getInstance().getUsername());
if (j.u0.f40392d == null || TextUtils.isEmpty(jidByName)) {
return null;
}
return (j.u0.f40392d + u0.a.f40430a) + File.separator + e.j.MD5Hash(jidByName);
}
public static String getUserTempPath() {
if (j.u0.f40392d != null && ak.im.sdk.manager.f1.getInstance().getUsername() != null) {
return getPrefix(false, "/temp" + File.separator);
}
return null;
}
public static String getUserVideoImageNameForThumb(String str) {
return getUserTempPath() + ChatMessage.CHAT_IMAGE + "-" + str + ".jpg";
}
public static String getUserVideoPath() {
if (j.u0.f40392d != null && ak.im.sdk.manager.f1.getInstance().getUsername() != null) {
return getPrefix(false, "/video" + File.separator);
}
return null;
}
public static String getVaultPath(String str) {
if (str.startsWith("cryptomator")) {
return str.replace("cryptomator://", "").replace("cryptomator:", "");
}
return str;
}
public static String getVideoPathByWith(String str) {
if (j.u0.f40392d == null || ak.im.sdk.manager.f1.getInstance().getUsername() == null || str == null) {
return null;
}
return getUserVideoPath() + q5.getUserNameByJid(str) + File.separator;
}
public static String getVideoThumbById(String str, String str2) {
return getGlobalCachePath() + "video_thumb_" + str + "_" + new File(str2).getName();
}
public static void initAppLanguage(Context context, int i10) {
int i11 = Build.VERSION.SDK_INT;
if (i11 < 24 && i10 != 0) {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
Configuration configuration = context.getResources().getConfiguration();
n4 n4Var = n4.getInstance(context);
n4Var.setCurrentLanguage(i10);
configuration.setLocale(n4Var.getCurrentLocale());
context.getResources().updateConfiguration(configuration, displayMetrics);
return;
}
if (o(context)) {
return;
}
if (i11 >= 24) {
n(context, "en");
} else {
I(context, "en");
}
}
public static void initUserCacheFolder() {
createFileIfNotExistByName(getUserVideoPath());
createFileIfNotExistByName(getUserImagePath());
createFileIfNotExistByName(getUserFilePath());
createFileIfNotExistByName(getUserTempPath());
}
public static void initUserDataFolder(String str, boolean z10) {
if (!ak.im.sdk.manager.f1.getInstance().isHadDeleteRoot()) {
Log.i("FileUtil", "delete UserRootPath");
deleteFile(getUserRootPath());
deleteFile(getSandBoxPath());
ak.im.sdk.manager.f1.getInstance().setHadDeleteRoot(true);
}
createFileIfNotExistByName(getUserRootPath());
if (initUserVault(str)) {
Log.i("CryptoFile", "initUserVault success");
return;
}
Log.i("CryptoFile", "initUserVault failed,use old");
deleteFile(getUserRootPath());
j.u0.f40411m0 = Build.VERSION.SDK_INT + 1;
initUserCacheFolder();
}
public static boolean initUserVault(String str) {
Log.i("FileUtil", "init user vault now.");
return f10114a.initMasterKey(getUserRootPath() + "/mk", ak.im.sdk.manager.f1.getInstance().getServer().getEnterpriseId(), str);
}
public static void insertIntoMediaStore(Context context, boolean z10, boolean z11, String str, long j10) {
Uri uri;
if (str == null) {
return;
}
File file = new File(str);
if (!file.exists()) {
return;
}
if (Build.VERSION.SDK_INT >= 30) {
MediaScannerConnection.scanFile(context, new String[]{str}, null, new b());
return;
}
if (j10 == 0) {
j10 = System.currentTimeMillis();
}
ContentResolver contentResolver = context.getContentResolver();
ContentValues contentValues = new ContentValues();
contentValues.put("title", file.getName());
contentValues.put("_display_name", file.getName());
contentValues.put("datetaken", Long.valueOf(j10));
contentValues.put("date_modified", Long.valueOf(System.currentTimeMillis()));
contentValues.put("date_added", Long.valueOf(System.currentTimeMillis()));
if (!z10) {
contentValues.put(Constant.PROTOCOL_WEB_VIEW_ORIENTATION, (Integer) 0);
}
contentValues.put("_data", file.getAbsolutePath());
contentValues.put("_size", Long.valueOf(file.length()));
if (z10) {
contentValues.put("mime_type", "video/3gp");
} else if (z11) {
contentValues.put("mime_type", Attachment.GIF);
} else {
contentValues.put("mime_type", "image/jpg");
}
if (z10) {
uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
} else {
uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
}
Log.d("FileUtil", "==== insert to MediaStore.Uri:" + contentResolver.insert(uri, contentValues));
}
public static void insertMediaStore(Context context, String str) {
if (str == null) {
return;
}
File file = new File(str);
if (!file.exists()) {
return;
}
if (Build.VERSION.SDK_INT >= 30) {
MediaScannerConnection.scanFile(context, new String[]{str}, null, new c());
return;
}
ContentResolver contentResolver = context.getContentResolver();
ContentValues contentValues = new ContentValues();
contentValues.put("title", file.getName());
contentValues.put("_display_name", file.getName());
contentValues.put("date_modified", Long.valueOf(System.currentTimeMillis()));
contentValues.put("date_added", Long.valueOf(System.currentTimeMillis()));
contentValues.put("_data", file.getAbsolutePath());
contentValues.put("_size", Long.valueOf(file.length()));
contentValues.put("mime_type", (Integer) 0);
contentValues.put("parent", file.getParent());
contentValues.put("mime_type", getMIMEType(str));
try {
Log.d("FileUtil", "==== insert to MediaStore.Uri:1" + contentResolver.insert(MediaStore.Files.getContentUri("external"), contentValues));
} catch (Exception e10) {
Log.i("FileUtil", "insertMediaStore error is " + e10.getMessage());
e10.printStackTrace();
}
}
public static boolean isDownloadsDocument(Uri uri) {
return isDownloadsDocument(uri.getAuthority());
}
public static boolean isExternalStorageDocument(Uri uri) {
return isExternalStorageDocument(uri.getAuthority());
}
public static boolean isFileExist(String str) {
if (isVaultPath(str)) {
str = f10114a.getPath(getVaultPath(str));
}
return new File(str).exists();
}
public static boolean isMediaDocument(Uri uri) {
return "com.android.providers.media.documents".equals(uri.getAuthority());
}
public static boolean isTestFileExist() {
if (!TextUtils.isEmpty(getTestFile()) && isFileExist(getTestFile())) {
return true;
}
return false;
}
public static boolean isVaultPath(Uri uri) {
int i10 = Build.VERSION.SDK_INT;
return i10 >= 26 && "cryptomator".equals(uri.getScheme()) && i10 >= j.u0.f40411m0;
}
public static boolean judgeCanReviewByFileName(String str, boolean z10) {
String fileType = getFileType(str, z10);
if (!fileType.equals("other") && !fileType.equals("apk") && !fileType.equals("archiver") && !fileType.endsWith("epub")) {
return true;
}
return false;
}
public static String judgeOnlyReadBySwitch(String str, boolean z10) {
String fileType = getFileType(str, z10);
if (fileType.equals("ppt") || fileType.equals("excel") || fileType.equals("web") || fileType.equals("txt") || fileType.equals("form") || fileType.equals("word") || fileType.equals("epub") || fileType.equals("xps") || fileType.equals("pdf") || fileType.equals("document")) {
return "document";
}
if (fileType.equals("video") || fileType.equals(ChatMessage.CHAT_AUDIO)) {
return "video";
}
return fileType;
}
public static String longSizeToStr(long j10) {
String str;
String str2;
if (j10 >= 1073741824) {
return String.format("%.1f GB", Float.valueOf(((float) j10) / ((float) 1073741824)));
}
if (j10 >= PlaybackStateCompat.ACTION_SET_CAPTIONING_ENABLED) {
float f10 = ((float) j10) / ((float) PlaybackStateCompat.ACTION_SET_CAPTIONING_ENABLED);
if (f10 > 100.0f) {
str2 = "%.0f MB";
} else {
str2 = "%.1f MB";
}
return String.format(str2, Float.valueOf(f10));
}
if (j10 >= 1024) {
float f11 = ((float) j10) / ((float) 1024);
if (f11 > 100.0f) {
str = "%.0f KB";
} else {
str = "%.1f KB";
}
return String.format(str, Float.valueOf(f11));
}
return String.format("%d B", Long.valueOf(j10));
}
private static void m(String str) {
if (isVaultPath(str)) {
str = f10114a.getPath(str);
}
File file = new File(str);
ArrayList arrayList = new ArrayList();
if (file.exists()) {
q(file.getAbsolutePath(), arrayList);
}
Iterator it = arrayList.iterator();
while (it.hasNext()) {
Log.i("FileUtil", "clearFile file " + file.getName() + ",result " + ((File) it.next()).delete());
}
}
public static String modifyFilePath(String str) {
String absolutePath = Environment.getExternalStorageDirectory().getAbsolutePath();
String[] split = absolutePath.split(CookieSpec.PATH_DELIM);
String[] split2 = str.split(CookieSpec.PATH_DELIM);
Log.i("FileUtil", "checking file path:" + absolutePath);
if (split.length > 3) {
if (Bookmarks.ELEMENT.equals(split[1]) && "emulated".equals(split[2]) && !split2[3].equals(split[3])) {
split2[3] = split[3];
StringBuilder sb2 = new StringBuilder();
for (int i10 = 1; i10 < split2.length; i10++) {
sb2.append(CookieSpec.PATH_DELIM);
sb2.append(split2[i10]);
}
Log.i("FileUtil", "checking modified file path:" + sb2.toString());
return sb2.toString();
}
return str;
}
return str;
}
public static void moveFile(String str, String str2) {
if (isVaultPath(str)) {
new File(f10114a.getPath(str)).renameTo(new File(f10114a.getPath(str2)));
} else {
new File(str).renameTo(new File(str2));
}
}
@RequiresApi(api = 24)
private static Context n(Context context, String str) {
Resources resources = context.getResources();
Locale locale = new Locale(str);
Configuration configuration = resources.getConfiguration();
configuration.setLocale(locale);
LocaleList localeList = new LocaleList(locale);
LocaleList.setDefault(localeList);
configuration.setLocales(localeList);
return context.createConfigurationContext(configuration);
}
private static boolean o(Context context) {
String language;
LocaleList locales;
if (Build.VERSION.SDK_INT >= 24) {
locales = context.getResources().getConfiguration().getLocales();
language = locales.get(0).getLanguage();
} else {
language = context.getResources().getConfiguration().locale.getLanguage();
}
Log.e("LanguageUtil", "language = " + language);
if (!TextUtils.equals("zh", language) && !TextUtils.equals("vi", language)) {
return false;
}
return true;
}
private static String p(String str) {
String enterpriseId;
String str2;
Server server = ak.im.sdk.manager.f1.getInstance().getServer();
if (server == null) {
enterpriseId = "null";
} else {
enterpriseId = server.getEnterpriseId();
}
String curDateStr = o3.getCurDateStr("yyyy-MM-dd-HH");
String curDateStr2 = o3.getCurDateStr("yyyyMMddHHmmss");
User userMe = bf.getInstance().getUserMe();
String username = ak.im.sdk.manager.f1.getInstance().getUsername();
if (userMe != null) {
str2 = userMe.getAkeyId();
if (!TextUtils.isEmpty(str2)) {
if (str2.length() > 50) {
str2 = str2.substring(0, 50);
}
String format = String.format("android/%s/%s/%s/%s/%s-%s-%s-%s-%s.zip", enterpriseId, curDateStr, str, BuildConfig.PRODUCT_TYPE, username, r3.getDeviceModel(), str2, curDateStr2, ak.im.sdk.manager.f1.getInstance().getBigVersion());
Log.d("FileUtil", "lwx path is " + format);
return format;
}
}
str2 = username;
String format2 = String.format("android/%s/%s/%s/%s/%s-%s-%s-%s-%s.zip", enterpriseId, curDateStr, str, BuildConfig.PRODUCT_TYPE, username, r3.getDeviceModel(), str2, curDateStr2, ak.im.sdk.manager.f1.getInstance().getBigVersion());
Log.d("FileUtil", "lwx path is " + format2);
return format2;
}
private static void q(String str, ArrayList<File> arrayList) {
File[] listFiles;
File file = new File(str);
if (file.exists() && (listFiles = file.listFiles()) != null) {
for (File file2 : listFiles) {
if (file2.isDirectory()) {
q(file2.getAbsolutePath(), arrayList);
} else {
if (!file2.getAbsolutePath().equals(getUserRootPath() + "/mk")) {
if (o3.getRightTime() - file2.lastModified() >= AKCAppConfiguration.f9925a.clearCacheFileTime()) {
arrayList.add(file2);
}
} else {
Log.debug("mk", file2.getAbsolutePath());
}
}
}
}
}
private static String r() {
return getGlobalCachePath();
}
public static Bitmap readBitmapFromLocalFile(String str) {
return readBitmapFromLocalFile(str, null);
}
public static List<String> readFile(File file, int i10, int i11) {
FileReader fileReader;
String readLine;
?? r02 = 0;
r02 = 0;
r02 = 0;
r02 = 0;
if (file != null) {
boolean z10 = true;
if (i10 >= 1 && i11 >= 1) {
?? exists = file.exists();
try {
try {
} catch (IOException e10) {
e10.printStackTrace();
r02 = r02;
exists = exists;
}
if (exists == 0) {
return null;
}
try {
exists = new ArrayList();
try {
fileReader = new FileReader(file);
} catch (Exception e11) {
e = e11;
}
} catch (Exception e12) {
e = e12;
exists = 0;
}
try {
LineNumberReader lineNumberReader = new LineNumberReader(fileReader);
int i12 = 0;
int i13 = 1;
while (true) {
if (i13 >= i10) {
z10 = false;
break;
}
if (lineNumberReader.readLine() == null) {
break;
}
i13++;
}
if (!z10) {
i12 = i10;
while (i12 < i10 + i11 && (readLine = lineNumberReader.readLine()) != null) {
exists.add(readLine);
i12++;
}
}
fileReader.close();
r02 = i12;
exists = exists;
} catch (Exception e13) {
e = e13;
r02 = fileReader;
Log.e("FileUtil", "read log error!", e);
if (r02 != 0) {
r02.close();
r02 = r02;
exists = exists;
}
return exists;
} catch (Throwable th) {
th = th;
r02 = fileReader;
if (r02 != 0) {
try {
r02.close();
} catch (IOException e14) {
e14.printStackTrace();
}
}
throw th;
}
return exists;
} catch (Throwable th2) {
th = th2;
}
}
}
return null;
}
public static String readFileCompact(File file) {
BufferedReader bufferedReader;
FileReader fileReader;
Exception e10;
String str = "";
FileReader fileReader2 = null;
try {
try {
fileReader = new FileReader(file);
} catch (Exception e11) {
e11.printStackTrace();
}
} catch (Exception e12) {
fileReader = null;
e10 = e12;
bufferedReader = null;
} catch (Throwable th) {
th = th;
bufferedReader = null;
try {
fileReader2.close();
bufferedReader.close();
} catch (Exception e13) {
e13.printStackTrace();
}
throw th;
}
try {
bufferedReader = new BufferedReader(fileReader);
while (true) {
try {
try {
String readLine = bufferedReader.readLine();
if (readLine == null) {
break;
}
str = str + readLine.trim();
} catch (Exception e14) {
e10 = e14;
e10.printStackTrace();
fileReader.close();
bufferedReader.close();
return str;
}
} catch (Throwable th2) {
th = th2;
fileReader2 = fileReader;
fileReader2.close();
bufferedReader.close();
throw th;
}
}
fileReader.close();
bufferedReader.close();
} catch (Exception e15) {
e10 = e15;
bufferedReader = null;
} catch (Throwable th3) {
th = th3;
bufferedReader = null;
fileReader2 = fileReader;
fileReader2.close();
bufferedReader.close();
throw th;
}
return str;
}
private static InputStream s(String str) throws Exception {
File copyVaultFileToTemp = copyVaultFileToTemp(str);
if (copyVaultFileToTemp != null) {
Log.i("lwxcopy", "file is " + copyVaultFileToTemp.exists());
}
return new FileInputStream(copyVaultFileToTemp);
}
public static String saveAttachToAkeychatFolder(ChatMessage chatMessage) throws Exception {
String fileOriginSimpleNameByPath;
String str;
String srcUri = chatMessage.getAttachment().getSrcUri();
if (isVaultPath(srcUri)) {
File copyVaultFileToTemp = copyVaultFileToTemp(srcUri);
Objects.requireNonNull(copyVaultFileToTemp);
srcUri = copyVaultFileToTemp.getPath();
}
String type = chatMessage.getType();
Log.d("FileUtil", "==== Before we saving attach.type:" + type + ",src path:" + srcUri);
if (ChatMessage.CHAT_FILE.equals(type)) {
fileOriginSimpleNameByPath = chatMessage.getAttachment().getFilename();
} else {
fileOriginSimpleNameByPath = getFileOriginSimpleNameByPath(srcUri, type);
}
if (fileOriginSimpleNameByPath != null) {
String str2 = null;
if (ChatMessage.CHAT_IMAGE.equals(type)) {
str2 = getSaveAttachImagePath();
if (fileOriginSimpleNameByPath.endsWith(".src")) {
str = str2 + fileOriginSimpleNameByPath.substring(0, fileOriginSimpleNameByPath.length() - 3) + "jpg";
} else if (!fileOriginSimpleNameByPath.endsWith(".jpg") && !fileOriginSimpleNameByPath.endsWith(".png") && !fileOriginSimpleNameByPath.endsWith(".bmp")) {
if (!Attachment.GIF.equals(chatMessage.getAttachment().getAkcType()) && !fileOriginSimpleNameByPath.toLowerCase().endsWith(".gif")) {
str = str2 + fileOriginSimpleNameByPath + ".jpg";
} else {
str = str2 + fileOriginSimpleNameByPath + ".gif";
}
} else {
str = str2 + fileOriginSimpleNameByPath;
}
} else if ("video".equals(type)) {
str2 = getSaveAttachVideoPath();
if (fileOriginSimpleNameByPath.endsWith(".mp4")) {
str = str2 + fileOriginSimpleNameByPath;
} else {
str = str2 + fileOriginSimpleNameByPath + ".mp4";
}
} else if (ChatMessage.CHAT_AUDIO.equals(type)) {
str2 = getSaveAttachAudioPath();
if (fileOriginSimpleNameByPath.endsWith(".src")) {
str = str2 + fileOriginSimpleNameByPath.substring(0, fileOriginSimpleNameByPath.length() - 3) + "amr";
} else if (fileOriginSimpleNameByPath.endsWith(".aac")) {
str = str2 + fileOriginSimpleNameByPath;
} else {
str = str2 + fileOriginSimpleNameByPath + ".amr";
}
} else if (ChatMessage.CHAT_FILE.equals(type)) {
str2 = getSaveAttachFilePath();
str = str2 + fileOriginSimpleNameByPath;
} else {
str = null;
}
if (str2 != null && !new File(str2).exists()) {
Log.d("FileUtil", "attach folder does not exist");
new File(str2).mkdirs();
}
if (new File(str).exists()) {
Log.d("FileUtil", "this attach file has saved");
return str;
}
File file = new File(srcUri);
if (Build.VERSION.SDK_INT >= 30) {
writeToMediaStore(str, file);
} else {
copyFile(file, str);
}
Log.d("FileUtil", "==== After we saving attach.save path:" + str);
return str;
}
Log.w("FileUtil", "No! attachName is null.");
throw new Exception("No! attachName is null.");
}
public static void scanIntoMediaStore(Context context, String str) {
if (!isFileExist(str)) {
return;
}
Intent intent = new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE");
intent.setData(Uri.fromFile(new File(str)));
context.sendBroadcast(intent);
Log.d("FileUtil", "scan file.");
}
public static ArrayList<com.alibaba.fastjson.JSONObject> searchRestoreFile() {
ArrayList<com.alibaba.fastjson.JSONObject> arrayList = new ArrayList<>();
try {
if (Build.VERSION.SDK_INT > 29) {
ArrayList arrayList2 = new ArrayList();
Cursor query = j.a.get().getContentResolver().query(MediaStore.Files.getContentUri("external"), null, "_data like ? ", new String[]{"%/carrot/kv/%"}, null);
try {
int columnIndexOrThrow = query.getColumnIndexOrThrow(StrangerUserTable.STRANGER_ID);
int columnIndexOrThrow2 = query.getColumnIndexOrThrow("_display_name");
while (query.moveToNext()) {
long j10 = query.getLong(columnIndexOrThrow);
query.getString(columnIndexOrThrow2);
arrayList2.add(ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, j10));
}
Iterator it = arrayList2.iterator();
while (it.hasNext()) {
Uri uri = (Uri) it.next();
Log.i("FileUtil", "uri is " + uri);
try {
com.alibaba.fastjson.JSONObject parseObject = JSON.parseObject(readFile(uri));
if (parseObject == null) {
Log.d("FileUtil", "jo is null");
} else if (parseObject.containsKey("c3efa684ec28a6ccfc9ca0a1f855c479")) {
Server.loads(parseObject.getString("c3efa684ec28a6ccfc9ca0a1f855c479"));
arrayList.add(parseObject);
}
} catch (Exception e10) {
e10.printStackTrace();
}
}
query.close();
} finally {
}
} else {
for (File file : new File(getNewBackupPath()).listFiles()) {
try {
com.alibaba.fastjson.JSONObject parseObject2 = JSON.parseObject(readFile(file));
if (parseObject2 == null) {
Log.d("FileUtil", "jo is null");
} else if (parseObject2.containsKey("c3efa684ec28a6ccfc9ca0a1f855c479")) {
Server.loads(parseObject2.getString("c3efa684ec28a6ccfc9ca0a1f855c479"));
arrayList.add(parseObject2);
}
} catch (Exception e11) {
e11.printStackTrace();
}
}
}
Log.i("FileUtil", "searchRestoreFile size is " + arrayList.size());
} catch (Exception e12) {
e12.printStackTrace();
}
Collections.reverse(arrayList);
return arrayList;
}
private static retrofit2.k t(okhttp3.m mVar, String str) {
return new k.b().client(mVar).baseUrl(str).addCallAdapterFactory(mf.g.create()).addConverterFactory(of.k.create()).build();
}
private static retrofit2.k u(okhttp3.m mVar, String str) {
return new k.b().client(mVar).baseUrl(str).addCallAdapterFactory(mf.g.create()).addConverterFactory(u0.f0.getAKGsonConvertFactory()).build();
}
public static fc.z<UploadFileResult> uploadFileToAliyunfs(String str, final String str2, final File file, u0.e0<String> e0Var) {
StringBuilder sb2 = new StringBuilder();
int indexOf = str.indexOf("?");
if (indexOf <= 0) {
return null;
}
sb2.append(str.substring(0, indexOf));
sb2.append(CookieSpec.PATH_DELIM);
HttpUrl parse = HttpUrl.parse(str);
if (parse == null) {
return null;
}
HashMap hashMap = new HashMap();
for (String str3 : parse.queryParameterNames()) {
hashMap.put(str3, parse.queryParameter(str3));
}
m.b okHttpClientBuilder = HttpURLTools.getOkHttpClientBuilder(sb2.toString(), null, false);
TimeUnit timeUnit = TimeUnit.SECONDS;
m.b addInterceptor = okHttpClientBuilder.connectTimeout(30L, timeUnit).readTimeout(30L, timeUnit).writeTimeout(30L, timeUnit).addInterceptor(new u0.g0(3));
if (AKCAppConfiguration.f9925a.CanDnsResolve()) {
addInterceptor.dns(new HttpURLTools.d());
}
return ((u0.k0) t(addInterceptor.build(), sb2.toString()).create(u0.k0.class)).putBodyFile(str2, hashMap, new u0.v(file, e0Var)).map(new mc.o() {
@Override
public final Object apply(Object obj) {
UploadFileResult E;
E = FileUtil.E(str2, file, (retrofit2.j) obj);
return E;
}
});
}
public static fc.z<UploadFileResult> uploadFileToSeaweedSF(final Akeychat.GetSeaweedfsUploadTokenResponse getSeaweedfsUploadTokenResponse, final File file, final u0.e0<String> e0Var, String str) {
final StringBuilder sb2 = new StringBuilder();
if (getSeaweedfsUploadTokenResponse.getPublicUrl().startsWith("https://")) {
sb2.append(getSeaweedfsUploadTokenResponse.getPublicUrl());
} else {
sb2.append("http://");
sb2.append(getSeaweedfsUploadTokenResponse.getPublicUrl());
}
final okhttp3.m build = HttpURLTools.getOkHttpClientBuilder(sb2.toString(), str, false).addInterceptor(new u0.g0(3)).build();
sb2.append(CookieSpec.PATH_DELIM);
if (getSeaweedfsUploadTokenResponse.hasChunksize()) {
return fc.z.create(new fc.c0() {
@Override
public final void subscribe(fc.b0 b0Var) {
FileUtil.F(Akeychat.GetSeaweedfsUploadTokenResponse.this, file, e0Var, build, sb2, b0Var);
}
}).flatMap(new mc.o() {
@Override
public final Object apply(Object obj) {
fc.e0 H;
H = FileUtil.H(okhttp3.m.this, sb2, getSeaweedfsUploadTokenResponse, file, (l.b) obj);
return H;
}
});
}
return ((u0.l0) u(build, sb2.toString()).create(u0.l0.class)).uploadFiles(getSeaweedfsUploadTokenResponse.getFid(), u0.f0.filesToMultipartBodies(file, e0Var));
}
public static void uploadLogFile(int i10, final String str) throws Exception {
final String str2 = "daily";
String generateLogZipUri = generateLogZipUri(i10, "daily");
Log.i("lwxtlog", generateLogZipUri);
if (generateLogZipUri == null) {
s3.sendEvent(new y7(""));
}
Uri parse = Uri.parse(generateLogZipUri);
String p10 = p("daily");
Log.i("FileUtil", "lwxtest key is " + p10);
s0.a.putFile(j.a.get(), TokenManager.getSingleton().getLocalQiNiuToken(p10), p10, parse, new s0.b(), true, new r0.b() {
@Override
public void onFailure(Exception exc) {
exc.printStackTrace();
Log.i("lwxtest", "ex is " + exc.getMessage());
}
@Override
public void onProcess(long j10, long j11) {
}
@Override
public void onSuccess(JSONObject jSONObject) {
String str3;
Log.i("lwxtest", "AKCoreService resp is " + jSONObject);
try {
str3 = jSONObject.getString("key");
} catch (JSONException e10) {
Log.d("FileUtil", "parse the uploadlog failed " + e10.getMessage());
e10.printStackTrace();
str3 = "";
}
s3.sendEvent(new g.o(str));
com.alibaba.fastjson.JSONObject jSONObject2 = new com.alibaba.fastjson.JSONObject();
jSONObject2.put("url", (Object) ("http://applogs.pro.akeychat.cn/" + str3));
jSONObject2.put("type", (Object) str2);
AKCCheckPoint.aliyunLog(new HashMap<String, String>(jSONObject2) {
final com.alibaba.fastjson.JSONObject f10121a;
{
this.f10121a = jSONObject2;
put("t", "7000");
put("msg", jSONObject2.toJSONString());
}
}, AKCCheckPoint.AKCSLSLogTopic.AKCSLSLogTopic_APPERROR.getValue());
}
});
}
private static String v(Context context, Uri uri) {
String[] split = DocumentsContract.getDocumentId(uri).split(":");
String str = split[0];
Uri uri2 = null;
if (ChatMessage.CHAT_IMAGE.equals(str)) {
uri2 = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
} else if ("video".equals(str)) {
uri2 = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
} else if (ChatMessage.CHAT_AUDIO.equals(str)) {
uri2 = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
}
return getDataColumn(context, uri2, "_id=?", new String[]{split[1]});
}
public static String w(ChatMessage chatMessage, String str) throws Exception {
if (ChatMessage.CHAT_AUDIO.equals(str)) {
downloadAudioAttachment(chatMessage);
} else if (!"video".equals(str) && !ChatMessage.CHAT_IMAGE.equals(str)) {
if (ChatMessage.CHAT_FILE.equals(str) && !TextUtils.isEmpty(chatMessage.getAttachment().getThumbKey()) && !TextUtils.isEmpty(chatMessage.getAttachment().getThumbSize())) {
return downloadImageThumb(chatMessage);
}
} else {
downloadImageThumb(chatMessage);
}
return "";
}
public static boolean write(String str, byte[] bArr) {
return write(str, bArr, false);
}
@RequiresApi(api = 30)
public static void writeToMediaStore(String str, File file) throws IOException {
Uri contentUri = MediaStore.Files.getContentUri("external");
ContentValues contentValues = new ContentValues();
contentValues.put("relative_path", Environment.DIRECTORY_DOWNLOADS + CookieSpec.PATH_DELIM + BuildConfig.FLAVOR_akProduct + CookieSpec.PATH_DELIM + new File(str).getParentFile().getName());
contentValues.put("_display_name", str.split(CookieSpec.PATH_DELIM)[str.split(CookieSpec.PATH_DELIM).length + (-1)]);
contentValues.put("date_modified", Long.valueOf(System.currentTimeMillis()));
contentValues.put("date_added", Long.valueOf(System.currentTimeMillis()));
ContentResolver contentResolver = j.a.get().getContentResolver();
copyFile(file, contentResolver.openOutputStream(contentResolver.insert(contentUri, contentValues)));
}
@RequiresApi(api = 30)
public static Uri writeToMediaStoreForBackUps(String str) {
Uri contentUri = MediaStore.Files.getContentUri("external");
ContentValues contentValues = new ContentValues();
contentValues.put("relative_path", Environment.DIRECTORY_DOWNLOADS + CookieSpec.PATH_DELIM + BuildConfig.FLAVOR_akProduct + "/kv");
contentValues.put("_display_name", str);
contentValues.put("date_modified", Long.valueOf(System.currentTimeMillis()));
contentValues.put("date_added", Long.valueOf(System.currentTimeMillis()));
contentValues.put("datetaken", Long.valueOf(System.currentTimeMillis()));
return j.a.get().getContentResolver().insert(contentUri, contentValues);
}
public static int x(Map.Entry entry, Map.Entry entry2) {
return ((Long) entry2.getKey()).compareTo((Long) entry.getKey());
}
public static void y(String str, long j10, String str2, Akeychat.RecordType recordType, String str3, Akeychat.ChatType chatType, long j11, int i10, fc.b0 b0Var) throws Exception {
try {
b0Var.onNext(TokenManager.getSingleton().getAliyunfsUploadTokenFromServer(str, j10, str2, recordType, str3, chatType, j11, i10));
b0Var.onComplete();
} catch (Throwable th) {
b0Var.onError(th);
}
}
public static void z(String str, long j10, String str2, Akeychat.RecordType recordType, String str3, Akeychat.ChatType chatType, long j11, fc.b0 b0Var) throws Exception {
try {
b0Var.onNext(TokenManager.getSingleton().getAliyunfsUploadTokenFromServer(str, j10, str2, recordType, str3, chatType, j11, -1));
b0Var.onComplete();
} catch (Throwable th) {
b0Var.onError(th);
}
}
public static fc.z<Akeychat.GetAliyunfsUploadTokenResponse> getAliyunFsUploadResource(final String str, final long j10, final String str2, final Akeychat.RecordType recordType, final String str3, final Akeychat.ChatType chatType, final long j11) {
return fc.z.create(new fc.c0() {
@Override
public final void subscribe(fc.b0 b0Var) {
FileUtil.z(str, j10, str2, recordType, str3, chatType, j11, b0Var);
}
});
}
public static fc.z<Akeychat.GetAWSUploadUrlResponse> getS3UploadResource(final String str, final long j10, final String str2, final Akeychat.RecordType recordType, final String str3, final Akeychat.ChatType chatType, final long j11) {
return fc.z.create(new fc.c0() {
@Override
public final void subscribe(fc.b0 b0Var) {
FileUtil.C(str, j10, str2, recordType, str3, chatType, j11, b0Var);
}
});
}
public static boolean isDownloadsDocument(String str) {
return "com.android.providers.downloads.documents".equals(str);
}
public static boolean isExternalStorageDocument(String str) {
return "com.android.externalstorage.documents".equals(str);
}
public static boolean isVaultPath(String str) {
return str.startsWith("cryptomator");
}
public static Bitmap readBitmapFromLocalFile(String str, BitmapFactory.Options options) {
Bitmap bitmap;
InputStream fileInputStream;
InputStream inputStream = null;
Bitmap bitmap2 = null;
InputStream inputStream2 = null;
if (TextUtils.isEmpty(str)) {
Log.w("FileUtil", "file path is empty:" + str);
return null;
}
Log.i("FileUtil", "start decode bitmap:" + str);
try {
try {
if (isVaultPath(str)) {
fileInputStream = s(str);
} else {
fileInputStream = new FileInputStream(str);
}
} catch (Exception e10) {
e = e10;
bitmap = null;
}
} catch (Throwable th) {
th = th;
}
try {
bitmap2 = BitmapFactory.decodeStream(fileInputStream, null, options);
StringBuilder sb2 = new StringBuilder();
sb2.append("bitmap is ");
sb2.append(bitmap2 == null);
Log.i("lwxcopy", sb2.toString());
if (fileInputStream == null) {
return bitmap2;
}
try {
fileInputStream.close();
return bitmap2;
} catch (Exception e11) {
e11.printStackTrace();
return bitmap2;
}
} catch (Exception e12) {
Bitmap bitmap3 = bitmap2;
inputStream2 = fileInputStream;
e = e12;
bitmap = bitmap3;
e.printStackTrace();
Log.w("FileUtil", "decode bitmap failed:" + e.getMessage());
if (inputStream2 != null) {
try {
inputStream2.close();
} catch (Exception e13) {
e13.printStackTrace();
}
}
return bitmap;
} catch (Throwable th2) {
inputStream = fileInputStream;
th = th2;
if (inputStream != null) {
try {
inputStream.close();
} catch (Exception e14) {
e14.printStackTrace();
}
}
throw th;
}
}
public static boolean write(String str, String str2) {
return write(str, str2, false);
}
public static boolean checkFileValid(String str, String str2, String str3) {
File file = new File(str);
if (file.length() == Long.parseLong(str2)) {
StringBuffer stringBuffer = new StringBuffer();
try {
MessageDigest messageDigest = MessageDigest.getInstance(StringUtils.SHA1);
FileInputStream fileInputStream = new FileInputStream(str);
byte[] bArr = new byte[4096];
while (true) {
int read = fileInputStream.read(bArr);
if (read == -1) {
break;
}
messageDigest.update(bArr, 0, read);
}
byte[] digest = messageDigest.digest();
for (byte b10 : digest) {
stringBuffer.append(Integer.toString((b10 & 255) + 256, 16).substring(1));
}
Log.d("FileUtil", "rule SHA-1: " + stringBuffer.toString() + ", download SHA1 = " + str3);
} catch (FileNotFoundException e10) {
Log.e("FileUtil", "Update package does not exists");
e10.printStackTrace();
} catch (IOException e11) {
Log.e("FileUtil", "Read file error. Maybe file is corrupted");
e11.printStackTrace();
} catch (NoSuchAlgorithmException e12) {
Log.e("FileUtil", "There is no SHA-1 algorithm");
e12.printStackTrace();
}
return str3 != null && str3.equalsIgnoreCase(stringBuffer.toString());
}
Log.e("FileUtil", "rule size: " + str2 + ", download size = " + file.length());
return false;
}
public static String getEmoticonPath(String str) {
return getEmoticonPath() + h4.decreaseFileNameLength(str);
}
public static String getFilePathByWith(String str, boolean z10) {
if (j.u0.f40392d == null || ak.im.sdk.manager.f1.getInstance().getUsername() == null || str == null) {
return null;
}
return getUserFilePath() + q5.getUserNameByJid(str) + File.separator;
}
public static String getImagePathByWith(String str, boolean z10) {
if (j.u0.f40392d == null || ak.im.sdk.manager.f1.getInstance().getUsername() == null || str == null) {
return null;
}
return getUserImagePath() + q5.getUserNameByJid(str) + File.separator;
}
public static String getVideoPathByWith(String str, boolean z10) {
if (j.u0.f40392d == null || ak.im.sdk.manager.f1.getInstance().getUsername() == null || str == null) {
return null;
}
return getUserVideoPath() + q5.getUserNameByJid(str) + File.separator;
}
public static boolean write(String str, String str2, boolean z10) {
return write(new File(str), str2, z10);
}
public static boolean write(String str, byte[] bArr, boolean z10) {
return write(new File(str), bArr, z10);
}
public static void deleteFile(File file) {
if (file != null && file.exists()) {
if (file.isFile()) {
file.delete();
} else if (file.isDirectory()) {
for (File file2 : file.listFiles()) {
deleteFile(file2);
}
}
file.delete();
return;
}
Log.w("FileUtil", "file does not exsit do not need delete");
}
public static boolean write(File file, String str) {
return write(file, str, false);
}
public static boolean write(File file, byte[] bArr, boolean z10) {
FileOutputStream fileOutputStream;
if (file == null || bArr.length == 0) {
return false;
}
if (!file.exists()) {
file = createNewFile(file);
}
FileOutputStream fileOutputStream2 = null;
try {
try {
fileOutputStream = new FileOutputStream(file, z10);
} catch (Throwable th) {
th = th;
}
} catch (Exception e10) {
e = e10;
}
try {
fileOutputStream.write(bArr);
fileOutputStream.flush();
try {
fileOutputStream.close();
return true;
} catch (IOException e11) {
Log.e("FileUtil", "", e11);
return true;
}
} catch (Exception e12) {
e = e12;
fileOutputStream2 = fileOutputStream;
Log.e("FileUtil", "", e);
if (fileOutputStream2 != null) {
try {
fileOutputStream2.close();
} catch (IOException e13) {
Log.e("FileUtil", "", e13);
}
}
return false;
} catch (Throwable th2) {
th = th2;
fileOutputStream2 = fileOutputStream;
if (fileOutputStream2 != null) {
try {
fileOutputStream2.close();
} catch (IOException e14) {
Log.e("FileUtil", "", e14);
}
}
throw th;
}
}
public static String getFileName(Context context, Uri uri) {
Cursor cursor;
?? r02 = 0;
try {
try {
cursor = context.getContentResolver().query(uri, null, null, null, null);
if (cursor != null) {
try {
if (cursor.moveToFirst()) {
int columnCount = cursor.getColumnCount();
for (int i10 = 0; i10 < columnCount; i10++) {
try {
Log.i("FileUtil", "check column-" + i10 + ",c-name:" + cursor.getColumnName(i10) + ":" + cursor.getString(i10));
} catch (Exception e10) {
e10.printStackTrace();
}
}
int columnIndex = cursor.getColumnIndex("_data");
int columnIndex2 = cursor.getColumnIndex("_display_name");
int columnIndex3 = cursor.getColumnIndex("document_id:raw");
String string = columnIndex3 != -1 ? cursor.getString(columnIndex3) : null;
if (!TextUtils.isEmpty(string)) {
Log.i("FileUtil", "we get raw path:" + string);
cursor.close();
return string;
}
String string2 = columnIndex != -1 ? cursor.getString(columnIndex) : null;
String string3 = columnIndex2 != -1 ? cursor.getString(columnIndex2) : null;
Log.i("FileUtil", "check dn:" + string3 + ",path:" + string2);
cursor.close();
return string3;
}
} catch (Exception e11) {
e = e11;
e.printStackTrace();
}
}
} catch (Throwable th) {
th = th;
r02 = context;
if (r02 != 0) {
r02.close();
}
throw th;
}
} catch (Exception e12) {
e = e12;
cursor = null;
} catch (Throwable th2) {
th = th2;
if (r02 != 0) {
}
throw th;
}
}
public static void copyFile(File file, OutputStream outputStream) throws IOException {
FileInputStream fileInputStream;
FileInputStream fileInputStream2 = null;
try {
fileInputStream = new FileInputStream(file);
} catch (Throwable th) {
th = th;
}
try {
byte[] bArr = new byte[1024];
while (true) {
int read = fileInputStream.read(bArr);
if (read != -1) {
outputStream.write(bArr, 0, read);
} else {
try {
break;
} catch (IOException e10) {
Log.w("FileUtil", "", e10);
}
}
}
fileInputStream.close();
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e11) {
Log.w("FileUtil", "", e11);
}
}
} catch (Throwable th2) {
th = th2;
fileInputStream2 = fileInputStream;
if (fileInputStream2 != null) {
try {
fileInputStream2.close();
} catch (IOException e12) {
Log.w("FileUtil", "", e12);
}
}
if (outputStream != null) {
try {
outputStream.close();
throw th;
} catch (IOException e13) {
Log.w("FileUtil", "", e13);
throw th;
}
}
throw th;
}
}
public static File createNewFile(String str) {
return createNewFile(new File(str));
}
public static void uploadLogFile(final String str) throws Exception {
long rightTime = o3.getRightTime();
String generateLogZipUri = generateLogZipUri(rightTime - 7200000, rightTime, str);
Log.i("lwxtlog", generateLogZipUri);
if (generateLogZipUri == null) {
s3.sendEvent(new y7(""));
}
Uri parse = Uri.parse(generateLogZipUri);
String p10 = p(str);
Log.i("FileUtil", "lwxtest key is " + p10);
s0.a.putFile(j.a.get(), TokenManager.getSingleton().getLocalQiNiuToken(p10), p10, parse, new s0.b(), true, new r0.b() {
@Override
public void onFailure(Exception exc) {
exc.printStackTrace();
Log.i("lwxtest", "ex is " + exc.getMessage());
if ("auto".equals(str) || "beep_manual".equals(str) || "manual".equals(str)) {
s3.sendEvent(new w7());
}
}
@Override
public void onProcess(long j10, long j11) {
}
@Override
public void onSuccess(JSONObject jSONObject) {
String str2;
Log.i("lwxtest", "resp is " + jSONObject);
try {
str2 = jSONObject.getString("key");
} catch (JSONException e10) {
Log.d("FileUtil", "parse the uploadlog failed " + e10.getMessage());
e10.printStackTrace();
str2 = "";
}
if ("auto".equals(str) || "beep_manual".equals(str) || "manual".equals(str)) {
s3.sendEvent(new y7(str2));
}
com.alibaba.fastjson.JSONObject jSONObject2 = new com.alibaba.fastjson.JSONObject();
jSONObject2.put("url", (Object) ("http://applogs.pro.akeychat.cn/" + str2));
jSONObject2.put("type", (Object) str);
AKCCheckPoint.aliyunLog(new HashMap<String, String>(jSONObject2) {
final com.alibaba.fastjson.JSONObject f10124a;
{
this.f10124a = jSONObject2;
put("t", "7000");
put("msg", jSONObject2.toJSONString());
}
}, AKCCheckPoint.AKCSLSLogTopic.AKCSLSLogTopic_APPERROR.getValue());
}
});
}
public static String readFile(Uri uri) {
BufferedReader bufferedReader;
InputStreamReader inputStreamReader;
BufferedReader bufferedReader2;
Exception e10;
String str = "";
InputStream inputStream = null;
try {
} catch (Throwable th) {
th = th;
}
try {
try {
uri = j.a.get().getContentResolver().openInputStream(uri);
try {
inputStreamReader = new InputStreamReader(uri);
try {
bufferedReader2 = new BufferedReader(inputStreamReader);
while (true) {
try {
String readLine = bufferedReader2.readLine();
if (readLine == null) {
break;
}
str = str + readLine.trim() + "\r\n";
} catch (Exception e11) {
e10 = e11;
AkeyChatUtils.logException(e10);
if (uri != 0) {
uri.close();
}
if (inputStreamReader != null) {
inputStreamReader.close();
}
}
}
if (uri != 0) {
uri.close();
}
inputStreamReader.close();
} catch (Exception e12) {
bufferedReader2 = null;
e10 = e12;
} catch (Throwable th2) {
th = th2;
bufferedReader = null;
inputStream = uri;
if (inputStream != null) {
}
if (inputStreamReader != null) {
}
if (bufferedReader != null) {
}
throw th;
}
} catch (Exception e13) {
bufferedReader2 = null;
e10 = e13;
inputStreamReader = null;
} catch (Throwable th3) {
th = th3;
inputStreamReader = null;
bufferedReader = null;
}
} catch (Exception unused) {
}
} catch (Exception e14) {
inputStreamReader = null;
bufferedReader2 = null;
e10 = e14;
uri = 0;
} catch (Throwable th4) {
th = th4;
inputStreamReader = null;
bufferedReader = null;
if (inputStream != null) {
try {
inputStream.close();
} catch (Exception unused2) {
throw th;
}
}
if (inputStreamReader != null) {
inputStreamReader.close();
}
if (bufferedReader != null) {
bufferedReader.close();
}
throw th;
}
bufferedReader2.close();
return str;
}
public static void uploadLogFile(String str, Activity activity, Boolean bool) throws Exception {
long rightTime = o3.getRightTime();
String generateLogZipUri = generateLogZipUri(rightTime - 7200000, rightTime, str);
if (TextUtils.isEmpty(generateLogZipUri)) {
Log.d("FileUtil", "the log file path is empty");
new a1.c1(activity, 1, bool.booleanValue()).start();
} else {
Uri parse = Uri.parse(generateLogZipUri);
String p10 = p(str);
s0.a.putFile(j.a.get(), TokenManager.getSingleton().getLocalQiNiuToken(p10), p10, parse, new s0.b(), true, new e(str, activity, bool));
}
}
public static String generateLogZipUri(int i10, String str) {
File[] listFiles = new File(getGlobalLogPath()).listFiles();
if (listFiles != null && listFiles.length != 0) {
ArrayList arrayList = new ArrayList();
HashMap hashMap = new HashMap();
for (File file : listFiles) {
if (file.getName().startsWith(BaseWorkflow.TEMPLATE_TYPE_NORMAL)) {
hashMap.put(Long.valueOf(o3.str2Long(getNameFromFilename(file.getName()).substring(7), "yyyy-MM-dd-HH-mm-ss")), file.getAbsolutePath());
}
}
ArrayList<Map.Entry> arrayList2 = new ArrayList(hashMap.entrySet());
Collections.sort(arrayList2, new Comparator() {
@Override
public final int compare(Object obj, Object obj2) {
int x10;
x10 = FileUtil.x((Map.Entry) obj, (Map.Entry) obj2);
return x10;
}
});
for (Map.Entry entry : arrayList2) {
if (arrayList.size() >= i10) {
break;
}
arrayList.add((String) entry.getValue());
}
if (arrayList.size() == 0) {
return null;
}
String str2 = getGlobalCachePath() + p(str);
deleteFile(str2);
createNewFile(str2);
try {
x5.writeByApacheZipOutputStream(arrayList, str2, "");
return str2;
} catch (FileNotFoundException e10) {
e10.printStackTrace();
} catch (IOException e11) {
e11.printStackTrace();
return null;
}
}
return null;
}
public static Bitmap readBitmapFromLocalFile(Uri uri) {
Bitmap bitmap;
Throwable th;
InputStream inputStream;
Bitmap bitmap2 = null;
bitmap2 = null;
InputStream inputStream2 = null;
if (uri == null) {
Log.w("FileUtil", "uri is empty:" + uri);
return null;
}
Log.i("FileUtil", "start decode bitmap:" + uri);
try {
try {
inputStream = j.a.get().getContentResolver().openInputStream(uri);
} catch (Throwable th2) {
Bitmap bitmap3 = bitmap2;
th = th2;
inputStream = bitmap3;
}
} catch (Exception e10) {
e = e10;
bitmap = null;
}
try {
bitmap2 = BitmapFactory.decodeStream(inputStream);
StringBuilder sb2 = new StringBuilder();
sb2.append("bitmap is ");
sb2.append(bitmap2 == null);
Log.i("lwxcopy", sb2.toString());
if (inputStream != null) {
try {
inputStream.close();
} catch (Exception e11) {
e11.printStackTrace();
}
}
} catch (Exception e12) {
e = e12;
Bitmap bitmap4 = bitmap2;
inputStream2 = inputStream;
bitmap = bitmap4;
e.printStackTrace();
Log.w("FileUtil", "decode bitmap failed:" + e.getMessage());
if (inputStream2 != null) {
try {
inputStream2.close();
} catch (Exception e13) {
e13.printStackTrace();
}
}
bitmap2 = bitmap;
return bitmap2;
} catch (Throwable th3) {
th = th3;
if (inputStream != null) {
try {
inputStream.close();
} catch (Exception e14) {
e14.printStackTrace();
}
}
throw th;
}
return bitmap2;
}
public static void copyFile(InputStream inputStream, String str) throws IOException {
FileOutputStream fileOutputStream;
FileOutputStream fileOutputStream2 = null;
try {
fileOutputStream = new FileOutputStream(str);
} catch (Throwable th) {
th = th;
}
try {
byte[] bArr = new byte[1024];
while (true) {
int read = inputStream.read(bArr);
if (read != -1) {
fileOutputStream.write(bArr, 0, read);
} else {
inputStream.close();
fileOutputStream.close();
return;
}
}
} catch (Throwable th2) {
th = th2;
fileOutputStream2 = fileOutputStream;
if (inputStream != null) {
inputStream.close();
}
if (fileOutputStream2 != null) {
fileOutputStream2.close();
}
throw th;
}
}
public static boolean write(OutputStream outputStream, String str) {
try {
try {
outputStream.write(str.getBytes());
outputStream.flush();
try {
outputStream.close();
return true;
} catch (IOException e10) {
e10.printStackTrace();
Log.e("FileUtil", "", e10);
return true;
}
} catch (Exception e11) {
e11.printStackTrace();
Log.e("FileUtil", "", e11);
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e12) {
e12.printStackTrace();
Log.e("FileUtil", "", e12);
}
}
return false;
}
} catch (Throwable th) {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e13) {
e13.printStackTrace();
Log.e("FileUtil", "", e13);
}
}
throw th;
}
}
public static String readFile(File file) {
?? r52;
FileReader fileReader;
Exception e10;
BufferedReader bufferedReader;
String str = "";
FileReader fileReader2 = null;
try {
try {
try {
fileReader = new FileReader(file);
} catch (Throwable th) {
th = th;
}
} catch (Exception e11) {
fileReader = null;
e10 = e11;
bufferedReader = null;
} catch (Throwable th2) {
th = th2;
r52 = 0;
if (fileReader2 != null) {
try {
fileReader2.close();
} catch (Exception unused) {
throw th;
}
}
if (r52 != 0) {
r52.close();
}
throw th;
}
try {
bufferedReader = new BufferedReader(fileReader);
while (true) {
try {
String readLine = bufferedReader.readLine();
if (readLine == null) {
break;
}
str = str + readLine.trim() + "\r\n";
} catch (Exception e12) {
e10 = e12;
AkeyChatUtils.logException(e10);
if (fileReader != null) {
fileReader.close();
}
}
}
fileReader.close();
} catch (Exception e13) {
e10 = e13;
bufferedReader = null;
} catch (Throwable th3) {
th = th3;
file = null;
fileReader2 = fileReader;
r52 = file;
if (fileReader2 != null) {
}
if (r52 != 0) {
}
throw th;
}
bufferedReader.close();
} catch (Exception unused2) {
}
return str;
}
public static boolean write(File file, String str, boolean z10) {
FileOutputStream fileOutputStream;
if (file == null || q5.empty(str)) {
return false;
}
if (!file.exists()) {
file = createNewFile(file);
}
FileOutputStream fileOutputStream2 = null;
try {
try {
fileOutputStream = new FileOutputStream(file, z10);
} catch (Exception e10) {
e = e10;
}
} catch (Throwable th) {
th = th;
}
try {
fileOutputStream.write(str.getBytes());
fileOutputStream.flush();
try {
fileOutputStream.close();
return true;
} catch (IOException e11) {
Log.e("FileUtil", "", e11);
return true;
}
} catch (Exception e12) {
e = e12;
fileOutputStream2 = fileOutputStream;
Log.e("FileUtil", "", e);
if (fileOutputStream2 != null) {
try {
fileOutputStream2.close();
} catch (IOException e13) {
Log.e("FileUtil", "", e13);
}
}
return false;
} catch (Throwable th2) {
th = th2;
fileOutputStream2 = fileOutputStream;
if (fileOutputStream2 != null) {
try {
fileOutputStream2.close();
} catch (IOException e14) {
Log.e("FileUtil", "", e14);
}
}
throw th;
}
}
public static boolean write(File file, InputStream inputStream) {
return write(file, inputStream, false);
}
public static boolean write(File file, InputStream inputStream, boolean z10) {
try {
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
if (file.exists() && !z10) {
file.delete();
}
FileOutputStream fileOutputStream = new FileOutputStream(file, z10);
byte[] bArr = new byte[131072];
while (true) {
int read = inputStream.read(bArr);
if (read != -1) {
fileOutputStream.write(bArr, 0, read);
} else {
fileOutputStream.flush();
fileOutputStream.close();
inputStream.close();
return true;
}
}
} catch (IOException e10) {
e10.printStackTrace();
Log.w("FileUtil", "download file excp " + e10.getMessage());
return true;
}
}
}