diff --git a/app/src/main/java/com/vanced/manager/core/installer/AppUninstallerService.kt b/app/src/main/java/com/vanced/manager/core/installer/AppUninstallerService.kt index 46aff374..0c63ae21 100644 --- a/app/src/main/java/com/vanced/manager/core/installer/AppUninstallerService.kt +++ b/app/src/main/java/com/vanced/manager/core/installer/AppUninstallerService.kt @@ -5,6 +5,7 @@ import android.content.Intent import android.content.pm.PackageInstaller import android.os.IBinder import android.util.Log +import android.widget.Toast import androidx.localbroadcastmanager.content.LocalBroadcastManager import com.vanced.manager.ui.MainActivity @@ -12,6 +13,16 @@ class AppUninstallerService: Service() { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { when (intent?.getIntExtra(PackageInstaller.EXTRA_STATUS, -999)) { + PackageInstaller.STATUS_PENDING_USER_ACTION -> { + Toast.makeText(this, "Installing...", Toast.LENGTH_SHORT).show() + Log.d(AppInstallerService.TAG, "Requesting user confirmation for installation") + val confirmationIntent = intent.getParcelableExtra(Intent.EXTRA_INTENT) + confirmationIntent?.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + try { + startActivity(confirmationIntent) + } catch (e: Exception) { + } + } PackageInstaller.STATUS_SUCCESS -> { sendBroadCast(MainActivity.APP_UNINSTALLED) Log.d("VMpm", "Successfully uninstalled ${PackageInstaller.EXTRA_PACKAGE_NAME}") diff --git a/app/src/main/java/com/vanced/manager/ui/MainActivity.kt b/app/src/main/java/com/vanced/manager/ui/MainActivity.kt index 7196c5ec..1bf97a72 100644 --- a/app/src/main/java/com/vanced/manager/ui/MainActivity.kt +++ b/app/src/main/java/com/vanced/manager/ui/MainActivity.kt @@ -2,7 +2,6 @@ package com.vanced.manager.ui import android.content.* import android.os.Bundle -import android.util.Log import android.view.MenuItem import androidx.appcompat.widget.Toolbar import androidx.databinding.DataBindingUtil @@ -17,7 +16,7 @@ import com.vanced.manager.core.Main import com.vanced.manager.databinding.ActivityMainBinding import com.vanced.manager.ui.dialogs.DialogContainer.installAlertBuilder import com.vanced.manager.ui.dialogs.DialogContainer.launchVanced -import com.vanced.manager.ui.fragments.HomeFragment +import com.vanced.manager.ui.dialogs.DialogContainer.regularPackageInstalled import com.vanced.manager.utils.ThemeHelper.setFinalTheme class MainActivity : Main() { @@ -62,7 +61,7 @@ class MainActivity : Main() { else installAlertBuilder(getString(R.string.microg_installed), this@MainActivity) } - INSTALL_FAILED -> installAlertBuilder(intent.getStringExtra("errorMsg") as String, this@MainActivity) + INSTALL_FAILED -> regularPackageInstalled(intent.getStringExtra("errorMsg") as String, this@MainActivity) APP_UNINSTALLED -> restartActivity() APP_NOT_UNINSTALLED -> installAlertBuilder(getString(R.string.failed_uninstall) + intent.getStringExtra("pkgName"), this@MainActivity) } @@ -136,7 +135,7 @@ class MainActivity : Main() { } - private fun restartActivity() { + fun restartActivity() { startActivity(Intent(this, MainActivity::class.java)) finish() } diff --git a/app/src/main/java/com/vanced/manager/ui/dialogs/DialogContainer.kt b/app/src/main/java/com/vanced/manager/ui/dialogs/DialogContainer.kt index c5e822f8..c846f876 100644 --- a/app/src/main/java/com/vanced/manager/ui/dialogs/DialogContainer.kt +++ b/app/src/main/java/com/vanced/manager/ui/dialogs/DialogContainer.kt @@ -87,10 +87,19 @@ object DialogContainer { .show() } + fun regularPackageInstalled(msg: String, context: Context) { + AlertDialog.Builder(context) + .setTitle("Success") + .setMessage(msg) + .setPositiveButton(context.getString(R.string.close)) { _, _ -> MainActivity().restartActivity() } + .create() + .show() + } + fun launchVanced(context: Context) { val intent = Intent() intent.component = - if (PreferenceManager.getDefaultSharedPreferences(context).getString("vanced_variant", "Nonroot") == "Root") + if (PreferenceManager.getDefaultSharedPreferences(context).getString("vanced_variant", "nonroot") == "root") ComponentName("com.google.android.youtube", "com.google.android.youtube.HomeActivity") else ComponentName("com.vanced.android.youtube", "com.google.android.youtube.HomeActivity") @@ -103,8 +112,7 @@ object DialogContainer { .setNegativeButton("Cancel") { dialog, _ -> run { dialog.dismiss() - startActivity(context, Intent(context, MainActivity::class.java), null) - MainActivity().finish() + MainActivity().restartActivity() } } .setCancelable(false)