• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.net.wifi;
18 
19 import android.os.Build;
20 import android.os.ServiceManager;
21 import android.os.SystemProperties;
22 import android.security.legacykeystore.ILegacyKeystore;
23 import android.util.Log;
24 
25 import com.android.internal.net.ConnectivityBlobStore;
26 
27 /**
28  * Database blob store for Wifi.
29  * @hide
30  */
31 public class WifiBlobStore extends ConnectivityBlobStore {
32     private static final String TAG = "WifiBlobStore";
33     private static final String DB_NAME = "WifiBlobStore.db";
34     private static final String LEGACY_KEYSTORE_SERVICE_NAME = "android.security.legacykeystore";
35     private static final boolean sIsVendorApiLevelGreaterThanT = isVendorApiLevelGreaterThanT();
36     private static WifiBlobStore sInstance;
WifiBlobStore()37     private WifiBlobStore() {
38         super(DB_NAME);
39     }
40 
isVendorApiLevelGreaterThanT()41     private static boolean isVendorApiLevelGreaterThanT() {
42         int androidT = Build.VERSION_CODES.TIRAMISU; // redefine to avoid errorprone build issue
43         String[] vendorApiLevelProps = {
44                 "ro.board.api_level", "ro.board.first_api_level", "ro.vndk.version"};
45         for (String propertyName : vendorApiLevelProps) {
46             int apiLevel = SystemProperties.getInt(propertyName, -1);
47             if (apiLevel != -1) {
48                 Log.i(TAG, "Retrieved API level property, value=" + apiLevel);
49                 return apiLevel > androidT;
50             }
51         }
52         // If none of the properties are defined, we are using the current API level (> V)
53         Log.i(TAG, "No API level properties are defined");
54         return true;
55     }
56 
57     /**
58      * Check whether supplicant can access values stored in WifiBlobstore.
59      *
60      * NonStandardCertCallback was added in Android U, allowing supplicant to access the
61      * WifiKeystore APIs, which access WifiBlobstore. Previously, supplicant used
62      * WifiKeystoreHalConnector to access values stored in Legacy Keystore.
63      *
64      * @hide
65      */
supplicantCanAccessBlobstore()66     public static boolean supplicantCanAccessBlobstore() {
67         return sIsVendorApiLevelGreaterThanT;
68     }
69 
70     /** Returns an instance of WifiBlobStore. */
getInstance()71     public static WifiBlobStore getInstance() {
72         if (sInstance == null) {
73             sInstance = new WifiBlobStore();
74         }
75         return sInstance;
76     }
77 
78     /** Returns an interface to access the Legacy Keystore service. */
getLegacyKeystore()79     public static ILegacyKeystore getLegacyKeystore() {
80         return ILegacyKeystore.Stub.asInterface(
81                 ServiceManager.checkService(LEGACY_KEYSTORE_SERVICE_NAME));
82     }
83 }
84