Skip to content

Commit

Permalink
Fix SecurityException
Browse files Browse the repository at this point in the history
  • Loading branch information
j4velin committed Jul 8, 2019
1 parent 6f1249f commit 09d8bda
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
package="de.j4velin.wifiAutoOff"
xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="internalOnly"
android:versionCode="1820"
android:versionName="1.8.2">
android:versionCode="1830"
android:versionName="1.8.3">

<uses-sdk
android:minSdkVersion="14"
Expand All @@ -14,7 +14,7 @@
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK" android:maxSdkVersion="26"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>

<application
android:allowBackup="true"
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/de/j4velin/wifiAutoOff/Receiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
public class Receiver extends BroadcastReceiver {

public final static String LOCATION_ENTERED_ACTION = "LOCATION_ENTERED";
// to prevent SecurityException: Not allowed to send ACTION_POWER_CONNECTED
public final static String POWER_CONNECTED = "POWER_CONNECTED";
public final static String EXTRA_LOCATION_NAME = "name";
private static NetworkInfo.State previousState = null;

Expand Down Expand Up @@ -335,6 +337,7 @@ public void onReceive(final Context context, final Intent intent) {
}
previousState = nwi2.getState();
break;
case POWER_CONNECTED:
case Intent.ACTION_POWER_CONNECTED:
// connected to external power supply
if (prefs.getBoolean("power_connected", false)) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/de/j4velin/wifiAutoOff/StartReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ public void onReceive(final Context context, final Intent intent) {
int plugged = batteryIntent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
if (plugged == BatteryManager.BATTERY_PLUGGED_AC ||
plugged == BatteryManager.BATTERY_PLUGGED_USB) {
context.sendBroadcast(new Intent(context, Receiver.class)
.setAction(Intent.ACTION_POWER_CONNECTED));
context.sendBroadcast(
// we're not allowed to send Intent.ACTION_POWER_CONNECTED, so use our own action
new Intent(context, Receiver.class).setAction(Receiver.POWER_CONNECTED));
}
}
Start.start(context);
Expand Down

0 comments on commit 09d8bda

Please sign in to comment.