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

一. 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 文件进行替换
相关推荐
杉氧38 分钟前
副作用 (Side Effects) 全攻略:如何像大师一样掌控 Composable 的生命周期?
android·架构·android jetpack
Kapaseker5 小时前
Kotlin Toolchain 0.11 发布:主要是把 Amper 干没了
android·kotlin
三少爷的鞋6 小时前
Android 现代架构不需要事件总线进阶篇
android
杉氧21 小时前
深入理解 Compose 重组机制:快照系统如何驱动 UI 精准刷新?
android·架构·android jetpack
召钱熏21 小时前
状态枚举正确≠渲染正确:一个语音按钮的状态机边界修复实录
android·前端
杉氧1 天前
深度解析:Jetpack Compose 核心架构与底层原理 —— 十年安卓老兵的“破茧重生”
android·架构·android jetpack
通玄1 天前
Jetpack Compose 入门系列(七):ViewModel 与界面状态管理
android
落魄Android在线炒饭1 天前
Android Framework 开发技巧:android.jar 生成与系统快速编译验证
android
如此风景1 天前
Kotlin Flow操作符学习
android·kotlin
plainGeekDev1 天前
GreenDAO → Room
android·java·kotlin