Many fixes

This commit is contained in:
2025-07-10 18:39:07 +02:00
parent 6d9a77a990
commit bf78ecc794
7 changed files with 207 additions and 9 deletions

View File

@ -32,7 +32,6 @@ import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.WindowManager;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
@ -65,10 +64,10 @@ import java.lang.reflect.Method;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.NetworkInterface; import java.net.NetworkInterface;
import java.security.KeyStore; import java.security.KeyStore;
import java.text.Normalizer;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collections; import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
@ -2054,13 +2053,12 @@ public class Actions
else else
android.provider.Settings.System.putInt(context.getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE, android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); android.provider.Settings.System.putInt(context.getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE, android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
int actualBrightnessValue = (int) ((float) brightnessValue / 100.0 * 255.0); // Old mathematical approach doesn't seem to be working anymore
if(actualBrightnessValue == 0) // int actualBrightnessValue = (int) ((float) brightnessValue / 100.0 * 255.0);
actualBrightnessValue = 1; // seems to be the minimum, 0 isn't working
// try // try
// { // {
// for (int i = 1; i < 255; i++) // for (int i = 160; i < 255; i++)
// { // {
// android.provider.Settings.System.putInt(context.getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS, i); // android.provider.Settings.System.putInt(context.getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS, i);
// Thread.sleep(1000); // Thread.sleep(1000);
@ -2072,10 +2070,191 @@ public class Actions
// //
// } // }
Miscellaneous.logEvent("i", "Screen brightness", "Setting screen brightness to " + String.valueOf(actualBrightnessValue), 4); int actualBrightnessValue = getBrightnessSetting(brightnessValue);
Miscellaneous.logEvent("i", "Screen brightness", "Setting screen brightness to " + String.valueOf(brightnessValue) + " by using " + String.valueOf(actualBrightnessValue), 4);
android.provider.Settings.System.putInt(context.getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS, actualBrightnessValue); android.provider.Settings.System.putInt(context.getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS, actualBrightnessValue);
} }
static int getBrightnessSetting(int percentage)
{
if(percentage == 0)
return 1; // seems to be the minimum, 0 isn't working
/*
By taking notes which value results in which brightness percentage I came up with this lookup list.
Somebody at Google must have been smoking something.
Not all percentages can be implemented. Hence the next possible value will be used.
*/
Map<Integer, Integer> percentageSettingValueMap = new HashMap<>();
if(Build.VERSION.SDK_INT < 34)
{
// Noted from Android 10
percentageSettingValueMap.put(11, 10);
percentageSettingValueMap.put(16, 11);
percentageSettingValueMap.put(19, 12);
percentageSettingValueMap.put(22, 13);
percentageSettingValueMap.put(25, 14);
percentageSettingValueMap.put(27, 15);
percentageSettingValueMap.put(29, 16);
percentageSettingValueMap.put(31, 17);
percentageSettingValueMap.put(33, 18);
percentageSettingValueMap.put(35, 19);
percentageSettingValueMap.put(37, 20);
percentageSettingValueMap.put(38, 21);
percentageSettingValueMap.put(40, 22);
percentageSettingValueMap.put(41, 23);
percentageSettingValueMap.put(43, 24);
percentageSettingValueMap.put(44, 25);
percentageSettingValueMap.put(46, 26);
percentageSettingValueMap.put(47, 27);
percentageSettingValueMap.put(48, 28);
percentageSettingValueMap.put(49, 29);
percentageSettingValueMap.put(51, 30);
percentageSettingValueMap.put(52, 31);
percentageSettingValueMap.put(53, 32);
percentageSettingValueMap.put(54, 33);
percentageSettingValueMap.put(55, 34);
percentageSettingValueMap.put(56, 35);
percentageSettingValueMap.put(57, 36);
percentageSettingValueMap.put(58, 38);
percentageSettingValueMap.put(59, 39);
percentageSettingValueMap.put(60, 40);
percentageSettingValueMap.put(61, 42);
percentageSettingValueMap.put(62, 43);
percentageSettingValueMap.put(63, 45);
percentageSettingValueMap.put(64, 46);
percentageSettingValueMap.put(65, 48);
percentageSettingValueMap.put(66, 50);
percentageSettingValueMap.put(67, 52);
percentageSettingValueMap.put(68, 54);
percentageSettingValueMap.put(69, 56);
percentageSettingValueMap.put(70, 59);
percentageSettingValueMap.put(71, 61);
percentageSettingValueMap.put(72, 64);
percentageSettingValueMap.put(73, 67);
percentageSettingValueMap.put(74, 70);
percentageSettingValueMap.put(75, 73);
percentageSettingValueMap.put(76, 76);
percentageSettingValueMap.put(77, 80);
percentageSettingValueMap.put(78, 84);
percentageSettingValueMap.put(79, 87);
percentageSettingValueMap.put(80, 91);
percentageSettingValueMap.put(81, 96);
percentageSettingValueMap.put(82, 100);
percentageSettingValueMap.put(83, 105);
percentageSettingValueMap.put(84, 111);
percentageSettingValueMap.put(85, 116);
percentageSettingValueMap.put(86, 122);
percentageSettingValueMap.put(87, 128);
percentageSettingValueMap.put(88, 134);
percentageSettingValueMap.put(89, 141);
percentageSettingValueMap.put(90, 148);
percentageSettingValueMap.put(91, 156);
percentageSettingValueMap.put(92, 164);
percentageSettingValueMap.put(93, 173);
percentageSettingValueMap.put(94, 182);
percentageSettingValueMap.put(95, 191);
percentageSettingValueMap.put(96, 201);
percentageSettingValueMap.put(97, 212);
percentageSettingValueMap.put(98, 223);
percentageSettingValueMap.put(99, 235);
percentageSettingValueMap.put(100, 247);
}
else
{
// Noted from Android 14
percentageSettingValueMap.put(11,1);
percentageSettingValueMap.put(15,2);
percentageSettingValueMap.put(19,3);
percentageSettingValueMap.put(22,4);
percentageSettingValueMap.put(24,5);
percentageSettingValueMap.put(27,6);
percentageSettingValueMap.put(29,7);
percentageSettingValueMap.put(31,8);
percentageSettingValueMap.put(33,9);
percentageSettingValueMap.put(34,10);
percentageSettingValueMap.put(36,11);
percentageSettingValueMap.put(38,12);
percentageSettingValueMap.put(39,13);
percentageSettingValueMap.put(41,14);
percentageSettingValueMap.put(42,15);
percentageSettingValueMap.put(43,16);
percentageSettingValueMap.put(45,17);
percentageSettingValueMap.put(46,18);
percentageSettingValueMap.put(47,47);
percentageSettingValueMap.put(48,49);
percentageSettingValueMap.put(50,21);
percentageSettingValueMap.put(51,22);
percentageSettingValueMap.put(52,23);
percentageSettingValueMap.put(53,24);
percentageSettingValueMap.put(54,25);
percentageSettingValueMap.put(55,26);
percentageSettingValueMap.put(56,27);
percentageSettingValueMap.put(57,28);
percentageSettingValueMap.put(58,30);
percentageSettingValueMap.put(59,31);
percentageSettingValueMap.put(60,32);
percentageSettingValueMap.put(61,34);
percentageSettingValueMap.put(62,35);
percentageSettingValueMap.put(63,37);
percentageSettingValueMap.put(64,39);
percentageSettingValueMap.put(65,41);
percentageSettingValueMap.put(66,43);
percentageSettingValueMap.put(67,45);
percentageSettingValueMap.put(68,47);
percentageSettingValueMap.put(69,49);
percentageSettingValueMap.put(70,52);
percentageSettingValueMap.put(71,54);
percentageSettingValueMap.put(72,57);
percentageSettingValueMap.put(73,60);
percentageSettingValueMap.put(74,63);
percentageSettingValueMap.put(75,66);
percentageSettingValueMap.put(76,70);
percentageSettingValueMap.put(77,73);
percentageSettingValueMap.put(78,77);
percentageSettingValueMap.put(79,81);
percentageSettingValueMap.put(80,85);
percentageSettingValueMap.put(81,90);
percentageSettingValueMap.put(82,95);
percentageSettingValueMap.put(83,100);
percentageSettingValueMap.put(84,105);
percentageSettingValueMap.put(85,111);
percentageSettingValueMap.put(86,117);
percentageSettingValueMap.put(87,124);
percentageSettingValueMap.put(88,130);
percentageSettingValueMap.put(89,137);
percentageSettingValueMap.put(90,144);
percentageSettingValueMap.put(91,152);
percentageSettingValueMap.put(92,161);
percentageSettingValueMap.put(93,170);
percentageSettingValueMap.put(94,179);
percentageSettingValueMap.put(95,189);
percentageSettingValueMap.put(96,199);
percentageSettingValueMap.put(97,210);
percentageSettingValueMap.put(98,223);
percentageSettingValueMap.put(99,235);
percentageSettingValueMap.put(100,248);
}
if(percentageSettingValueMap.containsKey(percentage))
return percentageSettingValueMap.get(percentage);
else
{
// Find next best value
for(int i = percentage; i <= 100; i++)
{
if(percentageSettingValueMap.containsKey(i))
return percentageSettingValueMap.get(i);
}
}
return 0;
}
public boolean isAirplaneModeOn(Context context) public boolean isAirplaneModeOn(Context context)
{ {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)

View File

@ -757,6 +757,9 @@ public class ActivityPermissions extends Activity
case setLocationService: case setLocationService:
addToArrayListUnique(Manifest.permission.WRITE_SECURE_SETTINGS, requiredPermissions); addToArrayListUnique(Manifest.permission.WRITE_SECURE_SETTINGS, requiredPermissions);
break; break;
case setScreenBrightness:
addToArrayListUnique(Manifest.permission.WRITE_SETTINGS, requiredPermissions);
break;
default: default:
break; break;
} }

View File

@ -129,7 +129,10 @@ public class BroadcastListener extends android.content.BroadcastReceiver impleme
try try
{ {
broadcastStatus = automationServiceRef.registerReceiver(broadcastReceiverInstance, broadcastIntentFilter); if(Build.VERSION.SDK_INT >= 33)
broadcastStatus = automationServiceRef.registerReceiver(broadcastReceiverInstance, broadcastIntentFilter, Context.RECEIVER_EXPORTED);
else
broadcastStatus = automationServiceRef.registerReceiver(broadcastReceiverInstance, broadcastIntentFilter);
broadcastReceiverActive = true; broadcastReceiverActive = true;
} }
catch(Exception e) catch(Exception e)

View File

@ -14,6 +14,7 @@ import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import com.jens.automation2.AutomationService; import com.jens.automation2.AutomationService;
import com.jens.automation2.Miscellaneous; import com.jens.automation2.Miscellaneous;
@ -580,7 +581,10 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis
calendarIntentFilter.addDataAuthority("com.android.calendar", null); calendarIntentFilter.addDataAuthority("com.android.calendar", null);
} }
calendarIntent = automationServiceRef.registerReceiver(calendarReceiverInstance, calendarIntentFilter); if(Build.VERSION.SDK_INT >= 33)
calendarIntent = automationServiceRef.registerReceiver(calendarReceiverInstance, calendarIntentFilter, Context.RECEIVER_EXPORTED);
else
calendarIntent = automationServiceRef.registerReceiver(calendarReceiverInstance, calendarIntentFilter);
calendarReceiverActive = true; calendarReceiverActive = true;

View File

@ -31,6 +31,12 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="@dimen/default_margin"
android:text="@string/screenBrightGoogleComment" />
<Button <Button
android:layout_marginTop="@dimen/default_margin" android:layout_marginTop="@dimen/default_margin"
android:id="@+id/bApplyBrightness" android:id="@+id/bApplyBrightness"

View File

@ -954,4 +954,5 @@
<string name="logToConsole">Log to console (logcat)</string> <string name="logToConsole">Log to console (logcat)</string>
<string name="locationPermissionRequired">Location permission is required to continue.</string> <string name="locationPermissionRequired">Location permission is required to continue.</string>
<string name="Android14TimePickerHint">Apparently there\'s a bug in Android 14 regarding a time picker dialog. If the following screen crashes when you try to use the up and down buttons next to a field, try inputting numbers with the keyboard instead. I did never find a solution for this and my app is not the only one affected. It looks like this was fixed in Android 15.</string> <string name="Android14TimePickerHint">Apparently there\'s a bug in Android 14 regarding a time picker dialog. If the following screen crashes when you try to use the up and down buttons next to a field, try inputting numbers with the keyboard instead. I did never find a solution for this and my app is not the only one affected. It looks like this was fixed in Android 15.</string>
<string name="screenBrightGoogleComment">Because someone at Google seems to have been smoking something the screen brightness setting has been behaving very weird for some Android versions. This behavior has nothing to do with what you\'d think it does according to their own documentation.\nI\'ve tried to adapt to this as best as I could, but do not expect very precise settings. That means the resulting setting may deviate a bit from what you configure here.</string>
</resources> </resources>

View File

@ -3,4 +3,6 @@
* Fixed: Fixed warnings in logs for formatted notifications * Fixed: Fixed warnings in logs for formatted notifications
* Fixed: Location permission requested now when creating a new location object. * Fixed: Location permission requested now when creating a new location object.
* Fixed: Display-over-other-apps permission was not requested anymore for start another app actions. * Fixed: Display-over-other-apps permission was not requested anymore for start another app actions.
* Fixed: Screen brightness value should work a bit better now
* Fixed: Calendar events were not regarded if created after Automation service start
* Added: Setting to turn on/off console logging (logcat) * Added: Setting to turn on/off console logging (logcat)