Merge branch 'android12' into 'master'

Android 12 updates

See merge request AuroraOSS/AuroraStore!153
This commit is contained in:
Rahul Patel
2021-12-18 17:34:27 +00:00
8 changed files with 60 additions and 23 deletions

View File

@@ -96,11 +96,13 @@ fun <T> Context.open(className: Class<T>, newTask: Boolean = false) {
}
fun Context.restartApp() {
val flags = if (isMAndAbove()) PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE
else PendingIntent.FLAG_CANCEL_CURRENT
val pendingIntent = PendingIntent.getActivity(
this,
1337,
Intent(this, MainActivity::class.java),
PendingIntent.FLAG_CANCEL_CURRENT
flags
)
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager

View File

@@ -52,6 +52,10 @@ fun isRAndAbove(): Boolean {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
}
fun isSAndAbove(): Boolean {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
}
fun isMIUI(): Boolean {
return getSystemProperty("ro.miui.ui.version.name").isNotEmpty()
}

View File

@@ -27,7 +27,9 @@ import android.net.Uri
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.core.content.FileProvider
import com.aurora.extensions.isMAndAbove
import com.aurora.extensions.isNAndAbove
import com.aurora.extensions.isSAndAbove
import com.aurora.store.BuildConfig
import com.aurora.store.util.Log
import org.apache.commons.io.IOUtils
@@ -63,6 +65,9 @@ class SessionInstaller(context: Context) : InstallerBase(context) {
if (isNAndAbove()) {
setOriginatingUid(android.os.Process.myUid())
}
if (isSAndAbove()) {
setRequireUserAction(SessionParams.USER_ACTION_NOT_REQUIRED)
}
}
val sessionId = packageInstaller.createSession(sessionParams)
val session = packageInstaller.openSession(sessionId)
@@ -87,11 +92,14 @@ class SessionInstaller(context: Context) : InstallerBase(context) {
}
val callBackIntent = Intent(context, InstallerService::class.java)
val flags = if (isSAndAbove())
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE else
PendingIntent.FLAG_UPDATE_CURRENT;
val pendingIntent = PendingIntent.getService(
context,
sessionId,
callBackIntent,
PendingIntent.FLAG_UPDATE_CURRENT
flags
)
Log.i("Starting install session for $packageName")

View File

@@ -32,6 +32,7 @@ import androidx.core.content.ContextCompat
import com.aurora.Constants
import com.aurora.extensions.getStyledAttributeColor
import com.aurora.extensions.isLAndAbove
import com.aurora.extensions.isMAndAbove
import com.aurora.gplayapi.data.models.App
import com.aurora.store.R
import com.aurora.store.data.downloader.DownloadManager
@@ -331,45 +332,63 @@ class NotificationService : Service() {
private fun getPauseIntent(groupId: Int): PendingIntent {
val intent = Intent(this, DownloadPauseReceiver::class.java)
intent.putExtra(Constants.FETCH_GROUP_ID, groupId)
return PendingIntent.getBroadcast(this, groupId, intent, PendingIntent.FLAG_UPDATE_CURRENT)
val flags = if (isMAndAbove())
PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE
else PendingIntent.FLAG_CANCEL_CURRENT
return PendingIntent.getBroadcast(this, groupId, intent, flags)
}
private fun getResumeIntent(groupId: Int): PendingIntent {
val intent = Intent(this, DownloadResumeReceiver::class.java)
intent.putExtra(Constants.FETCH_GROUP_ID, groupId)
return PendingIntent.getBroadcast(this, groupId, intent, PendingIntent.FLAG_UPDATE_CURRENT)
val flags = if (isMAndAbove())
PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE
else PendingIntent.FLAG_CANCEL_CURRENT
return PendingIntent.getBroadcast(this, groupId, intent, flags)
}
private fun getCancelIntent(groupId: Int): PendingIntent {
val intent = Intent(this, DownloadCancelReceiver::class.java)
intent.putExtra(Constants.FETCH_GROUP_ID, groupId)
return PendingIntent.getBroadcast(this, groupId, intent, PendingIntent.FLAG_UPDATE_CURRENT)
val flags = if (isMAndAbove())
PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE
else PendingIntent.FLAG_CANCEL_CURRENT
return PendingIntent.getBroadcast(this, groupId, intent, flags)
}
private fun getContentIntentForDetails(app: App?): PendingIntent {
val intent = Intent(this, AppDetailsActivity::class.java)
intent.putExtra(Constants.STRING_EXTRA, gson.toJson(app))
val flags = if (isMAndAbove())
PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE
else PendingIntent.FLAG_CANCEL_CURRENT
return PendingIntent.getActivity(
this,
packageName.hashCode(),
intent,
PendingIntent.FLAG_UPDATE_CURRENT
flags
)
}
private fun getContentIntentForDownloads(): PendingIntent {
val intent = Intent(this, DownloadActivity::class.java)
return PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
val flags = if (isMAndAbove())
PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE
else PendingIntent.FLAG_CANCEL_CURRENT
return PendingIntent.getActivity(this, 0, intent, flags)
}
private fun getInstallIntent(packageName: String, versionCode: String): PendingIntent {
val intent = Intent(this, InstallReceiver::class.java)
intent.putExtra(Constants.STRING_EXTRA, packageName)
val flags = if (isMAndAbove())
PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE
else PendingIntent.FLAG_CANCEL_CURRENT
return PendingIntent.getBroadcast(
this,
packageName.hashCode(),
intent,
PendingIntent.FLAG_UPDATE_CURRENT
flags
)
}