mirror of
https://github.com/pppscn/SmsForwarder
synced 2025-08-02 17:07:41 +08:00
优化:应用列表增加UID & APP通知自定义模板增加可用标签 {{UID}}
#366
This commit is contained in:
parent
d4c7b1f731
commit
0c380caebd
@ -29,7 +29,6 @@ import com.idormy.sms.forwarder.utils.sdkinit.UMengInit
|
||||
import com.idormy.sms.forwarder.utils.sdkinit.XBasicLibInit
|
||||
import com.idormy.sms.forwarder.utils.sdkinit.XUpdateInit
|
||||
import com.idormy.sms.forwarder.utils.tinker.TinkerLoadLibrary
|
||||
import com.xuexiang.xutil.app.AppUtils
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
@ -49,6 +48,7 @@ class App : Application(), CactusCallback, Configuration.Provider by Core {
|
||||
val logsRepository by lazy { LogsRepository(database.logsDao()) }
|
||||
val ruleRepository by lazy { RuleRepository(database.ruleDao()) }
|
||||
val senderRepository by lazy { SenderRepository(database.senderDao()) }
|
||||
val taskRepository by lazy { TaskRepository(database.taskDao()) }
|
||||
|
||||
companion object {
|
||||
const val TAG: String = "SmsForwarder"
|
||||
@ -61,8 +61,8 @@ class App : Application(), CactusCallback, Configuration.Provider by Core {
|
||||
|
||||
//已安装App信息
|
||||
var LoadingAppList = false
|
||||
var UserAppList: MutableList<AppUtils.AppInfo> = mutableListOf()
|
||||
var SystemAppList: MutableList<AppUtils.AppInfo> = mutableListOf()
|
||||
var UserAppList: MutableList<AppInfo> = mutableListOf()
|
||||
var SystemAppList: MutableList<AppInfo> = mutableListOf()
|
||||
|
||||
/**
|
||||
* @return 当前app是否是调试开发模式
|
||||
|
@ -3,11 +3,11 @@ package com.idormy.sms.forwarder.adapter
|
||||
import android.widget.ImageView
|
||||
import com.idormy.sms.forwarder.R
|
||||
import com.idormy.sms.forwarder.adapter.base.broccoli.BroccoliRecyclerAdapter
|
||||
import com.idormy.sms.forwarder.utils.AppInfo
|
||||
import com.idormy.sms.forwarder.utils.AppUtils
|
||||
import com.idormy.sms.forwarder.utils.PlaceholderHelper
|
||||
import com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder
|
||||
import com.xuexiang.xui.widget.imageview.ImageLoader
|
||||
import com.xuexiang.xutil.app.AppUtils
|
||||
import com.xuexiang.xutil.app.AppUtils.AppInfo
|
||||
import me.samlss.broccoli.Broccoli
|
||||
|
||||
class AppListAdapter(
|
||||
@ -34,8 +34,9 @@ class AppListAdapter(
|
||||
ImageLoader.get().loadImage(ivAppIcon, model.icon)
|
||||
holder.text(R.id.tv_app_name, model.name)
|
||||
holder.text(R.id.tv_pkg_name, model.packageName)
|
||||
holder.text(R.id.tv_ver_name, model.versionName)
|
||||
//holder.text(R.id.tv_ver_code, model.versionCode)
|
||||
holder.text(R.id.tv_ver_name, "VER. " + model.versionName)
|
||||
//holder.text(R.id.tv_ver_code, model.versionCode.toString())
|
||||
holder.text(R.id.tv_uid, "UID. " + model.uid.toString())
|
||||
}
|
||||
|
||||
/**
|
||||
@ -51,14 +52,16 @@ class AppListAdapter(
|
||||
.addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.tv_app_name)))
|
||||
.addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.tv_pkg_name)))
|
||||
.addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.tv_ver_name)))
|
||||
//.addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.tv_ver_code)))
|
||||
//.addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.tv_ver_code)))
|
||||
.addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.tv_uid)))
|
||||
} else {
|
||||
broccoli.addPlaceholders(
|
||||
holder.findView(R.id.iv_app_icon),
|
||||
holder.findView(R.id.tv_app_name),
|
||||
holder.findView(R.id.tv_pkg_name),
|
||||
holder.findView(R.id.tv_ver_name),
|
||||
//holder.findView(R.id.tv_ver_code)
|
||||
//holder.findView(R.id.tv_ver_code),
|
||||
holder.findView(R.id.tv_uid)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ data class MsgInfo(
|
||||
var simSlot: Int = -1, //卡槽id:-1=获取失败、0=卡槽1、1=卡槽2
|
||||
var subId: Int = 0, //卡槽主键
|
||||
var callType: Int = 0, //通话类型:1.来电挂机 2.去电挂机 3.未接来电 4.来电提醒 5.来电接通 6.去电拨出
|
||||
var uid: Int = 0,
|
||||
var uid: Int = 0, //APP通知的UID
|
||||
) : Serializable {
|
||||
|
||||
val titleForSend: String
|
||||
@ -54,6 +54,7 @@ data class MsgInfo(
|
||||
.replace(getString(R.string.tag_card_subid), subId.toString())
|
||||
.replace(getString(R.string.tag_title), title)
|
||||
.replace(getString(R.string.tag_scheme), scheme)
|
||||
.replace(getString(R.string.tag_uid), uid.toString())
|
||||
.replace(getString(R.string.tag_receive_time), SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date))
|
||||
.replace(getString(R.string.tag_current_time), SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date()))
|
||||
.replace(getString(R.string.tag_device_name), deviceMark)
|
||||
@ -102,6 +103,7 @@ data class MsgInfo(
|
||||
.replace(getString(R.string.tag_card_subid), subId.toString())
|
||||
.replace(getString(R.string.tag_title), title)
|
||||
.replace(getString(R.string.tag_scheme), scheme)
|
||||
.replace(getString(R.string.tag_uid), uid.toString())
|
||||
.replace(getString(R.string.tag_receive_time), SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date))
|
||||
.replace(getString(R.string.tag_current_time), SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date()))
|
||||
.replace(getString(R.string.tag_device_name), deviceMark)
|
||||
|
@ -15,6 +15,7 @@ import com.idormy.sms.forwarder.R
|
||||
import com.idormy.sms.forwarder.adapter.AppListAdapter
|
||||
import com.idormy.sms.forwarder.core.BaseFragment
|
||||
import com.idormy.sms.forwarder.databinding.FragmentAppListBinding
|
||||
import com.idormy.sms.forwarder.utils.AppInfo
|
||||
import com.idormy.sms.forwarder.utils.EVENT_LOAD_APP_LIST
|
||||
import com.idormy.sms.forwarder.utils.XToastUtils
|
||||
import com.idormy.sms.forwarder.workers.LoadAppListWorker
|
||||
@ -29,7 +30,6 @@ import com.xuexiang.xui.utils.ThemeUtils
|
||||
import com.xuexiang.xui.utils.WidgetUtils
|
||||
import com.xuexiang.xui.widget.actionbar.TitleBar
|
||||
import com.xuexiang.xutil.XUtil
|
||||
import com.xuexiang.xutil.app.AppUtils
|
||||
|
||||
@Suppress("PrivatePropertyName")
|
||||
@Page(name = "应用列表")
|
||||
@ -118,7 +118,7 @@ class AppListFragment : BaseFragment<FragmentAppListBinding?>() {
|
||||
super.onDestroyView()
|
||||
}
|
||||
|
||||
private fun getAppsList(refresh: Boolean): MutableList<AppUtils.AppInfo> {
|
||||
private fun getAppsList(refresh: Boolean): MutableList<AppInfo> {
|
||||
if (refresh || (currentType == "user" && App.UserAppList.isEmpty()) || (currentType == "system" && App.SystemAppList.isEmpty())) {
|
||||
XToastUtils.info(getString(R.string.loading_app_list))
|
||||
val request = OneTimeWorkRequestBuilder<LoadAppListWorker>().build()
|
||||
|
80
app/src/main/java/com/idormy/sms/forwarder/utils/AppUtils.kt
Normal file
80
app/src/main/java/com/idormy/sms/forwarder/utils/AppUtils.kt
Normal file
@ -0,0 +1,80 @@
|
||||
package com.idormy.sms.forwarder.utils
|
||||
|
||||
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 com.idormy.sms.forwarder.App
|
||||
|
||||
data class AppInfo(
|
||||
val name: String,
|
||||
val icon: Drawable,
|
||||
val packageName: String,
|
||||
val packagePath: String,
|
||||
val versionName: String,
|
||||
val versionCode: Int,
|
||||
val isSystem: Boolean,
|
||||
val uid: Int
|
||||
)
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
@Suppress("DEPRECATION")
|
||||
object AppUtils {
|
||||
|
||||
fun getAppsInfo(): List<AppInfo> {
|
||||
val packageManager = App.context.packageManager ?: return emptyList()
|
||||
val appsInfo = mutableListOf<AppInfo>()
|
||||
|
||||
val apps = packageManager.getInstalledApplications(PackageManager.GET_META_DATA)
|
||||
for (app in apps) {
|
||||
try {
|
||||
val packageInfo = packageManager.getPackageInfo(app.packageName, 0)
|
||||
val appInfo = AppInfo(
|
||||
app.loadLabel(packageManager).toString(),
|
||||
app.loadIcon(packageManager),
|
||||
app.packageName,
|
||||
app.sourceDir,
|
||||
packageInfo?.versionName ?: "Unknown",
|
||||
packageInfo?.versionCode ?: 0,
|
||||
(app.flags and ApplicationInfo.FLAG_SYSTEM) != 0,
|
||||
app.uid
|
||||
)
|
||||
appsInfo.add(appInfo)
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
return appsInfo
|
||||
}
|
||||
|
||||
fun getAppVersionName(): String? {
|
||||
return getAppVersionName(App.context.packageName)
|
||||
}
|
||||
|
||||
fun getAppVersionName(packageName: String): String? {
|
||||
if (packageName.isBlank()) {
|
||||
return null
|
||||
}
|
||||
return try {
|
||||
val pm: PackageManager = App.context.packageManager
|
||||
val pi: PackageInfo = pm.getPackageInfo(packageName, 0)
|
||||
pi.versionName
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
e.printStackTrace()
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun openApp(packageName: String) {
|
||||
val packageManager = App.context.packageManager
|
||||
val intent = packageManager.getLaunchIntentForPackage(packageName)
|
||||
if (intent != null) {
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
App.context.startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -5,9 +5,9 @@ import android.util.Log
|
||||
import androidx.work.CoroutineWorker
|
||||
import androidx.work.WorkerParameters
|
||||
import com.idormy.sms.forwarder.App
|
||||
import com.idormy.sms.forwarder.utils.AppUtils
|
||||
import com.idormy.sms.forwarder.utils.EVENT_LOAD_APP_LIST
|
||||
import com.jeremyliao.liveeventbus.LiveEventBus
|
||||
import com.xuexiang.xutil.app.AppUtils
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
|
@ -29,7 +29,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dip"
|
||||
android:layout_weight="1"
|
||||
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
@ -44,16 +43,32 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="3dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_ver_name"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="3dp" />
|
||||
android:layout_marginTop="3dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<!--<TextView
|
||||
android:id="@+id/tv_ver_code"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />-->
|
||||
<TextView
|
||||
android:id="@+id/tv_ver_name"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<!--<TextView
|
||||
android:id="@+id/tv_ver_code"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />-->
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_uid"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="right" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
<string name="menu_rules">Rules</string>
|
||||
<string name="menu_settings">Settings</string>
|
||||
|
||||
<string name="menu_task">Task</string>
|
||||
<string name="menu_server">Server</string>
|
||||
<string name="menu_client">Client</string>
|
||||
<string name="menu_frpc">Frpc</string>
|
||||
@ -608,6 +609,7 @@
|
||||
<string name="tag_scheme">{{SCHEME}}</string>
|
||||
<string name="tag_call_type">{{CALL_TYPE}}</string>
|
||||
<string name="tag_location">{{LOCATION}}</string>
|
||||
<string name="tag_uid">{{UID}}</string>
|
||||
<string name="rule_sms">SMS</string>
|
||||
<string name="rule_call">CALL</string>
|
||||
<string name="rule_app">APP</string>
|
||||
@ -1073,4 +1075,6 @@
|
||||
<string name="enable_location_tag">Enable {{LOCATION}} Tag</string>
|
||||
<string name="enable_location_tag_tips">Insert location info into forwarded msg.</string>
|
||||
<string name="uid">UID</string>
|
||||
|
||||
<string name="select_task_type">Please select task type</string>
|
||||
</resources>
|
||||
|
@ -10,6 +10,7 @@
|
||||
<string name="menu_rules">转发规则</string>
|
||||
<string name="menu_settings">通用设置</string>
|
||||
|
||||
<string name="menu_task">自动任务·快捷指令</string>
|
||||
<string name="menu_server">主动控制·服务端</string>
|
||||
<string name="menu_client">主动控制·客户端</string>
|
||||
<string name="menu_frpc">内网穿透·Frpc</string>
|
||||
@ -609,6 +610,7 @@
|
||||
<string name="tag_scheme">{{通知Scheme}}</string>
|
||||
<string name="tag_call_type">{{通话类型}}</string>
|
||||
<string name="tag_location">{{定位信息}}</string>
|
||||
<string name="tag_uid">{{UID}}</string>
|
||||
<string name="rule_sms">短信</string>
|
||||
<string name="rule_call">来电</string>
|
||||
<string name="rule_app">应用</string>
|
||||
@ -1074,4 +1076,6 @@
|
||||
<string name="enable_location_tag">启用 {{定位信息}} 标签</string>
|
||||
<string name="enable_location_tag_tips">在转发信息中插入手机的当前定位信息</string>
|
||||
<string name="uid">UID</string>
|
||||
|
||||
<string name="select_task_type">请选择自动任务类型</string>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user