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

一. [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 文件进行替换
相关推荐
提子拌饭13317 小时前
番茄时间管理:鸿蒙Flutter 实现的高效时间管理工具
android·flutter·华为·架构·开源·harmonyos·鸿蒙
4311媒体网17 小时前
帝国CMS二次开发实战:精准实现“最新资讯”标识与高亮判断
android
BLUcoding17 小时前
Android 轻量级本地存储 SharedPreferences
android
冬奇Lab18 小时前
Camera HAL3 接口:Android 相机的真正底牌
android·音视频开发·源码阅读
sensen_kiss18 小时前
CAN302 Technologies for E-Commerce 电子商务技术 Pt.6 市场营销与SEO(搜索引擎优化)
android·学习·搜索引擎
菜鸟国国18 小时前
Compose + Koin ViewModel 实战完全手册
android
小羊子说18 小时前
Android 音频系统深度解析:从 App 到内核的完整链路
android·人工智能·性能优化·车载系统
fengci.18 小时前
php反序列化(复习)(第三章)
android·开发语言·学习·php
D4c-lovetrain19 小时前
linux个人心得24 (mysql③,AI排版尝试)
android·adb
csj5019 小时前
安卓基础之《(25)—竖屏与横屏切换》
android