没有合适的资源?快使用搜索试试~ 我知道了~
(两百零七)Android Q wifi config开机加载流程
1 下载量 3 浏览量
2021-01-03
22:12:23
上传
评论 1
收藏 167KB PDF 举报
温馨提示
目录 1.思路 2.流程梳理 3. 总结 1.思路 wifi config在手机中是以文件形式保存的,那开机的时候手机必然要解析文件成对应的config对象,梳理下流程 2.流程梳理 ClientModeImpl case CMD_BOOT_COMPLETED: // get other services that we need to manage getAdditionalWifiServiceInterfaces(); new Memo
资源推荐
资源详情
资源评论
(两百零七)(两百零七)Android Q wifi config开机加载流程开机加载流程
目录目录
1.思路
2.流程梳理
3. 总结
1.思路思路
wifi config在手机中是以文件形式保存的,那开机的时候手机必然要解析文件成对应的config对象,梳理下流程
2.流程梳理流程梳理
ClientModeImpl
case CMD_BOOT_COMPLETED:
// get other services that we need to manage
getAdditionalWifiServiceInterfaces();
new MemoryStoreImpl(mContext, mWifiInjector, mWifiScoreCard).start();
if (!mWifiConfigManager.loadFromStore()) {
Log.e(TAG, "Failed to load from config store");
}
registerNetworkFactory();
break;
WifiConfigManager
/**
* Read the config store and load the in-memory lists from the store data retrieved and sends
* out the networks changed broadcast.
*
* This reads all the network configurations from:
* 1. Shared WifiConfigStore.xml
* 2. User WifiConfigStore.xml
*
* @return true on success or not needed (fresh install), false otherwise.
*/
public boolean loadFromStore() {
// If the user unlock comes in before we load from store, which means the user store have
// not been setup yet for the current user. Setup the user store before the read so that
// configurations for the current user will also being loaded.
if (mDeferredUserUnlockRead) {
Log.i(TAG, "Handling user unlock before loading from store.");
List userStoreFiles =
WifiConfigStore.createUserFiles(mCurrentUserId);
if (userStoreFiles == null) {
Log.wtf(TAG, "Failed to create user store files");
return false;
}
mWifiConfigStore.setUserStores(userStoreFiles);
mDeferredUserUnlockRead = false;
}
try {
mWifiConfigStore.read();
} catch (IOException e) {
Log.wtf(TAG, "Reading from new store failed. All saved networks are lost!", e);
return false;
} catch (XmlPullParserException e) {
Log.wtf(TAG, "XML deserialization of store failed. All saved networks are lost!", e);
return false;
}
loadInternalData(mNetworkListSharedStoreData.getConfigurations(),
mNetworkListUserStoreData.getConfigurations(),
mDeletedEphemeralSsidsStoreData.getSsidToTimeMap(),
mRandomizedMacStoreData.getMacMapping());
return true;
}
WifiConfigStore
/**
* API to read the store data from the config stores.
* The method reads the user specific configurations from user specific config store and the
* shared configurations from the shared config store.
*/
public void read() throws XmlPullParserException, IOException {
// Reset both share and user store data.
resetStoreData(mSharedStore);
if (mUserStores != null) {
for (StoreFile userStoreFile : mUserStores) {
resetStoreData(userStoreFile);
}
}
long readStartTime = mClock.getElapsedSinceBootMillis();
byte[] sharedDataBytes = mSharedStore.readRawData();
deserializeData(sharedDataBytes, mSharedStore);
if (mUserStores != null) {
for (StoreFile userStoreFile : mUserStores) {
byte[] userDataBytes = userStoreFile.readRawData();
deserializeData(userDataBytes, userStoreFile);
}
}
long readTime = mClock.getElapsedSinceBootMillis() - readStartTime;
try {
mWifiMetrics.noteWifiConfigStoreReadDuration(toIntExact(readTime));
} catch (ArithmeticException e) {
// Silently ignore on any overflow errors.
}
Log.d(TAG, "Reading from all stores completed in " + readTime + " ms.");
}
顺便看下WifiConfigStore在WifiInjector的初始化
mWifiConfigStore = new WifiConfigStore(
mContext, clientModeImplLooper, mClock, mWifiMetrics,
WifiConfigStore.createSharedFile());
/**
* Create a new instance of the shared store file.
*
* @return new instance of the store file or null if the directory cannot be created.
*/
public static @Nullable StoreFile createSharedFile() {
return createFile(Environment.getDataMiscDirectory(), STORE_FILE_SHARED_GENERAL);
}
/**
* Config store file for general shared store file.
*/
public static final int STORE_FILE_SHARED_GENERAL = 0;
/**
* Helper method to create a store file instance for either the shared store or user store.
* Note: The method creates the store directory if not already present. This may be needed for
* user store files.
*
* @param storeBaseDir Base directory under which the store file is to be stored. The store file
* will be at /wifi/WifiConfigStore.xml.
* @param fileId Identifier for the file. See {@link StoreFileId}.
* @return new instance of the store file or null if the directory cannot be created.
*/
private static @Nullable StoreFile createFile(File storeBaseDir, @StoreFileId int fileId) {
File storeDir = new File(storeBaseDir, STORE_DIRECTORY_NAME);
if (!storeDir.exists()) {
if (!storeDir.mkdir()) {
Log.w(TAG, "Could not create store directory " + storeDir);
return null;
}
}
return new StoreFile(new File(storeDir, STORE_ID_TO_FILE_NAME.get(fileId)), fileId);
}
/**
* Directory to store the config store files in.
*/
private static final String STORE_DIRECTORY_NAME = "wifi";
/**
* Config store file name for general shared store file.
*/
private static final String STORE_FILE_NAME_SHARED_GENERAL = "WifiConfigStore.xml";
文件路径保存为data/misc/wifi/WifiConfigStore.xml
数据解析
/**
* Deserialize data from a {@link StoreFile} for all {@link StoreData} instances registered.
*
* @param dataBytes The data to parse
* @param storeFile StoreFile that we read from. Will be used to retrieve the list of clients
* who have data to deserialize from this file.
*
* @throws XmlPullParserException
* @throws IOException
*/
private void deserializeData(@NonNull byte[] dataBytes, @NonNull StoreFile storeFile)
throws XmlPullParserException, IOException {
List storeDataList = retrieveStoreDataListForStoreFile(storeFile);
if (dataBytes == null) {
indicateNoDataForStoreDatas(storeDataList);
return;
}
final XmlPullParser in = Xml.newPullParser();
final ByteArrayInputStream inputStream = new ByteArrayInputStream(dataBytes);
in.setInput(inputStream, StandardCharsets.UTF_8.name());
// Start parsing the XML stream.
int rootTagDepth = in.getDepth() + 1;
parseDocumentStartAndVersionFromXml(in);
String[] headerName = new String[1];
Set storeDatasInvoked = new HashSet();
while (XmlUtil.gotoNextSectionOrEnd(in, headerName, rootTagDepth)) {
// There can only be 1 store data matching the tag (O indicates a fatal
// error).
StoreData storeData = storeDataList.stream()
.filter(s -> s.getName().equals(headerName[0]))
.findAny()
.orElse(null);
if (storeData == null) {
throw new XmlPullParserException("Unknown store data: " + headerName[0] + ". List of store data: " + storeDataList);
}
storeData.deserializeData(in, rootTagDepth + 1);
storeDatasInvoked.add(storeData);
}
剩余7页未读,继续阅读
资源评论
weixin_38590996
- 粉丝: 8
- 资源: 929
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功