[FAQ19780]How to auto update apn database by OTA
2017-09-05 10:21
615 查看
[DESCRIPTION]
通过fota 升级apns-conf.xml文件,系统不能自动去更新apn数据库,需要手动去操作。为了便于用户使用,需要进行客制化实现。
[SOLUTION]
第一步: 修改code,并通过OTA升级更新上述修改
1) 定义OTA升级后的文件
File path: /bootable/recovery/
int main(int argc,
char **argv) {
...
...
if (status != INSTALL_SUCCESS) {
ui->Print("Installation
aborted.\n");
ui->Print("OTA failed!
Please power off the device to keep it in this state and file a bug report!\n");
// If this is an eng or userdebug build,
then automatically
// turn the text display on if the script fails so the error
// message is visible.
if (is_ro_debuggable())
{
ui->ShowText(true);
}
+ }else{
+ create_ota_done_file();
+ }
...
...
}
+ static const char *OTA_DONE_FILE = "/cache/otadone";
+ int create_ota_done_file(void){
+ FILE *fd;
+ printf("--create_ota_done_file %s",
OTA_DONE_FILE);
+ fd = fopen_path(OTA_DONE_FILE,
"w");
+ printf(" fd=%d
, file open :", fd);
+ if (fd == NULL) {
+ printf(" failed, error code: %s", strerror(errno));
+ return -1;
+ }else{
+ printf("success ");
+ chown(OTA_DONE_FILE,2001,2001);
+ chmod(OTA_DONE_FILE,0777);
+ }
+ fclose(fd);
+ return 0;
+ }
}
2) file path : packages\apps\Settings\AndroidManifest.xml
...
....
+ <receiver android:name="com.android.settings.ApnBootCompleteReceiver">
+ <intent-filter>
+ <action android:name="android.intent.action.BOOT_COMPLETED"></action>
+ </intent-filter>
+ </receiver>
</application>
}
3)新增一支处理APN 数据更新的文件
package com.android.settings;
import android.content.BroadcastReceiver;
import android.util.Log;
import java.io.File;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.net.Uri;
import java.util.List;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Environment;
public class ApnBootCompleteReceiver extends BroadcastReceiver{
private static final String OTA_DONE_FILE="/cache/otadone";
private static final String TAG = "ApnBootCompleteReceiver";
private static final boolean DBG = true;
public static final String RESTORE_CARRIERS_URI = "content://telephony/carriers/restore";
private static final Uri DEFAULTAPN_URI = Uri.parse(RESTORE_CARRIERS_URI);
private List<SubscriptionInfo> mSelectableSubInfos;
private final String ACTION_BOOT ="android.intent.action.BOOT_COMPLETED";
private void OtaDoneFile(Context context){
File otaFile=new File(OTA_DONE_FILE);
Log.d(TAG,"cachedirectory is:+"+Environment.getDownloadCacheDirectory());
if (DBG) Log.d(TAG,"otaFile = " + otaFile);
if(otaFile.exists()){
Log.d(TAG,"OTA done success and update APN Info");
ContentResolver resolver = context.getContentResolver();
/// M: add sub id for APN
// resolver.delete(DEFAULTAPN_URI, null, null);
mSelectableSubInfos = SubscriptionManager.from(context).getActiveSubscriptionInfoList();
if(mSelectableSubInfos ==null){
Log.d(TAG,"no sim is inserted");
return;
}
for(int i=0; i< mSelectableSubInfos.size();i++){
SubscriptionInfo mSubscriptionInfo=mSelectableSubInfos.get(i);
if(mSubscriptionInfo != null){
Log.d(TAG,"delete db start");
int delete_id = resolver.delete(getDefaultApnUri(mSubscriptionInfo.getSubscriptionId()), null, null);
Log.d(TAG,"delete id is:"+delete_id);
otaFile.delete();
Log.d(TAG,"delete db end");
}
}
}else{
Log.d(TAG,"No OTA");
return;
}
}
private Uri getDefaultApnUri(int subId) {
return Uri.withAppendedPath(DEFAULTAPN_URI, "/subId/" + subId);
}
@Override
public void onReceive(Context context,Intent intent){
if(ACTION_BOOT.equals(intent.getAction())){
OtaDoneFile(context);
}
}
第二步: 在第一步基础上,再通过OTA 推送 APN 的数据更新
补充说明: 为什么要经过两次OTA更新才能生效。由于OTA 升级会先启动recovery.cpp,虽然修改了recovery.cpp中的流程,但第一次OTA升级时默认会走recovery.cpp修改之前的逻辑,也就无法生成临时文件,无法触发APN
数据的自动更新。只有先通过OTA更新recovery.cpp的流程,让修改部分被执行, 再次OTA升级时,才能生成临时文件,触发APN数据的自动更新。
通过fota 升级apns-conf.xml文件,系统不能自动去更新apn数据库,需要手动去操作。为了便于用户使用,需要进行客制化实现。
[SOLUTION]
第一步: 修改code,并通过OTA升级更新上述修改
1) 定义OTA升级后的文件
File path: /bootable/recovery/
int main(int argc,
char **argv) {
...
...
if (status != INSTALL_SUCCESS) {
ui->Print("Installation
aborted.\n");
ui->Print("OTA failed!
Please power off the device to keep it in this state and file a bug report!\n");
// If this is an eng or userdebug build,
then automatically
// turn the text display on if the script fails so the error
// message is visible.
if (is_ro_debuggable())
{
ui->ShowText(true);
}
+ }else{
+ create_ota_done_file();
+ }
...
...
}
+ static const char *OTA_DONE_FILE = "/cache/otadone";
+ int create_ota_done_file(void){
+ FILE *fd;
+ printf("--create_ota_done_file %s",
OTA_DONE_FILE);
+ fd = fopen_path(OTA_DONE_FILE,
"w");
+ printf(" fd=%d
, file open :", fd);
+ if (fd == NULL) {
+ printf(" failed, error code: %s", strerror(errno));
+ return -1;
+ }else{
+ printf("success ");
+ chown(OTA_DONE_FILE,2001,2001);
+ chmod(OTA_DONE_FILE,0777);
+ }
+ fclose(fd);
+ return 0;
+ }
}
2) file path : packages\apps\Settings\AndroidManifest.xml
...
....
+ <receiver android:name="com.android.settings.ApnBootCompleteReceiver">
+ <intent-filter>
+ <action android:name="android.intent.action.BOOT_COMPLETED"></action>
+ </intent-filter>
+ </receiver>
</application>
}
3)新增一支处理APN 数据更新的文件
package com.android.settings;
import android.content.BroadcastReceiver;
import android.util.Log;
import java.io.File;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.net.Uri;
import java.util.List;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Environment;
public class ApnBootCompleteReceiver extends BroadcastReceiver{
private static final String OTA_DONE_FILE="/cache/otadone";
private static final String TAG = "ApnBootCompleteReceiver";
private static final boolean DBG = true;
public static final String RESTORE_CARRIERS_URI = "content://telephony/carriers/restore";
private static final Uri DEFAULTAPN_URI = Uri.parse(RESTORE_CARRIERS_URI);
private List<SubscriptionInfo> mSelectableSubInfos;
private final String ACTION_BOOT ="android.intent.action.BOOT_COMPLETED";
private void OtaDoneFile(Context context){
File otaFile=new File(OTA_DONE_FILE);
Log.d(TAG,"cachedirectory is:+"+Environment.getDownloadCacheDirectory());
if (DBG) Log.d(TAG,"otaFile = " + otaFile);
if(otaFile.exists()){
Log.d(TAG,"OTA done success and update APN Info");
ContentResolver resolver = context.getContentResolver();
/// M: add sub id for APN
// resolver.delete(DEFAULTAPN_URI, null, null);
mSelectableSubInfos = SubscriptionManager.from(context).getActiveSubscriptionInfoList();
if(mSelectableSubInfos ==null){
Log.d(TAG,"no sim is inserted");
return;
}
for(int i=0; i< mSelectableSubInfos.size();i++){
SubscriptionInfo mSubscriptionInfo=mSelectableSubInfos.get(i);
if(mSubscriptionInfo != null){
Log.d(TAG,"delete db start");
int delete_id = resolver.delete(getDefaultApnUri(mSubscriptionInfo.getSubscriptionId()), null, null);
Log.d(TAG,"delete id is:"+delete_id);
otaFile.delete();
Log.d(TAG,"delete db end");
}
}
}else{
Log.d(TAG,"No OTA");
return;
}
}
private Uri getDefaultApnUri(int subId) {
return Uri.withAppendedPath(DEFAULTAPN_URI, "/subId/" + subId);
}
@Override
public void onReceive(Context context,Intent intent){
if(ACTION_BOOT.equals(intent.getAction())){
OtaDoneFile(context);
}
}
第二步: 在第一步基础上,再通过OTA 推送 APN 的数据更新
补充说明: 为什么要经过两次OTA更新才能生效。由于OTA 升级会先启动recovery.cpp,虽然修改了recovery.cpp中的流程,但第一次OTA升级时默认会走recovery.cpp修改之前的逻辑,也就无法生成临时文件,无法触发APN
数据的自动更新。只有先通过OTA更新recovery.cpp的流程,让修改部分被执行, 再次OTA升级时,才能生成临时文件,触发APN数据的自动更新。
相关文章推荐
- How to identify all the Corrupted Objects in the Database reported by RMAN
- How to remove Oracle Database from your computer---By Roger Gong
- How to create physical standby database with 11g RMAN DUPLICATE FROM ACTIVE DATABASE [ID 747250.1]
- How To Make Cscope Database by Shell
- How to update windows by manual
- How to create physical standby database with 11g RMAN DUPLICATE FROM ACTIVE DATABASE [ID 747250.1]
- How to Convert a 32-bit Database to 64-bit Database on Linux (update olap)
- How to remove Oracle Database from your computer---By Roger Gong
- How to create physical standby database with 11g RMAN DUPLICATE FROM ACTIVE DATABASE [ID 747250.1]
- FAQ: How to Use AWR reports to Diagnose Database Performance Issues [ID 1359094.1]
- [linux] How to update locate database?
- How to determine who is logged on to a database by using Microsoft Jet UserRoster in Access 2000
- Master Note- How to diagnose Database Performance - FAQ [ID 402983.1]
- nrf51822 secure DFU by OTA: How to Set Password in the DFU zip File
- How to grant access to SQL logins on a standby database when the guest user is disabled in SQL Serve
- How to create physical standby database with 11g RMAN DUPLICATE FROM ACTIVE DATABASE [ID 747250.1]
- Master Note: How to diagnose Database Performance - FAQ [ID 402983.1]
- FAQ: How to Use AWR reports to Diagnose Database Performance Issues [ID 1359094.1]
- Oracle 11g Active Data Guard step by step: How to create a Physical Standby Database using RMAN
- How to remove Oracle Database from your computer---By Roger Gong