开机后无网络,多次重启手机发现开机时间永远是版本编译时间(高通)

一. Solution Time cannot set successfully after boot up

KBA number: KBA-180411191707

Applicable platform: android O/P/Q

二. Issue description:

Under some conditions, time set is not expected after device

reboot.

三.Precondition

Not insert sim card and not connect wifi network.

四. Steps

Contain Trade Secreo

  1. observe the time when device boot-up, for example the fix time is 2018/4/8 14:10;

  2. put device aside for a few minutes, for example the time is 2018/4/8 14:14 now, then reboot the device and observe the time ;

  3. change the time in settings ui, for example change time prior to fix time 2018/4/8 14:10,then reboot the device and observe the time ;

  4. change the time in settings ui, for example change time 10min later than fix time 2018/4/8 ,

then reboot the device and observe the time ;

五. Actual Result

at step2, observed time is the fix time 2018/4/8 14:10

at step3, observed time is the fix time 2018/4/8 14:10

at step4, observed time is a little later the time set in settings ui, not the fix time

六. Expect Result

at step2, observed time is a few later than the fix time 2018/4/8 14:10

at step3, observed time is a few later than the time set in settings ui, not the fix time

at step4, observed time is a little later the time set in settings ui, not the fix time

七. Probability

100%

八. Log snippet

01-03 08:35:35.946 1673 1673 I AlarmManager: Current time only 174935946, advancing to build time

1522836079000 //here 174935946 (1970/1/3 8:35:35) is System.currentTimeMillis(),and build time

1522836079000 (2018/4/4 18:1:19) is the last modified time of system directory .

01-03 08:35:35.946 1673 1673 D AlarmManagerService: Setting time of day to sec=1522836079

04-04 18:01:19.000 1673 1673 W AlarmManagerService: Unable to set rtc to 1522836079: Invalid argument

九. Issue Analysis:

In AlarmManagerService.java on android O, we can see setKernelTime will be invoked:

// Also sure that we're booting with a halfway sensible current time

if (mNativeData != 0) {

final long systemBuildTime #Environment.getRootDirectory().lastModified();

if (System.currentTimeMillis() < systemBuildTime) {

Slog.i(TAG, "Current time only "+ System.currentTimeMillis()+", advancing to build time "+ systemBuildTime);

setKernelTime(mNativeData, systemBuildTime);

}

}

And in com_android_server_AlarmManagerService.cpp, setTime will be infoked, and ret < 0 :

static jint android_server_AlarmManagerService_setKernelTime(JNIEnv*, jobject, jlong nativeData,jlong millis)

{

...

ALOGD("Setting time of day to sec= %d\n", (int) tv.tv_sec); 129 if (res < 0) {

ret = impl->setTime(&tv);

if(ret <0) {

ALOGW("Unable to set rtc to %ld: %s\n", tv.tv_sec, strerror(errno));

ret =- 1;

return ret;

}

int Alarmlmpl :: setTime(struct timeval *tv)

{

struct rtc_time rtc;

struct tm tm, *gmtimoential - May Contain Trade Secrete

int fd;

int res;

res = settimeofday(tv, NULL); ]//here will change the time in RAM. So the phone time will

changed by UI

......

res = ioctl(fd, RTC_SET_TIME, &rtc);]//cannot set it successful, because RTC is readonly, so

Waitforalarm will return fail. Broadcast time_set cannot set to time_daemon, the offset cannot save successfully, after reboot , the time will reset.

if (res <0)

ALOGV("RTC_SET_TIME ioctl failed: %s\n", strerror(errno));

done:

close(fd);

return res;

}

And, AlarmManagerService always send the "ACTION_TIME_CHANGED" broadcast after

mlnjector.setKernelTime(systemBuildTime).

in AlarmManagerService.java

Intent intent = new

Intent(Intent.ACTION_TIME_CHANGED);

intent.addFlags (Intent.FLAG_RECEIVER_REPLACE PENDING,

Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE BOOT,

Intent.FLAG_RECEIVER INCLUDE_BACKGROUND,

Intent. FLAG_RECEIVER VISIBLE_TO_INSTANT APPS);

getContext ().sendBroadcastAsUser (intent,

UserHandle.ALL) ;

But this broadcast is sent before system boot completed, only dynamically registered receivers can receive this broadcast.

Since TimeServiceBroadcastReceiver is static registered receiver, so it can't receive the broadcast.

We can also let TimeServiceBroadcastReceiver.java receive the "locked_boot_completed" broadcast to restores the time of the day.

十.Solution:

Please revert above google patch in AlarmManagerService.java which is added from android O :

https://android.googlesource.com/platform/frameworks/base/+/24757146d1a70f3f483b660a2d20bbdd71152782^!/services/core/java/com/android/server/AlarmManagerService.java

Also please modify vendor/qcom/proprietary/time-services/src/com/qualcomm/timeservice/ as below

to try:

diff -- git a/AndroidManifest.xml b/AndroidManifest.xml

old mode 100644

new mode 100755

index 123dc57 .. 0541a25

--- a/AndroidManifest.xml

+++ b/AndroidManifest.xml

@@ -12,6 +12,8 @@

package="com.qualcomm.timeservice">

<uses-permission android:name="android.permission.WAKE_LOCK" />
+ <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application>

<receiver android:name=".TimeServiceBroadcastReceiver"

android:exported="false"

@@ -19,6 +21,7 @@

android:label="TimeServiceBroadcastReceiver">

<intent-filter>
+ <action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />

</intent-filter>

</receiver>

</application>

Contain

diff -- git a/src/com/qualcomm/timeservice/TimeServiceBroadcastReceiver.java

b/src/com/qualcomm/timeservice/TimeServiceBroadcastReceiver.java

old mode 100644

new mode 100755

index ce599d2 .. fb69df8
--- a/src/com/qualcomm/timeservice/TimeServiceBroadcastReceiver.java
+++ b/src/com/qualcomm/timeservice/TimeServiceBroadcastReceiver.java

@@ -56,8 +56,8 @@ public class TimeServiceBroadcastReceiver extends BroadcastReceiver {

@Override

public void onReceive(Context context, Intent intent) {
**- if ((Intent.ACTION_TIME_CHANGED.equals(intent.getAction()))) {

  • if ((Intent.ACTION_TIME_CHANGED.equals(intent.getAction()))
  • || Intent.ACTION_LOCKED_BOOT_COMPLETED.equals(intent.getAction())) {**

Log.d(TAG, "Received" + intent.getAction() + " intent. " +

"Current Time is "+ System.currentTimeMillis());

PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);

十一. 本地修改验证:

http://172.16.5.191:8080/c/qualcomm/platform/vendor/qcom/proprietary/time-services/+/138630

diff --git a/AndroidManifest.xml b/AndroidManifest.xml

index 5123b28..b14cb4d 100755

--- a/AndroidManifest.xml

+++ b/AndroidManifest.xml

@@ -12,6 +12,7 @@

package="com.qualcomm.timeservice">

<uses-sdk android:targetSdkVersion="35" />

<uses-permission android:name="android.permission.WAKE_LOCK" />

  • <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application>

<receiver android:name=".TimeServiceBroadcastReceiver"

android:exported="false"

@@ -20,6 +21,8 @@

<intent-filter>

<action android:name="android.intent.action.TIME_SET" />

<action android:name="android.intent.action.TIMEZONE_CHANGED" />

  • <action android:name="android.intent.action.BOOT_COMPLETED" />

  • <action android:name="android.intent.action.LOCKED_BOOT_COMPLETED"/>

</intent-filter>

</receiver>

</application>

diff --git a/TimeService.apk b/TimeService.apk

index 4172643..d487dae 100755

--- a/TimeService.apk

+++ b/TimeService.apk

Binary files differ

diff --git a/src/com/qualcomm/timeservice/TimeServiceBroadcastReceiver.java b/src/com/qualcomm/timeservice/TimeServiceBroadcastReceiver.java

index 5fbfa2e..35580fe 100755

--- a/src/com/qualcomm/timeservice/TimeServiceBroadcastReceiver.java

+++ b/src/com/qualcomm/timeservice/TimeServiceBroadcastReceiver.java

@@ -59,7 +59,8 @@

@Override

public void onReceive(Context context, Intent intent) {

  • if ((Intent.ACTION_TIME_CHANGED.equals(intent.getAction()))) {
  • if (Intent.ACTION_TIME_CHANGED.equals(intent.getAction())

  • || Intent.ACTION_LOCKED_BOOT_COMPLETED.equals(intent.getAction())) {

Log.d(TAG, "Received" + intent.getAction() + " intent. " +

"Current Time is " + System.currentTimeMillis());

注意:

  1. 实际上生效的TimeService.apk, 需要单独编译出来TimeService.apk,进行替换。

Android.bp

android_app_import {

name: "TimeService",

apk: "TimeService.apk ",

certificate: "platform",

proprietary: true,

owner: "qti",

}

2.需要将注释的文件copy ,到packages/app 目录下创建time-services。

操作:

$mkdir packages/apps/time-services

$rm init.time_daemon.rc *.h *.c TimeService.apk

$chmod 777 Android.bp

修改Android.bp 文件

android_app {

name: "TimeService",

//增加AndroidManifest.xml 文件
+ manifest: "AndroidManifest.xml",

optimize: {

enabled: false,

},

**//只编译APK文件

  • dex_preopt: {
  • enabled: false,
  • },**

srcs: "\*\*/\*.java",

certificate: "platform",

proprietary: true,

owner: "qti",

sdk_version: "system_current",

}

编译命令:$ mma

  1. 将生成的TimeService.apk 文件进行替换
相关推荐
00后程序员张18 分钟前
Jenkins 自动上传 IPA 到 App Store 把发布步骤融入 CI/CD
android·ios·小程序·https·uni-app·iphone·webview
Gary Studio26 分钟前
复杂 SoC(RK3568)PCB 布局的五步
android·linux·硬件
plainGeekDev1 小时前
HttpURLConnection → OkHttp + Kotlin
android·java·kotlin
QING6181 小时前
Kotlin 协程新手指南 —— 协程基础与挂起函数
android·kotlin·android jetpack
2601_961766641 小时前
【分享】分身空间 2.3.7[特殊字符]生活工作互不打扰
android·生活
百度搜知知学社1 小时前
抖音双模块架构:兼容全安卓版本并支持登录
android·架构·安卓·登录·兼容性·抖音
文阿花1 小时前
Echarts实现柱状3D扇形图
android·3d·echarts
故渊at1 小时前
第六板块:Android 安全与权限体系 | 第十九篇:SELinux 强制访问控制与沙箱机制
android·安全·访问控制·selinux·权限体系·沙箱机制
千里马学框架1 小时前
重学Perfetto浏览器在线抓取trace及高频sql分享
android·sql·智能手机·架构·aaos·perfetto·车机
plainGeekDev2 小时前
批量写入 → Room 事务
android·java·kotlin