6.7.0 - Alpha23 - 插件中心 M3 - 插件中心支持传统 SDK 插件的开发者与描述的元数据信息发现并优化自动激活机制
This commit is contained in:
@@ -9,6 +9,7 @@ import android.os.Build
|
|||||||
import androidx.core.content.pm.PackageInfoCompat
|
import androidx.core.content.pm.PackageInfoCompat
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import org.autojs.autojs.core.pref.Language
|
||||||
import org.autojs.autojs6.R
|
import org.autojs.autojs6.R
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@@ -42,7 +43,7 @@ class LegacyInstalledPluginRepository {
|
|||||||
val meta = appInfo.metaData ?: return@mapNotNull null
|
val meta = appInfo.metaData ?: return@mapNotNull null
|
||||||
val registry = meta.getString(KEY_REGISTRY) ?: return@mapNotNull null
|
val registry = meta.getString(KEY_REGISTRY) ?: return@mapNotNull null
|
||||||
val packageName = appInfo.packageName
|
val packageName = appInfo.packageName
|
||||||
val label = appInfo.loadLabel(pm)?.toString()
|
val label = appInfo.loadLabel(pm).takeUnless { it.isBlank() }?.toString()
|
||||||
val icon = appInfo.loadIcon(pm)
|
val icon = appInfo.loadIcon(pm)
|
||||||
val isStopped = (appInfo.flags and ApplicationInfo.FLAG_STOPPED) != 0
|
val isStopped = (appInfo.flags and ApplicationInfo.FLAG_STOPPED) != 0
|
||||||
|
|
||||||
@@ -53,11 +54,26 @@ class LegacyInstalledPluginRepository {
|
|||||||
val lastUpdateTime = pkgInfo?.lastUpdateTime
|
val lastUpdateTime = pkgInfo?.lastUpdateTime
|
||||||
val packageSize = calcPackageSize(appInfo)
|
val packageSize = calcPackageSize(appInfo)
|
||||||
|
|
||||||
|
val metaDescriptionRes = meta.getInt(KEY_DESCRIPTION_RESOURCE, 0)
|
||||||
|
val description = when {
|
||||||
|
metaDescriptionRes != 0 -> {
|
||||||
|
val metaContext = context.createPackageContext(packageName, 0)
|
||||||
|
val configuration = context.resources.configuration.apply {
|
||||||
|
setLocale(Language.getPrefLanguage().locale)
|
||||||
|
}
|
||||||
|
val localizedMetaContext = metaContext.createConfigurationContext(configuration)
|
||||||
|
localizedMetaContext.getString(metaDescriptionRes)
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
meta.getString(KEY_DESCRIPTION)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LegacyInstalledPlugin(
|
LegacyInstalledPlugin(
|
||||||
packageName = packageName,
|
packageName = packageName,
|
||||||
title = label ?: packageName,
|
title = label ?: packageName,
|
||||||
description = null,
|
description = description,
|
||||||
author = null,
|
author = meta.getString(KEY_AUTHOR),
|
||||||
versionName = versionName,
|
versionName = versionName,
|
||||||
versionCode = versionCode,
|
versionCode = versionCode,
|
||||||
packageSize = packageSize,
|
packageSize = packageSize,
|
||||||
@@ -83,5 +99,8 @@ class LegacyInstalledPluginRepository {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val KEY_REGISTRY = "org.autojs.plugin.sdk.registry"
|
private const val KEY_REGISTRY = "org.autojs.plugin.sdk.registry"
|
||||||
|
private const val KEY_AUTHOR = "org.autojs.plugin.info.AUTHOR"
|
||||||
|
private const val KEY_DESCRIPTION_RESOURCE = "org.autojs.plugin.info.DESCRIPTION_RESOURCE"
|
||||||
|
private const val KEY_DESCRIPTION = "org.autojs.plugin.info.DESCRIPTION"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
package org.autojs.autojs.core.plugin.center
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import androidx.core.content.edit
|
|
||||||
|
|
||||||
object PluginActivationStore {
|
|
||||||
|
|
||||||
private const val SP_NAME = "plugin_center_activation"
|
|
||||||
|
|
||||||
fun markActivated(context: Context, pluginId: String, timeMillis: Long = System.currentTimeMillis()) {
|
|
||||||
val sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE)
|
|
||||||
sp.edit { putLong(key(pluginId), timeMillis) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getLastActivatedAt(context: Context, pluginId: String): Long? {
|
|
||||||
val sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE)
|
|
||||||
val value = sp.getLong(key(pluginId), -1L)
|
|
||||||
return value.takeIf { it > 0L }
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun key(pluginId: String) = "key_\$_plugin_activated_\$_$pluginId"
|
|
||||||
}
|
|
||||||
@@ -484,7 +484,6 @@ class PluginCenterFragment : Fragment(R.layout.fragment_plugin_center) {
|
|||||||
val started = openIntent.startSafely(contextRef, true)
|
val started = openIntent.startSafely(contextRef, true)
|
||||||
d.dismiss()
|
d.dismiss()
|
||||||
if (started) {
|
if (started) {
|
||||||
PluginActivationStore.markActivated(contextRef, item.packageName)
|
|
||||||
item.activatedState = PluginActivatedState.DONE
|
item.activatedState = PluginActivatedState.DONE
|
||||||
ViewUtils.showToast(contextRef, getString(R.string.text_activated_successfully), true)
|
ViewUtils.showToast(contextRef, getString(R.string.text_activated_successfully), true)
|
||||||
adapter.notifyDataSetChanged()
|
adapter.notifyDataSetChanged()
|
||||||
@@ -564,7 +563,6 @@ class PluginCenterFragment : Fragment(R.layout.fragment_plugin_center) {
|
|||||||
// Package uninstallation (pre-update phase) does not record "Recently uninstalled" when replacing.
|
// Package uninstallation (pre-update phase) does not record "Recently uninstalled" when replacing.
|
||||||
// zh-CN: 替换卸载 (更新前阶段) 不记录 "最近卸载".
|
// zh-CN: 替换卸载 (更新前阶段) 不记录 "最近卸载".
|
||||||
if (!replacing) {
|
if (!replacing) {
|
||||||
PluginWakeManager.clearAutoWakeAttempt(packageName)
|
|
||||||
PluginRecentStore.setLastUninstalled(packageName)
|
PluginRecentStore.setLastUninstalled(packageName)
|
||||||
vm.load(context, forceRefreshIndex = false)
|
vm.load(context, forceRefreshIndex = false)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -102,10 +102,8 @@ class PluginCenterViewModel : ViewModel() {
|
|||||||
|
|
||||||
installed.forEach { local ->
|
installed.forEach { local ->
|
||||||
if (local.bindError != null) {
|
if (local.bindError != null) {
|
||||||
enableStore.setEnabled(context, local.packageName, false)
|
val isAutoWakeSuccess = PluginWakeManager.tryAutoWakeIfNeeded(context, local.packageName)
|
||||||
}
|
enableStore.setEnabled(context, local.packageName, isAutoWakeSuccess)
|
||||||
if (local.isStopped) {
|
|
||||||
PluginWakeManager.tryAutoWakeIfNeeded(context, local.packageName)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,7 +224,6 @@ class PluginCenterViewModel : ViewModel() {
|
|||||||
val canActivate = isInstalled && PluginWakeManager.buildWakeIntent(context, packageName) != null
|
val canActivate = isInstalled && PluginWakeManager.buildWakeIntent(context, packageName) != null
|
||||||
var activatedState = when {
|
var activatedState = when {
|
||||||
!canActivate -> PluginActivatedState.NOT_SUPPORTED
|
!canActivate -> PluginActivatedState.NOT_SUPPORTED
|
||||||
PluginActivationStore.getLastActivatedAt(context, packageName) != null -> PluginActivatedState.DONE
|
|
||||||
else -> PluginActivatedState.UNKNOWN
|
else -> PluginActivatedState.UNKNOWN
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,6 @@ object PluginTrustManager {
|
|||||||
PluginIdentifier(
|
PluginIdentifier(
|
||||||
setOf(
|
setOf(
|
||||||
"517c51b16bead916296eb3cadfd57cd4f871ae8a4f767094ddf635338bad21c1", // Auto.js M
|
"517c51b16bead916296eb3cadfd57cd4f871ae8a4f767094ddf635338bad21c1", // Auto.js M
|
||||||
"2e64822e13a6c80c12e1c4b47e8fb32d1e9334526289da75777b7a79145de4b8", // Plugins
|
|
||||||
"a40da80a59d170caa950cf15c18c454d47a39b26989d8b640ecd745ba71bf5dc", // Plugins
|
"a40da80a59d170caa950cf15c18c454d47a39b26989d8b640ecd745ba71bf5dc", // Plugins
|
||||||
),
|
),
|
||||||
"TonyJiangWJ", PluginAuthorizedState.TRUSTED,
|
"TonyJiangWJ", PluginAuthorizedState.TRUSTED,
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ import android.content.ComponentName
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import androidx.core.content.edit
|
|
||||||
import org.autojs.autojs.app.GlobalAppContext
|
|
||||||
import org.autojs.autojs.util.IntentUtils.startSafely
|
import org.autojs.autojs.util.IntentUtils.startSafely
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -13,18 +11,12 @@ import org.autojs.autojs.util.IntentUtils.startSafely
|
|||||||
*/
|
*/
|
||||||
object PluginWakeManager {
|
object PluginWakeManager {
|
||||||
|
|
||||||
private const val SP = "plugin_center_wake"
|
private const val ACTION_WAKE = "org.autojs.plugin.action.WAKE"
|
||||||
private const val ACTION_OCR_WAKE = "org.autojs.plugin.PADDLE_OCR.WAKE"
|
|
||||||
private const val WAKE_ACTIVITY_META = "org.autojs.plugin.WAKE_ACTIVITY"
|
private const val WAKE_ACTIVITY_META = "org.autojs.plugin.WAKE_ACTIVITY"
|
||||||
|
|
||||||
private val storeContext by lazy { GlobalAppContext.get() }
|
|
||||||
|
|
||||||
fun tryAutoWakeIfNeeded(context: Context, packageName: String): Boolean {
|
fun tryAutoWakeIfNeeded(context: Context, packageName: String): Boolean {
|
||||||
if (isAutoWakeAttempted(packageName)) return false
|
|
||||||
val intent = buildWakeIntent(context, packageName) ?: return false
|
val intent = buildWakeIntent(context, packageName) ?: return false
|
||||||
val started = intent.startSafely(context, true)
|
return intent.startSafely(context, true)
|
||||||
markAutoWakeAttempted(packageName)
|
|
||||||
return started
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun buildWakeIntent(context: Context, packageName: String): Intent? {
|
fun buildWakeIntent(context: Context, packageName: String): Intent? {
|
||||||
@@ -36,30 +28,13 @@ object PluginWakeManager {
|
|||||||
ComponentName(packageName, fullName)
|
ComponentName(packageName, fullName)
|
||||||
}
|
}
|
||||||
val wakeComponent = metaComponent ?: run {
|
val wakeComponent = metaComponent ?: run {
|
||||||
val implicitIntent = Intent(ACTION_OCR_WAKE).setPackage(packageName)
|
val implicitIntent = Intent(ACTION_WAKE).setPackage(packageName)
|
||||||
val info = pm.queryIntentActivities(implicitIntent, 0).firstOrNull()
|
val info = pm.queryIntentActivities(implicitIntent, 0).firstOrNull()
|
||||||
info?.activityInfo?.let { ComponentName(it.packageName, it.name) }
|
info?.activityInfo?.let { ComponentName(it.packageName, it.name) }
|
||||||
}
|
}
|
||||||
return when {
|
return when {
|
||||||
wakeComponent != null -> Intent().setComponent(wakeComponent)
|
wakeComponent != null -> Intent().setComponent(wakeComponent)
|
||||||
else -> Intent(ACTION_OCR_WAKE).setPackage(packageName).takeIf { it.resolveActivity(pm) != null }
|
else -> Intent(ACTION_WAKE).setPackage(packageName).takeIf { it.resolveActivity(pm) != null }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isAutoWakeAttempted(packageName: String): Boolean {
|
|
||||||
val sp = storeContext.getSharedPreferences(SP, Context.MODE_PRIVATE)
|
|
||||||
return sp.getBoolean(key(packageName), false)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun markAutoWakeAttempted(packageName: String) {
|
|
||||||
val sp = storeContext.getSharedPreferences(SP, Context.MODE_PRIVATE)
|
|
||||||
sp.edit { putBoolean(key(packageName), true) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun clearAutoWakeAttempt(packageName: String) {
|
|
||||||
val sp = storeContext.getSharedPreferences(SP, Context.MODE_PRIVATE)
|
|
||||||
sp.edit { remove(key(packageName)) }
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun key(packageName: String) = "key_\$_auto_wake_attempted_\$_$packageName"
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user