Put Privileged callbacks to use
This commit is contained in:
@@ -21,4 +21,10 @@ interface IPrivilegedCallback {
|
|||||||
in String packageName,
|
in String packageName,
|
||||||
in int returnCode
|
in int returnCode
|
||||||
);
|
);
|
||||||
|
|
||||||
|
void handleResultX(
|
||||||
|
in String packageName,
|
||||||
|
in int returnCode,
|
||||||
|
in String extra
|
||||||
|
);
|
||||||
}
|
}
|
||||||
@@ -20,13 +20,28 @@
|
|||||||
package com.aurora.store.data.installer
|
package com.aurora.store.data.installer
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.pm.PackageInstaller
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import com.aurora.store.data.SingletonHolder
|
import com.aurora.store.R
|
||||||
import com.aurora.store.util.Preferences
|
import com.aurora.store.util.Preferences
|
||||||
import com.aurora.store.util.Preferences.PREFERENCE_INSTALLER_ID
|
import com.aurora.store.util.Preferences.PREFERENCE_INSTALLER_ID
|
||||||
|
|
||||||
open class AppInstaller constructor(var context: Context) {
|
open class AppInstaller constructor(var context: Context) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun getErrorString(context: Context, status: Int): String {
|
||||||
|
return when (status) {
|
||||||
|
PackageInstaller.STATUS_FAILURE_ABORTED -> context.getString(R.string.installer_status_user_action)
|
||||||
|
PackageInstaller.STATUS_FAILURE_BLOCKED -> context.getString(R.string.installer_status_failure_blocked)
|
||||||
|
PackageInstaller.STATUS_FAILURE_CONFLICT -> context.getString(R.string.installer_status_failure_conflict)
|
||||||
|
PackageInstaller.STATUS_FAILURE_INCOMPATIBLE -> context.getString(R.string.installer_status_failure_incompatible)
|
||||||
|
PackageInstaller.STATUS_FAILURE_INVALID -> context.getString(R.string.installer_status_failure_invalid)
|
||||||
|
PackageInstaller.STATUS_FAILURE_STORAGE -> context.getString(R.string.installer_status_failure_storage)
|
||||||
|
else -> context.getString(R.string.installer_status_failure)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun getPreferredInstaller(): IInstaller {
|
fun getPreferredInstaller(): IInstaller {
|
||||||
val prefValue = Preferences.getInteger(
|
val prefValue = Preferences.getInteger(
|
||||||
context,
|
context,
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import android.content.pm.PackageInstaller
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import com.aurora.store.R
|
|
||||||
import com.aurora.store.data.event.InstallerEvent
|
import com.aurora.store.data.event.InstallerEvent
|
||||||
import com.aurora.store.util.Log
|
import com.aurora.store.util.Log
|
||||||
import org.greenrobot.eventbus.EventBus
|
import org.greenrobot.eventbus.EventBus
|
||||||
@@ -37,6 +36,7 @@ class InstallerService : Service() {
|
|||||||
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)
|
||||||
else -> postStatus(status, packageName, extra)
|
else -> postStatus(status, packageName, extra)
|
||||||
@@ -68,25 +68,16 @@ class InstallerService : Service() {
|
|||||||
EventBus.getDefault().post(InstallerEvent.Success(packageName, "Success"))
|
EventBus.getDefault().post(InstallerEvent.Success(packageName, "Success"))
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
val errorString = getErrorString(status)
|
val errorString =
|
||||||
|
AppInstaller.getErrorString(this, status)
|
||||||
|
val event =
|
||||||
|
InstallerEvent.Failed(packageName, errorString, extra)
|
||||||
Log.e("$packageName : $errorString")
|
Log.e("$packageName : $errorString")
|
||||||
EventBus.getDefault().post(InstallerEvent.Failed(packageName, errorString, extra))
|
EventBus.getDefault().post(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getErrorString(status: Int): String {
|
|
||||||
return when (status) {
|
|
||||||
PackageInstaller.STATUS_FAILURE_ABORTED -> getString(R.string.installer_status_user_action)
|
|
||||||
PackageInstaller.STATUS_FAILURE_BLOCKED -> getString(R.string.installer_status_failure_blocked)
|
|
||||||
PackageInstaller.STATUS_FAILURE_CONFLICT -> getString(R.string.installer_status_failure_conflict)
|
|
||||||
PackageInstaller.STATUS_FAILURE_INCOMPATIBLE -> getString(R.string.installer_status_failure_incompatible)
|
|
||||||
PackageInstaller.STATUS_FAILURE_INVALID -> getString(R.string.installer_status_failure_invalid)
|
|
||||||
PackageInstaller.STATUS_FAILURE_STORAGE -> getString(R.string.installer_status_failure_storage)
|
|
||||||
else -> getString(R.string.installer_status_failure)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onBind(intent: Intent): IBinder? {
|
override fun onBind(intent: Intent): IBinder? {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import android.content.ComponentName
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.ServiceConnection
|
import android.content.ServiceConnection
|
||||||
|
import android.content.pm.PackageInstaller
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
@@ -80,6 +81,67 @@ class ServiceInstaller(context: Context) : InstallerBase(context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun uninstall(packageName: String) {
|
||||||
|
val serviceConnection = object : ServiceConnection {
|
||||||
|
override fun onServiceConnected(name: ComponentName, binder: IBinder) {
|
||||||
|
val service = IPrivilegedService.Stub.asInterface(binder)
|
||||||
|
|
||||||
|
if (service.hasPrivilegedPermissions()) {
|
||||||
|
Log.i(context.getString(R.string.installer_service_available))
|
||||||
|
|
||||||
|
val callback = object : IPrivilegedCallback.Stub() {
|
||||||
|
|
||||||
|
override fun handleResult(packageName: String, returnCode: Int) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun handleResultX(
|
||||||
|
packageName: String,
|
||||||
|
returnCode: Int,
|
||||||
|
extra: String?
|
||||||
|
) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
service.deletePackageX(
|
||||||
|
packageName,
|
||||||
|
2,
|
||||||
|
BuildConfig.APPLICATION_ID,
|
||||||
|
callback
|
||||||
|
)
|
||||||
|
} catch (e: RemoteException) {
|
||||||
|
Log.e("Failed to connect Aurora Services")
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Log.e(context.getString(R.string.installer_service_misconfigured))
|
||||||
|
val event = InstallerEvent.Failed(
|
||||||
|
packageName,
|
||||||
|
context.getString(R.string.installer_status_failure),
|
||||||
|
context.getString(R.string.installer_service_misconfigured)
|
||||||
|
)
|
||||||
|
EventBus.getDefault().post(event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onServiceDisconnected(name: ComponentName) {
|
||||||
|
removeFromInstallQueue(packageName)
|
||||||
|
Log.e("Disconnected from Aurora Services")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val intent = Intent(PRIVILEGED_EXTENSION_SERVICE_INTENT)
|
||||||
|
intent.setPackage(PRIVILEGED_EXTENSION_PACKAGE_NAME)
|
||||||
|
|
||||||
|
context.bindService(
|
||||||
|
intent,
|
||||||
|
serviceConnection,
|
||||||
|
Context.BIND_AUTO_CREATE
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
|
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
|
||||||
private fun xInstall(packageName: String, uriList: List<Uri>) {
|
private fun xInstall(packageName: String, uriList: List<Uri>) {
|
||||||
val serviceConnection = object : ServiceConnection {
|
val serviceConnection = object : ServiceConnection {
|
||||||
@@ -89,10 +151,39 @@ 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")
|
Log.e("$packageName : $returnCode")
|
||||||
removeFromInstallQueue(packageName)
|
removeFromInstallQueue(packageName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun handleResultX(
|
||||||
|
packageName: String,
|
||||||
|
returnCode: Int,
|
||||||
|
extra: String?
|
||||||
|
) {
|
||||||
|
when (returnCode) {
|
||||||
|
PackageInstaller.STATUS_SUCCESS -> {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -105,15 +196,12 @@ class ServiceInstaller(context: Context) : InstallerBase(context) {
|
|||||||
)
|
)
|
||||||
} catch (e: RemoteException) {
|
} catch (e: RemoteException) {
|
||||||
removeFromInstallQueue(packageName)
|
removeFromInstallQueue(packageName)
|
||||||
EventBus
|
val event = InstallerEvent.Failed(
|
||||||
.getDefault()
|
packageName,
|
||||||
.post(
|
e.localizedMessage,
|
||||||
InstallerEvent.Failed(
|
e.stackTraceToString()
|
||||||
packageName,
|
)
|
||||||
e.localizedMessage,
|
EventBus.getDefault().post(event)
|
||||||
e.stackTraceToString()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
Log.e("Failed to connect Aurora Services")
|
Log.e("Failed to connect Aurora Services")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user