diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 8885009d1..5d54db2a6 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -68,9 +68,6 @@ dependencies { exclude(group = "androidx.recyclerview") exclude(group = "androidx.appcompat") } - implementation("org.smali:dexlib2:2.5.2") { - exclude(group = "com.google.guava", module = "guava") - } implementation("androidx.room:room-runtime:2.4.2") kapt("androidx.room:room-compiler:2.4.2") diff --git a/app/src/main/assets/proxy_packagename.txt b/app/src/main/assets/proxy_packagename.txt new file mode 100644 index 000000000..ab5625143 --- /dev/null +++ b/app/src/main/assets/proxy_packagename.txt @@ -0,0 +1,370 @@ +amanita_design.samorost3.gp +android +au.com.shiftyjelly.pocketcasts +bbc.mobile.news.ww +be.mygod.vpnhotspot +ch.protonmail.android +cm.aptoide.pt +co.wanqu.android +com.alphainventor.filemanager +com.amazon.kindle +com.amazon.mshop.android.shopping +com.android.chrome +com.android.providers.downloads +com.android.providers.downloads.ui +com.android.providers.telephony +com.android.settings +com.android.vending +com.android6park.m6park +com.apkpure.aegon +com.apkupdater +com.app.pornhub +com.arthurivanets.owly +com.asahi.tida.tablet +com.authy.authy +com.avmovie +com.ballistiq.artstation +com.binance.dev +com.bitly.app +com.brave.browser +com.brave.browser_beta +com.breel.wallpapers18 +com.bvanced.android.youtube +com.chrome.beta +com.chrome.canary +com.chrome.dev +com.cl.newt66y +com.cradle.iitc_mobile +org.exarhteam.iitc_mobile +com.cygames.shadowverse +com.dcard.freedom +com.devhd.feedly +com.devolver.reigns2 +com.discord +com.downloader.video.tumblr +com.driverbrowser +com.dropbox.android +com.duolingo +com.duckduckgo.mobile.android +com.dv.adm +com.estrongs.android.pop +com.estrongs.android.pop.pro +com.evernote +com.facebook.katana +com.facebook.lite +com.facebook.mlite +com.facebook.orca +com.facebook.services +com.facebook.system +com.fastaccess.github +com.felixfilip.scpae +com.fireproofstudios.theroom4 +com.firstrowria.pushnotificationtester +com.flyersoft.moonreaderp +com.fooview.android.fooview +com.fvd.eversync +com.gameloft.android.anmp.glofta8hm +com.gameloft.android.anmp.glofta9hm +com.gianlu.aria2app +com.github.yeriomin.yalpstore +com.google.android.apps.adm +com.google.android.apps.books +com.google.android.apps.docs +com.google.android.apps.docs.editors.sheets +com.google.android.apps.fitness +com.google.android.apps.googleassistant +com.google.android.apps.googlevoice +com.google.android.apps.hangoutsdialer +com.google.android.apps.inbox +com.google.android.apps.magazines +com.google.android.apps.maps +com.google.android.apps.nbu.files +com.google.android.apps.paidtasks +com.google.android.apps.pdfviewer +com.google.android.apps.photos +com.google.android.apps.plus +com.google.android.apps.translate +com.google.android.gm +com.google.android.gms +com.google.android.gms.setup +com.google.android.googlequicksearchbox +com.google.android.gsf +com.google.android.gsf.login +com.google.android.ims +com.google.android.inputmethod.latin +com.google.android.instantapps.supervisor +com.google.android.keep +com.google.android.music +com.google.android.ogyoutube +com.google.android.partnersetup +com.google.android.play.games +com.google.android.street +com.google.android.syncadapters.calendar +com.google.android.syncadapters.contacts +com.google.android.talk +com.google.android.tts +com.google.android.videos +com.google.android.youtube +com.google.ar.lens +com.hochan.coldsoup +com.ifttt.ifttt +com.imgur.mobile +com.innologica.inoreader +com.instagram.android +com.instagram.lite +com.instapaper.android +com.jarvanh.vpntether +com.kapp.youtube.final +com.klinker.android.twitter_l +com.lastpass.lpandroid +com.linecorp.linelite +com.lingodeer +com.ltnnews.news +com.mediapods.tumbpods +com.mgoogle.android.gms +com.microsoft.emmx +com.microsoft.office.powerpoint +com.microsoft.skydrive +com.mixplorer +com.msd.consumerchinese +com.msd.professionalchinese +com.mss2011c.sharehelper +com.netflix.mediaclient +com.newin.nplayer.pro +com.nianticlabs.ingress.prime.qa +com.nianticproject.ingress +com.ninefolders.hd3 +com.ninegag.android.app +com.nintendo.zara +com.nytimes.cn +com.oasisfeng.island +com.ocnt.liveapp.hw +com.orekie.search +com.patreon.android +com.paypal.android.p2pmobile +com.perol.asdpl.pixivez +com.pinterest +com.popularapp.periodcalendar +com.popularapp.videodownloaderforinstagram +com.pushbullet.android +com.quoord.tapatalkpro.activity +com.quora.android +com.rayark.cytus2 +com.rayark.implosion +com.rayark.pluto +com.reddit.frontpage +com.resilio.sync +com.rhmsoft.edit +com.rubenmayayo.reddit +com.sec.android.app.sbrowser +com.sec.android.app.sbrowser.beta +com.shanga.walli +com.simplehabit.simplehabitapp +com.slack +com.snaptube.premium +com.sololearn +com.sonelli.juicessh +com.sparkslab.dcardreader +com.spotify.music +com.tencent.huatuo +com.termux +com.teslacoilsw.launcher +com.theinitium.news +com.thomsonreuters.reuters +com.thunkable.android.hritvik00.freenom +com.topjohnwu.magisk +com.tripadvisor.tripadvisor +com.tumblr +com.twitter.android +com.u91porn +com.u9porn +com.ubisoft.dance.justdance2015companion +com.udn.news +com.utopia.pxview +com.valvesoftware.android.steam.community +com.vanced.manager +com.vanced.android.youtube +com.vanced.android.apps.youtube.music +com.mgoogle.android.gms +com.vimeo.android.videoapp +com.vivaldi.browser +com.vivaldi.browser.snapshot +com.vkontakte.android +com.whatsapp +com.wire +com.wuxiangai.refactor +com.xda.labs +com.xvideos.app +com.yahoo.mobile.client.android.superapp +com.yandex.browser +com.yandex.browser.beta +com.yandex.browser.alpha +com.z28j.feel +com.zhiliaoapp.musically +con.medium.reader +de.apkgrabber +de.robv.android.xposed.installer +dk.tacit.android.foldersync.full +es.rafalense.telegram.themes +es.rafalense.themes +flipboard.app +fm.moon.app +fr.gouv.etalab.mastodon +github.tornaco.xposedmoduletest +idm.internet.download.manager +idm.internet.download.manager.plus +io.github.javiewer +io.github.skyhacker2.magnetsearch +io.va.exposed +it.mvilla.android.fenix2 +jp.bokete.app.android +jp.naver.line.android +jp.pxv.android +luo.speedometergpspro +m.cna.com.tw.App +mark.via.gp +me.tshine.easymark +net.teeha.android.url_shortener +net.tsapps.appsales +onion.fire +org.fdroid.fdroid +org.freedownloadmanager.fdm +org.kustom.widget +org.mozilla.fennec_aurora +org.mozilla.fenix +org.mozilla.fenix.nightly +org.mozilla.firefox +org.mozilla.firefox_beta +org.mozilla.focus +org.schabi.newpipe +org.telegram.messenger +org.telegram.multi +org.telegram.plus +org.thunderdog.challegram +org.torproject.android +org.torproject.torbrowser_alpha +org.wikipedia +org.xbmc.kodi +pl.zdunex25.updater +tv.twitch.android.app +tw.com.gamer.android.activecenter +videodownloader.downloadvideo.downloader +uk.co.bbc.learningenglish +com.ted.android +de.danoeh.antennapod +com.kiwibrowser.browser +nekox.messenger +com.nextcloud.client +com.aurora.store +com.aurora.adroid +chat.simplex.app +im.vector.app +network.loki.messenger +eu.siacs.conversations +xyz.nextalone.nagram +de.danoeh.antennapod +net.programmierecke.radiodroid2 +im.fdx.v2ex +ml.docilealligator.infinityforreddit +com.bytemyth.ama +app.vanadium.browser +com.cakewallet.cake_wallet +org.purplei2p.i2pd +dk.tacit.android.foldersync.lite +com.nononsenseapps.feeder +com.m2049r.xmrwallet +com.paypal.android.p2pmobile +com.google.android.apps.googlevoice +com.readdle.spark +org.torproject.torbrowser +com.deepl.mobiletranslator +com.microsoft.bing +com.keylesspalace.tusky +com.ottplay.ottplay +ru.iptvremote.android.iptv.pro +jp.naver.line.android +com.xmflsct.app.tooot +com.forem.android +app.revanced.android.youtube +com.mgoogle.android.gms +com.pionex.client +vip.mytokenpocket +im.token.app +com.linekong.mars24 +com.feixiaohao +com.aicoin.appandroid +com.binance.dev +com.kraken.trade +com.okinc.okex.gp +com.authy.authy +air.com.rosettastone.mobile.CoursePlayer +com.blizzard.bma +com.amazon.kindle +com.google.android.apps.fitness +net.tsapps.appsales +com.wemesh.android +com.google.android.apps.googleassistant +allen.town.focus.reader +me.hyliu.fluent_reader_lite +com.aljazeera.mobile +com.ft.news +de.marmaro.krt.ffupdater +myradio.radio.fmradio.liveradio.radiostation +com.google.earth +eu.kanade.tachiyomi.j2k +com.audials +com.microsoft.skydrive +com.mb.android.tg +com.melodis.midomiMusicIdentifier.freemium +com.foxnews.android +ch.threema.app +com.briarproject.briar.android +foundation.e.apps +com.valvesoftware.android.steam.friendsui +com.imback.yeetalk +so.onekey.app.wallet +com.xc3fff0e.xmanager +meditofoundation.medito +com.picol.client +com.streetwriters.notesnook +shanghai.panewsApp.com +org.coursera.android +com.positron_it.zlib +com.blizzard.messenger +com.javdb.javrocket +com.picacomic.fregata +com.fxl.chacha +me.proton.android.drive +com.lastpass.lpandroid +com.tradingview.tradingviewapp +com.deviantart.android.damobile +com.fusionmedia.investing +com.ewa.ewaapp +com.duolingo +com.hellotalk +io.github.huskydg.magisk +com.jsy.xpgbox +com.hostloc.app.hostloc +com.dena.pokota +com.vitorpamplona.amethyst +com.zhiliaoapp.musically +us.spotco.fennec_dos +com.fongmi.android.tv +com.pocketprep.android.itcybersecurity +com.cloudtv +com.glassdoor.app +com.indeed.android.jobsearch +com.linkedin.android +com.github.tvbox.osc.bh +com.example.douban +com.sipnetic.app +com.microsoft.rdc.androidx +org.zwanoo.android.speedtest +com.sonelli.juicessh +com.scmp.newspulse +org.lsposed.manager +mnn.Android +com.thomsonretuers.reuters +com.guardian +com.ttxapps.onesyncv2 +org.fcitx.fcitx5.android.updater \ No newline at end of file diff --git a/app/src/main/java/io/nekohasekai/sagernet/ui/AppManagerActivity.kt b/app/src/main/java/io/nekohasekai/sagernet/ui/AppManagerActivity.kt index 6f6eba364..f31293f33 100644 --- a/app/src/main/java/io/nekohasekai/sagernet/ui/AppManagerActivity.kt +++ b/app/src/main/java/io/nekohasekai/sagernet/ui/AppManagerActivity.kt @@ -22,15 +22,14 @@ package io.nekohasekai.sagernet.ui import android.annotation.SuppressLint import android.content.Intent import android.content.pm.ApplicationInfo -import android.content.pm.PackageInfo import android.content.pm.PackageManager import android.graphics.drawable.Drawable import android.os.Bundle +import android.text.TextUtils import android.util.SparseBooleanArray import android.view.* import android.widget.Filter import android.widget.Filterable -import android.widget.TextView import androidx.annotation.UiThread import androidx.core.util.contains import androidx.core.util.set @@ -49,8 +48,8 @@ import io.nekohasekai.sagernet.SagerNet import io.nekohasekai.sagernet.database.DataStore import io.nekohasekai.sagernet.databinding.LayoutAppsBinding import io.nekohasekai.sagernet.databinding.LayoutAppsItemBinding -import io.nekohasekai.sagernet.databinding.LayoutLoadingBinding import io.nekohasekai.sagernet.ktx.Logs +import io.nekohasekai.sagernet.ktx.app import io.nekohasekai.sagernet.ktx.crossFadeFrom import io.nekohasekai.sagernet.ktx.onMainDispatcher import io.nekohasekai.sagernet.ktx.runOnDefaultDispatcher @@ -61,12 +60,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.ensureActive import kotlinx.coroutines.withContext -import okhttp3.internal.closeQuietly -import org.jf.dexlib2.dexbacked.DexBackedDexFile -import org.jf.dexlib2.iface.DexFile -import java.io.File -import java.util.zip.ZipException -import java.util.zip.ZipFile +import moe.matsuri.nya.utils.NGUtil import kotlin.coroutines.coroutineContext class AppManagerActivity : ThemedActivity() { @@ -164,7 +158,8 @@ class AppManagerActivity : ThemedActivity() { } override fun publishResults(constraint: CharSequence, results: FilterResults) { - @Suppress("UNCHECKED_CAST") filteredApps = results.values as List + @Suppress("UNCHECKED_CAST") + filteredApps = results.values as List notifyDataSetChanged() } } @@ -231,10 +226,12 @@ class AppManagerActivity : ThemedActivity() { DataStore.proxyApps = false finish() } + R.id.appProxyModeOn -> DataStore.bypass = false R.id.appProxyModeBypass -> DataStore.bypass = true } } + binding.autoSelectProxyApps.setOnClickListener { selectProxyApp() } initProxiedUids() binding.list.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false) @@ -266,10 +263,6 @@ class AppManagerActivity : ThemedActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - R.id.action_scan_china_apps -> { - scanChinaApps() - return true - } R.id.action_invert_selections -> { runOnDefaultDispatcher { for (app in apps) { @@ -289,6 +282,7 @@ class AppManagerActivity : ThemedActivity() { return true } + R.id.action_clear_selections -> { runOnDefaultDispatcher { proxiedUids.clear() @@ -299,8 +293,10 @@ class AppManagerActivity : ThemedActivity() { } } } + R.id.action_export_clipboard -> { - val success = SagerNet.trySetPrimaryClip("${DataStore.bypass}\n${DataStore.individual}") + val success = + SagerNet.trySetPrimaryClip("${DataStore.bypass}\n${DataStore.individual}") Snackbar.make( binding.list, if (success) R.string.action_export_msg else R.string.action_export_err, @@ -308,8 +304,10 @@ class AppManagerActivity : ThemedActivity() { ).show() return true } + R.id.action_import_clipboard -> { - val proxiedAppString = SagerNet.clipboard.primaryClip?.getItemAt(0)?.text?.toString() + val proxiedAppString = + SagerNet.clipboard.primaryClip?.getItemAt(0)?.text?.toString() if (!proxiedAppString.isNullOrEmpty()) { val i = proxiedAppString.indexOf('\n') try { @@ -335,150 +333,53 @@ class AppManagerActivity : ThemedActivity() { return super.onOptionsItemSelected(item) } - @SuppressLint("SetTextI18n") - private fun scanChinaApps() { - - val text: TextView - - val dialog = MaterialAlertDialogBuilder(this).setView( - LayoutLoadingBinding.inflate(layoutInflater).apply { - text = loadingText - }.root - ).setCancelable(false).show() - - val txt = text.text.toString() - - runOnDefaultDispatcher { - val chinaApps = ArrayList>() - val chinaRegex = ("(" + arrayOf( - "com.tencent", - "com.alibaba", - "com.umeng", - "com.qihoo", - "com.ali", - "com.alipay", - "com.amap", - "com.sina", - "com.weibo", - "com.vivo", - "com.xiaomi", - "com.huawei", - "com.taobao", - "com.secneo", - "s.h.e.l.l", - "com.stub", - "com.kiwisec", - "com.secshell", - "com.wrapper", - "cn.securitystack", - "com.mogosec", - "com.secoen", - "com.netease", - "com.mx", - "com.qq.e", - "com.baidu", - "com.bytedance", - "com.bugly", - "com.miui", - "com.oppo", - "com.coloros", - "com.iqoo", - "com.meizu", - "com.gionee", - "cn.nubia" - ).joinToString("|") { "${it.replace(".", "\\.")}\\." } + ").*").toRegex() - - val bypass = DataStore.bypass - val cachedApps = cachedApps - - apps = cachedApps.map { (packageName, packageInfo) -> - kotlin.coroutines.coroutineContext[Job]!!.ensureActive() - ProxiedApp(packageManager, packageInfo.applicationInfo, packageName) - }.sortedWith(compareBy({ !isProxiedApp(it) }, { it.name.toString() })) - - scan@ for ((pkg, app) in cachedApps.entries) { - /*if (!sysApps && app.applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM != 0) { - continue - }*/ - - val index = appsAdapter.filteredApps.indexOfFirst { it.uid == app.applicationInfo.uid } - var changed = false - - onMainDispatcher { - text.text = (txt + " " + app.packageName + "\n\n" + chinaApps.map { it.second } - .reversed() - .joinToString("\n", postfix = "\n")).trim() - } - + private fun selectProxyApp() { + MaterialAlertDialogBuilder(this).setTitle(R.string.confirm) + .setMessage(R.string.auto_select_proxy_apps_message) + .setPositiveButton(R.string.yes) { _, _ -> try { - - val dex = File(app.applicationInfo.publicSourceDir) - val zipFile = ZipFile(dex) - var dexFile: DexFile - - for (entry in zipFile.entries()) { - if (entry.name.startsWith("classes") && entry.name.endsWith(".dex")) { - val input = zipFile.getInputStream(entry).readBytes() - dexFile = try { - DexBackedDexFile.fromInputStream(null, input.inputStream()) - } catch (e: Exception) { - Logs.w(e) - break + val needProxyAppsList = getAutoProxyApps("") + val bypass = DataStore.bypass + proxiedUids.clear() + for (app in cachedApps) { + val needProxy = + needProxyAppsList.contains(app.key) || app.value.applicationInfo.uid == 1000 + if (needProxy) { + if (!bypass) { + proxiedUids[app.value.applicationInfo.uid] = true } - for (clazz in dexFile.classes) { - val clazzName = clazz.type.substring(1, clazz.type.length - 1) - .replace("/", ".") - .replace("$", ".") - - if (clazzName.matches(chinaRegex)) { - chinaApps.add( - app to app.applicationInfo.loadLabel(packageManager) - .toString() - ) - zipFile.closeQuietly() - - if (bypass) { - changed = !proxiedUids[app.applicationInfo.uid] - proxiedUids[app.applicationInfo.uid] = true - } else { - proxiedUids.delete(app.applicationInfo.uid) - } - - continue@scan - } + } else { + if (bypass) { + proxiedUids[app.value.applicationInfo.uid] = true } } } - zipFile.closeQuietly() - - if (bypass) { - proxiedUids.delete(app.applicationInfo.uid) - } else { - changed = !proxiedUids[index] - proxiedUids[app.applicationInfo.uid] = true - } - - } catch (e: ZipException) { - Logs.w("Error in pkg ${app.packageName}:${app.versionName}", e) - continue + DataStore.individual = + apps.filter { isProxiedApp(it) }.joinToString("\n") { it.packageName } + apps = apps.sortedWith(compareBy({ !isProxiedApp(it) }, { it.name.toString() })) + appsAdapter.filter.filter(binding.search.text?.toString() ?: "") + } catch (e: Exception) { + Logs.e(e) } - } + .setNegativeButton(R.string.no, null) + .show() + } - DataStore.individual = apps.filter { isProxiedApp(it) } - .joinToString("\n") { it.packageName } - - apps = apps.sortedWith(compareBy({ !isProxiedApp(it) }, { it.name.toString() })) - - onMainDispatcher { - appsAdapter.filter.filter(binding.search.text?.toString() ?: "") - - dialog.dismiss() + private fun getAutoProxyApps(content: String): List { + var list = listOf() + try { + val proxyApps = if (TextUtils.isEmpty(content)) { + NGUtil.readTextFromAssets(app, "proxy_packagename.txt") + } else { + content } - + if (!TextUtils.isEmpty(proxyApps)) { + list = proxyApps.split("\n") + } + } catch (_: Exception) { } - - + return list } override fun supportNavigateUpTo(upIntent: Intent) = diff --git a/app/src/main/res/layout/layout_apps.xml b/app/src/main/res/layout/layout_apps.xml index b05d93ac6..f218d916e 100644 --- a/app/src/main/res/layout/layout_apps.xml +++ b/app/src/main/res/layout/layout_apps.xml @@ -77,13 +77,28 @@ - + android:orientation="horizontal"> + + + + + + - 重置连接 删除重复的服务器 测试并发 + 自动选择需要代理的应用 + 自动选择需要代理的应用,这将清除您当前的选择。 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 576292bad..cc98f648b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -526,5 +526,7 @@ Anyone can write advanced plugins, which can control Matsuri. please download an Reset Connections Remove duplicate servers Test concurrency + Auto select proxy apps + Auto select proxy apps, this will clear your current selection. \ No newline at end of file