package com.liajt.otaapk; import android.app.DownloadManager; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageInstaller; import android.content.pm.PackageManager; import android.content.res.Resources; import android.graphics.Point; import android.net.Uri; import android.os.Environment; import android.os.IBinder; import android.util.Log; import android.view.WindowManager; import androidx.appcompat.app.C0121y; import androidx.appcompat.widget.C0125a0; import androidx.recyclerview.widget.C0402b; import com.blankj.utilcode.util.AbstractC0597f; import com.blankj.utilcode.util.AbstractC0598g; import com.blankj.utilcode.util.AbstractC0602k; import com.blankj.utilcode.util.AbstractC0605n; import com.blankj.utilcode.util.AbstractC0607p; import com.liajt.otaapk.bean.AsDevice; import com.liajt.otaapk.bean.AsFile; import java.io.File; import java.io.IOException; import java.nio.charset.Charset; import java.util.Timer; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.SynchronousQueue; import kotlin.jvm.internal.AbstractC1167e; import org.greenrobot.eventbus.ThreadMode; import org.slf4j.Marker; import p005a4.C0029q; import p015c3.C0530b; import p015c3.C0531c; import p015c3.C0532d; import p027e3.AbstractC0974a; import p031f3.C0989c; import p081o4.C1349d; import p081o4.InterfaceC1356k; import p094r3.AbstractC1535d; import p108u2.C1611f; import p109u3.AbstractC1632a; import p109u3.C1639h; import p119w3.AbstractC1723t; import p119w3.C1719p; import p119w3.C1720q; import p119w3.C1722s; import p123x3.AbstractC1782e; /* loaded from: classes.dex */ public class MyService extends Service { /* renamed from: A */ public static String f4458A; /* renamed from: B */ public static String f4459B; /* renamed from: C */ public static String f4460C; /* renamed from: D */ public static String f4461D; /* renamed from: E */ public static String f4462E; /* renamed from: F */ public static String f4463F; /* renamed from: G */ public static long f4464G; /* renamed from: H */ public static long f4465H; /* renamed from: v */ public static String f4466v; /* renamed from: w */ public static String f4467w; /* renamed from: x */ public static String f4468x; /* renamed from: y */ public static String f4469y; /* renamed from: z */ public static String f4470z; /* renamed from: h */ public String f4472h; /* renamed from: i */ public String f4473i; /* renamed from: j */ public String f4474j; /* renamed from: k */ public double f4475k; /* renamed from: l */ public double f4476l; /* renamed from: n */ public int f4478n; /* renamed from: o */ public int f4479o; /* renamed from: p */ public int f4480p; /* renamed from: q */ public Timer f4481q; /* renamed from: r */ public volatile long f4482r; /* renamed from: s */ public C0121y f4483s; /* renamed from: t */ public C0532d f4484t; /* renamed from: g */ public final C1720q f4471g = new C1720q(); /* renamed from: m */ public volatile AsDevice f4477m = new AsDevice(); /* renamed from: u */ public final ConcurrentHashMap f4485u = new ConcurrentHashMap(); /* renamed from: a */ public static void m2303a(MyService myService, AsFile asFile) { File externalStoragePublicDirectory; myService.getClass(); String strM2306g = m2306g(asFile.getPath()); String fileName = asFile.getFileName(); int i5 = AbstractC0602k.f2852a; String absolutePath = ""; if ("mounted".equals(Environment.getExternalStorageState()) && (externalStoragePublicDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)) != null) { absolutePath = externalStoragePublicDirectory.getAbsolutePath(); } File file = new File(absolutePath, fileName); Log.w("MyService", "downloadUpdate: " + fileName + " url:" + strM2306g); if (AbstractC0597f.m1758c(file)) { if ((file.isDirectory() ? AbstractC0597f.m1757b(file) : (file.exists() && file.isFile()) ? file.length() : -1L) == asFile.getSize().longValue()) { Log.w("MyService", "downloadUpdate, file exist, same length, install..."); myService.m2309f(fileName); return; } Log.e("MyService", "downloadUpdate, file exist, length error, delete to download..."); if (file.isDirectory()) { AbstractC0597f.m1756a(file); } else if (file.exists() && file.isFile()) { file.delete(); } } else { Log.d("MyService", "downloadUpdate: file not exist:" + file.getAbsolutePath()); } DownloadManager.Request request = new DownloadManager.Request(Uri.parse(strM2306g)); request.setTitle("OTA"); request.setDescription("downloading..."); request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName); request.setNotificationVisibility(1); DownloadManager downloadManager = (DownloadManager) myService.getSystemService("download"); if (downloadManager != null) { long jEnqueue = downloadManager.enqueue(request); myService.f4485u.put(Long.valueOf(jEnqueue), fileName); Log.d("MyService", "downloadUpdate start, id: " + jEnqueue); } } /* JADX WARN: Code restructure failed: missing block: B:30:0x00ca, code lost: if (r5.compareTo(r2) <= 0) goto L43; */ /* renamed from: b */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ public static boolean m2304b(com.liajt.otaapk.MyService r5, java.lang.String r6, java.lang.String r7, java.lang.String r8, java.lang.String r9) { /* Method dump skipped, instructions count: 321 To view this dump change 'Code comments level' option to 'DEBUG' */ throw new UnsupportedOperationException("Method not decompiled: com.liajt.otaapk.MyService.m2304b(com.liajt.otaapk.MyService, java.lang.String, java.lang.String, java.lang.String, java.lang.String):boolean"); } /* renamed from: c */ public static void m2305c(MyService myService, String str) { myService.getClass(); Log.e("MyService", "delete app: " + str); SynchronousQueue synchronousQueue = AbstractC0974a.f4831a; Intent intent = new Intent(); intent.setFlags(268435456); myService.getPackageManager().getPackageInstaller().uninstall(str, PendingIntent.getActivity(myService, 0, intent, 67108864).getIntentSender()); } /* renamed from: g */ public static String m2306g(String str) { if (AbstractC0605n.m1780p(str)) { return ""; } return "https://appstore.coob.top/prod-api".replace("/prod-api", "") + str.replace("/profile", ""); } /* renamed from: d */ public final void m2307d() { Log.d("MyService", "checkDelApk: https://appstore.coob.top/prod-api/system/api/listDelApp"); C0402b c0402b = new C0402b(4); c0402b.m1283u("https://appstore.coob.top/prod-api/system/api/listDelApp"); C0125a0 c0125a0 = new C0125a0(c0402b); C1720q c1720q = this.f4471g; c1720q.getClass(); new C0029q(c1720q, c0125a0).m86d(new C0530b(this, 0)); } /* renamed from: e */ public final void m2308e() { Log.d("MyService", "checkUpdate: https://appstore.coob.top/prod-api/system/api/listFiles"); C0402b c0402b = new C0402b(4); c0402b.m1283u("https://appstore.coob.top/prod-api/system/api/listFiles"); C0125a0 c0125a0 = new C0125a0(c0402b); C1720q c1720q = this.f4471g; c1720q.getClass(); new C0029q(c1720q, c0125a0).m86d(new C0530b(this, 2)); } /* renamed from: f */ public final void m2309f(String str) { int iCreateSession; File externalStoragePublicDirectory; Log.d("MyService", "downloadDone: " + str); if (AbstractC0605n.m1780p(str) || !str.endsWith(".apk")) { return; } int i5 = AbstractC0602k.f2852a; String absolutePath = ""; if ("mounted".equals(Environment.getExternalStorageState()) && (externalStoragePublicDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)) != null) { absolutePath = externalStoragePublicDirectory.getAbsolutePath(); } String absolutePath2 = new File(absolutePath, str).getAbsolutePath(); Log.e("MyService", "installApp: " + absolutePath2); SynchronousQueue synchronousQueue = AbstractC0974a.f4831a; synchronized (AbstractC0974a.class) { File file = new File(absolutePath2); if (file.exists() && file.canRead() && file.length() != 0) { long freeSpace = new File(getFilesDir().getAbsolutePath()).getFreeSpace(); if (freeSpace < file.length() * 2) { Log.e("WNCC INSTALLER", "InstallManager: 存储空间不足。可用空间: " + freeSpace + ", 需要空间: " + (file.length() * 2)); return; } if (getPackageManager().getPackageArchiveInfo(absolutePath2, 0) == null) { Log.e("WNCC INSTALLER", "InstallManager: 无效的APK文件"); return; } PackageInstaller packageInstaller = getPackageManager().getPackageInstaller(); PackageInstaller.SessionParams sessionParams = new PackageInstaller.SessionParams(1); sessionParams.setSize(file.length()); try { iCreateSession = packageInstaller.createSession(sessionParams); } catch (IOException e4) { e4.printStackTrace(); iCreateSession = -1; } if (iCreateSession != -1) { boolean zM2472a = AbstractC0974a.m2472a(packageInstaller, iCreateSession, absolutePath2); Log.i("WNCC INSTALLER", "InstallManager: copySuccess: " + zM2472a); if (zM2472a) { boolean zM2473b = AbstractC0974a.m2473b(this, packageInstaller, iCreateSession, absolutePath2); Log.i("WNCC INSTALLER", "InstallManager: installForP: ----------------------"); Log.i("WNCC INSTALLER", "InstallManager: " + absolutePath2); Log.i("WNCC INSTALLER", "InstallManager: packageInstaller: " + packageInstaller); Log.i("WNCC INSTALLER", "InstallManager: installSuccess: " + zM2473b); Log.i("WNCC INSTALLER", "InstallManager: installState: installed"); Log.i("WNCC INSTALLER", "InstallManager: installForP: ----------------------"); } } return; } Log.e("WNCC INSTALLER", "InstallManager: APK文件不存在、无法读取或文件大小为0: " + absolutePath2); } } /* renamed from: h */ public final void m2310h() { Log.d("MyService", "updateDev: https://appstore.coob.top/prod-api/system/api/updateDev " + AbstractC0598g.m1759a().toJson(this.f4477m)); String json = AbstractC0598g.m1759a().toJson(this.f4477m); C1639h c1639h = C1719p.f7001c; C1719p c1719pM3531V = AbstractC1535d.m3531V("application/json"); int i5 = AbstractC1723t.f7046a; AbstractC1167e.m2847e(json, ""); Charset charset = AbstractC1632a.f6731a; if (c1719pM3531V != null) { Charset charsetM3928a = C1719p.m3928a(c1719pM3531V); if (charsetM3928a == null) { c1719pM3531V = AbstractC1535d.m3531V(c1719pM3531V + "; charset=utf-8"); } else { charset = charsetM3928a; } } C0989c c0989c = new C0989c(charset, c1719pM3531V); Charset charset2 = (Charset) c0989c.m2484a(); C1719p c1719p = (C1719p) c0989c.m2485b(); byte[] bytes = json.getBytes(charset2); AbstractC1167e.m2846d(bytes, "getBytes(...)"); int length = bytes.length; AbstractC1782e.m4028a(bytes.length, 0, length); C1722s c1722s = new C1722s(c1719p, length, bytes); C0402b c0402b = new C0402b(4); c0402b.m1283u("https://appstore.coob.top/prod-api/system/api/updateDev"); c0402b.m1274l("POST", c1722s); C0125a0 c0125a0 = new C0125a0(c0402b); C1720q c1720q = this.f4471g; c1720q.getClass(); new C0029q(c1720q, c0125a0).m86d(new C1611f(12)); } @Override // android.app.Service public final IBinder onBind(Intent intent) { Log.d("MyService", "onBind: "); return null; } @Override // android.app.Service public final void onCreate() throws SecurityException { int i5; int i6 = 2; int i7 = 1; super.onCreate(); Log.d("MyService", "startForeground start"); NotificationManager notificationManager = (NotificationManager) getSystemService("notification"); NotificationChannel notificationChannel = new NotificationChannel("my_channel_01", "001", 4); notificationChannel.setDescription("002"); notificationChannel.enableLights(true); notificationChannel.setLightColor(-65536); notificationChannel.enableVibration(true); notificationChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400}); notificationManager.createNotificationChannel(notificationChannel); startForeground(1, new Notification.Builder(this).setContentTitle("OTA").setContentText(getResources().getString(R.string.check_rom_update)).setSmallIcon(R.drawable.ic_launcher_foreground).setChannelId("my_channel_01").build()); Log.d("MyService", "startForeground end"); WindowManager windowManager = (WindowManager) AbstractC0605n.m1767c().getSystemService("window"); int i8 = -1; if (windowManager == null) { i5 = -1; } else { Point point = new Point(); windowManager.getDefaultDisplay().getRealSize(point); i5 = point.x; } this.f4478n = i5; WindowManager windowManager2 = (WindowManager) AbstractC0605n.m1767c().getSystemService("window"); if (windowManager2 != null) { Point point2 = new Point(); windowManager2.getDefaultDisplay().getRealSize(point2); i8 = point2.y; } this.f4479o = i8; this.f4480p = Resources.getSystem().getDisplayMetrics().densityDpi; Log.d("MyService", "onCreate: app v" + AbstractC0605n.m1768d(AbstractC0605n.m1767c().getPackageName()) + " screen:" + this.f4478n + Marker.ANY_MARKER + this.f4479o + " density:" + this.f4480p); StringBuilder sb = new StringBuilder("isroot: "); sb.append(AbstractC0605n.m1779o()); Log.d("MyService", sb.toString()); try { AbstractC0605n.m1779o(); f4466v = (String) AbstractC0607p.m1787a("getprop ro.xrota.oem").f875c; f4467w = (String) AbstractC0607p.m1787a("getprop ro.xrota.device").f875c; f4468x = (String) AbstractC0607p.m1787a("getprop ro.xrota.version").f875c; f4458A = (String) AbstractC0607p.m1787a("getprop ro.xrota.chiptype").f875c; Log.d("MyService", "fotaOem: " + f4466v + " fotaDevice:" + f4467w + " fotaVer:" + f4468x); } catch (Exception e4) { e4.printStackTrace(); } C1349d.m3084b().m3091i(this); IntentFilter intentFilter = new IntentFilter("android.intent.action.DOWNLOAD_COMPLETE"); C0121y c0121y = new C0121y(1, this); this.f4483s = c0121y; registerReceiver(c0121y, intentFilter, 2); IntentFilter intentFilter2 = new IntentFilter(); intentFilter2.addAction("android.intent.action.PACKAGE_ADDED"); intentFilter2.addAction("android.intent.action.PACKAGE_REPLACED"); intentFilter2.addAction("android.intent.action.PACKAGE_REMOVED"); intentFilter2.addDataScheme("package"); C0532d c0532d = new C0532d(); this.f4484t = c0532d; registerReceiver(c0532d, intentFilter2, 2); C0402b c0402b = new C0402b(4); c0402b.m1283u("https://realip.cc/"); C0125a0 c0125a0 = new C0125a0(c0402b); Log.d("MyService", "getLocationByIp: https://realip.cc/"); C1720q c1720q = this.f4471g; c1720q.getClass(); new C0029q(c1720q, c0125a0).m86d(new C0530b(this, i7)); m2307d(); new Timer().schedule(new C0531c(i7, this), 1000L); this.f4482r = System.currentTimeMillis(); Timer timer = new Timer(); this.f4481q = timer; timer.schedule(new C0531c(i6, this), 60000L, 60000L); } @Override // android.app.Service public final void onDestroy() { super.onDestroy(); Log.d("MyService", "onDestroy: "); C1349d.m3084b().m3093k(this); C0121y c0121y = this.f4483s; if (c0121y != null) { unregisterReceiver(c0121y); } C0532d c0532d = this.f4484t; if (c0532d != null) { unregisterReceiver(c0532d); } Timer timer = this.f4481q; if (timer != null) { timer.cancel(); } } @InterfaceC1356k(threadMode = ThreadMode.MAIN) public void onMessageEvent(String str) throws PackageManager.NameNotFoundException { if (AbstractC0605n.m1780p(str)) { return; } Log.d("MyService", "onMessageEvent: " + str); if (!str.equals("check_update")) { str.equals("download_update"); return; } AbstractC0605n.m1772h().getClass(); AbstractC0605n.m1772h().getClass(); AbstractC0605n.m1768d(AbstractC0605n.m1767c().getPackageName()); AbstractC0605n.m1769e(); m2308e(); m2307d(); m2310h(); } @Override // android.app.Service public final int onStartCommand(Intent intent, int i5, int i6) { Log.d("MyService", "onStartCommand: "); return super.onStartCommand(intent, i5, i6); } }