diff --git a/lineage/lib/main/java/org/lineageos/platform/internal/LineageSystemServer.java b/lineage/lib/main/java/org/lineageos/platform/internal/LineageSystemServer.java index 5e346f7b..b2f1f1b6 100644 --- a/lineage/lib/main/java/org/lineageos/platform/internal/LineageSystemServer.java +++ b/lineage/lib/main/java/org/lineageos/platform/internal/LineageSystemServer.java @@ -1,5 +1,6 @@ /* * SPDX-FileCopyrightText: 2016 The CyanogenMod Project + * SPDX-FileCopyrightText: 2024 The LineageOS Project * SPDX-License-Identifier: Apache-2.0 */ @@ -20,8 +21,8 @@ import org.lineageos.platform.internal.common.LineageSystemServiceHelper; */ public class LineageSystemServer { private static final String TAG = "LineageSystemServer"; - private Context mSystemContext; - private LineageSystemServiceHelper mSystemServiceHelper; + private final Context mSystemContext; + private final LineageSystemServiceHelper mSystemServiceHelper; private static final String ENCRYPTING_STATE = "trigger_restart_min_framework"; private static final String ENCRYPTED_STATE = "1"; diff --git a/lineage/lib/main/java/org/lineageos/platform/internal/ProfileManagerService.java b/lineage/lib/main/java/org/lineageos/platform/internal/ProfileManagerService.java index 1c1d1ebc..0bf510eb 100644 --- a/lineage/lib/main/java/org/lineageos/platform/internal/ProfileManagerService.java +++ b/lineage/lib/main/java/org/lineageos/platform/internal/ProfileManagerService.java @@ -86,19 +86,14 @@ public class ProfileManagerService extends LineageSystemService { UUID.fromString("a126d48a-aaef-47c4-baed-7f0e44aeffe5"); private NotificationGroup mWildcardGroup; - private Context mContext; - private Handler mHandler; + private final Context mContext; + private final Handler mHandler; private boolean mDirty; private BackupManager mBackupManager; private ProfileTriggerHelper mTriggerHelper; private Profile mEmptyProfile; - private Runnable mBindKeyguard = new Runnable() { - @Override - public void run() { - bindKeyguard(); - } - }; + private final Runnable mBindKeyguard = this::bindKeyguard; private IKeyguardService mKeyguardService; private final ServiceConnection mKeyguardConnection = new ServiceConnection() { @Override @@ -117,7 +112,7 @@ public class ProfileManagerService extends LineageSystemService { } }; - private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { + private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); @@ -291,8 +286,8 @@ public class ProfileManagerService extends LineageSystemService { private void initialize(boolean skipFile) { mTriggerHelper = new ProfileTriggerHelper(mContext, mHandler, this); - mProfiles = new HashMap(); - mProfileNames = new HashMap(); + mProfiles = new HashMap<>(); + mProfileNames = new HashMap<>(); mGroups = new HashMap(); mEmptyProfile = new Profile("EmptyProfile"); mDirty = false; @@ -302,9 +297,7 @@ public class ProfileManagerService extends LineageSystemService { if (!skipFile) { try { loadFromFile(); - } catch (XmlPullParserException e) { - init = true; - } catch (IOException e) { + } catch (XmlPullParserException | IOException e) { init = true; } } diff --git a/lineage/lib/main/java/org/lineageos/platform/internal/ProfileTriggerHelper.java b/lineage/lib/main/java/org/lineageos/platform/internal/ProfileTriggerHelper.java index 49ed43f7..76c4276f 100644 --- a/lineage/lib/main/java/org/lineageos/platform/internal/ProfileTriggerHelper.java +++ b/lineage/lib/main/java/org/lineageos/platform/internal/ProfileTriggerHelper.java @@ -1,5 +1,6 @@ /* * SPDX-FileCopyrightText: 2013-2014 The CyanogenMod Project + * SPDX-FileCopyrightText: 2024 The LineageOS Project * SPDX-License-Identifier: Apache-2.0 */ @@ -30,13 +31,13 @@ import java.util.UUID; public class ProfileTriggerHelper extends BroadcastReceiver { private static final String TAG = "ProfileTriggerHelper"; - private Context mContext; - private ProfileManagerService mManagerService; + private final Context mContext; + private final ProfileManagerService mManagerService; - private WifiManager mWifiManager; + private final WifiManager mWifiManager; private String mLastConnectedSSID; - private IntentFilter mIntentFilter; + private final IntentFilter mIntentFilter; private boolean mFilterRegistered = false; private class SettingsObserver extends ContentObserver { diff --git a/lineage/lib/main/java/org/lineageos/platform/internal/common/LineageSystemServiceHelper.java b/lineage/lib/main/java/org/lineageos/platform/internal/common/LineageSystemServiceHelper.java index e00f72bd..e6e02788 100644 --- a/lineage/lib/main/java/org/lineageos/platform/internal/common/LineageSystemServiceHelper.java +++ b/lineage/lib/main/java/org/lineageos/platform/internal/common/LineageSystemServiceHelper.java @@ -1,5 +1,6 @@ /* * SPDX-FileCopyrightText: 2016 The CyanogenMod Project + * SPDX-FileCopyrightText: 2024 The LineageOS Project * SPDX-License-Identifier: Apache-2.0 */ @@ -15,7 +16,7 @@ import java.lang.reflect.InvocationTargetException; * Helper methods for fetching a LineageSystemService from a class declaration */ public class LineageSystemServiceHelper { - private Context mContext; + private final Context mContext; public LineageSystemServiceHelper(Context context) { mContext = context; @@ -41,10 +42,7 @@ public class LineageSystemServiceHelper { } catch (InstantiationException ex) { throw new RuntimeException("Failed to create service " + serviceClass + ": service could not be instantiated", ex); - } catch (IllegalAccessException ex) { - throw new RuntimeException("Failed to create service " + serviceClass - + ": service must have a public constructor with a Context argument", ex); - } catch (NoSuchMethodException ex) { + } catch (IllegalAccessException | NoSuchMethodException ex) { throw new RuntimeException("Failed to create service " + serviceClass + ": service must have a public constructor with a Context argument", ex); } catch (InvocationTargetException ex) { diff --git a/lineage/lib/main/java/org/lineageos/platform/internal/common/UserContentObserver.java b/lineage/lib/main/java/org/lineageos/platform/internal/common/UserContentObserver.java index 64bf7158..00641ce7 100644 --- a/lineage/lib/main/java/org/lineageos/platform/internal/common/UserContentObserver.java +++ b/lineage/lib/main/java/org/lineageos/platform/internal/common/UserContentObserver.java @@ -1,5 +1,6 @@ /* * SPDX-FileCopyrightText: 2016 The CyanogenMod Project + * SPDX-FileCopyrightText: 2024 The LineageOS Project * SPDX-License-Identifier: Apache-2.0 */ package org.lineageos.platform.internal.common; @@ -19,9 +20,9 @@ import android.util.Log; public abstract class UserContentObserver extends ContentObserver { private static final String TAG = "UserContentObserver"; - private Runnable mUpdateRunnable; + private final Runnable mUpdateRunnable; - private IUserSwitchObserver mUserSwitchObserver = new IUserSwitchObserver.Stub() { + private final IUserSwitchObserver mUserSwitchObserver = new IUserSwitchObserver.Stub() { @Override public void onBeforeUserSwitching(int newUserId) throws RemoteException { } @@ -40,7 +41,7 @@ public abstract class UserContentObserver extends ContentObserver { } }; - private Handler mHandler; + private final Handler mHandler; /** * Content observer that tracks user switches @@ -49,12 +50,7 @@ public abstract class UserContentObserver extends ContentObserver { public UserContentObserver(Handler handler) { super(handler); mHandler = handler; - mUpdateRunnable = new Runnable() { - @Override - public void run() { - update(); - } - }; + mUpdateRunnable = this::update; } protected void observe() { diff --git a/lineage/lib/main/java/org/lineageos/platform/internal/display/AmbientLuxObserver.java b/lineage/lib/main/java/org/lineageos/platform/internal/display/AmbientLuxObserver.java index 401365d5..bfd4a8d8 100644 --- a/lineage/lib/main/java/org/lineageos/platform/internal/display/AmbientLuxObserver.java +++ b/lineage/lib/main/java/org/lineageos/platform/internal/display/AmbientLuxObserver.java @@ -1,5 +1,6 @@ /* * SPDX-FileCopyrightText: 2016 The CyanogenMod Project + * SPDX-FileCopyrightText: 2024 The LineageOS Project * SPDX-License-Identifier: Apache-2.0 */ package org.lineageos.platform.internal.display; @@ -31,7 +32,7 @@ public class AmbientLuxObserver { private final int mThresholdDuration; private boolean mLightSensorEnabled = false; - private int mLightSensorRate; + private final int mLightSensorRate; private float mAmbientLux = 0.0f; @@ -176,7 +177,7 @@ public class AmbientLuxObserver { */ private static class TimedMovingAverageRingBuffer { - private final LinkedList mRing = new LinkedList(); + private final LinkedList mRing = new LinkedList<>(); private final int mPeriod; @@ -242,7 +243,7 @@ public class AmbientLuxObserver { sb.append(i.next()); } return "average=" + getAverage() + " length=" + mRing.size() + - " mRing=[" + sb.toString() + "]"; + " mRing=[" + sb + "]"; } } } diff --git a/lineage/lib/main/java/org/lineageos/platform/internal/display/ColorTemperatureController.java b/lineage/lib/main/java/org/lineageos/platform/internal/display/ColorTemperatureController.java index 52757691..f01d557a 100644 --- a/lineage/lib/main/java/org/lineageos/platform/internal/display/ColorTemperatureController.java +++ b/lineage/lib/main/java/org/lineageos/platform/internal/display/ColorTemperatureController.java @@ -1,12 +1,11 @@ /* * SPDX-FileCopyrightText: 2016 The CyanogenMod Project - * SPDX-FileCopyrightText: 2018-2019 The LineageOS Project + * SPDX-FileCopyrightText: 2018-2024 The LineageOS Project * SPDX-License-Identifier: Apache-2.0 */ package org.lineageos.platform.internal.display; import android.animation.ValueAnimator; -import android.animation.ValueAnimator.AnimatorUpdateListener; import android.content.Context; import android.net.Uri; import android.os.Handler; @@ -48,7 +47,7 @@ public class ColorTemperatureController extends LiveDisplayFeature { private int mDayTemperature; private int mNightTemperature; - private AccelerateDecelerateInterpolator mInterpolator; + private final AccelerateDecelerateInterpolator mInterpolator; private ValueAnimator mAnimator; private final LineageHardwareManager mHardware; @@ -159,12 +158,7 @@ public class ColorTemperatureController extends LiveDisplayFeature { pw.println(" isTransitioning=" + isTransitioning()); } - private final Runnable mTransitionRunnable = new Runnable() { - @Override - public void run() { - updateColorTemperature(); - } - }; + private final Runnable mTransitionRunnable = this::updateColorTemperature; private boolean isTransitioning() { return getMode() == MODE_AUTO && @@ -212,7 +206,7 @@ public class ColorTemperatureController extends LiveDisplayFeature { return; } - long duration = (long)(5 * Math.abs(current - balance)); + long duration = 5L * Math.abs(current - balance); if (DEBUG) { @@ -228,14 +222,11 @@ public class ColorTemperatureController extends LiveDisplayFeature { mAnimator = ValueAnimator.ofInt(current, balance); mAnimator.setDuration(duration); mAnimator.setInterpolator(mInterpolator); - mAnimator.addUpdateListener(new AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(final ValueAnimator animation) { - synchronized (ColorTemperatureController.this) { - if (isScreenOn()) { - int value = (int) animation.getAnimatedValue(); - mHardware.setColorBalance(value); - } + mAnimator.addUpdateListener(animation -> { + synchronized (ColorTemperatureController.this) { + if (isScreenOn()) { + int value = (int) animation.getAnimatedValue(); + mHardware.setColorBalance(value); } } }); @@ -247,7 +238,8 @@ public class ColorTemperatureController extends LiveDisplayFeature { * correct configuration at the device level! */ private int mapColorTemperatureToBalance(int temperature) { - double z = org.lineageos.internal.util.MathUtils.powerCurveToLinear(mColorBalanceCurve, temperature); + double z = org.lineageos.internal.util.MathUtils.powerCurveToLinear(mColorBalanceCurve, + temperature); return Math.round(MathUtils.lerp((float)mColorBalanceRange.getLower(), (float)mColorBalanceRange.getUpper(), (float)z)); } @@ -294,12 +286,14 @@ public class ColorTemperatureController extends LiveDisplayFeature { // Scale the transition into night mode in 0.5hr before civil sunset if (now <= sunset) { - return mInterpolator.getInterpolation((float) (sunset - now) / TWILIGHT_ADJUSTMENT_TIME); + return mInterpolator.getInterpolation((float) (sunset - now) + / TWILIGHT_ADJUSTMENT_TIME); } // Scale the transition into day mode in 0.5hr after civil sunrise if (now >= sunrise) { - return mInterpolator.getInterpolation((float) (now - sunrise) / TWILIGHT_ADJUSTMENT_TIME); + return mInterpolator.getInterpolation((float) (now - sunrise) + / TWILIGHT_ADJUSTMENT_TIME); } // More than 0.5hr past civil sunset diff --git a/lineage/lib/main/java/org/lineageos/platform/internal/display/DisplayHardwareController.java b/lineage/lib/main/java/org/lineageos/platform/internal/display/DisplayHardwareController.java index 9cb03160..2cf403f2 100644 --- a/lineage/lib/main/java/org/lineageos/platform/internal/display/DisplayHardwareController.java +++ b/lineage/lib/main/java/org/lineageos/platform/internal/display/DisplayHardwareController.java @@ -1,13 +1,12 @@ /* * SPDX-FileCopyrightText: 2016 The CyanogenMod Project - * SPDX-FileCopyrightText: 2018-2021 The LineageOS Project + * SPDX-FileCopyrightText: 2018-2024 The LineageOS Project * SPDX-License-Identifier: Apache-2.0 */ package org.lineageos.platform.internal.display; import android.animation.FloatArrayEvaluator; import android.animation.ValueAnimator; -import android.animation.ValueAnimator.AnimatorUpdateListener; import android.content.Context; import android.net.Uri; import android.os.Handler; @@ -112,7 +111,7 @@ public class DisplayHardwareController extends LiveDisplayFeature { @Override public void onStart() { - final ArrayList settings = new ArrayList(); + final ArrayList settings = new ArrayList<>(); if (mUseCABC) { settings.add(DISPLAY_CABC); @@ -333,19 +332,16 @@ public class DisplayHardwareController extends LiveDisplayFeature { new FloatArrayEvaluator(new float[3]), currentColors, targetColors); mAnimator.setDuration(duration); mAnimator.setInterpolator(new LinearInterpolator()); - mAnimator.addUpdateListener(new AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(final ValueAnimator animation) { - synchronized (DisplayHardwareController.this) { - if (isScreenOn()) { - float[] value = (float[]) animation.getAnimatedValue(); - mHardware.setDisplayColorCalibration(new int[] { - (int) (value[0] * mMaxColor), - (int) (value[1] * mMaxColor), - (int) (value[2] * mMaxColor) - }); - screenRefresh(); - } + mAnimator.addUpdateListener(animation -> { + synchronized (DisplayHardwareController.this) { + if (isScreenOn()) { + float[] value = (float[]) animation.getAnimatedValue(); + mHardware.setDisplayColorCalibration(new int[] { + (int) (value[0] * mMaxColor), + (int) (value[1] * mMaxColor), + (int) (value[2] * mMaxColor) + }); + screenRefresh(); } } }); diff --git a/lineage/lib/main/java/org/lineageos/platform/internal/display/LiveDisplayService.java b/lineage/lib/main/java/org/lineageos/platform/internal/display/LiveDisplayService.java index a4e78199..7240110e 100644 --- a/lineage/lib/main/java/org/lineageos/platform/internal/display/LiveDisplayService.java +++ b/lineage/lib/main/java/org/lineageos/platform/internal/display/LiveDisplayService.java @@ -1,6 +1,6 @@ /* * SPDX-FileCopyrightText: 2016 The CyanogenMod Project - * SPDX-FileCopyrightText: 2017-2019,2021 The LineageOS Project + * SPDX-FileCopyrightText: 2017-2024 The LineageOS Project * SPDX-License-Identifier: Apache-2.0 */ package org.lineageos.platform.internal.display; @@ -210,12 +210,9 @@ public class LiveDisplayService extends LineageSystemService { } private void updateFeatures(final int flags) { - mHandler.post(new Runnable() { - @Override - public void run() { - for (int i = 0; i < mFeatures.size(); i++) { - mFeatures.get(i).update(flags, mState); - } + mHandler.post(() -> { + for (int i = 0; i < mFeatures.size(); i++) { + mFeatures.get(i).update(flags, mState); } }); } @@ -405,7 +402,7 @@ public class LiveDisplayService extends LineageSystemService { // Display postprocessing can have power impact. - private PowerManagerInternal.LowPowerModeListener mLowPowerModeListener = + private final PowerManagerInternal.LowPowerModeListener mLowPowerModeListener = new PowerManagerInternal.LowPowerModeListener() { @Override public void onLowPowerModeChanged(PowerSaveState state) { diff --git a/lineage/lib/main/java/org/lineageos/platform/internal/display/TwilightTracker.java b/lineage/lib/main/java/org/lineageos/platform/internal/display/TwilightTracker.java index d0b122cd..a2c2a6b7 100644 --- a/lineage/lib/main/java/org/lineageos/platform/internal/display/TwilightTracker.java +++ b/lineage/lib/main/java/org/lineageos/platform/internal/display/TwilightTracker.java @@ -1,6 +1,6 @@ /* * SPDX-FileCopyrightText: 2012 The Android Open Source Project - * SPDX-FileCopyrightText: 2017-2018,2021 The LineageOS Project + * SPDX-FileCopyrightText: 2017-20224 The LineageOS Project * SPDX-License-Identifier: Apache-2.0 */ @@ -12,7 +12,6 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; @@ -48,8 +47,7 @@ public final class TwilightTracker { private final LocationManager mLocationManager; private final LocationHandler mLocationHandler; - private final ArrayList mListeners = - new ArrayList(); + private final ArrayList mListeners = new ArrayList<>(); private TwilightState mTwilightState; diff --git a/lineage/lib/main/java/org/lineageos/platform/internal/health/ChargingControlController.java b/lineage/lib/main/java/org/lineageos/platform/internal/health/ChargingControlController.java index 066f86b3..0ab1f278 100644 --- a/lineage/lib/main/java/org/lineageos/platform/internal/health/ChargingControlController.java +++ b/lineage/lib/main/java/org/lineageos/platform/internal/health/ChargingControlController.java @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 The LineageOS Project + * SPDX-FileCopyrightText: 2023-2024 The LineageOS Project * SPDX-License-Identifier: Apache-2.0 */ @@ -100,7 +100,7 @@ public class ChargingControlController extends LineageHealthFeature { private static final SimpleDateFormat mDateFormatter = new SimpleDateFormat("hh:mm:ss a"); // Only when the battery level is above this limit will the charging control be activated. - private static int CHARGE_CTRL_MIN_LEVEL = 80; + private static final int CHARGE_CTRL_MIN_LEVEL = 80; private static final String INTENT_PARTS = "org.lineageos.lineageparts.CHARGING_CONTROL_SETTINGS"; diff --git a/sdk/src/java/org/lineageos/internal/notification/LineageBatteryLights.java b/sdk/src/java/org/lineageos/internal/notification/LineageBatteryLights.java index 1f246c1d..6898fc80 100644 --- a/sdk/src/java/org/lineageos/internal/notification/LineageBatteryLights.java +++ b/sdk/src/java/org/lineageos/internal/notification/LineageBatteryLights.java @@ -48,7 +48,7 @@ public final class LineageBatteryLights { private final Context mContext; - private NotificationManager mNotificationManager; + private final NotificationManager mNotificationManager; private int mZenMode; public interface LedUpdater { @@ -285,7 +285,7 @@ public final class LineageBatteryLights { com.android.internal.R.integer.config_notificationsBatteryFullARGB), UserHandle.USER_CURRENT); - // Adustable battery LED brightness. + // Adjustable battery LED brightness. if (mCanAdjustBrightness) { // Battery brightness level mBatteryBrightnessLevel = LineageSettings.System.getIntForUser(resolver, diff --git a/sdk/src/java/org/lineageos/internal/notification/LineageNotificationLights.java b/sdk/src/java/org/lineageos/internal/notification/LineageNotificationLights.java index f5f503e7..8d7fe61d 100644 --- a/sdk/src/java/org/lineageos/internal/notification/LineageNotificationLights.java +++ b/sdk/src/java/org/lineageos/internal/notification/LineageNotificationLights.java @@ -38,12 +38,12 @@ public final class LineageNotificationLights { // Light capabilities // Whether the notification light is RGB adjustable. - private boolean mMultiColorNotificationLed; + private final boolean mMultiColorNotificationLed; // Whether the lights HAL supports changing brightness. - private boolean mHALAdjustableBrightness; + private final boolean mHALAdjustableBrightness; // Whether the light should be considered brightness adjustable // (via HAL or via modifying RGB values). - private boolean mCanAdjustBrightness; + private final boolean mCanAdjustBrightness; // Light config private boolean mAutoGenerateNotificationColor; @@ -56,10 +56,9 @@ public final class LineageNotificationLights { private int mDefaultNotificationLedOn; private int mDefaultNotificationLedOff; - private ArrayMap mNotificationPulseCustomLedValues; - private Map mPackageNameMappings; - private final ArrayMap mGeneratedPackageLedColors = - new ArrayMap(); + private final ArrayMap mNotificationPulseCustomLedValues; + private final Map mPackageNameMappings; + private final ArrayMap mGeneratedPackageLedColors = new ArrayMap<>(); private int mZenMode; @@ -455,7 +454,7 @@ public final class LineageNotificationLights { LineageSettings.System.NOTIFICATION_LIGHT_SCREEN_ON, 0, UserHandle.USER_CURRENT) != 0); - // Adustable notification LED brightness. + // Adjustable notification LED brightness. if (mCanAdjustBrightness) { // Normal brightness. mNotificationLedBrightnessLevel = LineageSettings.System.getIntForUser(resolver,