sdk: A few finals don't hurt

And a few language features (HashMap constructors, collapsing
catch blocks, method references)
plus two typos

Change-Id: I9ae2f7c006c5f2f9c7c99eab81059c08bece1202
This commit is contained in:
Michael W
2024-11-15 20:39:22 +01:00
parent 28185f0f54
commit 423cec2b12
13 changed files with 72 additions and 98 deletions

View File

@@ -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";

View File

@@ -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<UUID, Profile>();
mProfileNames = new HashMap<String, UUID>();
mProfiles = new HashMap<>();
mProfileNames = new HashMap<>();
mGroups = new HashMap<UUID, NotificationGroup>();
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;
}
}

View File

@@ -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 {

View File

@@ -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) {

View File

@@ -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() {

View File

@@ -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<Sample> mRing = new LinkedList<Sample>();
private final LinkedList<Sample> 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 + "]";
}
}
}

View File

@@ -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

View File

@@ -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<Uri> settings = new ArrayList<Uri>();
final ArrayList<Uri> 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();
}
}
});

View File

@@ -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) {

View File

@@ -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<TwilightListenerRecord> mListeners =
new ArrayList<TwilightListenerRecord>();
private final ArrayList<TwilightListenerRecord> mListeners = new ArrayList<>();
private TwilightState mTwilightState;

View File

@@ -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";

View File

@@ -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,

View File

@@ -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<String, LedValues> mNotificationPulseCustomLedValues;
private Map<String, String> mPackageNameMappings;
private final ArrayMap<String, Integer> mGeneratedPackageLedColors =
new ArrayMap<String, Integer>();
private final ArrayMap<String, LedValues> mNotificationPulseCustomLedValues;
private final Map<String, String> mPackageNameMappings;
private final ArrayMap<String, Integer> 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,