Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dad7b306 authored by Gabriel Biren's avatar Gabriel Biren
Browse files

Add method to check whether the vendor partition

version is > T.

Bug: 353140706
Flag: EXEMPT bugfix
Test: Manual test - check for the expected result
      on a device with a T vendor partion, and
      another with a V vendor partition.
Change-Id: Ie96855f477dfc388885f97335516c54f16e389a5
parent 7a733fd9
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -16,8 +16,11 @@

package android.net.wifi;

import android.os.Build;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.security.legacykeystore.ILegacyKeystore;
import android.util.Log;

import com.android.internal.net.ConnectivityBlobStore;

@@ -26,13 +29,44 @@ import com.android.internal.net.ConnectivityBlobStore;
 * @hide
 */
public class WifiBlobStore extends ConnectivityBlobStore {
    private static final String TAG = "WifiBlobStore";
    private static final String DB_NAME = "WifiBlobStore.db";
    private static final String LEGACY_KEYSTORE_SERVICE_NAME = "android.security.legacykeystore";
    private static final boolean sIsVendorApiLevelGreaterThanT = isVendorApiLevelGreaterThanT();
    private static WifiBlobStore sInstance;
    private WifiBlobStore() {
        super(DB_NAME);
    }

    private static boolean isVendorApiLevelGreaterThanT() {
        int androidT = Build.VERSION_CODES.TIRAMISU; // redefine to avoid errorprone build issue
        String[] vendorApiLevelProps = {
                "ro.board.api_level", "ro.board.first_api_level", "ro.vndk.version"};
        for (String propertyName : vendorApiLevelProps) {
            int apiLevel = SystemProperties.getInt(propertyName, -1);
            if (apiLevel != -1) {
                Log.i(TAG, "Retrieved API level property, value=" + apiLevel);
                return apiLevel > androidT;
            }
        }
        // If none of the properties are defined, we are using the current API level (> V)
        Log.i(TAG, "No API level properties are defined");
        return true;
    }

    /**
     * Check whether supplicant can access values stored in WifiBlobstore.
     *
     * NonStandardCertCallback was added in Android U, allowing supplicant to access the
     * WifiKeystore APIs, which access WifiBlobstore. Previously, supplicant used
     * WifiKeystoreHalConnector to access values stored in Legacy Keystore.
     *
     * @hide
     */
    public static boolean supplicantCanAccessBlobstore() {
        return sIsVendorApiLevelGreaterThanT;
    }

    /** Returns an instance of WifiBlobStore. */
    public static WifiBlobStore getInstance() {
        if (sInstance == null) {