Improve installer & error handling
This commit is contained in:
@@ -162,7 +162,15 @@
|
|||||||
android:resource="@xml/paths" />
|
android:resource="@xml/paths" />
|
||||||
</provider>
|
</provider>
|
||||||
|
|
||||||
<receiver android:name=".data.receiver.PackageManagerReceiver" />
|
<receiver android:name=".data.receiver.PackageManagerReceiver">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.PACKAGE_ADDED" />
|
||||||
|
<action android:name="android.intent.action.PACKAGE_CHANGED" />
|
||||||
|
<action android:name="android.intent.action.PACKAGE_REMOVED" />
|
||||||
|
|
||||||
|
<data android:scheme="package" />
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
<receiver android:name=".data.receiver.DownloadResumeReceiver" />
|
<receiver android:name=".data.receiver.DownloadResumeReceiver" />
|
||||||
<receiver android:name=".data.receiver.DownloadPauseReceiver" />
|
<receiver android:name=".data.receiver.DownloadPauseReceiver" />
|
||||||
<receiver android:name=".data.receiver.DownloadCancelReceiver" />
|
<receiver android:name=".data.receiver.DownloadCancelReceiver" />
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ import android.os.Build
|
|||||||
import androidx.core.content.FileProvider
|
import androidx.core.content.FileProvider
|
||||||
import com.aurora.store.AuroraApplication
|
import com.aurora.store.AuroraApplication
|
||||||
import com.aurora.store.BuildConfig
|
import com.aurora.store.BuildConfig
|
||||||
|
import com.aurora.store.data.event.InstallerEvent
|
||||||
|
import com.aurora.store.util.Log
|
||||||
|
import org.greenrobot.eventbus.EventBus
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
abstract class InstallerBase(protected var context: Context) : IInstaller {
|
abstract class InstallerBase(protected var context: Context) : IInstaller {
|
||||||
@@ -59,6 +62,18 @@ abstract class InstallerBase(protected var context: Context) : IInstaller {
|
|||||||
context.startActivity(intent)
|
context.startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open fun postError(packageName: String, error: String?, extra: String?) {
|
||||||
|
Log.e("Service Error :$error")
|
||||||
|
|
||||||
|
val event = InstallerEvent.Failed(
|
||||||
|
packageName,
|
||||||
|
error,
|
||||||
|
extra
|
||||||
|
)
|
||||||
|
|
||||||
|
EventBus.getDefault().post(event)
|
||||||
|
}
|
||||||
|
|
||||||
open fun getUri(file: File): Uri {
|
open fun getUri(file: File): Uri {
|
||||||
return FileProvider.getUriForFile(
|
return FileProvider.getUriForFile(
|
||||||
context,
|
context,
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class InstallerService : Service() {
|
|||||||
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
|
||||||
val status = intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -69)
|
val status = intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -69)
|
||||||
val packageName = intent.getStringExtra(PackageInstaller.EXTRA_PACKAGE_NAME)
|
val packageName = intent.getStringExtra(PackageInstaller.EXTRA_PACKAGE_NAME)
|
||||||
val extra = intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE);
|
val extra = intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE)
|
||||||
|
|
||||||
when (status) {
|
when (status) {
|
||||||
PackageInstaller.STATUS_PENDING_USER_ACTION -> promptUser(intent)
|
PackageInstaller.STATUS_PENDING_USER_ACTION -> promptUser(intent)
|
||||||
|
|||||||
@@ -71,12 +71,11 @@ class ServiceInstaller(context: Context) : InstallerBase(context) {
|
|||||||
xInstall(packageName, uriList)
|
xInstall(packageName, uriList)
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
val event = InstallerEvent.Failed(
|
postError(
|
||||||
packageName,
|
packageName,
|
||||||
context.getString(R.string.installer_status_failure),
|
context.getString(R.string.installer_status_failure),
|
||||||
context.getString(R.string.installer_service_unavailable)
|
context.getString(R.string.installer_service_unavailable)
|
||||||
)
|
)
|
||||||
EventBus.getDefault().post(event)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,7 +99,8 @@ class ServiceInstaller(context: Context) : InstallerBase(context) {
|
|||||||
returnCode: Int,
|
returnCode: Int,
|
||||||
extra: String?
|
extra: String?
|
||||||
) {
|
) {
|
||||||
|
removeFromInstallQueue(packageName)
|
||||||
|
handleCallback(packageName, returnCode, extra)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,15 +114,12 @@ class ServiceInstaller(context: Context) : InstallerBase(context) {
|
|||||||
} catch (e: RemoteException) {
|
} catch (e: RemoteException) {
|
||||||
Log.e("Failed to connect Aurora Services")
|
Log.e("Failed to connect Aurora Services")
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Log.e(context.getString(R.string.installer_service_misconfigured))
|
postError(
|
||||||
val event = InstallerEvent.Failed(
|
|
||||||
packageName,
|
packageName,
|
||||||
context.getString(R.string.installer_status_failure),
|
context.getString(R.string.installer_status_failure),
|
||||||
context.getString(R.string.installer_service_misconfigured)
|
context.getString(R.string.installer_service_misconfigured)
|
||||||
)
|
)
|
||||||
EventBus.getDefault().post(event)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,11 +147,11 @@ class ServiceInstaller(context: Context) : InstallerBase(context) {
|
|||||||
|
|
||||||
if (service.hasPrivilegedPermissions()) {
|
if (service.hasPrivilegedPermissions()) {
|
||||||
Log.i(context.getString(R.string.installer_service_available))
|
Log.i(context.getString(R.string.installer_service_available))
|
||||||
|
|
||||||
val callback = object : IPrivilegedCallback.Stub() {
|
val callback = object : IPrivilegedCallback.Stub() {
|
||||||
|
|
||||||
override fun handleResult(packageName: String, returnCode: Int) {
|
override fun handleResult(packageName: String, returnCode: Int) {
|
||||||
Log.e("$packageName : $returnCode")
|
|
||||||
removeFromInstallQueue(packageName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handleResultX(
|
override fun handleResultX(
|
||||||
@@ -162,27 +159,8 @@ class ServiceInstaller(context: Context) : InstallerBase(context) {
|
|||||||
returnCode: Int,
|
returnCode: Int,
|
||||||
extra: String?
|
extra: String?
|
||||||
) {
|
) {
|
||||||
when (returnCode) {
|
removeFromInstallQueue(packageName)
|
||||||
PackageInstaller.STATUS_SUCCESS -> {
|
handleCallback(packageName, returnCode, extra)
|
||||||
EventBus.getDefault()
|
|
||||||
.post(InstallerEvent.Success(packageName, "Success"))
|
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
val errorString = AppInstaller.getErrorString(
|
|
||||||
context,
|
|
||||||
returnCode
|
|
||||||
)
|
|
||||||
|
|
||||||
val event = InstallerEvent.Failed(
|
|
||||||
packageName,
|
|
||||||
errorString,
|
|
||||||
extra
|
|
||||||
)
|
|
||||||
|
|
||||||
Log.e("$packageName : $errorString")
|
|
||||||
EventBus.getDefault().post(event)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,22 +174,14 @@ class ServiceInstaller(context: Context) : InstallerBase(context) {
|
|||||||
)
|
)
|
||||||
} catch (e: RemoteException) {
|
} catch (e: RemoteException) {
|
||||||
removeFromInstallQueue(packageName)
|
removeFromInstallQueue(packageName)
|
||||||
val event = InstallerEvent.Failed(
|
postError(packageName, e.localizedMessage, e.stackTraceToString())
|
||||||
packageName,
|
|
||||||
e.localizedMessage,
|
|
||||||
e.stackTraceToString()
|
|
||||||
)
|
|
||||||
EventBus.getDefault().post(event)
|
|
||||||
Log.e("Failed to connect Aurora Services")
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.e(context.getString(R.string.installer_service_misconfigured))
|
postError(
|
||||||
val event = InstallerEvent.Failed(
|
|
||||||
packageName,
|
packageName,
|
||||||
context.getString(R.string.installer_status_failure),
|
context.getString(R.string.installer_status_failure),
|
||||||
context.getString(R.string.installer_service_misconfigured)
|
context.getString(R.string.installer_service_misconfigured)
|
||||||
)
|
)
|
||||||
EventBus.getDefault().post(event)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,6 +201,24 @@ class ServiceInstaller(context: Context) : InstallerBase(context) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleCallback(packageName: String, returnCode: Int, extra: String?) {
|
||||||
|
Log.i("Services Callback : $packageName $returnCode $extra")
|
||||||
|
|
||||||
|
when (returnCode) {
|
||||||
|
PackageInstaller.STATUS_SUCCESS -> {
|
||||||
|
EventBus.getDefault().post(InstallerEvent.Success(packageName, "Success"))
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
val error = AppInstaller.getErrorString(
|
||||||
|
context,
|
||||||
|
returnCode
|
||||||
|
)
|
||||||
|
|
||||||
|
postError(packageName, error, extra)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun getUri(file: File): Uri {
|
override fun getUri(file: File): Uri {
|
||||||
val uri = FileProvider.getUriForFile(
|
val uri = FileProvider.getUriForFile(
|
||||||
context,
|
context,
|
||||||
|
|||||||
@@ -29,10 +29,8 @@ import androidx.annotation.RequiresApi
|
|||||||
import androidx.core.content.FileProvider
|
import androidx.core.content.FileProvider
|
||||||
import com.aurora.extensions.isNAndAbove
|
import com.aurora.extensions.isNAndAbove
|
||||||
import com.aurora.store.BuildConfig
|
import com.aurora.store.BuildConfig
|
||||||
import com.aurora.store.data.event.InstallerEvent
|
|
||||||
import com.aurora.store.util.Log
|
import com.aurora.store.util.Log
|
||||||
import org.apache.commons.io.IOUtils
|
import org.apache.commons.io.IOUtils
|
||||||
import org.greenrobot.eventbus.EventBus
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class SessionInstaller(context: Context) : InstallerBase(context) {
|
class SessionInstaller(context: Context) : InstallerBase(context) {
|
||||||
@@ -102,13 +100,12 @@ class SessionInstaller(context: Context) : InstallerBase(context) {
|
|||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
session.abandon()
|
session.abandon()
|
||||||
removeFromInstallQueue(packageName)
|
removeFromInstallQueue(packageName)
|
||||||
val event = InstallerEvent.Failed(
|
|
||||||
|
postError(
|
||||||
packageName,
|
packageName,
|
||||||
e.localizedMessage,
|
e.localizedMessage,
|
||||||
e.stackTraceToString()
|
e.stackTraceToString()
|
||||||
)
|
)
|
||||||
EventBus.getDefault().post(event)
|
|
||||||
Log.e("Failed to install $packageName : %s", e.message)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -216,7 +216,7 @@
|
|||||||
<string name="installer_service_available">"Aurora services is available and ready to install."</string>
|
<string name="installer_service_available">"Aurora services is available and ready to install."</string>
|
||||||
<string name="installer_service_unavailable">"Aurora services is either not installed or version is incorrect (required >= 1.0.9), kindly install it or change installer"</string>
|
<string name="installer_service_unavailable">"Aurora services is either not installed or version is incorrect (required >= 1.0.9), kindly install it or change installer"</string>
|
||||||
<string name="installer_service_misconfigured">"Aurora services not configured. Make sure service is enabled & all permissions are granted"</string>
|
<string name="installer_service_misconfigured">"Aurora services not configured. Make sure service is enabled & all permissions are granted"</string>
|
||||||
<string name="installer_status_failure">"Installation failed"</string>
|
<string name="installer_status_failure">"Installer failed"</string>
|
||||||
<string name="installer_status_failure_aborted">"Installation cancelled"</string>
|
<string name="installer_status_failure_aborted">"Installation cancelled"</string>
|
||||||
<string name="installer_status_failure_blocked">"Installation was blocked"</string>
|
<string name="installer_status_failure_blocked">"Installation was blocked"</string>
|
||||||
<string name="installer_status_failure_session">"Could not create session"</string>
|
<string name="installer_status_failure_session">"Could not create session"</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user