mirror of
https://github.com/Michatec/michas-droid.git
synced 2026-05-31 02:12:42 +02:00
Better install/uninstall events handling
This commit is contained in:
+8
-8
@@ -69,16 +69,16 @@ android {
|
|||||||
ignore 'InvalidVectorPath'
|
ignore 'InvalidVectorPath'
|
||||||
}
|
}
|
||||||
|
|
||||||
def signingPropertiesFile = rootProject.file('keystore.properties')
|
def keystorePropertiesFile = rootProject.file('keystore.properties')
|
||||||
if (signingPropertiesFile.exists()) {
|
if (keystorePropertiesFile.exists()) {
|
||||||
def signingProperties = new Properties()
|
def keystoreProperties = new Properties()
|
||||||
signingProperties.load(signingPropertiesFile.newDataInputStream())
|
keystoreProperties.load(keystorePropertiesFile.newDataInputStream())
|
||||||
|
|
||||||
def signing = [
|
def signing = [
|
||||||
storeFile: signingProperties['store.file'],
|
storeFile: keystoreProperties['store.file'],
|
||||||
storePassword: signingProperties['store.password'],
|
storePassword: keystoreProperties['store.password'],
|
||||||
keyAlias: signingProperties['key.alias'],
|
keyAlias: keystoreProperties['key.alias'],
|
||||||
keyPassword: signingProperties['key.password']
|
keyPassword: keystoreProperties['key.password']
|
||||||
]
|
]
|
||||||
|
|
||||||
if (!signing.any { _, v -> v == null }) {
|
if (!signing.any { _, v -> v == null }) {
|
||||||
|
|||||||
@@ -29,9 +29,9 @@ import java.net.Proxy
|
|||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
class MainApplication: Application() {
|
class MainApplication: Application() {
|
||||||
private fun PackageInfo.toInstalledItem(): InstalledItem? {
|
private fun PackageInfo.toInstalledItem(): InstalledItem {
|
||||||
val signatureString = singleSignature?.let(Utils::calculateHash).orEmpty()
|
val signatureString = singleSignature?.let(Utils::calculateHash).orEmpty()
|
||||||
return InstalledItem(packageName, versionName, versionCodeCompat, signatureString)
|
return InstalledItem(packageName, versionName.orEmpty(), versionCodeCompat, signatureString)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun attachBaseContext(base: Context) {
|
override fun attachBaseContext(base: Context) {
|
||||||
@@ -46,10 +46,52 @@ class MainApplication: Application() {
|
|||||||
ProductPreferences.init(this)
|
ProductPreferences.init(this)
|
||||||
RepositoryUpdater.init(this)
|
RepositoryUpdater.init(this)
|
||||||
listenApplications()
|
listenApplications()
|
||||||
|
listenPreferences()
|
||||||
|
|
||||||
Coil.setImageLoader(ImageLoader.Builder(this)
|
Coil.setImageLoader(ImageLoader.Builder(this)
|
||||||
.callFactory(CoilDownloader.Factory(Cache.getImagesDir(this))).build())
|
.callFactory(CoilDownloader.Factory(Cache.getImagesDir(this))).build())
|
||||||
|
|
||||||
|
if (databaseUpdated) {
|
||||||
|
forceSyncAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
Cache.cleanup(this)
|
||||||
|
updateSyncJob()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun listenApplications() {
|
||||||
|
registerReceiver(object: BroadcastReceiver() {
|
||||||
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
val packageName = intent.data?.let { if (it.scheme == "package") it.schemeSpecificPart else null }
|
||||||
|
if (packageName != null) {
|
||||||
|
when (intent.action.orEmpty()) {
|
||||||
|
Intent.ACTION_PACKAGE_ADDED,
|
||||||
|
Intent.ACTION_PACKAGE_REMOVED -> {
|
||||||
|
val packageInfo = try {
|
||||||
|
packageManager.getPackageInfo(packageName, Android.PackageManager.signaturesFlag)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
if (packageInfo != null) {
|
||||||
|
Database.InstalledAdapter.put(packageInfo.toInstalledItem())
|
||||||
|
} else {
|
||||||
|
Database.InstalledAdapter.delete(packageName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, IntentFilter().apply {
|
||||||
|
addAction(Intent.ACTION_PACKAGE_ADDED)
|
||||||
|
addAction(Intent.ACTION_PACKAGE_REMOVED)
|
||||||
|
addDataScheme("package")
|
||||||
|
})
|
||||||
|
val installedItems = packageManager.getInstalledPackages(Android.PackageManager.signaturesFlag)
|
||||||
|
.map { it.toInstalledItem() }
|
||||||
|
Database.InstalledAdapter.putAll(installedItems)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun listenPreferences() {
|
||||||
updateProxy()
|
updateProxy()
|
||||||
var lastAutoSync = Preferences[Preferences.Key.AutoSync]
|
var lastAutoSync = Preferences[Preferences.Key.AutoSync]
|
||||||
var lastUpdateUnstable = Preferences[Preferences.Key.UpdateUnstable]
|
var lastUpdateUnstable = Preferences[Preferences.Key.UpdateUnstable]
|
||||||
@@ -70,40 +112,6 @@ class MainApplication: Application() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (databaseUpdated) {
|
|
||||||
forceSyncAll()
|
|
||||||
}
|
|
||||||
|
|
||||||
Cache.cleanup(this)
|
|
||||||
updateSyncJob()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun listenApplications() {
|
|
||||||
registerReceiver(object: BroadcastReceiver() {
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
|
||||||
val packageName = intent.data?.let { if (it.scheme == "package") it.schemeSpecificPart else null }
|
|
||||||
if (packageName != null) {
|
|
||||||
when (intent.action.orEmpty()) {
|
|
||||||
Intent.ACTION_PACKAGE_ADDED -> {
|
|
||||||
val installedItem = packageManager.getPackageInfo(packageName,
|
|
||||||
Android.PackageManager.signaturesFlag)?.toInstalledItem()
|
|
||||||
installedItem?.let(Database.InstalledAdapter::put)
|
|
||||||
}
|
|
||||||
Intent.ACTION_PACKAGE_REMOVED -> {
|
|
||||||
Database.InstalledAdapter.delete(packageName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, IntentFilter().apply {
|
|
||||||
addAction(Intent.ACTION_PACKAGE_ADDED)
|
|
||||||
addAction(Intent.ACTION_PACKAGE_REMOVED)
|
|
||||||
addDataScheme("package")
|
|
||||||
})
|
|
||||||
val installedItems = packageManager.getInstalledPackages(Android.PackageManager.signaturesFlag)
|
|
||||||
.mapNotNull { it.toInstalledItem() }
|
|
||||||
Database.InstalledAdapter.putAll(installedItems)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateSyncJob() {
|
private fun updateSyncJob() {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package nya.kitsunyan.foxydroid.database
|
package nya.kitsunyan.foxydroid.database
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.content.ContentValues
|
import android.content.ContentValues
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
@@ -386,7 +385,6 @@ object Database {
|
|||||||
.use { it.firstOrNull()?.getInt(0) ?: 0 }
|
.use { it.firstOrNull()?.getInt(0) ?: 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("Recycle")
|
|
||||||
fun query(installed: Boolean, updates: Boolean, searchQuery: String,
|
fun query(installed: Boolean, updates: Boolean, searchQuery: String,
|
||||||
category: String, signal: CancellationSignal?): Cursor {
|
category: String, signal: CancellationSignal?): Cursor {
|
||||||
val builder = QueryBuilder()
|
val builder = QueryBuilder()
|
||||||
@@ -507,8 +505,10 @@ object Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun delete(packageName: String) {
|
fun delete(packageName: String) {
|
||||||
db.delete(Schema.Installed.name, "${Schema.Installed.ROW_PACKAGE_NAME} = ?", arrayOf(packageName))
|
val count = db.delete(Schema.Installed.name, "${Schema.Installed.ROW_PACKAGE_NAME} = ?", arrayOf(packageName))
|
||||||
notifyChanged(Subject.Products)
|
if (count > 0) {
|
||||||
|
notifyChanged(Subject.Products)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun transform(cursor: Cursor): InstalledItem {
|
private fun transform(cursor: Cursor): InstalledItem {
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ class ProductFragment(): Fragment(), ProductAdapter.Callbacks {
|
|||||||
if (recyclerView != null) {
|
if (recyclerView != null) {
|
||||||
(recyclerView.adapter as ProductAdapter).setStatus(recyclerView, status)
|
(recyclerView.adapter as ProductAdapter).setStatus(recyclerView, status)
|
||||||
}
|
}
|
||||||
if (state is DownloadService.State.Success) {
|
if (state is DownloadService.State.Success && isResumed) {
|
||||||
state.consume()
|
state.consume()
|
||||||
screenActivity.startPackageInstaller(state.release.cacheFileName)
|
screenActivity.startPackageInstaller(state.release.cacheFileName)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user