This commit is contained in:
Administrator 2025-07-05 14:56:11 +08:00
parent ef7f148e13
commit 2ed86fb2b7
16 changed files with 51 additions and 45 deletions

View File

@ -83,7 +83,9 @@ class ApkSourceBuilder(private val mContext: Context) {
val apkFileDescriptors: MutableList<FileDescriptor> = ArrayList<FileDescriptor>( val apkFileDescriptors: MutableList<FileDescriptor> = ArrayList<FileDescriptor>(
mApkFiles?.size?: 0 mApkFiles?.size?: 0
) )
for (apkFile in mApkFiles!!) apkFileDescriptors.add(NormalFileDescriptor(apkFile)) mApkFiles?.let {
for (apkFile in it) apkFileDescriptors.add(NormalFileDescriptor(apkFile))
}
apkSource = DefaultApkSource(apkFileDescriptors) apkSource = DefaultApkSource(apkFileDescriptors)
} else if (mZipFile != null) { } else if (mZipFile != null) {

View File

@ -59,13 +59,16 @@ class FlexSaiPackageInstaller private constructor(c: Context) : SaiPackageInstal
installer: SaiPackageInstaller, installer: SaiPackageInstaller,
params: SaiPiSessionParams params: SaiPiSessionParams
): String { ): String {
val sessionId = installer.createSession(params) val sessionId = installer.createSession(params)?:""
mSessionIdToInstaller[sessionId!!] = installer mSessionIdToInstaller[sessionId] = installer
return sessionId return sessionId
} }
override fun createSession(params: SaiPiSessionParams): String { override fun createSession(params: SaiPiSessionParams): String {
return createSessionOnInstaller(mDefaultInstaller!!, params) mDefaultInstaller?.let {
return createSessionOnInstaller(it, params)
}
return ""
} }
override fun enqueueSession(sessionId: String) { override fun enqueueSession(sessionId: String) {

View File

@ -18,7 +18,7 @@ class MyBroadcastReceiver : BroadcastReceiver() {
//接收广播消息 //接收广播消息
fruit = intent.getStringExtra("fruit") fruit = intent.getStringExtra("fruit")
//调用接口MyReceiver里面的interFruit方法传入接收的内容 //调用接口MyReceiver里面的interFruit方法传入接收的内容
mReceiver!!.interFruit(fruit) mReceiver?.interFruit(fruit)
//使用Toast显示广播消息 //使用Toast显示广播消息
Toast.makeText(context, fruit, Toast.LENGTH_SHORT).show() Toast.makeText(context, fruit, Toast.LENGTH_SHORT).show()
} }

View File

@ -116,7 +116,7 @@ class RootlessSaiPiBroadcastReceiver(c: Context) : BroadcastReceiver() {
val androidPackageInstallerError: AndroidPackageInstallerError = val androidPackageInstallerError: AndroidPackageInstallerError =
getAndroidPmError(errorCode, error) getAndroidPmError(errorCode, error)
if (androidPackageInstallerError !== AndroidPackageInstallerError.UNKNOWN) { if (androidPackageInstallerError != AndroidPackageInstallerError.UNKNOWN) {
return androidPackageInstallerError.getDescription(mContext) return androidPackageInstallerError.getDescription(mContext)
} }

View File

@ -53,9 +53,9 @@ abstract class ShellSaiPackageInstaller protected constructor(c: Context?) :
val installedPackage: String val installedPackage: String
try { try {
installedPackage = intent.dataString!!.replace("package:", "") installedPackage = intent.dataString?.replace("package:", "")?:""
val installerPackage: String = val installerPackage: String =
context.getPackageManager().getInstallerPackageName(installedPackage)?:"" context.packageManager.getInstallerPackageName(installedPackage)?:""
Log.d(tag(), "installerPackage=$installerPackage") Log.d(tag(), "installerPackage=$installerPackage")
if ("com.android.grape" != installerPackage) return if ("com.android.grape" != installerPackage) return
} catch (e: Exception) { } catch (e: Exception) {
@ -135,6 +135,7 @@ abstract class ShellSaiPackageInstaller protected constructor(c: Context?) :
return return
} }
androidSessionId = createSession() androidSessionId = createSession()
//todo params.apkSource().apkLocalPath?
val path = "/sdcard/apks/" + "com.zhiliaoapp.musically" val path = "/sdcard/apks/" + "com.zhiliaoapp.musically"
val file = File(path) val file = File(path)

View File

@ -28,7 +28,7 @@ class CopyToFileApkSource(context: Context, wrappedApkSource: ApkSource) :
IOUtils.deleteRecursively(it) IOUtils.deleteRecursively(it)
} }
mCurrentApkFile = File(mTempDir, mWrappedApkSource.apkName) mCurrentApkFile = File(mTempDir, mWrappedApkSource.apkName?:"")
mWrappedApkSource.openApkInputStream().use { `in` -> mWrappedApkSource.openApkInputStream().use { `in` ->
FileOutputStream(mCurrentApkFile).use { out -> FileOutputStream(mCurrentApkFile).use { out ->

View File

@ -34,7 +34,7 @@ class SignerApkSource(private val mContext: Context, apkSource: ApkSource) : Apk
) )
} }
mCurrentSignedApkFile = File(mTempDir, apkName) mCurrentSignedApkFile = File(mTempDir, apkName?:"")
mWrappedApkSource.openApkInputStream()?.let { mWrappedApkSource.openApkInputStream()?.let {
mApkSigner?.sign( mApkSigner?.sign(
it, it,

View File

@ -38,11 +38,11 @@ object FileUtils {
} }
private fun trimFilename(res: StringBuilder, maxBytes: Int) { private fun trimFilename(res: StringBuilder, maxBytes: Int) {
var maxBytes = maxBytes var bytes = maxBytes
var raw = res.toString().toByteArray(StandardCharsets.UTF_8) var raw = res.toString().toByteArray(StandardCharsets.UTF_8)
if (raw.size > maxBytes) { if (raw.size > bytes) {
maxBytes -= 3 bytes -= 3
while (raw.size > maxBytes) { while (raw.size > bytes) {
res.deleteCharAt(res.length / 2) res.deleteCharAt(res.length / 2)
raw = res.toString().toByteArray(StandardCharsets.UTF_8) raw = res.toString().toByteArray(StandardCharsets.UTF_8)
} }

View File

@ -25,14 +25,15 @@ class ZipApkSource(private val mContext: Context, private val mZipFileDescriptor
@Throws(Exception::class) @Throws(Exception::class)
override fun nextApk(): Boolean { override fun nextApk(): Boolean {
if (!mIsOpen) { if (!mIsOpen) {
mZipInputStream = ZipInputStream(mZipFileDescriptor.open()) mZipInputStream = ZipInputStream(mZipFileDescriptor.open()).apply {
mWrappedStream = ZipInputStreamWrapper(mZipInputStream!!) mWrappedStream = ZipInputStreamWrapper(this)
}
mIsOpen = true mIsOpen = true
} }
do { do {
try { try {
entry = mZipInputStream!!.nextEntry entry = mZipInputStream?.nextEntry
} catch (e: ZipException) { } catch (e: ZipException) {
if (e.message == "only DEFLATED entries can have EXT descriptor") { if (e.message == "only DEFLATED entries can have EXT descriptor") {
throw ZipException("only DEFLATED entries can have EXT descriptor") throw ZipException("only DEFLATED entries can have EXT descriptor")

View File

@ -35,13 +35,14 @@ class ZipFileApkSource(context: Context, private val mZipFileDescriptor: FileDes
if (mZipFile == null) copyAndOpenZip() if (mZipFile == null) copyAndOpenZip()
entry = null entry = null
while (entry == null && mZipEntries!!.hasMoreElements()) { while (entry == null && mZipEntries?.hasMoreElements() == true) {
val nextEntry = mZipEntries!!.nextElement() mZipEntries?.nextElement()?.let { nextEntry ->
if (!nextEntry.isDirectory && nextEntry.name.lowercase(Locale.getDefault()) if (!nextEntry.isDirectory && nextEntry.name.lowercase(Locale.getDefault())
.endsWith(".apk") .endsWith(".apk")
) { ) {
entry = nextEntry entry = nextEntry
mSeenApkFile = true mSeenApkFile = true
}
} }
} }

View File

@ -138,7 +138,7 @@ class PackageMeta : Parcelable {
return Builder(applicationInfo.packageName) return Builder(applicationInfo.packageName)
.setLabel(applicationInfo.loadLabel(pm).toString()) .setLabel(applicationInfo.loadLabel(pm).toString())
.setHasSplits(applicationInfo.splitPublicSourceDirs != null && applicationInfo.splitPublicSourceDirs!!.size > 0) .setHasSplits(applicationInfo.splitPublicSourceDirs != null && applicationInfo.splitPublicSourceDirs?.isNotEmpty() == true)
.setIsSystemApp((applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM) != 0) .setIsSystemApp((applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM) != 0)
.setVersionCode(if (Utils.apiIsAtLeast(Build.VERSION_CODES.P)) packageInfo.longVersionCode else packageInfo.versionCode.toLong()) .setVersionCode(if (Utils.apiIsAtLeast(Build.VERSION_CODES.P)) packageInfo.longVersionCode else packageInfo.versionCode.toLong())
.setVersionName(packageInfo.versionName) .setVersionName(packageInfo.versionName)

View File

@ -127,11 +127,11 @@ class SaiPiSessionState private constructor(
} }
fun error(shortError: String?, fullError: String?): Builder { fun error(shortError: String?, fullError: String?): Builder {
var fullError = fullError var error = fullError
mState.mShortError = shortError mState.mShortError = shortError
if (fullError == null) fullError = shortError if (error == null) error = shortError
mState.mFullError = fullError mState.mFullError = error
return this return this
} }

View File

@ -3,6 +3,7 @@ package com.android.grape.sai.prefers
import android.content.Context import android.content.Context
import android.content.SharedPreferences import android.content.SharedPreferences
import android.os.Environment import android.os.Environment
import androidx.core.content.edit
class PreferencesHelper private constructor(c: Context) { class PreferencesHelper private constructor(c: Context) {
@ -50,7 +51,7 @@ class PreferencesHelper private constructor(c: Context) {
} }
fun setShouldSignApks(signApks: Boolean) { fun setShouldSignApks(signApks: Boolean) {
prefs.edit().putBoolean(PreferencesKeys.SIGN_APKS, signApks).apply() prefs.edit { putBoolean(PreferencesKeys.SIGN_APKS, signApks) }
} }
fun shouldExtractArchives(): Boolean { fun shouldExtractArchives(): Boolean {
@ -64,7 +65,7 @@ class PreferencesHelper private constructor(c: Context) {
var installer: Int var installer: Int
get() = prefs.getInt(PreferencesKeys.INSTALLER, PreferencesValues.INSTALLER_ROOTED) get() = prefs.getInt(PreferencesKeys.INSTALLER, PreferencesValues.INSTALLER_ROOTED)
set(installer) { set(installer) {
prefs.edit().putInt(PreferencesKeys.INSTALLER, installer).apply() prefs.edit { putInt(PreferencesKeys.INSTALLER, installer) }
} }
var backupFileNameFormat: String? var backupFileNameFormat: String?
@ -73,7 +74,7 @@ class PreferencesHelper private constructor(c: Context) {
PreferencesValues.BACKUP_FILE_NAME_FORMAT_DEFAULT PreferencesValues.BACKUP_FILE_NAME_FORMAT_DEFAULT
) )
set(format) { set(format) {
prefs.edit().putString(PreferencesKeys.BACKUP_FILE_NAME_FORMAT, format).apply() prefs.edit { putString(PreferencesKeys.BACKUP_FILE_NAME_FORMAT, format) }
} }
var installLocation: Int var installLocation: Int
@ -87,8 +88,9 @@ class PreferencesHelper private constructor(c: Context) {
} }
} }
set(installLocation) { set(installLocation) {
prefs.edit().putString(PreferencesKeys.INSTALL_LOCATION, installLocation.toString()) prefs.edit {
.apply() putString(PreferencesKeys.INSTALL_LOCATION, installLocation.toString())
}
} }
fun useOldInstaller(): Boolean { fun useOldInstaller(): Boolean {
@ -108,7 +110,7 @@ class PreferencesHelper private constructor(c: Context) {
} }
fun setSafTipShown() { fun setSafTipShown() {
prefs.edit().putBoolean(PreferencesKeys.SAF_TIP_SHOWN, true).apply() prefs.edit { putBoolean(PreferencesKeys.SAF_TIP_SHOWN, true) }
} }
val isInstallerXEnabled: Boolean val isInstallerXEnabled: Boolean
@ -120,19 +122,19 @@ class PreferencesHelper private constructor(c: Context) {
var isAnalyticsEnabled: Boolean var isAnalyticsEnabled: Boolean
get() = prefs.getBoolean(PreferencesKeys.ENABLE_ANALYTICS, true) get() = prefs.getBoolean(PreferencesKeys.ENABLE_ANALYTICS, true)
set(enabled) { set(enabled) {
prefs.edit().putBoolean(PreferencesKeys.ENABLE_ANALYTICS, enabled).apply() prefs.edit { putBoolean(PreferencesKeys.ENABLE_ANALYTICS, enabled) }
} }
var isInitialIndexingDone: Boolean var isInitialIndexingDone: Boolean
get() = prefs.getBoolean(PreferencesKeys.INITIAL_INDEXING_RUN, false) get() = prefs.getBoolean(PreferencesKeys.INITIAL_INDEXING_RUN, false)
set(done) { set(done) {
prefs.edit().putBoolean(PreferencesKeys.INITIAL_INDEXING_RUN, done).apply() prefs.edit { putBoolean(PreferencesKeys.INITIAL_INDEXING_RUN, done) }
} }
var isSingleApkExportEnabled: Boolean var isSingleApkExportEnabled: Boolean
get() = prefs.getBoolean(PreferencesKeys.BACKUP_APK_EXPORT, false) get() = prefs.getBoolean(PreferencesKeys.BACKUP_APK_EXPORT, false)
set(enabled) { set(enabled) {
prefs.edit().putBoolean(PreferencesKeys.BACKUP_APK_EXPORT, enabled).apply() prefs.edit { putBoolean(PreferencesKeys.BACKUP_APK_EXPORT, enabled) }
} }
companion object { companion object {

View File

@ -40,9 +40,7 @@ class MyAccessibilityService:AccessibilityService(){
val manager: NotificationManager = getSystemService<NotificationManager>( val manager: NotificationManager = getSystemService<NotificationManager>(
NotificationManager::class.java NotificationManager::class.java
) )
if (manager != null) { manager.createNotificationChannel(channel)
manager.createNotificationChannel(channel)
}
} }
} }

View File

@ -275,10 +275,7 @@ object Util {
} }
fun isInstallRet(): Boolean { fun isInstallRet(): Boolean {
if (installRet == null) { return installRet?:false
return false
}
return installRet!!
} }
fun setAfLog(afLogV: String) { fun setAfLog(afLogV: String) {

View File

@ -9,6 +9,7 @@ import android.text.TextUtils
import androidx.work.CoroutineWorker import androidx.work.CoroutineWorker
import androidx.work.WorkerParameters import androidx.work.WorkerParameters
import com.android.grape.service.MyAccessibilityService import com.android.grape.service.MyAccessibilityService
import androidx.core.content.edit
class CheckAccessibilityWorker( class CheckAccessibilityWorker(
context: Context, context: Context,
@ -32,7 +33,7 @@ class CheckAccessibilityWorker(
applicationContext.startActivity(intent) applicationContext.startActivity(intent)
// 更新状态 // 更新状态
sharedPreferences.edit().putBoolean("accessibility_prompted", true).apply() sharedPreferences.edit { putBoolean("accessibility_prompted", true) }
} }
return Result.retry() return Result.retry()
} }