Skip to content

Commit

Permalink
Merge pull request #2 from topjohnwu/master
Browse files Browse the repository at this point in the history
upstream changes
  • Loading branch information
Robotition authored May 10, 2024
2 parents 16d025e + eed0308 commit aac8a77
Show file tree
Hide file tree
Showing 97 changed files with 3,109 additions and 2,645 deletions.
39 changes: 38 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
run: ./gradlew --stop

test:
name: Test on API ${{ matrix.api }}
name: Test x86_64 on API ${{ matrix.api }}
runs-on: ubuntu-latest
needs: build
strategy:
Expand Down Expand Up @@ -115,3 +115,40 @@ jobs:
- name: AVD test
run: scripts/avd_test.sh ${{ matrix.api }}

test-32:
name: Test x86 on API ${{ matrix.api }}
runs-on: ubuntu-latest
needs: build
strategy:
fail-fast: false
matrix:
api: [23, 24, 25, 26, 27, 28, 29, 30]

steps:
- name: Check out
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python 3
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: ${{ github.sha }}
path: out

- name: Enable KVM group perms
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: AVD test
env:
FORCE_32_BIT: 1
run: scripts/avd_test.sh ${{ matrix.api }}
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ configurations.all {
dependencies {
implementation(project(":app:shared"))

implementation("com.github.topjohnwu:jtar:1.0.0")
implementation("com.github.topjohnwu:jtar:1.1.0")
implementation("com.github.topjohnwu:indeterminate-checkbox:1.0.7")
implementation("com.github.topjohnwu:lz4-java:1.7.1")
implementation("com.jakewharton.timber:timber:5.0.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ public static Session startSession(Context context, String pkg,
public interface Session {
// @WorkerThread
OutputStream openStream(Context context) throws IOException;
// @WorkerThread
void install(Context context, File apk) throws IOException;
// @WorkerThread @Nullable
Intent waitIntent();
}
Expand Down Expand Up @@ -167,13 +165,5 @@ public void close() throws IOException {
}
};
}

@Override
public void install(Context context, File apk) throws IOException {
try (var src = new FileInputStream(apk);
var out = openStream(context)) {
transfer(src, out);
}
}
}
}
3 changes: 3 additions & 0 deletions app/src/main/java/com/topjohnwu/magisk/core/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.app.Application
import android.content.Context
import android.content.res.Configuration
import android.os.Bundle
import android.system.Os
import androidx.profileinstaller.ProfileInstaller
import com.topjohnwu.magisk.BuildConfig
import com.topjohnwu.magisk.StubApk
Expand Down Expand Up @@ -46,6 +47,8 @@ open class App() : Application() {
Timber.e(e)
exitProcess(1)
}

Os.setenv("PATH", "${Os.getenv("PATH")}:/debug_ramdisk:/sbin", true)
}

override fun attachBaseContext(context: Context) {
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/java/com/topjohnwu/magisk/core/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import com.topjohnwu.magisk.core.repository.DBConfig
import com.topjohnwu.magisk.core.repository.PreferenceConfig
import com.topjohnwu.magisk.core.utils.refreshLocale
import com.topjohnwu.magisk.ui.theme.Theme
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.runBlocking
import java.io.File
import java.io.IOException

object Config : PreferenceConfig, DBConfig {

Expand Down Expand Up @@ -171,8 +174,14 @@ object Config : PreferenceConfig, DBConfig {

fun load(pkg: String?) {
// Only try to load prefs when fresh install and a previous package name is set
if (pkg != null && prefs.all.isEmpty()) runCatching {
context.contentResolver.openInputStream(Provider.preferencesUri(pkg))?.writeTo(prefsFile)
if (pkg != null && prefs.all.isEmpty()) {
runBlocking {
try {
context.contentResolver
.openInputStream(Provider.preferencesUri(pkg))
?.writeTo(prefsFile, dispatcher = Dispatchers.Unconfined)
} catch (ignored: IOException) {}
}
return
}

Expand Down
23 changes: 11 additions & 12 deletions app/src/main/java/com/topjohnwu/magisk/core/JobService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,25 @@ import java.util.concurrent.TimeUnit
class JobService : BaseJobService() {

private var mSession: Session? = null
private var mEngine: DownloadEngine? = null

@TargetApi(value = 34)
inner class Session(
var params: JobParameters
private var params: JobParameters
) : DownloadEngine.Session {

override val context get() = this@JobService
val engine = DownloadEngine(this)

override fun attach(id: Int, builder: Notification.Builder) {
fun updateParams(params: JobParameters) {
this.params = params
engine.reattach()
}

override fun attachNotification(id: Int, builder: Notification.Builder) {
setNotification(params, id, builder.build(), JOB_END_NOTIFICATION_POLICY_REMOVE)
}

override fun stop() {
override fun onDownloadComplete() {
jobFinished(params, false)
}
}
Expand All @@ -59,18 +64,12 @@ class JobService : BaseJobService() {
return false

val session = mSession?.also {
it.params = params
it.updateParams(params)
} ?: run {
Session(params).also { mSession = it }
}

val engine = mEngine?.also {
it.reattach()
} ?: run {
DownloadEngine(session).also { mEngine = it }
}

engine.download(subject)
session.engine.download(subject)
return true
}

Expand Down
16 changes: 7 additions & 9 deletions app/src/main/java/com/topjohnwu/magisk/core/Service.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,28 @@ import com.topjohnwu.magisk.core.download.Subject

class Service : BaseService(), DownloadEngine.Session {

private lateinit var mEngine: DownloadEngine
private var mEngine: DownloadEngine? = null
override val context get() = this

override fun onCreate() {
super.onCreate()
mEngine = DownloadEngine(this)
}

override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
if (intent.action == DownloadEngine.ACTION) {
IntentCompat
.getParcelableExtra(intent, DownloadEngine.SUBJECT_KEY, Subject::class.java)
?.let { mEngine.download(it) }
?.let { subject ->
val engine = mEngine ?: DownloadEngine(this).also { mEngine = it }
engine.download(subject)
}
}
return START_NOT_STICKY
}

override fun attach(id: Int, builder: Notification.Builder) {
override fun attachNotification(id: Int, builder: Notification.Builder) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
builder.setForegroundServiceBehavior(Notification.FOREGROUND_SERVICE_IMMEDIATE)
startForeground(id, builder.build())
}

override fun stop() {
override fun onDownloadComplete() {
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
}
}
Loading

0 comments on commit aac8a77

Please sign in to comment.