Skip to content

Commit

Permalink
Run code cleanup in Android Studio (#1020)
Browse files Browse the repository at this point in the history
* Run code cleanup in Android Studio

* update comment

* update lowercase call

* Update CI release branch
  • Loading branch information
atavism authored Mar 14, 2024
1 parent 4ed680b commit 731c028
Show file tree
Hide file tree
Showing 26 changed files with 60 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish releases

on:
push:
branches: [ atavism/android-agp-8.0 ]
branches: [ main ]
tags:
- '*'

Expand Down
7 changes: 2 additions & 5 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ android {
enableSplit = true
}
language {
// Specifies that the app bundle should not support
// configuration APKs for language resources. These
// resources are instead packaged with each base and
// dynamic feature APK.
//
// Specifies that the app bundle should not support configuration APKs for language resources.
// These resources are instead packaged with each base and dynamic feature APK.
// See https://stackoverflow.com/a/52733674
enableSplit = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected Context getTargetContext() {
public void setupTempDir() {
tempDir = new File(
getTargetContext().getCacheDir(),
new Long(new Random().nextLong()).toString()
Long.valueOf(new Random().nextLong()).toString()
);
tempDir.mkdirs();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public boolean checkForCondition() {
device.registerWatcher("ANR2", new UiWatcher() {
@Override
public boolean checkForCondition() {
Log.d(LOG_TAG, "Checking if there's an 'app isn\'t responding' dialog");
Log.d(LOG_TAG, "Checking if there's an 'app isn't responding' dialog");
UiObject window = new UiObject(new UiSelector().packageName("android")
.textContains("isn't responding."));
if (window.exists()) {
Log.d(LOG_TAG, "There's an 'app isn\'t responding' dialog");
Log.d(LOG_TAG, "There's an 'app isn't responding' dialog");
String errorText = null;
try {
errorText = window.getText();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,12 @@ class MainActivity : FlutterActivity(), MethodChannel.MethodCallHandler,
response: Response,
user: ProUser,
) {
val devices = user?.devices
val devices = user.devices
val deviceID = LanternApp.getSession().deviceID()
// if the payment test mode is enabled
// then do nothing To avoid restarting app while debugging
// we are setting static user for payment mode
if (user?.isProUser == false || LanternApp.getSession().isPaymentTestMode) return
if (user.isProUser == false || LanternApp.getSession().isPaymentTestMode) return

// Switch to free account if device it not linked
devices?.filter { it.id == deviceID }?.run {
Expand Down Expand Up @@ -386,7 +386,7 @@ class MainActivity : FlutterActivity(), MethodChannel.MethodCallHandler,
var key = countryCode
var survey = loconf.surveys!![key]
if (survey == null) {
key = countryCode.toLowerCase()
key = countryCode.lowercase()
survey = loconf.surveys!![key]
}
if (survey == null || !survey.enabled) {
Expand All @@ -408,13 +408,13 @@ class MainActivity : FlutterActivity(), MethodChannel.MethodCallHandler,
)
val userType = survey.userType
if (userType != null) {
if (userType == "free" && LanternApp.getSession().isProUser()) {
if (userType == "free" && LanternApp.getSession().isProUser) {
Logger.debug(
SURVEY_TAG,
"Not showing messages targetted to free users to Pro users",
)
return
} else if (userType == "pro" && !LanternApp.getSession().isProUser()) {
} else if (userType == "pro" && !LanternApp.getSession().isProUser) {
Logger.debug(
SURVEY_TAG,
"Not showing messages targetted to free users to Pro users",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ open class FreeKassaActivity : BaseFragmentActivity() {

@ViewById
@JvmField
protected var progressBar: ProgressBar? = null;
protected var progressBar: ProgressBar? = null

@Extra
@JvmField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ open class WebViewActivity : BaseFragmentActivity() {
}

private fun hideProgressDialog() {
dialog?.let { if (it.isShowing()) it.dismiss() }
dialog?.let { if (it.isShowing) it.dismiss() }
}

private fun openWebview(url: String) {
Expand All @@ -69,16 +69,16 @@ open class WebViewActivity : BaseFragmentActivity() {
}
})
val settings = webView.getSettings()
settings.setLoadWithOverviewMode(true)
settings.setUseWideViewPort(true)
settings.setJavaScriptEnabled(true)
settings.setPluginState(PluginState.ON)
settings.loadWithOverviewMode = true
settings.useWideViewPort = true
settings.javaScriptEnabled = true
settings.pluginState = PluginState.ON
settings.setSupportZoom(false)
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY)
webView.loadUrl(url)
}

public fun closeWebView(view: View) {
fun closeWebView(view: View) {
finish()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ open class ProgressDialogFragment : DialogFragment() {

@NonNull
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val msgId: Int? = getArguments()?.getInt("msgId")
val msgId: Int? = arguments?.getInt("msgId")
val dialog = ProgressDialog(requireContext())
if (msgId != null) dialog.setMessage(getString(msgId))
return dialog
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.getlantern.lantern.model

data class AccountInitializationStatus(val status: AccountInitializationStatus.Status) {
data class AccountInitializationStatus(val status: Status) {

enum class Status {
PROCESSING, SUCCESS, FAILURE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class InAppBilling(
it.startConnection(
object : BillingClientStateListener {
override fun onBillingSetupFinished(billingResult: BillingResult) {
val responseCode = billingResult.getResponseCode()
val responseCode = billingResult.responseCode
Logger.d(TAG, "onBillingSetupFinished with response code: $responseCode")
if (billingResult.responseCodeOK()) {
updateSkus()
Expand Down Expand Up @@ -128,7 +128,7 @@ class InAppBilling(
launchBillingFlow(activity, params)
.takeIf { billingResult -> !billingResult.responseCodeOK() }
?.let { result ->
Logger.e(TAG, "Unexpected response code trying to launch billing flow: ${result.getResponseCode()}")
Logger.e(TAG, "Unexpected response code trying to launch billing flow: ${result.responseCode}")
}
}
}
Expand Down Expand Up @@ -164,11 +164,11 @@ class InAppBilling(
plans.clear()
skus.clear()
skuDetailsList?.forEach {
val currency = it.getPriceCurrencyCode().lowercase()
val id = it.getSku()
val years = it.getSku().substring(0, 1)
val price = it.getPriceAmountMicros() / 10000
val priceWithoutTax = it.getOriginalPriceAmountMicros() / 10000
val currency = it.priceCurrencyCode.lowercase()
val id = it.sku
val years = it.sku.substring(0, 1)
val price = it.priceAmountMicros / 10000
val priceWithoutTax = it.originalPriceAmountMicros / 10000
plans.put(
id,
ProPlan(
Expand Down Expand Up @@ -251,8 +251,8 @@ class InAppBilling(
}

private fun isRetriable(billingResult: BillingResult): Boolean {
val responseCode = billingResult.getResponseCode()
val message = billingResult.getDebugMessage()
val responseCode = billingResult.responseCode
val message = billingResult.debugMessage
return when (responseCode) {
BillingClient.BillingResponseCode.SERVICE_TIMEOUT,
BillingClient.BillingResponseCode.SERVICE_UNAVAILABLE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ class LanternSessionManager(application: Application) : SessionManager(applicati

if (user.isProUser) {
EventBus.getDefault().post(UserStatus(user.isActive, user.monthsLeft().toLong()))
prefs.edit().putInt(PRO_MONTHS_LEFT, user.monthsLeft() ?: 0)
.putInt(PRO_DAYS_LEFT, user.daysLeft() ?: 0)
prefs.edit().putInt(PRO_MONTHS_LEFT, user.monthsLeft())
.putInt(PRO_DAYS_LEFT, user.daysLeft())
.apply()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ data class ProError(
result.get("errorId").asString,
result.get("error").asString,
result.get("details").asJsonObject,
) {

}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ data class ProUser(
fun monthsLeft(): Int {
val expDate = expirationDate()
if (expDate == null) return 0
return Months.monthsBetween(LocalDateTime.now(), expDate).getMonths()
return Months.monthsBetween(LocalDateTime.now(), expDate).months
}

fun daysLeft(): Int {
val expDate = expirationDate()
if (expDate == null) return 0
return Days.daysBetween(LocalDateTime.now(), expDate).getDays()
return Days.daysBetween(LocalDateTime.now(), expDate).days
}

fun newUserDetails(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ class NotificationHelper(
}


public fun vpnConnectedNotification() {
fun vpnConnectedNotification() {
manager.notify(VPN_CONNECTED, vpnBuilder.build())
}

public fun dataUsageNotification() {
fun dataUsageNotification() {
manager.notify(DATA_USAGE, dataUsageBuilder.build())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.getlantern.mobilesdk.Logger
import org.greenrobot.eventbus.EventBus


class NotificationReceiver() : BroadcastReceiver() {
class NotificationReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
Logger.debug(TAG, "Received disconnect broadcast")
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ internal class NetworkFirstPlausibleClient(
Proxy.Type.HTTP,
InetSocketAddress(
"127.0.0.1",
uri.getPort(),
uri.port,
),
)
OkHttpClient.Builder().proxy(proxy).build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import org.getlantern.mobilesdk.Logger
open class AutoStarter : BroadcastReceiver() {

override fun onReceive(context: Context, intent: Intent) {
Logger.d(TAG, "Automatically starting Lantern Service on: ${intent.getAction()}")
Logger.d(TAG, "Automatically starting Lantern Service on: ${intent.action}")
val serviceIntent = Intent(context, LanternService_::class.java)
.putExtra(LanternService.AUTO_BOOTED, intent.getAction() == Intent.ACTION_BOOT_COMPLETED)
.putExtra(LanternService.AUTO_BOOTED, intent.action == Intent.ACTION_BOOT_COMPLETED)
context.startService(serviceIntent)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ open class LanternService : Service(), Runnable {
private const val MAX_CREATE_USER_TRIES = 11
private const val baseWaitMs = 3000
private val lanternClient: LanternHttpClient = LanternApp.getLanternHttpClient()
public val AUTO_BOOTED = "autoBooted"
val AUTO_BOOTED = "autoBooted"
}

private var thread: Thread? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fun Activity.restartApp() {
PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
val mgr: AlarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
mgr.set(AlarmManager.RTC, java.lang.System.currentTimeMillis() + 100, mPendingIntent)
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent)
Process.killProcess(Process.myPid())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ApkInstaller(
private suspend fun installWithPackageInstaller() =
withContext(Dispatchers.IO) {
try {
val params = PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL)
val params = SessionParams(SessionParams.MODE_FULL_INSTALL)
// create a new session using the given params, returning a unique ID that represents the session
val sessionId = packageInstaller.createSession(params)
// open an existing session to actively perform work
Expand Down Expand Up @@ -106,7 +106,7 @@ class ApkInstaller(
Logger.error(TAG, "Failed to launch apk installer", e)
}

private fun createInstallIntentContentUri(): Intent? {
private fun createInstallIntentContentUri(): Intent {
val packageName = context.packageName
val authority = "$packageName.fileProvider"
val apkFileUri = FileProvider.getUriForFile(context, authority, apkFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ object ApkSignatureVerifier {
// also this class calls [bytes2Hex] and with that proceeds to return a value which has their representation
// as a signed string.
// refers: https://stackoverflow.com/questions/5578871/how-to-get-apk-signing-signature
@kotlin.jvm.JvmStatic
@JvmStatic
fun sha256(data: ByteArray?): String {
var value = ""
if (data == null || data.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object DeviceInfo : internalsdk.DeviceInfo {
}

override fun sdkVersion(): Long {
return android.os.Build.VERSION.SDK_INT.toLong() ?: 0
return android.os.Build.VERSION.SDK_INT.toLong()
}

override fun deviceID(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.Request
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import okhttp3.Response
import org.getlantern.lantern.LanternApp
import org.getlantern.mobilesdk.Logger
Expand Down Expand Up @@ -238,7 +239,7 @@ open class LanternHttpClient : HttpClient() {
error: ProError?,
)

abstract fun onSuccess(
fun onSuccess(
response: Response?,
result: JsonObject?,
)
Expand Down Expand Up @@ -300,7 +301,7 @@ open class LanternHttpClient : HttpClient() {
}

fun createJsonBody(json: JsonObject): RequestBody {
return RequestBody.create(JSON, json.toString())
return json.toString().toRequestBody(JSON)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class LanternProxySelector(private val session: LanternSessionManager) : ProxySe
setDefault(this)
}

override fun select(uri: URI): MutableList<Proxy>? {
override fun select(uri: URI): MutableList<Proxy> {
val proxyAddress: SocketAddress = addrFromString(
session.settings.getHttpProxyHost() + ":" +
session.settings.getHttpProxyPort(),
session.settings.httpProxyHost + ":" +
session.settings.httpProxyPort,
)
val proxiesList: MutableList<Proxy> = mutableListOf()
proxiesList.add(Proxy(Proxy.Type.HTTP, proxyAddress))
Expand All @@ -30,7 +30,7 @@ class LanternProxySelector(private val session: LanternSessionManager) : ProxySe
private fun addrFromString(addr: String): InetSocketAddress {
try {
val uri: URI = URI("my://$addr")
return InetSocketAddress(uri.getHost(), uri.getPort())
return InetSocketAddress(uri.host, uri.port)
} catch (e: Exception) {
throw RuntimeException(e)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.getlantern.mobilesdk.Logger
class PermissionUtil {
companion object {
private val TAG = PermissionUtil::class.java.simpleName
private val PERMISSIONS_TAG = "${PermissionUtil.TAG}.permissions"
private val PERMISSIONS_TAG = "$TAG.permissions"


/*Note - we do not include Manifest.permission.FOREGROUND_SERVICE because this is automatically
Expand Down
Loading

0 comments on commit 731c028

Please sign in to comment.