diff --git a/nt-fwk/Android.bp b/nt-fwk/Android.bp new file mode 100644 index 0000000..7f5ebb8 --- /dev/null +++ b/nt-fwk/Android.bp @@ -0,0 +1,14 @@ +// +// Copyright (C) 2024 The LineageOS Project +// +// SPDX-License-Identifier: Apache-2.0 +// + +java_library { + name: "nt-fwk", + installable: true, + + srcs: [ + "src/**/*.java", + ], +} diff --git a/nt-fwk/nt-fwk.mk b/nt-fwk/nt-fwk.mk new file mode 100644 index 0000000..914868e --- /dev/null +++ b/nt-fwk/nt-fwk.mk @@ -0,0 +1,8 @@ +# +# Copyright (C) 2024 The LineageOS Project +# +# SPDX-License-Identifier: Apache-2.0 +# + +PRODUCT_PACKAGES += nt-fwk +PRODUCT_BOOT_JARS += nt-fwk diff --git a/nt-fwk/src/com/nothing/NtFeaturesUtils.java b/nt-fwk/src/com/nothing/NtFeaturesUtils.java new file mode 100644 index 0000000..005b30a --- /dev/null +++ b/nt-fwk/src/com/nothing/NtFeaturesUtils.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2024 The LineageOS Project + * SPDX-License-Identifier: Apache-2.0 + */ + +package com.nothing; + +import android.os.Build; +import android.os.SystemProperties; + +import java.util.BitSet; + +public class NtFeaturesUtils { + + private static final BitSet sFeatures = new BitSet(38); + + static { + final String fullProp = SystemProperties.get("ro.build.nothing.feature.base", "0"); + final String productDiffProp = SystemProperties.get("ro.build.nothing.feature.diff.product." + Build.PRODUCT, "0"); + final String deviceDiffProp = SystemProperties.get("ro.build.nothing.feature.diff.device." + Build.DEVICE, "0"); + + base(Long.decode(fullProp).longValue()); + change(Long.decode(productDiffProp).longValue()); + change(Long.decode(deviceDiffProp).longValue()); + } + + public static boolean isSupport(int... features) { + for (int feature : features) { + if (feature < 0 || feature > 37) { + return false; + } + if (!sFeatures.get(feature)) { + return false; + } + } + return true; + } + + private static void base(long full) { + int index = 0; + while (full != 0) { + if (full % 2 != 0) { + sFeatures.set(index); + } + index++; + full >>>= 1; + } + } + + private static void change(long diff) { + int index = 0; + while (diff != 0) { + if (diff % 2 != 0) { + sFeatures.flip(index); + } + index++; + diff >>>= 1; + } + } +}