合并打包功能代码

autoJS打包目前只能兼容V1版本的签名,而由于谷歌的限制,如果targetSdk为30或以上的话,打包的应用就无法安装,所以打包(构建时选择inrt分支)时需要将TARGET_SDK_VERSION设置为29或以下。
This commit is contained in:
Ai
2023-09-30 13:51:10 +08:00
committed by SuperMonster003
parent 4481f539f9
commit 330ae87f4c
23 changed files with 1141 additions and 182 deletions

View File

@@ -288,6 +288,45 @@ android {
minSdk = versions.sdkVersionMin
targetSdk = versions.sdkVersionTarget
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
buildConfigField("boolean", "isInrt", "false")
}
flavorDimensions.add("channel")
productFlavors {
create("app") {
dimension = "channel"
versionCode = versions.appVersionCode
versionName = versions.appVersionName
buildConfigField("String", "CHANNEL", "\"app\"")
buildConfigField("boolean", "isInrt", "false")
manifestPlaceholders.putAll(
mapOf(
"CHANNEL" to "app",
"appName" to "@string/app_name",
"intentCategory" to "android.intent.category.LAUNCHER",
"intentCategoryInrt" to "android.intent.category.DEFAULT",
"authorities" to "org.autojs.autojs6.fileprovider"
)
)
}
create("inrt") {
dimension = "channel"
applicationIdSuffix = ".inrt"
versionCode = versions.appVersionCode
versionName = versions.appVersionName
buildConfigField("String", "CHANNEL", "\"inrt\"")
buildConfigField("boolean", "isInrt", "true")
manifestPlaceholders.putAll(
mapOf(
"CHANNEL" to "inrt",
"appName" to "AutoJs6.inrt",
"intentCategory" to "android.intent.category.DEFAULT",
"intentCategoryInrt" to "android.intent.category.LAUNCHER",
"authorities" to "org.autojs.autojs6.inrt.fileprovider"
)
)
}
}
compileOptions {
@@ -312,6 +351,9 @@ android {
"META-INF/ASL2.0",
"META-INF/*.kotlin_module",
).let { resources.pickFirsts.addAll(it) }
jniLibs {
useLegacyPackaging = true
}
}
kotlinOptions {
@@ -369,13 +411,22 @@ android {
javaCompileOptions {
annotationProcessorOptions {
mapOf(
"resourcePackageName" to (this@defaultConfig.applicationId ?: this@Build_gradle.applicationId),
"resourcePackageName" to (this@defaultConfig.applicationId
?: this@Build_gradle.applicationId),
"androidManifestFile" to ("$projectDir/src/main/AndroidManifest.xml")
).let { arguments(it) }
}
}
buildConfigField("String", "VERSION_DATE", "\"${Utils.getDateString("MMM d, yyyy", "GMT+08:00")}\"")
buildConfigField("String", "VSCODE_EXT_REQUIRED_VERSION", "\"${versions.vscodeExtRequiredVersion}\"")
buildConfigField(
"String",
"VERSION_DATE",
"\"${Utils.getDateString("MMM d, yyyy", "GMT+08:00")}\""
)
buildConfigField(
"String",
"VSCODE_EXT_REQUIRED_VERSION",
"\"${versions.vscodeExtRequiredVersion}\""
)
}
applicationVariants.all {

View File

@@ -3,7 +3,7 @@
<uses-feature
android:name="android.hardware.telephony"
android:required="false" />
android:required="false"/>
<!--
@Hint by SuperMonster003 on May 27, 2022.
@@ -22,127 +22,126 @@
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
android:maxSdkVersion="32"/>
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="29" />
android:maxSdkVersion="29"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>
<uses-permission
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
tools:ignore="ScopedStorage"/>
<uses-permission
android:name="android.permission.BROADCAST_CLOSE_SYSTEM_DIALOGS"
android:maxSdkVersion="31"
tools:ignore="ProtectedPermissions" />
tools:ignore="ProtectedPermissions"/>
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"/>
<uses-permission
android:name="android.permission.READ_PRIVILEGED_PHONE_STATE"
tools:ignore="ProtectedPermissions" />
tools:ignore="ProtectedPermissions"/>
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.REORDER_TASKS" />
<uses-permission android:name="android.permission.REORDER_TASKS"/>
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<!-- To allow posting notifications on Android 13. -->
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION"/>
<uses-permission
android:name="android.permission.DUMP"
tools:ignore="ProtectedPermissions" />
tools:ignore="ProtectedPermissions"/>
<uses-permission
android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />
tools:ignore="QueryAllPackagesPermission"/>
<uses-permission
android:name="android.permission.PACKAGE_USAGE_STATS"
tools:ignore="ProtectedPermissions" />
tools:ignore="ProtectedPermissions"/>
<uses-permission
android:name="android.permission.WRITE_SETTINGS"
tools:ignore="ProtectedPermissions" />
tools:ignore="ProtectedPermissions"/>
<uses-permission
android:name="android.permission.WRITE_SECURE_SETTINGS"
tools:ignore="ProtectedPermissions" />
tools:ignore="ProtectedPermissions"/>
<!-- 非 AutoJs6 运行必需, 不会主动申请, 脚本可自行申请 -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<!-- Dangerous permission witch should be treated carefully. -->
<!-- <uses-permission android:name="android.permission.READ_CONTACTS" />-->
<!-- <uses-permission android:name="android.permission.WRITE_CONTACTS" />-->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.READ_SMS"/>
<application
android:name="org.autojs.autojs.App"
android:allowBackup="false"
android:label="@string/app_name"
android:icon="@drawable/autojs6_material"
android:largeHeap="true"
android:extractNativeLibs="true"
android:hardwareAccelerated="true"
android:icon="@drawable/autojs6_material"
android:label="${appName}"
android:largeHeap="true"
android:requestLegacyExternalStorage="true"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
android:requestLegacyExternalStorage="true"
tools:ignore="DataExtractionRules">
<meta-data
android:name="android.max_aspect"
android:value="2.1" />
android:name="CHANNEL"
android:value="${CHANNEL}"/>
<activity
android:name="org.autojs.autojs.ui.splash.SplashActivity"
android:theme="@style/AppTheme.Splash"
android:label="@string/app_name"
android:icon="@drawable/autojs6_material"
android:exported="true"
android:icon="@drawable/autojs6_material"
android:label="@string/app_name"
android:theme="@style/AppTheme.Splash"
tools:ignore="RedundantLabel">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.MAIN"/>
<category android:name="${intentCategory}"/>
</intent-filter>
</activity>
@@ -150,148 +149,138 @@
android:name="org.autojs.autojs.ui.main.MainActivity"
android:exported="true"
android:launchMode="singleTask"
android:theme="@style/AppTheme.FullScreen" />
android:theme="@style/AppTheme.FullScreen"/>
<activity
android:name="org.autojs.autojs.external.shortcut.ShortcutActivity"
android:exported="true"
android:taskAffinity="org.autojs.autojs.external.shortcut.ShortcutActivity"
android:theme="@android:style/Theme.NoDisplay"
android:exported="true">
android:theme="@android:style/Theme.NoDisplay">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.MAIN"/>
</intent-filter>
</activity>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="org.autojs.autojs6.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
<activity
android:name="org.autojs.autojs.ui.edit.EditActivity"
android:configChanges="orientation|keyboardHidden|screenSize|locale"
android:launchMode="standard"
android:multiprocess="true"
android:taskAffinity="org.autojs.autojs.edit"
android:theme="@style/EditorTheme" />
android:theme="@style/EditorTheme"/>
<activity
android:name="org.autojs.autojs.ui.settings.AboutActivity"
android:theme="@style/AppTheme.Settings" />
android:theme="@style/AppTheme.Settings"/>
<activity
android:name="org.autojs.autojs.ui.settings.PreferencesActivity"
android:theme="@style/AppTheme.Settings" />
android:theme="@style/AppTheme.Settings"/>
<activity
android:name="org.autojs.autojs.ui.settings.DeveloperOptionsActivity"
android:theme="@style/AppTheme.Settings" />
android:theme="@style/AppTheme.Settings"/>
<activity android:name="org.autojs.autojs.ui.error.ErrorReportActivity" />
<activity android:name="org.autojs.autojs.ui.error.ErrorReportActivity"/>
<activity
android:name="org.autojs.autojs.external.tasker.TaskerScriptEditActivity"
android:configChanges="orientation|keyboardHidden|screenSize|locale" />
android:configChanges="orientation|keyboardHidden|screenSize|locale"/>
<activity
android:name="org.autojs.autojs.ui.project.BuildActivity"
android:configChanges="orientation|keyboardHidden|screenSize|locale" />
android:configChanges="orientation|keyboardHidden|screenSize|locale"/>
<activity android:name="org.autojs.autojs.ui.project.ProjectConfigActivity" />
<activity android:name="org.autojs.autojs.ui.project.ProjectConfigActivity"/>
<activity android:name="org.autojs.autojs.ui.log.LogActivity" />
<activity android:name="org.autojs.autojs.ui.log.LogActivity"/>
<activity
android:name="org.autojs.autojs.ui.doc.DocumentationActivity"
android:label="@string/docs_app_name"
android:exported="true"
android:icon="@drawable/ic_docs_app"
android:label="@string/docs_app_name"
android:taskAffinity="org.autojs.autojs.ui.doc.DocumentationActivity"
android:theme="@style/AppTheme.FullScreen"
android:exported="true">
android:theme="@style/AppTheme.FullScreen">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.MAIN"/>
</intent-filter>
</activity>
<activity android:name="org.autojs.autojs.ui.shortcut.AppsIconSelectActivity" />
<activity android:name="org.autojs.autojs.ui.shortcut.AppsIconSelectActivity"/>
<activity android:name="org.autojs.autojs.ui.timing.TimedTaskSettingActivity" />
<activity android:name="org.autojs.autojs.ui.timing.TimedTaskSettingActivity"/>
<activity
android:name="org.autojs.autojs.ui.shortcut.ShortcutCreateActivity"
android:theme="@style/AppTheme.Transparent" />
android:theme="@style/AppTheme.Transparent"/>
<activity
android:name="org.autojs.autojs.external.widget.ScriptWidgetSettingsActivity"
android:exported="false">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />
<action android:name="android.intent.action.CREATE_SHORTCUT"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<service android:name="org.autojs.autojs.ui.enhancedfloaty.FloatyService" />
<service android:name="org.autojs.autojs.ui.enhancedfloaty.FloatyService"/>
<service android:name="org.autojs.autojs.external.foreground.MainActivityForegroundService" />
<service android:name="org.autojs.autojs.external.foreground.MainActivityForegroundService"/>
<service android:name="org.autojs.autojs.external.ScriptExecutionIntentService" />
<service android:name="org.autojs.autojs.external.ScriptExecutionIntentService"/>
<activity android:name="org.autojs.autojs.external.tasker.TaskPrefEditActivity" />
<activity android:name="org.autojs.autojs.external.tasker.TaskPrefEditActivity"/>
<service
android:name="org.autojs.autojs.external.tile.LayoutBoundsTile"
android:exported="true"
android:icon="@drawable/ic_circular_menu_bounds"
android:label="@string/text_inspect_layout_bounds"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
android:exported="true">
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<meta-data
android:name="android.service.quicksettings.ACTIVE_TILE"
android:value="true" />
android:value="true"/>
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
<action android:name="android.service.quicksettings.action.QS_TILE"/>
</intent-filter>
</service>
<service
android:name="org.autojs.autojs.external.tile.LayoutHierarchyTile"
android:exported="true"
android:icon="@drawable/ic_circular_menu_hierarchy"
android:label="@string/text_inspect_layout_hierarchy"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
android:exported="true">
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<meta-data
android:name="android.service.quicksettings.ACTIVE_TILE"
android:value="true" />
android:value="true"/>
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
<action android:name="android.service.quicksettings.action.QS_TILE"/>
</intent-filter>
</service>
@@ -305,7 +294,7 @@
tools:ignore="ExportedActivity">
<intent-filter>
<action android:name="com.twofortyfouram.locale.intent.action.EDIT_SETTING" />
<action android:name="com.twofortyfouram.locale.intent.action.EDIT_SETTING"/>
</intent-filter>
</activity-alias>
@@ -316,71 +305,71 @@
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
<action android:name="android.intent.action.TIME_SET" />
<action android:name="android.intent.action.TIME_SET"/>
<action android:name="android.intent.action.TIMEZONE_CHANGED" />
<action android:name="android.intent.action.TIMEZONE_CHANGED"/>
<action android:name="android.intent.action.UID_REMOVED" />
<action android:name="android.intent.action.UID_REMOVED"/>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
<action android:name="android.intent.action.ACTION_SHUTDOWN"/>
<action android:name="android.intent.action.ACTION_BATTERY_CHANGED" />
<action android:name="android.intent.action.ACTION_BATTERY_CHANGED"/>
<action android:name="android.intent.action.DATE_CHANGED" />
<action android:name="android.intent.action.DATE_CHANGED"/>
<action android:name="android.intent.action.DREAMING_STARTED" />
<action android:name="android.intent.action.DREAMING_STARTED"/>
<action android:name="android.intent.action.DREAMING_STOPPED" />
<action android:name="android.intent.action.DREAMING_STOPPED"/>
<action android:name="android.intent.action.HEADSET_PLUG" />
<action android:name="android.intent.action.HEADSET_PLUG"/>
<action android:name="android.intent.action.INPUT_METHOD_CHANGED" />
<action android:name="android.intent.action.INPUT_METHOD_CHANGED"/>
<action android:name="android.intent.action.LOCALE_CHANGED" />
<action android:name="android.intent.action.LOCALE_CHANGED"/>
<action android:name="android.intent.action.MEDIA_BUTTON" />
<action android:name="android.intent.action.MEDIA_BUTTON"/>
<action android:name="android.intent.action.MEDIA_CHECKING" />
<action android:name="android.intent.action.MEDIA_CHECKING"/>
<action android:name="android.intent.action.MEDIA_MOUNTED" />
<action android:name="android.intent.action.MEDIA_MOUNTED"/>
<action android:name="android.intent.action.PACKAGE_FIRST_LAUNCH" />
<action android:name="android.intent.action.PACKAGE_FIRST_LAUNCH"/>
<action android:name="android.intent.action.PROVIDER_CHANGED" />
<action android:name="android.intent.action.PROVIDER_CHANGED"/>
<action android:name="android.intent.action.WALLPAPER_CHANGED" />
<action android:name="android.intent.action.WALLPAPER_CHANGED"/>
<action android:name="android.intent.action.USER_UNLOCKED" />
<action android:name="android.intent.action.USER_UNLOCKED"/>
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.intent.action.USER_PRESENT"/>
<action
android:name="android.net.conn.CONNECTIVITY_CHANGE"
tools:ignore="BatteryLife" />
tools:ignore="BatteryLife"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_CHANGED" />
<action android:name="android.intent.action.PACKAGE_CHANGED"/>
<action android:name="android.intent.action.PACKAGE_DATA_CLEARED" />
<action android:name="android.intent.action.PACKAGE_DATA_CLEARED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<action android:name="android.intent.action.PACKAGE_RESTARTED" />
<action android:name="android.intent.action.PACKAGE_RESTARTED"/>
<data android:scheme="package" />
<data android:scheme="package"/>
</intent-filter>
@@ -395,99 +384,99 @@
<!-- this Intent filter allows the plug-in to discovered by the host. -->
<intent-filter>
<action android:name="com.twofortyfouram.locale.intent.action.FIRE_SETTING" />
<action android:name="com.twofortyfouram.locale.intent.action.FIRE_SETTING"/>
</intent-filter>
</receiver>
<activity
android:name="org.autojs.autojs.external.open.EditIntentActivity"
android:exported="true"
android:icon="@drawable/autojs6_material"
android:label="@string/text_edit_script"
android:exported="true">
android:label="@string/text_edit_script">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.VIEW"/>
<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.EDIT"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="file" />
<data android:scheme="file"/>
<data android:scheme="content" />
<data android:scheme="content"/>
<data android:mimeType="application/x-javascript" />
<data android:mimeType="application/x-javascript"/>
<data android:mimeType="text/plain" />
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
<activity
android:name="org.autojs.autojs.external.open.RunIntentActivity"
android:exported="true"
android:icon="@drawable/autojs6_material"
android:label="@string/text_run_script"
android:taskAffinity="org.autojs.autojs.external.open.RunIntentActivity"
android:theme="@android:style/Theme.NoDisplay"
android:exported="true">
android:theme="@android:style/Theme.NoDisplay">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.VIEW"/>
<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.EDIT"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="file" />
<data android:scheme="file"/>
<data android:scheme="content" />
<data android:scheme="content"/>
<data android:mimeType="application/x-javascript" />
<data android:mimeType="application/x-javascript"/>
<data android:mimeType="text/plain" />
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
<activity
android:name="org.autojs.autojs.external.open.ImportIntentActivity"
android:exported="true"
android:icon="@drawable/autojs6_material"
android:label="@string/text_import_script"
android:theme="@style/AppTheme.Transparent"
android:exported="true">
android:theme="@style/AppTheme.Transparent">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.VIEW"/>
<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.EDIT"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="file" />
<data android:scheme="file"/>
<data android:scheme="content" />
<data android:scheme="content"/>
<data android:mimeType="application/x-javascript" />
<data android:mimeType="application/x-javascript"/>
<data android:mimeType="text/plain" />
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
<service
android:name="org.autojs.autojs.core.notification.NotificationListenerService"
android:exported="false"
android:label="@string/app_name"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"
android:exported="false">
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
<action android:name="android.service.notification.NotificationListenerService"/>
</intent-filter>
</service>
@@ -496,12 +485,12 @@
android:exported="false">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/script_widget_config" />
android:resource="@xml/script_widget_config"/>
</receiver>
@@ -509,7 +498,7 @@
android:name="org.autojs.autojs.timing.TaskReceiver"
android:exported="false">
<intent-filter>
<action android:name="org.autojs.autojs.action.task" />
<action android:name="org.autojs.autojs.action.task"/>
</intent-filter>
</receiver>
@@ -525,44 +514,44 @@
<activity
android:name="org.autojs.autojs.theme.app.ColorSelectActivity"
android:theme="@style/MtAppTheme.FullScreen" />
android:theme="@style/MtAppTheme.FullScreen"/>
<activity
android:name="org.autojs.autojs.execution.ScriptExecuteActivity"
android:configChanges="orientation|keyboardHidden|screenSize|locale"
android:theme="@style/ScriptTheme" />
android:theme="@style/ScriptTheme"/>
<activity
android:name="org.autojs.autojs.core.permission.PermissionRequestActivity"
android:excludeFromRecents="true"
android:taskAffinity="org.autojs.autojs.core.image.capture.ScreenCaptureRequestActivity"
android:theme="@style/ScriptTheme.Transparent" />
android:theme="@style/ScriptTheme.Transparent"/>
<activity
android:name="org.autojs.autojs.core.image.capture.ScreenCaptureRequestActivity"
android:excludeFromRecents="true"
android:taskAffinity="org.autojs.autojs.core.image.capture.ScreenCaptureRequestActivity"
android:theme="@style/ScriptTheme.Transparent" />
android:theme="@style/ScriptTheme.Transparent"/>
<service
android:name="org.autojs.autojs.core.accessibility.AccessibilityService"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
android:exported="true">
android:exported="true"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
<action android:name="android.accessibilityservice.AccessibilityService"/>
</intent-filter>
<meta-data
android:name="android.accessibilityservice"
android:resource="@xml/accessibility_service_config" />
android:resource="@xml/accessibility_service_config"/>
</service>
<service
android:name="org.autojs.autojs.core.image.capture.ScreenCapturerForegroundService"
android:enabled="true"
android:foregroundServiceType="mediaProjection" />
android:foregroundServiceType="mediaProjection"/>
<!-- This provider is required by Shizuku, remove this if your app only supports Sui -->
<provider
@@ -571,7 +560,32 @@
android:enabled="true"
android:exported="true"
android:multiprocess="false"
android:permission="android.permission.INTERACT_ACROSS_USERS_FULL" />
android:permission="android.permission.INTERACT_ACROSS_USERS_FULL"/>
<activity
android:name="org.autojs.autojs.inrt.SplashActivity"
android:exported="true"
android:theme="@style/AppTheme.Splash">
<intent-filter tools:ignore="ExtraText">
<action android:name="android.intent.action.MAIN"/>
<category android:name="${intentCategoryInrt}"/>
</intent-filter>
</activity>
<activity android:name="org.autojs.autojs.inrt.LogActivity"/>
<activity android:name="org.autojs.autojs.inrt.SettingsActivity"/>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${authorities}"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
</application>
</manifest>

View File

@@ -20,6 +20,7 @@ import org.autojs.autojs.engine.RootAutomatorEngine
import org.autojs.autojs.engine.ScriptEngineManager
import org.autojs.autojs.engine.ScriptEngineService
import org.autojs.autojs.engine.ScriptEngineServiceBuilder
import org.autojs.autojs.inrt.autojs.XJavaScriptEngine
import org.autojs.autojs.pref.Pref.registerOnSharedPreferenceChangeListener
import org.autojs.autojs.rhino.InterruptibleAndroidContextFactory
import org.autojs.autojs.runtime.ScriptRuntime
@@ -58,11 +59,19 @@ abstract class AbstractAutoJs protected constructor(protected val application: A
val infoProvider = ActivityInfoProvider(context)
val scriptEngineManager = ScriptEngineManager(context)
val scriptEngineService: ScriptEngineService = run {
if (org.autojs.autojs6.BuildConfig.isInrt) {
scriptEngineManager.registerEngine(JavaScriptSource.ENGINE) {
XJavaScriptEngine(context).also { engine ->
engine.runtime = createRuntime().also { runtime = it }
}
}
} else {
scriptEngineManager.registerEngine(JavaScriptSource.ENGINE) {
LoopBasedJavaScriptEngine(context).also { engine ->
engine.runtime = createRuntime().also { runtime = it }
}
}
}
initContextFactory()
scriptEngineManager.registerEngine(AutoFileSource.ENGINE) { RootAutomatorEngine(context) }
ScriptEngineServiceBuilder()
@@ -84,7 +93,14 @@ abstract class AbstractAutoJs protected constructor(protected val application: A
}
private fun initContextFactory() {
ContextFactory.initGlobal(InterruptibleAndroidContextFactory(File(context.cacheDir, "classes")))
ContextFactory.initGlobal(
InterruptibleAndroidContextFactory(
File(
context.cacheDir,
"classes"
)
)
)
}
protected open fun createRuntime(): ScriptRuntime = ScriptRuntime.Builder()

View File

@@ -38,7 +38,7 @@ import java.util.concurrent.Executors
* Modified by SuperMonster003 as of Dec 1, 2021.
* Transformed by SuperMonster003 on Oct 10, 2022.
*/
class AutoJs private constructor(private val appContext: Application) : AbstractAutoJs(appContext) {
open class AutoJs(private val appContext: Application) : AbstractAutoJs(appContext) {
// @Thank to Zen2H
private val printExecutor = Executors.newSingleThreadExecutor()

View File

@@ -0,0 +1,86 @@
package org.autojs.autojs.inrt
import android.app.Application
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.net.Uri
import android.view.View
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.SimpleTarget
import com.bumptech.glide.request.transition.Transition
import org.autojs.autojs.inrt.App
import org.autojs.autojs.AutoJs
import org.autojs.autojs.inrt.autojs.GlobalKeyObserver
import org.autojs.autojs.app.GlobalAppContext
import org.autojs.autojs.core.ui.inflater.ImageLoader
import org.autojs.autojs.core.ui.inflater.util.Drawables
import java.lang.ref.WeakReference
/**
* Created by Stardust on 2017/7/1.
*/
class App : Application() {
companion object {
private const val BUGLY_APP_ID = "19b3607b53"
private lateinit var instance: WeakReference<App>
val app: App
get() = instance.get()!!
}
override fun onCreate() {
super.onCreate()
GlobalAppContext.set(this)
instance = WeakReference(this)
AutoJs.initInstance(this)
GlobalKeyObserver.init()
Drawables.defaultImageLoader=object : ImageLoader {
override fun loadInto(imageView: ImageView, uri: Uri) {
Glide.with(this@App)
.load(uri)
.into(imageView)
}
override fun loadIntoBackground(view: View, uri: Uri) {
Glide.with(this@App)
.load(uri)
.into(object : SimpleTarget<Drawable>() {
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
view.background = resource
}
})
}
override fun load(view: View, uri: Uri): Drawable {
throw UnsupportedOperationException()
}
override fun load(view: View, uri: Uri, drawableCallback: ImageLoader.DrawableCallback) {
Glide.with(this@App)
.load(uri)
.into(object : SimpleTarget<Drawable>() {
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
drawableCallback.onLoaded(resource)
}
})
}
override fun load(view: View, uri: Uri, bitmapCallback: ImageLoader.BitmapCallback) {
Glide.with(this@App)
.asBitmap()
.load(uri)
.into(object : SimpleTarget<Bitmap>() {
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
bitmapCallback.onLoaded(resource)
}
})
}
}
}
}

View File

@@ -0,0 +1,51 @@
package org.autojs.autojs.inrt
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import android.view.Menu
import android.view.MenuItem
import android.view.View
import org.autojs.autojs.AutoJs
import org.autojs.autojs.inrt.launch.GlobalProjectLauncher
import org.autojs.autojs.core.console.ConsoleImpl
import org.autojs.autojs.core.console.ConsoleView
import org.autojs.autojs6.R
class LogActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setupView()
if (intent.getBooleanExtra(EXTRA_LAUNCH_SCRIPT, false)) {
GlobalProjectLauncher.launch(this)
}
}
private fun setupView() {
setContentView(R.layout.activity_main_inrt)
val toolbar = findViewById<Toolbar>(R.id.toolbar)
setSupportActionBar(toolbar)
val consoleView = findViewById<ConsoleView>(R.id.console)
consoleView.setConsole(AutoJs.instance.globalConsole as ConsoleImpl)
consoleView.findViewById<View>(R.id.input_container).visibility = View.GONE
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
startActivity(Intent(this, SettingsActivity::class.java))
return true
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_main_inrt, menu)
return true
}
companion object {
const val EXTRA_LAUNCH_SCRIPT = "launch_script"
}
}

View File

@@ -0,0 +1,50 @@
package org.autojs.autojs.inrt
import android.content.SharedPreferences
import androidx.preference.PreferenceManager
import org.autojs.autojs.app.GlobalAppContext
import org.autojs.autojs6.R
/**
* Created by Stardust on 2017/12/8.
*/
object Pref {
private const val KEY_FIRST_USING = "key_first_using"
private var sPreferences: SharedPreferences? = null
private val preferences: SharedPreferences
get() {
return sPreferences ?: run {
val pref = PreferenceManager.getDefaultSharedPreferences(GlobalAppContext.get())
sPreferences = pref
pref
}
}
val isFirstUsing: Boolean
get() {
val firstUsing = preferences.getBoolean(KEY_FIRST_USING, true)
if (firstUsing) {
preferences.edit().putBoolean(KEY_FIRST_USING, false).apply()
}
return firstUsing
}
private fun getString(res: Int): String {
return GlobalAppContext.get().getString(res)
}
fun shouldEnableAccessibilityServiceByRoot(): Boolean {
return preferences.getBoolean(getString(R.string.key_enable_a11y_service_with_root_access), true)
}
fun shouldHideLogs(): Boolean {
return preferences.getBoolean(getString(R.string.key_not_showing_main_activity), false)
}
fun shouldStopAllScriptsWhenVolumeUp(): Boolean {
return preferences.getBoolean(getString(R.string.key_use_volume_control_running), true)
}
}

View File

@@ -0,0 +1,38 @@
package org.autojs.autojs.inrt
import android.os.Bundle
import androidx.annotation.Nullable
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import org.autojs.autojs6.R
/**
* Created by Stardust on 2017/12/8.
*/
class SettingsActivity : AppCompatActivity() {
override fun onCreate(@Nullable savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setupViews()
}
private fun setupViews() {
setContentView(R.layout.activity_settings_inrt)
fragmentManager.beginTransaction().replace(R.id.fragment_setting, PreferenceFragment()).commit()
val toolbar = findViewById<Toolbar>(R.id.toolbar)
toolbar.setTitle(R.string.text_settings)
setSupportActionBar(toolbar)
toolbar.setNavigationOnClickListener { finish() }
supportActionBar?.setDisplayHomeAsUpEnabled(true)
}
class PreferenceFragment : androidx.preference.PreferenceFragment() {
override fun onCreate(@Nullable savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.preference_inrt)
}
}
}

View File

@@ -0,0 +1,89 @@
package org.autojs.autojs.inrt
import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager.PERMISSION_DENIED
import android.graphics.Typeface
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.widget.TextView
import android.widget.Toast
import androidx.annotation.NonNull
import androidx.annotation.Nullable
import androidx.appcompat.app.AppCompatActivity
import org.autojs.autojs.AutoJs
import org.autojs.autojs.inrt.launch.GlobalProjectLauncher
import org.autojs.autojs6.R
/**
* Created by Stardust on 2018/2/2.
*/
class SplashActivity : AppCompatActivity() {
override fun onCreate(@Nullable savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash_inrt)
val slug = findViewById<TextView>(R.id.slug)
slug.typeface = Typeface.createFromAsset(assets, "roboto_medium.ttf")
if (!Pref.isFirstUsing) {
main()
} else {
Handler(Looper.myLooper()!!).postDelayed({ this@SplashActivity.main() }, INIT_TIMEOUT)
}
}
private fun main() {
checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_PHONE_STATE)
}
private fun runScript() {
Thread {
try {
GlobalProjectLauncher.launch(this)
} catch (e: Exception) {
e.printStackTrace()
runOnUiThread {
Toast.makeText(this@SplashActivity, e.message, Toast.LENGTH_LONG).show()
startActivity(Intent(this@SplashActivity, LogActivity::class.java))
AutoJs.instance.globalConsole.printAllStackTrace(e)
}
}
}.start()
}
override fun onRequestPermissionsResult(requestCode: Int, @NonNull permissions: Array<String>, @NonNull grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
runScript()
}
private fun checkPermission(vararg permissions: String) {
val requestPermissions = getRequestPermissions(permissions)
if (requestPermissions.isNotEmpty()) {
requestPermissions(requestPermissions, PERMISSION_REQUEST_CODE)
} else {
runScript()
}
}
private fun getRequestPermissions(permissions: Array<out String>): Array<String> {
val list = ArrayList<String>()
for (permission in permissions) {
if (checkSelfPermission(permission) == PERMISSION_DENIED) {
list.add(permission)
}
}
return list.toTypedArray()
}
companion object {
private const val PERMISSION_REQUEST_CODE = 11186
private const val INIT_TIMEOUT: Long = 1000
}
}

View File

@@ -0,0 +1,98 @@
package org.autojs.autojs.inrt.autojs
import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import org.autojs.autojs.app.GlobalAppContext
import org.autojs.autojs.inrt.LogActivity
import org.autojs.autojs.inrt.SettingsActivity
import org.autojs.autojs.core.accessibility.AccessibilityTool
import org.autojs.autojs.core.accessibility.AccessibilityService
import org.autojs.autojs.runtime.ScriptRuntime
import org.autojs.autojs.runtime.api.AppUtils
import org.autojs.autojs.runtime.exception.ScriptException
import org.autojs.autojs.runtime.exception.ScriptInterruptedException
import org.autojs.autojs.script.JavaScriptSource
import org.autojs.autojs6.R
/**
* Created by Stardust on 2017/4/2.
*/
class AutoJs private constructor(application: Application) : org.autojs.autojs.AutoJs(application) {
init {
scriptEngineService.registerGlobalScriptExecutionListener(ScriptExecutionGlobalListener())
scriptEngineManager.registerEngine(JavaScriptSource.ENGINE) {
val engine = XJavaScriptEngine(application)
engine.runtime = createRuntime()
engine
}
}
override fun createAppUtils(context: Context): AppUtils {
return AppUtils(context, context.packageName + ".fileprovider")
}
override fun ensureAccessibilityServiceEnabled() {
if (AccessibilityService.instance != null) {
return
}
var errorMessage: String? = null
if (isAccessibilityServiceEnabled()) {
errorMessage = GlobalAppContext.get().getString(R.string.text_a11y_service_enabled_but_not_running)
} else if (!getAccessibilityServiceTool().service.enableIfNeededAndWaitFor(2000)) {
errorMessage = GlobalAppContext.get().getString(R.string.error_no_accessibility_permission)
}
if (errorMessage != null) {
getAccessibilityServiceTool().launchSettings()
throw ScriptException(errorMessage)
}
}
override fun waitForAccessibilityServiceEnabled(timeout: Long) {
if (AccessibilityService.instance != null) {
return
}
var errorMessage: String? = null
if (isAccessibilityServiceEnabled()) {
errorMessage = GlobalAppContext.get().getString(R.string.text_a11y_service_enabled_but_not_running)
} else if (!getAccessibilityServiceTool().service.enableIfNeededAndWaitFor(2000)) {
errorMessage = GlobalAppContext.get().getString(R.string.error_no_accessibility_permission)
}
if (errorMessage != null) {
getAccessibilityServiceTool().launchSettings()
if (!AccessibilityService.waitForEnabled(timeout)) {
throw ScriptInterruptedException()
}
}
}
override fun createRuntime(): ScriptRuntime {
val runtime = super.createRuntime()
runtime.putProperty("class.settings", SettingsActivity::class.java)
runtime.putProperty("class.console", LogActivity::class.java)
return runtime
}
private fun getAccessibilityServiceTool(): AccessibilityTool {
return AccessibilityTool(application)
}
private fun isAccessibilityServiceEnabled(): Boolean {
return getAccessibilityServiceTool().service.isEnabled()
}
companion object {
@SuppressLint("StaticFieldLeak")
@JvmStatic
lateinit var instance: AutoJs
private set
@Synchronized
fun initInstance(application: Application) {
instance = AutoJs(application)
}
}
}

View File

@@ -0,0 +1,93 @@
package org.autojs.autojs.inrt.autojs
import android.util.Log
import android.view.KeyEvent
import org.autojs.autojs.app.GlobalAppContext
import org.autojs.autojs.inrt.Pref
import org.autojs.autojs.core.accessibility.AccessibilityService
import org.autojs.autojs.core.accessibility.OnKeyListener
import org.autojs.autojs.core.inputevent.InputEventObserver
import org.autojs.autojs.core.inputevent.ShellKeyObserver
/**
* Created by Stardust on 2017/8/14.
*/
class GlobalKeyObserver internal constructor() : OnKeyListener, ShellKeyObserver.KeyListener {
private var mVolumeDownFromShell: Boolean = false
private var mVolumeDownFromAccessibility: Boolean = false
private var mVolumeUpFromShell: Boolean = false
private var mVolumeUpFromAccessibility: Boolean = false
init {
AccessibilityService.stickOnKeyObserver
.addListener(this)
val observer = ShellKeyObserver()
observer.setKeyListener(this)
InputEventObserver.getGlobal(GlobalAppContext.get()).addListener(observer)
}
fun onVolumeUp() {
Log.d(LOG_TAG, "onVolumeUp at " + System.currentTimeMillis())
if (Pref.shouldStopAllScriptsWhenVolumeUp()) {
AutoJs.instance.scriptEngineService.stopAllAndToast()
}
}
override fun onKeyEvent(keyCode: Int, event: KeyEvent) {
if (event.action != KeyEvent.ACTION_UP)
return
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
if (mVolumeDownFromShell) {
mVolumeDownFromShell = false
return
}
mVolumeUpFromAccessibility = true
onVolumeDown()
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
if (mVolumeUpFromShell) {
mVolumeUpFromShell = false
return
}
mVolumeUpFromAccessibility = true
onVolumeUp()
}
}
fun onVolumeDown() {
}
override fun onKeyDown(keyName: String) {
}
override fun onKeyUp(keyName: String) {
if ("KEY_VOLUMEUP" == keyName) {
if (mVolumeUpFromAccessibility) {
mVolumeUpFromAccessibility = false
return
}
mVolumeUpFromShell = true
onVolumeUp()
} else if ("KEY_VOLUMEDOWN" == keyName) {
if (mVolumeDownFromAccessibility) {
mVolumeDownFromAccessibility = false
return
}
mVolumeDownFromShell = true
onVolumeDown()
}
}
companion object {
private const val LOG_TAG = "GlobalKeyObserver"
private val sSingleton = GlobalKeyObserver()
fun init() {
//do nothing
}
}
}

View File

@@ -0,0 +1,36 @@
package org.autojs.autojs.inrt.autojs
import org.autojs.autojs.app.GlobalAppContext
import org.autojs.autojs.execution.ScriptExecution
import org.autojs.autojs.execution.ScriptExecutionListener
import org.autojs.autojs6.R
/**
* Created by Stardust on 2017/5/3.
*/
class ScriptExecutionGlobalListener : ScriptExecutionListener {
override fun onStart(execution: ScriptExecution) {
execution.engine.setTag(ENGINE_TAG_START_TIME, System.currentTimeMillis())
}
override fun onSuccess(execution: ScriptExecution, result: Any?) {
onFinish(execution)
}
private fun onFinish(execution: ScriptExecution) {
val millis = execution.engine.getTag(ENGINE_TAG_START_TIME) as Long? ?: return
val seconds = (System.currentTimeMillis() - millis) / 1000.0
AutoJs.instance.scriptEngineService.globalConsole
.verbose(GlobalAppContext.get().getString(R.string.text_execution_finished), execution.source.toString(), seconds)
}
override fun onException(execution: ScriptExecution, e: Throwable) {
onFinish(execution)
}
companion object {
private const val ENGINE_TAG_START_TIME = "start_time"
}
}

View File

@@ -0,0 +1,44 @@
package org.autojs.autojs.inrt.autojs
import android.content.Context
import org.autojs.autojs.engine.LoopBasedJavaScriptEngine
import org.autojs.autojs.engine.encryption.ScriptEncryption
import org.autojs.autojs.pio.PFiles
import org.autojs.autojs.script.EncryptedScriptFileHeader
import org.autojs.autojs.script.JavaScriptFileSource
import org.autojs.autojs.script.ScriptSource
import org.autojs.autojs.script.StringScriptSource
import java.io.File
import java.security.GeneralSecurityException
class XJavaScriptEngine(context: Context) : LoopBasedJavaScriptEngine(context) {
override fun execute(source: ScriptSource, callback: ExecuteCallback?) {
if (source is JavaScriptFileSource) {
try {
if (execute(source.file)) {
return
}
} catch (e: Throwable) {
e.printStackTrace()
return
}
}
super.execute(source, callback)
}
private fun execute(file: File): Boolean {
val bytes = PFiles.readBytes(file.path)
if (!EncryptedScriptFileHeader.isValidFile(bytes)) {
return false
}
try {
super.execute(StringScriptSource(file.name, String(ScriptEncryption.decrypt(bytes, EncryptedScriptFileHeader.BLOCK_SIZE))))
} catch (e: GeneralSecurityException) {
e.printStackTrace()
}
return true
}
}

View File

@@ -0,0 +1,110 @@
package org.autojs.autojs.inrt.launch
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Handler
import android.os.Looper
import android.text.TextUtils
import org.autojs.autojs.inrt.LogActivity
import org.autojs.autojs.inrt.Pref
import org.autojs.autojs.AutoJs
import org.autojs.autojs.engine.encryption.ScriptEncryption
import org.autojs.autojs.execution.ExecutionConfig
import org.autojs.autojs.execution.ScriptExecution
import org.autojs.autojs.pio.PFiles
import org.autojs.autojs.pio.UncheckedIOException
import org.autojs.autojs.project.ProjectConfig
import org.autojs.autojs.script.JavaScriptFileSource
import org.autojs.autojs.script.JavaScriptSource
import java.io.File
import java.io.IOException
/**
* Created by Stardust on 2018/1/24.
*/
open class AssetsProjectLauncher(private val mAssetsProjectDir: String, private val mActivity: Context) {
private val mProjectDir: String = File(mActivity.filesDir, "project/").path
private val mProjectConfig: ProjectConfig = ProjectConfig.fromAssets(mActivity, ProjectConfig.configFileOfDir(mAssetsProjectDir))
private val mMainScriptFile: File = File(mProjectDir, mProjectConfig.mainScriptFile)
private val mHandler: Handler = Handler(Looper.getMainLooper())
private var mScriptExecution: ScriptExecution? = null
init {
prepare()
}
fun launch(activity: Activity) {
//如果需要隐藏日志界面,则直接运行脚本
if (mProjectConfig.launchConfig.shouldHideLogs() || Pref.shouldHideLogs()) {
runScript(activity)
} else {
//如果不隐藏日志界面
//如果当前已经是日志界面则直接运行脚本
if (activity is LogActivity) {
runScript(null)
} else {
//否则显示日志界面并在日志界面中运行脚本
mHandler.post {
activity.startActivity(Intent(mActivity, LogActivity::class.java)
.putExtra(LogActivity.EXTRA_LAUNCH_SCRIPT, true))
activity.finish()
}
}
}
}
private fun runScript(activity: Activity?) {
if (mScriptExecution != null && mScriptExecution!!.engine != null &&
!mScriptExecution!!.engine.isDestroyed) {
return
}
try {
val source = JavaScriptFileSource("main", mMainScriptFile)
val config = ExecutionConfig(workingDirectory = mProjectDir)
if (source.executionMode and JavaScriptSource.EXECUTION_MODE_UI != 0) {
config.intentFlags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_TASK_ON_HOME
} else {
activity?.finish()
}
mScriptExecution = AutoJs.instance.scriptEngineService.execute(source, config)
} catch (e: Exception) {
AutoJs.instance.globalConsole.error(e)
}
}
private fun prepare() {
val projectConfigPath = PFiles.join(mProjectDir, ProjectConfig.CONFIG_FILE_NAME)
val projectConfig = ProjectConfig.fromFile(projectConfigPath)
if (projectConfig != null &&
TextUtils.equals(projectConfig.buildInfo.buildId, mProjectConfig.buildInfo.buildId)) {
initKey(projectConfig)
return
}
initKey(mProjectConfig)
PFiles.deleteRecursively(File(mProjectDir))
try {
PFiles.copyAssetDir(mActivity.assets, mAssetsProjectDir, mProjectDir, null)
} catch (e: IOException) {
throw UncheckedIOException(e)
}
}
private fun initKey(projectConfig: ProjectConfig) {
val key = MD5.md5(projectConfig.packageName + projectConfig.versionName + projectConfig.mainScriptFile)
val vec = MD5.md5(projectConfig.buildInfo.buildId + projectConfig.name).substring(0, 16)
try {
val fieldKey = ScriptEncryption::class.java.getDeclaredField("mKey")
fieldKey.isAccessible = true
fieldKey.set(null, key)
val fieldVector = ScriptEncryption::class.java.getDeclaredField("mInitVector")
fieldVector.isAccessible = true
fieldVector.set(null, vec)
} catch (e: Exception) {
e.printStackTrace()
}
}
}

View File

@@ -0,0 +1,10 @@
package org.autojs.autojs.inrt.launch
import android.annotation.SuppressLint
import org.autojs.autojs.app.GlobalAppContext
/**
* Created by Stardust on 2018/3/21.
*/
@SuppressLint("StaticFieldLeak")
object GlobalProjectLauncher: AssetsProjectLauncher("project", GlobalAppContext.get())

View File

@@ -0,0 +1,31 @@
package org.autojs.autojs.inrt.launch;
import java.security.MessageDigest;
public class MD5 {
public static byte[] md5Bytes(String message) {
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(message.getBytes());
return md5.digest();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static String md5(String message) {
byte[] bytes = md5Bytes(message);
StringBuilder hexString = new StringBuilder(32);
for (byte b : bytes) {
String hex = Integer.toHexString(0xFF & b);
if (hex.length() == 1) {
hexString.append('0');
}
hexString.append(hex);
}
return hexString.toString();
}
}

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:fitsSystemWindows="true"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</com.google.android.material.appbar.AppBarLayout>
<org.autojs.autojs.core.console.ConsoleView
android:id="@+id/console"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:color_debug="#cc000000"
app:color_verbose="#dfc0c0c0"/>
</LinearLayout>

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:fitsSystemWindows="true"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</com.google.android.material.appbar.AppBarLayout>
<FrameLayout
android:id="@+id/fragment_setting"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"/>
</LinearLayout>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:src="@drawable/autojs_material"/>
<TextView
android:id="@+id/slug"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:layout_marginBottom="12dp"
android:text="@string/text_powered_by_autojs"
android:textColor="#dd000000"
android:textSize="14sp"/>
</FrameLayout>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/settings"
android:title="@string/text_settings"/>
</menu>

View File

@@ -75,4 +75,12 @@
<attr name="message" format="string" />
</declare-styleable>
<declare-styleable name="ConsoleView">
<attr name="color_debug" format="reference|color" />
<attr name="color_verbose" format="reference|color" />
<attr name="color_info" format="reference|color" />
<attr name="color_warn" format="reference|color" />
<attr name="color_error" format="reference|color" />
<attr name="color_assert" format="reference|color" />
</declare-styleable>
</resources>

View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="@string/text_script_running">
<SwitchPreference
android:defaultValue="true"
android:key="@string/key_use_volume_control_running"
android:title="@string/text_use_volume_key_to_control_script_running"/>
<SwitchPreference
android:defaultValue="false"
android:key="@string/key_not_showing_main_activity"
android:summary="@string/summary_not_showing_main_activity"
android:title="@string/text_not_showing_main_activity"/>
</PreferenceCategory>
<PreferenceCategory
android:title="@string/text_a11y_service">
<SwitchPreference
android:defaultValue="false"
android:key="@string/key_enable_a11y_service_with_root_access"
android:summary="@string/summary_enable_a11y_service_with_root_access"
android:title="@string/text_enable_a11y_service_with_root_access_automatically"/>
<SwitchPreference
android:defaultValue="false"
android:key="@string/key_stable_mode"
android:summary="@string/summary_stable_mode"
android:title="@string/text_stable_mode"/>
</PreferenceCategory>
<PreferenceCategory
android:title="@string/text_others">
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
<files-path name="sample" path="sample"/>
<files-path name="project" path="project"/>
<root-path name="root_files" path="." />
<files-path name="sample" path="sample"/>
</paths>