pvsvamsi / Disable-Battery-Optimizations

A Flutter plugin to enable auto start and disable battery optimizations. Also shows custom steps to disable the optimizations in devices like mi, xiaomi, samsung, oppo, huawei, oneplus etc
MIT License
28 stars 29 forks source link

return type of DisableBatteryOptimization.isBatteryOptimizationDisabled could be tightened to bool instead of bool? #15

Open flodaniel opened 8 months ago

flodaniel commented 8 months ago

Basically the title. Looking at the implementation:

    public static boolean isIgnoringBatteryOptimizations(Context context) {
        if (Build.VERSION.SDK_INT < 23) {
            return true;
        }
        String packageName = context.getApplicationContext().getPackageName();
        PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        if (powerManager == null) {
            return true;
        }
        return powerManager.isIgnoringBatteryOptimizations(packageName);
    }

the method always returns a boolean, so the flutter implemenation could be changed to:

  static Future<bool> get isBatteryOptimizationDisabled async {
    return await _channel.invokeMethod("isBatteryOptimizationDisabled");
  }