-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(battery_plus): Use context compat to set exported state #1811
Changes from 4 commits
e18b384
d6af637
4a15f6a
4366f35
0d68d92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package dev.fluttercommunity.plus.battery | ||
|
||
import android.annotation.SuppressLint | ||
import io.flutter.plugin.common.MethodChannel.MethodCallHandler | ||
import io.flutter.plugin.common.EventChannel | ||
import io.flutter.embedding.engine.plugins.FlutterPlugin | ||
|
@@ -20,6 +21,9 @@ import java.util.Locale | |
import android.os.PowerManager | ||
import android.provider.Settings | ||
import androidx.annotation.RequiresApi | ||
import androidx.core.content.ContextCompat | ||
import androidx.core.content.ContextCompat.RECEIVER_NOT_EXPORTED | ||
|
||
|
||
/** BatteryPlusPlugin */ | ||
class BatteryPlusPlugin : MethodCallHandler, EventChannel.StreamHandler, FlutterPlugin { | ||
|
@@ -77,9 +81,16 @@ class BatteryPlusPlugin : MethodCallHandler, EventChannel.StreamHandler, Flutter | |
} | ||
} | ||
|
||
@SuppressLint("WrongConstant") // Error in ContextCompat for RECEIVER_NOT_EXPORTED | ||
override fun onListen(arguments: Any?, events: EventSink) { | ||
chargingStateChangeReceiver = createChargingStateChangeReceiver(events) | ||
applicationContext?.registerReceiver(chargingStateChangeReceiver, IntentFilter(Intent.ACTION_BATTERY_CHANGED)) | ||
// DO NOT MERGE, this alternates states. reidbaker debug before review. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a forgotten comment? Because I see that the PR is marked as ready for review, but this comment is here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, sorry I wanted to make sure not to merge/reivew until my local testing worked. Sorry, removed. |
||
applicationContext?.let { | ||
ContextCompat.registerReceiver( | ||
it, chargingStateChangeReceiver, | ||
IntentFilter(Intent.ACTION_BATTERY_CHANGED), RECEIVER_NOT_EXPORTED | ||
) | ||
} | ||
val status = getBatteryStatus() | ||
publishBatteryStatus(events, status) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I filed a bug against androidx for this behavior https://b.corp.google.com/issues/282596027