Skip to content

Commit

Permalink
Repair implicit intents
Browse files Browse the repository at this point in the history
  • Loading branch information
klassm committed Jul 16, 2024
1 parent 750f4a8 commit 9bd56f7
Show file tree
Hide file tree
Showing 33 changed files with 200 additions and 123 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ buildscript {
name = "kotlin-gradle-plugin",
version = kotlinVersion
)
classpath(group = "com.google.gms", name = "google-services", version = "4.4.1")
classpath(group = "com.google.gms", name = "google-services", version = "4.4.2")
classpath(group = "com.github.triplet.gradle", name = "play-publisher", version = "3.9.1")
classpath(
group = "org.jetbrains.kotlin",
Expand All @@ -65,7 +65,7 @@ val roomVersion = "2.6.1"

plugins {
id("net.researchgate.release") version "3.0.2"
id("com.android.application") version "8.4.1"
id("com.android.application") version "8.5.1"
kotlin("android").version("1.8.20")
kotlin("kapt").version("1.8.20")
kotlin("plugin.serialization") version "1.8.20"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ open class AndFHEMMainActivity : AppCompatActivity() {
onBackPressed()
return true
} else if (item.itemId == R.id.menu_refresh) {
sendBroadcast(Intent(Actions.DO_UPDATE).putExtra(BundleExtraKeys.DO_REFRESH, true))
sendBroadcast(Intent(Actions.DO_UPDATE).putExtra(BundleExtraKeys.DO_REFRESH, true).apply { setPackage(packageName) })
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class PremiumActivity : AppCompatActivity() {
viewBinding.shopPremiumBuy.visibility = View.VISIBLE
}
}
sendBroadcast(Intent(Actions.DISMISS_EXECUTING_DIALOG))
sendBroadcast(Intent(Actions.DISMISS_EXECUTING_DIALOG).apply { setPackage(packageName) })
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class UpdateTimerTask(private val context: Context) : TimerTask() {
Log.i(UpdateTimerTask::class.java.name, "send broadcast for device list update")
val updateIntent = Intent(Actions.DO_UPDATE)
updateIntent.putExtra(BundleExtraKeys.DO_REFRESH, true)
updateIntent.setPackage(context.packageName)
context.sendBroadcast(updateIntent)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ protected void onReceiveResult(int resultCode, Bundle resultData) {
super.onReceiveResult(resultCode, resultData);

if (resultCode == ResultCodes.SUCCESS) {
context.sendBroadcast(new Intent(Actions.INSTANCE.getDO_UPDATE()));
Intent intent = new Intent(Actions.INSTANCE.getDO_UPDATE());
intent.setPackage(context.getPackageName());
context.sendBroadcast(intent);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ class FHTModeStateOverwrite @Inject constructor(
)
}
spinnerActionRow.commitSelection()
context.sendBroadcast(Intent(BundleExtraKeys.DO_REFRESH))
context.sendBroadcast(Intent(BundleExtraKeys.DO_REFRESH)
.apply { setPackage(context.packageName) })

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ToggleDeviceActionRow(context: Context,
withContext(Dispatchers.IO) {
toggleableService.toggleState(device, connectionId = null)
}
context.sendBroadcast(Intent(Actions.DO_UPDATE))
context.sendBroadcast(Intent(Actions.DO_UPDATE).apply { setPackage(context.packageName) })
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ class StateUiService @Inject constructor(
}
}

private fun invokeUpdate(context: Context) = context.sendBroadcast(Intent(Actions.DO_UPDATE))
private fun invokeUpdate(context: Context) = context.sendBroadcast(Intent(Actions.DO_UPDATE).apply { setPackage(context.packageName) })
}
2 changes: 1 addition & 1 deletion app/src/main/java/li/klass/fhem/billing/BillingService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ constructor() : PurchasesUpdatedListener {
acknowledgePurchases(purchases)
ownedSkus.addAll(purchases.flatMap { it.skus })
val application = AndFHEMApplication.application
application?.sendBroadcast(Intent(Actions.DO_UPDATE))
application?.sendBroadcast(Intent(Actions.DO_UPDATE).apply { setPackage(application.packageName) })
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ enum class RequestResultError(val errorStringId: Int) {

fun handleError(context: Context) {
context.sendBroadcast(Intent(Actions.CONNECTION_ERROR)
.putExtra(BundleExtraKeys.STRING_ID, errorStringId))
.putExtra(BundleExtraKeys.STRING_ID, errorStringId)
.apply { setPackage(context.packageName) })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class AvailableConnectionDataAdapter(
Intent(Actions.DO_UPDATE).putExtra(
BundleExtraKeys.DO_REFRESH,
false
)
).apply { setPackage(context.packageName) }
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class ConnectionDetailFragment @Inject constructor(
override suspend fun update(refresh: Boolean) {
if (!isModify) {
LOG.info("I can only update if a connection is being modified!")
activity?.sendBroadcast(Intent(Actions.DISMISS_EXECUTING_DIALOG))
activity?.sendBroadcast(Intent(Actions.DISMISS_EXECUTING_DIALOG).apply { setPackage(context?.packageName) })
return
}

Expand All @@ -236,7 +236,7 @@ class ConnectionDetailFragment @Inject constructor(
}
if (result == null) {
LOG.error("update - cannot find server with ID ${args.connectionId}")
myContext.sendBroadcast(Intent(Actions.BACK))
myContext.sendBroadcast(Intent(Actions.BACK).apply { setPackage(myContext.packageName) })
} else {
setValuesForCurrentConnection(result)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class ConnectionListFragment @Inject constructor(
R.string.premium_multipleConnections
)
.putExtra(BundleExtraKeys.ALERT_TITLE_ID, R.string.premium)
.apply { setPackage(context?.packageName) }
)
} else {
logger.info("onOptionsItemSelected - showing connection detail for a new connection")
Expand Down Expand Up @@ -186,7 +187,7 @@ class ConnectionListFragment @Inject constructor(

hideEmptyView()
val myActivity = activity ?: return
if (refresh) myActivity.sendBroadcast(Intent(Actions.SHOW_EXECUTING_DIALOG))
if (refresh) myActivity.sendBroadcast(Intent(Actions.SHOW_EXECUTING_DIALOG).apply { setPackage(context?.packageName) })

doUpdate()
}
Expand All @@ -204,7 +205,7 @@ class ConnectionListFragment @Inject constructor(

adapter.updateData(nonDummyConnections, connectionId)
scrollToSelected(connectionId, adapter.getData())
activity?.sendBroadcast(Intent(Actions.DISMISS_EXECUTING_DIALOG))
activity?.sendBroadcast(Intent(Actions.DISMISS_EXECUTING_DIALOG).apply { setPackage(context?.packageName) })
}
}

Expand All @@ -226,7 +227,7 @@ class ConnectionListFragment @Inject constructor(

override fun onDetach() {
super.onDetach()
activity?.sendBroadcast(Intent(Actions.CONNECTIONS_CHANGED))
activity?.sendBroadcast(Intent(Actions.CONNECTIONS_CHANGED).apply { setPackage(context?.packageName) })
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ constructor(
commandExecutionService.executeSafely(Command("attr " + device.name + " room " + newRoomConcatenated), object : CommandExecutionService.SuccessfulResultListener() {
override fun onResult(result: String) {
device.roomConcatenated = newRoomConcatenated
context.sendBroadcast(Intent(Actions.DO_UPDATE))
context.sendBroadcast(Intent(Actions.DO_UPDATE).apply { setPackage(context.packageName) })
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class DeviceDetailFragment @Inject constructor(
}
deviceListService.getDeviceForName(name, args.connectionId)
}
myActivity.sendBroadcast(Intent(DISMISS_EXECUTING_DIALOG))
myActivity.sendBroadcast(Intent(DISMISS_EXECUTING_DIALOG).apply { setPackage(context?.packageName) })
device?.let {
this@DeviceDetailFragment.device = it
val detailView = genericOverviewDetailAdapter.getDeviceDetailView(myActivity, it, args.connectionId, findNavController(), deviceDetailViewModel.expandHandler())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,18 @@ abstract class DeviceListFragment(
override suspend fun update(refresh: Boolean) {
val myActivity = activity ?: return
if (refresh) {
myActivity.sendBroadcast(Intent(Actions.SHOW_EXECUTING_DIALOG))
myActivity.sendBroadcast(Intent(Actions.SHOW_EXECUTING_DIALOG).apply { setPackage(context?.packageName) })
}

Log.i(DeviceListFragment::class.java.name, "request device list update (doUpdate=$refresh)")

coroutineScope {
if (refresh) {
myActivity.sendBroadcast(Intent(Actions.SHOW_EXECUTING_DIALOG))
myActivity.sendBroadcast(Intent(Actions.SHOW_EXECUTING_DIALOG).apply { setPackage(context?.packageName) })
withContext(Dispatchers.IO) {
executeRemoteUpdate(myActivity)
}
myActivity.sendBroadcast(Intent(Actions.DISMISS_EXECUTING_DIALOG))
myActivity.sendBroadcast(Intent(Actions.DISMISS_EXECUTING_DIALOG).apply { setPackage(context?.packageName) })
}
val elements = withContext(Dispatchers.IO) {
val deviceList = getRoomDeviceListForUpdate(myActivity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class FcmHistoryMessagesFragment @Inject constructor(
fcmHistoryService.getMessages(localDate)
}

activity?.sendBroadcast(Intent(Actions.DISMISS_EXECUTING_DIALOG))
activity?.sendBroadcast(Intent(Actions.DISMISS_EXECUTING_DIALOG).apply { setPackage(context?.packageName) })
showEmptyViewIfRequired(messages.isEmpty(), binding.messages, binding.fcmNoMessages)
(binding.messages.adapter as FcmMessagesAdapter).updateWith(messages)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class FcmHistoryUpdatesFragment @Inject constructor(
fcmHistoryService.getChanges(localDate)
}

activity?.sendBroadcast(Intent(Actions.DISMISS_EXECUTING_DIALOG))
activity?.sendBroadcast(Intent(Actions.DISMISS_EXECUTING_DIALOG).apply { setPackage(context?.packageName) })
showEmptyViewIfRequired(updates.isEmpty(), binding.updates, binding.fcmNoUpdates)
(recyclerView.adapter as FcmUpdatesAdapter).updateWith(updates)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,16 @@ class FcmNotifyHandler @Inject constructor(
}

private fun updateUI(context: Context) {
context.sendBroadcast(Intent(Actions.DO_UPDATE))
context.sendBroadcast(Intent(Actions.DO_UPDATE).apply { setPackage(context.packageName) })
}


private fun sendUpdatedBroadcastFor(context: Context, deviceName: String, connectionId: String?) {
val connection = connectionId ?: connectionService.getSelectedId()
context.sendBroadcast(Intent(Actions.DEVICES_UPDATED)
.putExtra(BundleExtraKeys.UPDATED_DEVICE_NAMES, ArrayList(listOf(deviceName)))
.putExtra(BundleExtraKeys.CONNECTION_ID, connection))
.putExtra(BundleExtraKeys.CONNECTION_ID, connection)
.apply { setPackage(context.packageName) })
}


Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/li/klass/fhem/log/FhemLogDrawerAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import li.klass.fhem.AndFHEMApplication
import li.klass.fhem.R
import li.klass.fhem.activities.drawer.actions.AbstractDrawerAction
import li.klass.fhem.constants.Actions
Expand All @@ -49,12 +50,12 @@ class FhemLogDrawerAction @Inject constructor(
DialogUtil.showAlertDialog(activity, R.string.fhem_log, R.string.fhem_log_error_permission_external_storage)
return
}
activity.sendBroadcast(Intent(Actions.SHOW_EXECUTING_DIALOG))
activity.sendBroadcast(Intent(Actions.SHOW_EXECUTING_DIALOG).apply { setPackage(AndFHEMApplication.application?.packageName) })
GlobalScope.launch(Dispatchers.Main) {
val temporaryFile = withContext(Dispatchers.IO) {
fhemLogService.getLogAndWriteToTemporaryFile()
}
activity.sendBroadcast(Intent(Actions.DISMISS_EXECUTING_DIALOG))
activity.sendBroadcast(Intent(Actions.DISMISS_EXECUTING_DIALOG).apply { setPackage(AndFHEMApplication.application?.packageName) })
handle(activity, temporaryFile)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ abstract class RoomListSelectionFragment(

hideEmptyView()
if (refresh) {
activity?.sendBroadcast(Intent(Actions.SHOW_EXECUTING_DIALOG))
activity?.sendBroadcast(Intent(Actions.SHOW_EXECUTING_DIALOG).apply { setPackage(context?.packageName) })
}

coroutineScope {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class SendCommandFragment @Inject constructor(

override suspend fun update(refresh: Boolean) {
val myActivity = activity ?: return
myActivity.sendBroadcast(Intent(Actions.SHOW_EXECUTING_DIALOG))
myActivity.sendBroadcast(Intent(Actions.SHOW_EXECUTING_DIALOG).apply { setPackage(myActivity.packageName) })
coroutineScope {
val recentCommands = withContext(Dispatchers.IO) {
sendCommandService.getRecentCommands()
Expand All @@ -128,7 +128,7 @@ class SendCommandFragment @Inject constructor(

ListViewUtil.setHeightBasedOnChildren(binding.commandHistory)

myActivity.sendBroadcast(Intent(Actions.DISMISS_EXECUTING_DIALOG))
myActivity.sendBroadcast(Intent(Actions.DISMISS_EXECUTING_DIALOG).apply { setPackage(myActivity.packageName) })
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ protected void sendBroadcastWithAction(String action, Bundle bundle, Context con

Intent broadcastIntent = new Intent(action);
broadcastIntent.putExtras(bundle);
broadcastIntent.setPackage(context.getPackageName());
context.sendBroadcast(broadcastIntent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,22 @@ import li.klass.fhem.update.backend.command.execution.CommandExecutionService
import javax.inject.Inject

class ResendLastFailedCommandService @Inject constructor(
private val commandExecutionService: CommandExecutionService
private val commandExecutionService: CommandExecutionService
) {
fun resend(context: Context) {
val lastFailedCommand = commandExecutionService.lastFailedCommand
if (lastFailedCommand != null && "xmllist".equals(lastFailedCommand.command, ignoreCase = true)) {
context.sendBroadcast(Intent(Actions.DO_UPDATE)
.putExtra(DO_REFRESH, true))
if (lastFailedCommand != null && "xmllist".equals(
lastFailedCommand.command,
ignoreCase = true
)
) {
context.sendBroadcast(
Intent(Actions.DO_UPDATE)
.putExtra(DO_REFRESH, true).apply {
setPackage(context.packageName)
}
.apply { setPackage(context.packageName) }
)
} else {
commandExecutionService.resendLastFailedCommand()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ package li.klass.fhem.service.intent

import android.content.Intent
import android.os.ResultReceiver
import li.klass.fhem.AndFHEMApplication
import li.klass.fhem.appwidget.update.AppWidgetUpdateService
import li.klass.fhem.constants.Actions
import li.klass.fhem.constants.Actions.DO_UPDATE
Expand Down Expand Up @@ -73,7 +74,7 @@ class RoomListUpdateIntentService : ConvenientIntentService(RoomListUpdateIntent
when (result) {
is UpdateResult.Success -> {
LOG.info("doRemoteUpdate() - remote device list update finished")
sendBroadcast(Intent(DO_UPDATE))
sendBroadcast(Intent(DO_UPDATE).apply { setPackage(AndFHEMApplication.application?.packageName) })
widgetUpdateService.updateAllWidgets()
}
is UpdateResult.Error -> LOG.error("handleResult - update failed")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ class SettingsActivity : AppCompatActivity(),

override fun onStop() {
super.onStop()
sendBroadcast(Intent(Actions.REDRAW))
sendBroadcast(Intent(Actions.REDRAW).apply { setPackage(packageName) })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class TimerDetailFragment @Inject constructor(
if (targetDevice == null || isBlank(getTargetState()) || switchTime == null || timerDeviceName == null) {
activity?.sendBroadcast(
Intent(SHOW_TOAST)
.putExtra(STRING_ID, R.string.incompleteConfigurationError)
.putExtra(STRING_ID, R.string.incompleteConfigurationError).apply { setPackage(activity?.packageName) }
)
return
}
Expand Down Expand Up @@ -306,7 +306,7 @@ class TimerDetailFragment @Inject constructor(
atService.getTimerDeviceFor(timerDeviceName)
}?.let {
setValuesForCurrentTimerDevice(it)
myActivity.sendBroadcast(Intent(DISMISS_EXECUTING_DIALOG))
myActivity.sendBroadcast(Intent(DISMISS_EXECUTING_DIALOG).apply { setPackage(activity?.packageName) })
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class TimerListFragment @Inject constructor(
}
adapter.updateData(timerDevices.toMutableList())
binding.empty.visibility = if (timerDevices.isEmpty()) View.VISIBLE else View.GONE
myActivity.sendBroadcast(Intent(Actions.DISMISS_EXECUTING_DIALOG))
myActivity.sendBroadcast(Intent(Actions.DISMISS_EXECUTING_DIALOG).apply { setPackage(activity?.packageName) })
}
}

Expand Down
Loading

0 comments on commit 9bd56f7

Please sign in to comment.