Platform: Switch all extensions to property access syntax

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2024-10-28 11:53:54 +05:30
parent 74f1d09f88
commit e2f2188e60
22 changed files with 94 additions and 118 deletions

View File

@@ -84,7 +84,7 @@ class AuroraApp : Application(), Configuration.Provider, ImageLoaderFactory {
DynamicColors.applyToActivitiesIfAvailable(this)
// Required for Shizuku installer
if (isPAndAbove()) HiddenApiBypass.addHiddenApiExemptions("I", "L")
if (isPAndAbove) HiddenApiBypass.addHiddenApiExemptions("I", "L")
//Create Notification Channels
NotificationUtil.createNotificationChannel(this)

View File

@@ -159,7 +159,7 @@ class UpdateHelper @Inject constructor(
.setRequiredNetworkType(NetworkType.UNMETERED)
.setRequiresBatteryNotLow(true)
if (isMAndAbove()) constraints.setRequiresDeviceIdle(true)
if (isMAndAbove) constraints.setRequiresDeviceIdle(true)
return PeriodicWorkRequestBuilder<UpdateWorker>(
repeatInterval = updateCheckInterval,

View File

@@ -93,7 +93,7 @@ class AppInstaller @Inject constructor(
installers.add(AMInstaller.getInstallerInfo(context))
}
if (isOAndAbove() && hasShizukuOrSui(context)) {
if (isOAndAbove && hasShizukuOrSui(context)) {
installers.add(ShizukuInstaller.getInstallerInfo(context))
}
@@ -109,7 +109,7 @@ class AppInstaller @Inject constructor(
return when (getCurrentInstaller(context)) {
Installer.SESSION -> {
// Silent install cannot be done on initial install and below A12
if (!PackageUtil.isInstalled(context, packageName) || !isSAndAbove()) return false
if (!PackageUtil.isInstalled(context, packageName) || !isSAndAbove) return false
// We cannot do silent updates if we are not the update owner
if (context.packageManager.getUpdateOwnerPackageNameCompat(packageName) != BuildConfig.APPLICATION_ID) return false
@@ -127,7 +127,7 @@ class AppInstaller @Inject constructor(
Installer.ROOT -> hasRootAccess()
Installer.SERVICE -> false // Deprecated
Installer.AM -> false // We cannot check if AppManager has ability to auto-update
Installer.SHIZUKU -> isOAndAbove() && hasShizukuOrSui(context) && hasShizukuPerm()
Installer.SHIZUKU -> isOAndAbove && hasShizukuOrSui(context) && hasShizukuPerm()
}
}
@@ -188,7 +188,7 @@ class AppInstaller @Inject constructor(
val intent = Intent().apply {
data = Uri.fromParts("package", packageName, null)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
if (isPAndAbove()) {
if (isPAndAbove) {
action = Intent.ACTION_DELETE
} else {
@Suppress("DEPRECATION")
@@ -211,7 +211,7 @@ class AppInstaller @Inject constructor(
Installer.SERVICE -> if (hasAuroraService(context)) serviceInstaller else defaultInstaller
Installer.AM -> if (hasAppManager(context)) amInstaller else defaultInstaller
Installer.SHIZUKU -> {
if (isOAndAbove() && hasShizukuOrSui(context) && hasShizukuPerm()) {
if (isOAndAbove && hasShizukuOrSui(context) && hasShizukuPerm()) {
shizukuInstaller
} else {
defaultInstaller

View File

@@ -206,19 +206,19 @@ class SessionInstaller @Inject constructor(
return SessionParams(SessionParams.MODE_FULL_INSTALL).apply {
setAppPackageName(packageName)
setInstallLocation(PackageInfo.INSTALL_LOCATION_AUTO)
if (isNAndAbove()) {
if (isNAndAbove) {
setOriginatingUid(Process.myUid())
}
if (isOAndAbove()) {
if (isOAndAbove) {
setInstallReason(PackageManager.INSTALL_REASON_USER)
}
if (isSAndAbove()) {
if (isSAndAbove) {
setRequireUserAction(SessionParams.USER_ACTION_NOT_REQUIRED)
}
if (isTAndAbove()) {
if (isTAndAbove) {
setPackageSource(PACKAGE_SOURCE_STORE)
}
if (isUAndAbove()) {
if (isUAndAbove) {
setInstallerPackageName(context.packageName)
setRequestUpdateOwnership(true)
setApplicationEnabledSettingPersistent()

View File

@@ -87,11 +87,11 @@ class ShizukuInstaller @Inject constructor(
}
private val packageInstaller: PackageInstaller? by lazy {
if (isSAndAbove()) {
if (isSAndAbove) {
Refine.unsafeCast<PackageInstaller>(
PackageInstallerHidden(iPackageInstaller, "com.android.vending", null, 0)
)
} else if (isOAndAbove()) {
} else if (isOAndAbove) {
Refine.unsafeCast<PackageInstaller>(
PackageInstallerHidden(iPackageInstaller, "com.android.vending", 0)
)

View File

@@ -43,7 +43,7 @@ class BlacklistProvider @Inject constructor(
set(value) = Preferences.putString(context, PREFERENCE_BLACKLIST, gson.toJson(value))
get() {
return try {
val rawBlacklist = if (isNAndAbove()) {
val rawBlacklist = if (isNAndAbove) {
val refMethod = Context::class.java.getDeclaredMethod(
"getSharedPreferences",
File::class.java,

View File

@@ -104,7 +104,7 @@ class NativeDeviceInfoProvider(val context: Context) {
setProperty("SimOperator", "38")
}
if (isHuawei() && !isExport)
if (isHuawei && !isExport)
stripHuaweiProperties(properties)
return properties

View File

@@ -62,7 +62,7 @@ class PermissionProvider(private val fragment: Fragment) :
}
PermissionType.POST_NOTIFICATIONS -> {
if (isTAndAbove()) {
if (isTAndAbove) {
permissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
}
}
@@ -99,7 +99,7 @@ class PermissionProvider(private val fragment: Fragment) :
PermissionType.INSTALL_UNKNOWN_APPS -> PackageUtil.canRequestPackageInstalls(context)
PermissionType.POST_NOTIFICATIONS -> {
if (isTAndAbove()) {
if (isTAndAbove) {
context.checkManifestPermission(Manifest.permission.POST_NOTIFICATIONS)
} else {
true
@@ -107,7 +107,7 @@ class PermissionProvider(private val fragment: Fragment) :
}
PermissionType.DOZE_WHITELIST -> {
if (isMAndAbove()) context.isIgnoringBatteryOptimizations() else true
if (isMAndAbove) context.isIgnoringBatteryOptimizations() else true
}
PermissionType.APP_LINKS -> context.isDomainVerified("play.google.com") &&

View File

@@ -70,7 +70,7 @@ class MigrationReceiver : BroadcastReceiver() {
// 63 -> 64
if (currentVersion == 2) {
if (isOAndAbove()) {
if (isOAndAbove) {
with(context.getSystemService<NotificationManager>()!!) { // !1189
deleteNotificationChannel("NOTIFICATION_CHANNEL_GENERAL")
deleteNotificationChannel("NOTIFICATION_CHANNEL_ALERT")

View File

@@ -38,7 +38,7 @@ class UnarchivePackageReceiver: BroadcastReceiver() {
lateinit var downloadHelper: DownloadHelper
override fun onReceive(context: Context?, intent: Intent?) {
if (isVAndAbove() && context != null && intent?.action == Intent.ACTION_UNARCHIVE_PACKAGE) {
if (isVAndAbove && context != null && intent?.action == Intent.ACTION_UNARCHIVE_PACKAGE) {
val packageName = intent.getStringExtra(EXTRA_UNARCHIVE_PACKAGE_NAME)!!
Log.i(TAG, "Received request to unarchive $packageName")

View File

@@ -198,7 +198,7 @@ class DownloadWorker @AssistedInject constructor(
withContext(NonCancellable) {
Log.i(TAG, "Failed downloading ${download.packageName}")
val cancelReasons = listOf(STOP_REASON_USER, STOP_REASON_CANCELLED_BY_APP)
if (isSAndAbove() && stopReason in cancelReasons) {
if (isSAndAbove && stopReason in cancelReasons) {
notifyStatus(DownloadStatus.CANCELLED)
} else {
notifyStatus(DownloadStatus.FAILED)
@@ -222,7 +222,7 @@ class DownloadWorker @AssistedInject constructor(
private fun purchase(packageName: String, versionCode: Int, offerType: Int): List<GPlayFile> {
try {
// Android 9.0+ supports key rotation, so purchase with latest certificate's hash
return if (isPAndAbove() && download.isInstalled) {
return if (isPAndAbove && download.isInstalled) {
purchaseHelper.purchase(
packageName,
versionCode,
@@ -349,7 +349,7 @@ class DownloadWorker @AssistedInject constructor(
NotificationUtil.getDownloadNotification(appContext)
}
return if (isQAndAbove()) {
return if (isQAndAbove) {
ForegroundInfo(NOTIFICATION_ID, notification, FOREGROUND_SERVICE_TYPE_DATA_SYNC)
} else {
ForegroundInfo(NOTIFICATION_ID, notification)

View File

@@ -123,7 +123,7 @@ object CertUtil {
private fun getX509Certificates(context: Context, packageName: String): List<X509Certificate> {
return try {
val packageInfo = getPackageInfoWithSignature(context, packageName)
if (isPAndAbove()) {
if (isPAndAbove) {
if (packageInfo.signingInfo!!.hasMultipleSigners()) {
packageInfo.signingInfo!!.apkContentsSigners.map { it.generateX509Certificate() }
} else {
@@ -140,7 +140,7 @@ object CertUtil {
}
private fun getPackageInfoWithSignature(context: Context, packageName: String): PackageInfo {
return if (isPAndAbove()) {
return if (isPAndAbove) {
getPackageInfo(context, packageName, PackageManager.GET_SIGNING_CERTIFICATES)
} else {
@Suppress("DEPRECATION")

View File

@@ -64,7 +64,7 @@ object PackageUtil {
}
fun isSharedLibrary(context: Context, packageName: String): Boolean {
return if (isOAndAbove()) {
return if (isOAndAbove) {
getAllSharedLibraries(context).any { it.name == packageName }
} else {
false
@@ -72,9 +72,9 @@ object PackageUtil {
}
fun isSharedLibraryInstalled(context: Context, packageName: String, versionCode: Int): Boolean {
return if (isOAndAbove()) {
return if (isOAndAbove) {
val sharedLibraries = getAllSharedLibraries(context)
if (isPAndAbove()) {
if (isPAndAbove) {
sharedLibraries.any {
it.name == packageName && it.longVersion == versionCode.toLong()
}
@@ -148,7 +148,7 @@ object PackageUtil {
}
fun getInstallUnknownAppsIntent(): Intent {
return if (isOAndAbove()) {
return if (isOAndAbove) {
Intent(
Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES,
Uri.parse("package:${BuildConfig.APPLICATION_ID}")
@@ -159,7 +159,7 @@ object PackageUtil {
}
fun canRequestPackageInstalls(context: Context): Boolean {
return if (isOAndAbove()) {
return if (isOAndAbove) {
context.packageManager.canRequestPackageInstalls()
} else {
@Suppress("DEPRECATION")
@@ -174,7 +174,7 @@ object PackageUtil {
@Throws(Exception::class)
fun getPackageInfo(context: Context, packageName: String, flags: Int = 0): PackageInfo {
return if (isTAndAbove()) {
return if (isTAndAbove) {
context.packageManager.getPackageInfo(
packageName,
PackageInfoFlags.of(flags.toLong())
@@ -200,9 +200,9 @@ object PackageUtil {
}
private fun getAllSharedLibraries(context: Context, flags: Int = 0): List<SharedLibraryInfo> {
return if (isTAndAbove()) {
return if (isTAndAbove) {
context.packageManager.getSharedLibraries(PackageInfoFlags.of(flags.toLong()))
} else if (isOAndAbove()) {
} else if (isOAndAbove) {
context.packageManager.getSharedLibraries(flags)
} else {
emptyList()

View File

@@ -49,7 +49,7 @@ class PermissionsFragment : BaseFragment<FragmentOnboardingPermissionsBinding>()
Permission(
PermissionType.INSTALL_UNKNOWN_APPS,
getString(R.string.onboarding_permission_installer),
if (isOAndAbove()) {
if (isOAndAbove) {
getString(R.string.onboarding_permission_installer_desc)
} else {
getString(R.string.onboarding_permission_installer_legacy_desc)
@@ -57,7 +57,7 @@ class PermissionsFragment : BaseFragment<FragmentOnboardingPermissionsBinding>()
)
)
if (isRAndAbove()) {
if (isRAndAbove) {
permissions.add(
Permission(
PermissionType.STORAGE_MANAGER,
@@ -77,7 +77,7 @@ class PermissionsFragment : BaseFragment<FragmentOnboardingPermissionsBinding>()
)
}
if (isMAndAbove()) {
if (isMAndAbove) {
permissions.add(
Permission(
PermissionType.DOZE_WHITELIST,
@@ -88,7 +88,7 @@ class PermissionsFragment : BaseFragment<FragmentOnboardingPermissionsBinding>()
)
}
if (isTAndAbove()) {
if (isTAndAbove) {
permissions.add(
Permission(
PermissionType.POST_NOTIFICATIONS,
@@ -99,7 +99,7 @@ class PermissionsFragment : BaseFragment<FragmentOnboardingPermissionsBinding>()
)
}
if (isSAndAbove()) {
if (isSAndAbove) {
permissions.add(
Permission(
PermissionType.APP_LINKS,

View File

@@ -79,7 +79,7 @@ class InstallerFragment : BaseFragment<FragmentInstallerBinding>() {
installerId = Preferences.getInteger(requireContext(), PREFERENCE_INSTALLER_ID)
if (isOAndAbove() && AppInstaller.hasShizukuOrSui(requireContext())) {
if (isOAndAbove && AppInstaller.hasShizukuOrSui(requireContext())) {
Shizuku.addBinderReceivedListenerSticky(shizukuAliveListener)
Shizuku.addBinderDeadListener(shizukuDeadListener)
Shizuku.addRequestPermissionResultListener(shizukuResultListener)
@@ -102,13 +102,13 @@ class InstallerFragment : BaseFragment<FragmentInstallerBinding>() {
}
}
if (isMIUI() && !isMiuiOptimizationDisabled()) {
if (isMIUI && !isMiuiOptimizationDisabled) {
findNavController().navigate(R.id.deviceMiuiSheet)
}
}
override fun onDestroy() {
if (isOAndAbove() && AppInstaller.hasShizukuOrSui(requireContext())) {
if (isOAndAbove && AppInstaller.hasShizukuOrSui(requireContext())) {
Shizuku.removeBinderReceivedListener(shizukuAliveListener)
Shizuku.removeBinderDeadListener(shizukuDeadListener)
Shizuku.removeRequestPermissionResultListener(shizukuResultListener)
@@ -119,7 +119,7 @@ class InstallerFragment : BaseFragment<FragmentInstallerBinding>() {
private fun save(installerId: Int) {
when (installerId) {
0 -> {
if (isMIUI() && !isMiuiOptimizationDisabled()) {
if (isMIUI && !isMiuiOptimizationDisabled) {
findNavController().navigate(R.id.deviceMiuiSheet)
}
this.installerId = installerId
@@ -163,7 +163,7 @@ class InstallerFragment : BaseFragment<FragmentInstallerBinding>() {
}
5 -> {
if (isOAndAbove() && AppInstaller.hasShizukuOrSui(requireContext())) {
if (isOAndAbove && AppInstaller.hasShizukuOrSui(requireContext())) {
if (shizukuAlive && AppInstaller.hasShizukuPerm()) {
this.installerId = installerId
save(PREFERENCE_INSTALLER_ID, installerId)

View File

@@ -39,7 +39,7 @@ class UIPreference : BasePreferenceFragment() {
setPreferencesFromResource(R.xml.preferences_ui, rootKey)
findPreference<Preference>("PREFERENCE_APP_LANGUAGE")?.apply {
if (isTAndAbove()) {
if (isTAndAbove) {
summary = Locale.getDefault().displayName
setOnPreferenceClickListener {
startActivity(Intent(Settings.ACTION_APP_LOCALE_SETTINGS).apply {

View File

@@ -49,7 +49,7 @@ class NetworkDialogSheet : BaseDialogSheet<SheetNetworkBinding>() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.btnAction.setOnClickListener {
if (isQAndAbove()) {
if (isQAndAbove) {
startActivity(Intent(Settings.Panel.ACTION_INTERNET_CONNECTIVITY))
} else {
try {

View File

@@ -64,7 +64,7 @@ class NetworkViewModel @Inject constructor(
val networkRequest = NetworkRequest.Builder()
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
if (isMAndAbove()) {
if (isMAndAbove) {
networkRequest.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)
}