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

一. [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 文件进行替换
相关推荐
2501_937189235 小时前
莫凡电视:地方台专属聚合 稳定直播播放工具
android·源码·源代码管理
耶叶7 小时前
Android 新权限申请模型(Activity Result API)
android
阿拉斯攀登7 小时前
【RK3576 安卓 JNI/NDK 系列 04】JNI 核心语法(下):字符串、数组与对象操作
android·驱动开发·rk3568·瑞芯微·rk安卓驱动·jni字符串操作
2501_915909067 小时前
不用越狱就看不到 iOS App 内部文件?使用 Keymob 查看和导出应用数据目录
android·ios·小程序·https·uni-app·iphone·webview
llxxyy卢7 小时前
web部分中等题目
android·前端
轩情吖7 小时前
MySQL之事务管理
android·后端·mysql·adb·事务·隔离性·原子性
万物得其道者成7 小时前
uni-app Android 离线打包:多环境(prod/dev)配置
android·opencv·uni-app
符哥20087 小时前
Firebase 官方提供的Quick Start-Android 库的功能集讲解
android
koeda8 小时前
android17系统兼容
android·安卓
进击的cc9 小时前
面试官:Handler 没消息时为啥不卡死?带你从源码到底层内核彻底整明白!
android·面试