Add unsupport env check

This commit is contained in:
vvb2060 2020-10-30 16:43:11 +08:00 committed by John Wu
parent 331b1f542f
commit bba2ac8817
6 changed files with 83 additions and 12 deletions

View File

@ -1,6 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.topjohnwu.shared">
package="com.topjohnwu.shared"
android:installLocation="internalOnly">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
@ -16,7 +17,6 @@
<application
android:allowBackup="false"
android:installLocation="internalOnly"
android:label="Magisk"
android:requestLegacyExternalStorage="true"
android:supportsRtl="true"

View File

@ -3,6 +3,8 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.topjohnwu.magisk">
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />
<application
android:name=".core.App"
android:extractNativeLibs="true"

View File

@ -48,6 +48,7 @@ object Const {
object ID {
const val FETCH_ZIP = 2
const val SELECT_FILE = 3
const val UNINSTALL_APP = 4
const val MAX_ACTIVITY_RESULT = 10
// notifications

View File

@ -2,6 +2,8 @@ package com.topjohnwu.magisk.core
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import com.topjohnwu.magisk.BuildConfig.APPLICATION_ID
import com.topjohnwu.magisk.R
@ -11,9 +13,12 @@ import com.topjohnwu.magisk.ui.MainActivity
import com.topjohnwu.magisk.view.Notifications
import com.topjohnwu.magisk.view.Shortcuts
import com.topjohnwu.superuser.Shell
import java.util.concurrent.CountDownLatch
open class SplashActivity : Activity() {
private val latch = CountDownLatch(1)
override fun attachBaseContext(base: Context) {
super.attachBaseContext(base.wrap())
}
@ -36,7 +41,8 @@ open class SplashActivity : Activity() {
if (Config.suManager.isNotEmpty())
Config.suManager = ""
pkg ?: return
Shell.su("(pm uninstall $pkg)& >/dev/null 2>&1").exec()
val uninstall = Shell.su("(pm uninstall $pkg)& >/dev/null 2>&1").exec()
if (!uninstall.isSuccess) uninstallApp(pkg)
}
}
@ -58,6 +64,21 @@ open class SplashActivity : Activity() {
finish()
}
@Suppress("DEPRECATION")
private fun uninstallApp(pkg: String) {
val uri = Uri.Builder().scheme("package").opaquePart(pkg).build()
val intent = Intent(Intent.ACTION_UNINSTALL_PACKAGE, uri)
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true)
startActivityForResult(intent, Const.ID.UNINSTALL_APP)
latch.await()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == Const.ID.UNINSTALL_APP) {
if (resultCode != RESULT_CANCELED) latch.countDown()
} else super.onActivityResult(requestCode, resultCode, data)
}
companion object {
var DONE = false
}

View File

@ -1,6 +1,7 @@
package com.topjohnwu.magisk.ui
import android.content.Intent
import android.content.pm.ApplicationInfo
import android.os.Build
import android.os.Bundle
import android.view.MenuItem
@ -17,6 +18,7 @@ import com.topjohnwu.magisk.arch.BaseUIActivity
import com.topjohnwu.magisk.arch.BaseViewModel
import com.topjohnwu.magisk.arch.ReselectionTarget
import com.topjohnwu.magisk.core.*
import com.topjohnwu.magisk.core.tasks.HideAPK
import com.topjohnwu.magisk.databinding.ActivityMainMd2Binding
import com.topjohnwu.magisk.ktx.startAnimations
import com.topjohnwu.magisk.ui.home.HomeFragmentDirections
@ -24,7 +26,9 @@ import com.topjohnwu.magisk.utils.HideableBehavior
import com.topjohnwu.magisk.utils.Utils
import com.topjohnwu.magisk.view.MagiskDialog
import com.topjohnwu.magisk.view.Shortcuts
import com.topjohnwu.superuser.Shell
import org.koin.androidx.viewmodel.ext.android.viewModel
import java.io.File
class MainViewModel : BaseViewModel()
@ -81,7 +85,7 @@ open class MainActivity : BaseUIActivity<MainViewModel, ActivityMainMd2Binding>(
(currentFragment as? ReselectionTarget)?.onReselected()
}
val section = if (intent.action == ACTION_APPLICATION_PREFERENCES) Const.Nav.SETTINGS
val section = if (intent.action == Intent.ACTION_APPLICATION_PREFERENCES) Const.Nav.SETTINGS
else intent.getStringExtra(Const.Key.OPEN_SECTION)
getScreen(section)?.navigate()
@ -188,7 +192,49 @@ open class MainActivity : BaseUIActivity<MainViewModel, ActivityMainMd2Binding>(
.applyTitle(R.string.unsupport_magisk_title)
.applyMessage(R.string.unsupport_magisk_msg, Const.Version.MIN_VERSION)
.applyButton(MagiskDialog.ButtonType.POSITIVE) { titleRes = android.R.string.ok }
.cancellable(true)
.cancellable(false)
.reveal()
}
if (Info.env.isActive && System.getenv("PATH")
?.split(':')
?.filterNot { File("$it/magisk").exists() }
?.any { File("$it/su").exists() } == true) {
MagiskDialog(this)
.applyTitle(R.string.unsupport_other_su_title)
.applyMessage(R.string.unsupport_other_su_msg)
.applyButton(MagiskDialog.ButtonType.POSITIVE) { titleRes = android.R.string.ok }
.cancellable(false)
.reveal()
}
if (applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM != 0) {
MagiskDialog(this)
.applyTitle(R.string.unsupport_system_app_title)
.applyMessage(R.string.unsupport_system_app_msg)
.applyButton(MagiskDialog.ButtonType.POSITIVE) { titleRes = android.R.string.ok }
.cancellable(false)
.reveal()
}
if (applicationInfo.flags and ApplicationInfo.FLAG_EXTERNAL_STORAGE != 0) {
MagiskDialog(this)
.applyTitle(R.string.unsupport_external_storage_title)
.applyMessage(R.string.unsupport_external_storage_msg)
.applyButton(MagiskDialog.ButtonType.POSITIVE) { titleRes = android.R.string.ok }
.cancellable(false)
.reveal()
}
if (isRunningAsStub && !Shell.rootAccess()) {
MagiskDialog(this)
.applyTitle(R.string.unsupport_nonroot_stub_title)
.applyMessage(R.string.unsupport_nonroot_stub_msg)
.applyButton(MagiskDialog.ButtonType.POSITIVE) {
titleRes = R.string.install
onClick { HideAPK.restore(this@MainActivity) }
}
.cancellable(false)
.reveal()
}
}
@ -212,11 +258,4 @@ open class MainActivity : BaseUIActivity<MainViewModel, ActivityMainMd2Binding>(
.reveal()
}
}
companion object {
private val ACTION_APPLICATION_PREFERENCES get() =
if (Build.VERSION.SDK_INT >= 24) Intent.ACTION_APPLICATION_PREFERENCES
else "???"
}
}

View File

@ -230,6 +230,14 @@
<string name="authenticate">Authenticate</string>
<string name="unsupport_magisk_title">Unsupported Magisk Version</string>
<string name="unsupport_magisk_msg">This version of the app does not support Magisk version lower than %1$s.\n\nThe app will behave as if no Magisk is installed, please upgrade Magisk as soon as possible.</string>
<string name="unsupport_other_su_title">Other su found on this device</string>
<string name="unsupport_other_su_msg">The existence of other su may cause Magisk to run abnormally and MagiskHide to be invalid. Please remove other su.</string>
<string name="unsupport_system_app_title">Unsupported run as system app</string>
<string name="unsupport_system_app_msg">Magisk does not support run as system app, which breaks its hidden feature. Please revert to user app.</string>
<string name="unsupport_external_storage_title">Unsupported installed on external storage</string>
<string name="unsupport_external_storage_msg">Magisk is installed to a non-standard location. Please move app to internal storage.</string>
<string name="unsupport_nonroot_stub_title">@string/settings_restore_app_title</string>
<string name="unsupport_nonroot_stub_msg">Root is lost, the application can not continue to work in the hidden state, please restore it back to the original APK.</string>
<string name="external_rw_permission_denied">Grant storage permission to enable this functionality</string>
<string name="add_shortcut_title">Add shortcut to home screen</string>
<string name="add_shortcut_msg">After hiding this app, its name and icon might become difficult to recognize. Do you want to add a pretty shortcut to the home screen?</string>