Add AM installer
This commit is contained in:
@@ -24,5 +24,11 @@
|
|||||||
"title": "Aurora Service",
|
"title": "Aurora Service",
|
||||||
"subtitle": "Installer for background installations",
|
"subtitle": "Installer for background installations",
|
||||||
"description": "Requires Aurora Services to be installed as system app."
|
"description": "Requires Aurora Services to be installed as system app."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "4",
|
||||||
|
"title": "AM Installer",
|
||||||
|
"subtitle": "Install use App Manager",
|
||||||
|
"description": "You must have App Manager. Need adb/root mode to install when miui optimization is on."
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package com.aurora.store.data.installer
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import androidx.core.content.FileProvider
|
||||||
|
import com.aurora.store.util.Log
|
||||||
|
import java.io.*
|
||||||
|
import java.util.zip.ZipEntry
|
||||||
|
import java.util.zip.ZipOutputStream
|
||||||
|
|
||||||
|
class AMInstaller(context: Context) : InstallerBase(context) {
|
||||||
|
companion object {
|
||||||
|
const val AM_PACKAGE_NAME = "io.github.muntashirakon.AppManager"
|
||||||
|
const val AM_DEBUG_PACKAGE_NAME = "io.github.muntashirakon.AppManager.debug"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun install(packageName: String, files: List<Any>) {
|
||||||
|
if (isAlreadyQueued(packageName)) {
|
||||||
|
Log.i("$packageName already queued")
|
||||||
|
} else {
|
||||||
|
Log.i("Received AM install request for $packageName")
|
||||||
|
val fileList = files.map {
|
||||||
|
when (it) {
|
||||||
|
is File -> it.absolutePath
|
||||||
|
is String -> File(it).absolutePath
|
||||||
|
else -> {
|
||||||
|
throw Exception("Invalid data, expecting listOf() File or String")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val apks = zipFile(fileList)
|
||||||
|
xInstall(packageName, apks)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun xInstall(packageName: String, file: File) {
|
||||||
|
val intent: Intent = Intent(Intent.ACTION_VIEW)
|
||||||
|
intent.setDataAndType(
|
||||||
|
FileProvider.getUriForFile(
|
||||||
|
context,
|
||||||
|
context.applicationContext.packageName + ".fileProvider",
|
||||||
|
file
|
||||||
|
), "application/octet-stream"
|
||||||
|
);
|
||||||
|
intent.flags =
|
||||||
|
Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION or Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
|
||||||
|
context.startActivity(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
|
||||||
|
private fun zipFile(files: List<String>): File {
|
||||||
|
val outPath = File(files.first()).parentFile.absolutePath + "/bundle.apks"
|
||||||
|
val out = ZipOutputStream(BufferedOutputStream(FileOutputStream(outPath)))
|
||||||
|
for (file in files) {
|
||||||
|
val fi = FileInputStream(file)
|
||||||
|
val origin = BufferedInputStream(fi)
|
||||||
|
val entry = ZipEntry(file.substring(file.lastIndexOf("/")))
|
||||||
|
out.putNextEntry(entry)
|
||||||
|
origin.copyTo(out, 1024)
|
||||||
|
origin.close()
|
||||||
|
}
|
||||||
|
out.close()
|
||||||
|
return File(outPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -77,6 +77,11 @@ open class AppInstaller private constructor(var context: Context) {
|
|||||||
choiceAndInstaller[prefValue] = installer
|
choiceAndInstaller[prefValue] = installer
|
||||||
installer
|
installer
|
||||||
}
|
}
|
||||||
|
4 -> {
|
||||||
|
val installer = AMInstaller(context)
|
||||||
|
choiceAndInstaller[prefValue] = installer
|
||||||
|
installer
|
||||||
|
}
|
||||||
else -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
else -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
val installer = SessionInstaller(context)
|
val installer = SessionInstaller(context)
|
||||||
choiceAndInstaller[prefValue] = installer
|
choiceAndInstaller[prefValue] = installer
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import com.aurora.extensions.isMiuiOptimizationDisabled
|
|||||||
import com.aurora.extensions.showDialog
|
import com.aurora.extensions.showDialog
|
||||||
import com.aurora.store.BuildConfig
|
import com.aurora.store.BuildConfig
|
||||||
import com.aurora.store.R
|
import com.aurora.store.R
|
||||||
|
import com.aurora.store.data.installer.AMInstaller
|
||||||
import com.aurora.store.data.installer.ServiceInstaller
|
import com.aurora.store.data.installer.ServiceInstaller
|
||||||
import com.aurora.store.data.model.Installer
|
import com.aurora.store.data.model.Installer
|
||||||
import com.aurora.store.databinding.FragmentOnboardingInstallerBinding
|
import com.aurora.store.databinding.FragmentOnboardingInstallerBinding
|
||||||
@@ -130,6 +131,17 @@ class InstallerFragment : BaseFragment() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4 -> {
|
||||||
|
if (checkAMAvailability()) {
|
||||||
|
this.installerId = installerId
|
||||||
|
save(Preferences.PREFERENCE_INSTALLER_ID, installerId)
|
||||||
|
} else {
|
||||||
|
showDialog(
|
||||||
|
R.string.action_installations,
|
||||||
|
R.string.installer_am_unavailable
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
else -> {
|
else -> {
|
||||||
this.installerId = installerId
|
this.installerId = installerId
|
||||||
save(PREFERENCE_INSTALLER_ID, installerId)
|
save(PREFERENCE_INSTALLER_ID, installerId)
|
||||||
@@ -169,4 +181,14 @@ class InstallerFragment : BaseFragment() {
|
|||||||
|
|
||||||
return isInstalled && isCorrectVersionInstalled
|
return isInstalled && isCorrectVersionInstalled
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun checkAMAvailability(): Boolean {
|
||||||
|
return PackageUtil.isInstalled(
|
||||||
|
requireContext(),
|
||||||
|
AMInstaller.AM_PACKAGE_NAME
|
||||||
|
) or PackageUtil.isInstalled(
|
||||||
|
requireContext(),
|
||||||
|
AMInstaller.AM_DEBUG_PACKAGE_NAME
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -28,6 +28,7 @@ import com.aurora.extensions.showDialog
|
|||||||
import com.aurora.extensions.toast
|
import com.aurora.extensions.toast
|
||||||
import com.aurora.store.BuildConfig
|
import com.aurora.store.BuildConfig
|
||||||
import com.aurora.store.R
|
import com.aurora.store.R
|
||||||
|
import com.aurora.store.data.installer.AMInstaller
|
||||||
import com.aurora.store.data.installer.ServiceInstaller
|
import com.aurora.store.data.installer.ServiceInstaller
|
||||||
import com.aurora.store.util.CommonUtil
|
import com.aurora.store.util.CommonUtil
|
||||||
import com.aurora.store.util.PackageUtil
|
import com.aurora.store.util.PackageUtil
|
||||||
@@ -88,6 +89,17 @@ class InstallationPreference : PreferenceFragmentCompat() {
|
|||||||
)
|
)
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
} else if (selectedId == 4) {
|
||||||
|
if (checkAMAvailability()) {
|
||||||
|
save(Preferences.PREFERENCE_INSTALLER_ID, selectedId)
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
showDialog(
|
||||||
|
R.string.action_installations,
|
||||||
|
R.string.installer_am_unavailable
|
||||||
|
)
|
||||||
|
false
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
save(Preferences.PREFERENCE_INSTALLER_ID, selectedId)
|
save(Preferences.PREFERENCE_INSTALLER_ID, selectedId)
|
||||||
true
|
true
|
||||||
@@ -115,4 +127,14 @@ class InstallationPreference : PreferenceFragmentCompat() {
|
|||||||
|
|
||||||
return isInstalled && isCorrectVersionInstalled
|
return isInstalled && isCorrectVersionInstalled
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun checkAMAvailability(): Boolean {
|
||||||
|
return PackageUtil.isInstalled(
|
||||||
|
requireContext(),
|
||||||
|
AMInstaller.AM_PACKAGE_NAME
|
||||||
|
) or PackageUtil.isInstalled(
|
||||||
|
requireContext(),
|
||||||
|
AMInstaller.AM_DEBUG_PACKAGE_NAME
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,6 +112,7 @@
|
|||||||
<item>@string/pref_install_mode_native</item>
|
<item>@string/pref_install_mode_native</item>
|
||||||
<item>@string/pref_install_mode_root</item>
|
<item>@string/pref_install_mode_root</item>
|
||||||
<item>@string/pref_install_mode_services</item>
|
<item>@string/pref_install_mode_services</item>
|
||||||
|
<item>@string/pref_install_mode_am</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="pref_installation_method_values">
|
<string-array name="pref_installation_method_values">
|
||||||
@@ -119,6 +120,7 @@
|
|||||||
<item>1</item>
|
<item>1</item>
|
||||||
<item>2</item>
|
<item>2</item>
|
||||||
<item>3</item>
|
<item>3</item>
|
||||||
|
<item>4</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="link_urls">
|
<string-array name="link_urls">
|
||||||
|
|||||||
@@ -205,6 +205,7 @@
|
|||||||
<string name="filter_review_positive">"Positive"</string>
|
<string name="filter_review_positive">"Positive"</string>
|
||||||
<string name="filter_review_three">"Three"</string>
|
<string name="filter_review_three">"Three"</string>
|
||||||
<string name="filter_review_two">"Two"</string>
|
<string name="filter_review_two">"Two"</string>
|
||||||
|
<string name="installer_am_unavailable">Install App Manager or change the installer.</string>
|
||||||
<string name="installer_root_available">"Root access available"</string>
|
<string name="installer_root_available">"Root access available"</string>
|
||||||
<string name="installer_root_unavailable">No root access. Grant it or change the installer.</string>
|
<string name="installer_root_unavailable">No root access. Grant it or change the installer.</string>
|
||||||
<string name="installer_service_available">"Aurora services is available and ready to install."</string>
|
<string name="installer_service_available">"Aurora services is available and ready to install."</string>
|
||||||
@@ -279,6 +280,7 @@
|
|||||||
<string name="pref_install_auto_title">"Auto install APKs after download"</string>
|
<string name="pref_install_auto_title">"Auto install APKs after download"</string>
|
||||||
<string name="pref_install_delete_summary">"APKs will be deleted by default"</string>
|
<string name="pref_install_delete_summary">"APKs will be deleted by default"</string>
|
||||||
<string name="pref_install_delete_title">"Delete APK post-install"</string>
|
<string name="pref_install_delete_title">"Delete APK post-install"</string>
|
||||||
|
<string name="pref_install_mode_am">AM installer.</string>
|
||||||
<string name="pref_install_mode_native">"Native installer"</string>
|
<string name="pref_install_mode_native">"Native installer"</string>
|
||||||
<string name="pref_install_mode_root">"Root installer"</string>
|
<string name="pref_install_mode_root">"Root installer"</string>
|
||||||
<string name="pref_install_mode_services">"Aurora Services"</string>
|
<string name="pref_install_mode_services">"Aurora Services"</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user