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>(
mApkFiles?.size?: 0
)
for (apkFile in mApkFiles!!) apkFileDescriptors.add(NormalFileDescriptor(apkFile))
mApkFiles?.let {
for (apkFile in it) apkFileDescriptors.add(NormalFileDescriptor(apkFile))
}
apkSource = DefaultApkSource(apkFileDescriptors)
} else if (mZipFile != null) {

View File

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

View File

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

View File

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

View File

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

View File

@ -28,7 +28,7 @@ class CopyToFileApkSource(context: Context, wrappedApkSource: ApkSource) :
IOUtils.deleteRecursively(it)
}
mCurrentApkFile = File(mTempDir, mWrappedApkSource.apkName)
mCurrentApkFile = File(mTempDir, mWrappedApkSource.apkName?:"")
mWrappedApkSource.openApkInputStream().use { `in` ->
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 {
mApkSigner?.sign(
it,

View File

@ -38,11 +38,11 @@ object FileUtils {
}
private fun trimFilename(res: StringBuilder, maxBytes: Int) {
var maxBytes = maxBytes
var bytes = maxBytes
var raw = res.toString().toByteArray(StandardCharsets.UTF_8)
if (raw.size > maxBytes) {
maxBytes -= 3
while (raw.size > maxBytes) {
if (raw.size > bytes) {
bytes -= 3
while (raw.size > bytes) {
res.deleteCharAt(res.length / 2)
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)
override fun nextApk(): Boolean {
if (!mIsOpen) {
mZipInputStream = ZipInputStream(mZipFileDescriptor.open())
mWrappedStream = ZipInputStreamWrapper(mZipInputStream!!)
mZipInputStream = ZipInputStream(mZipFileDescriptor.open()).apply {
mWrappedStream = ZipInputStreamWrapper(this)
}
mIsOpen = true
}
do {
try {
entry = mZipInputStream!!.nextEntry
entry = mZipInputStream?.nextEntry
} catch (e: ZipException) {
if (e.message == "only DEFLATED entries can have EXT descriptor") {
throw ZipException("only DEFLATED entries can have EXT descriptor")

View File

@ -35,8 +35,8 @@ class ZipFileApkSource(context: Context, private val mZipFileDescriptor: FileDes
if (mZipFile == null) copyAndOpenZip()
entry = null
while (entry == null && mZipEntries!!.hasMoreElements()) {
val nextEntry = mZipEntries!!.nextElement()
while (entry == null && mZipEntries?.hasMoreElements() == true) {
mZipEntries?.nextElement()?.let { nextEntry ->
if (!nextEntry.isDirectory && nextEntry.name.lowercase(Locale.getDefault())
.endsWith(".apk")
) {
@ -44,6 +44,7 @@ class ZipFileApkSource(context: Context, private val mZipFileDescriptor: FileDes
mSeenApkFile = true
}
}
}
if (entry == null) {
require(mSeenApkFile) { mContext.getString(R.string.installer_error_zip_contains_no_apks) }

View File

@ -138,7 +138,7 @@ class PackageMeta : Parcelable {
return Builder(applicationInfo.packageName)
.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)
.setVersionCode(if (Utils.apiIsAtLeast(Build.VERSION_CODES.P)) packageInfo.longVersionCode else packageInfo.versionCode.toLong())
.setVersionName(packageInfo.versionName)

View File

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

View File

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

View File

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

View File

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

View File

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