@@ -47,7 +47,7 @@ public class PowerManagerWrapper {
4747 private static final String UNKNOWN_STATUS = "Unknown" ;
4848
4949 // In-memory cache for battery optimization status for each apps.
50- private final Map <String , String > batteryOptOutCache = new ConcurrentHashMap <>();
50+ private final Map <String , BatteryOptimizationStatus > batteryOptOutCache = new ConcurrentHashMap <>();
5151 /**
5252 * Set instance of PowerManagerWrapper.
5353 *
@@ -147,36 +147,37 @@ public boolean isIgnoringBatteryOptimizations(final Context connectionContext) {
147147 *
148148 * @param packageName The package name to check.
149149 * @param context The context to use for PowerManager.
150- * @return "OptOut" if the app is opted out, "NotOptOut" if not, or exception type string.
150+ * @return a {@link BatteryOptimizationStatus}
151151 */
152- public String isAppOptedOutFromBatteryOptimization (@ NonNull final String packageName , @ NonNull final Context context ) {
152+ public BatteryOptimizationStatus isAppOptedOutFromBatteryOptimization (@ NonNull final String packageName , @ NonNull final Context context ) {
153153 final String methodTag = TAG + ":isAppOptedOutFromBatteryOptimization" ;
154154
155155 return batteryOptOutCache .computeIfAbsent (packageName , key -> {
156156 try {
157157 final PowerManager powerManager = (PowerManager ) context .getSystemService (Context .POWER_SERVICE );
158158 if (powerManager == null ) {
159159 Logger .error (methodTag , "PowerManager is null for package: " + packageName , null );
160- return " CannotRetrievePowerManager" ;
160+ return BatteryOptimizationStatus . CannotRetrievePowerManager ;
161161 }
162162
163163 if (powerManager .isIgnoringBatteryOptimizations (key )) {
164- return "OptOut" ;
165- } else {
166- return "NotOptOut" ;
164+ return BatteryOptimizationStatus .OptOut ;
165+ } else
166+ {
167+ return BatteryOptimizationStatus .NotOptOut ;
167168 }
168169 } catch (NullPointerException e ) {
169170 Logger .error (methodTag , "NullPointerException when checking battery optimization status for package: " + packageName , e );
170- return " NullPointerException" ;
171+ return BatteryOptimizationStatus . NullPointerException ;
171172 } catch (SecurityException e ) {
172173 Logger .error (methodTag , "SecurityException when checking battery optimization status for package: " + packageName , e );
173- return " SecurityException" ;
174+ return BatteryOptimizationStatus . SecurityException ;
174175 } catch (IllegalArgumentException e ) {
175176 Logger .error (methodTag , "IllegalArgumentException when checking battery optimization status for package: " + packageName , e );
176- return " IllegalArgumentException" ;
177+ return BatteryOptimizationStatus . IllegalArgumentException ;
177178 } catch (Exception e ) {
178179 Logger .error (methodTag , "Unknown Exception when checking battery optimization status for package: " + packageName , e );
179- return " UnknownException" ;
180+ return BatteryOptimizationStatus . UnknownException ;
180181 }
181182 });
182183 }
0 commit comments