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

一. [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 文件进行替换
相关推荐
de之梦-御风6 分钟前
【电视投屏】针对“局域网投屏开源项目(Android 手机 ↔ Android TV)
android·智能手机·开源
threelab21 分钟前
Merge3D 三维引擎中 GeoJSON 数据加载的整体设计
android·3d
优选资源分享42 分钟前
Escrcpy 便携版 v2.0.0:安卓手机电脑同屏软件
android·智能手机·电脑
2501_915918411 小时前
介绍如何在电脑上查看 iPhone 和 iPad 的完整设备信息
android·ios·小程序·uni-app·电脑·iphone·ipad
TheNextByte11 小时前
如何通过蓝牙将照片从 iPhone 分享到Android ?
android·gitee·iphone
2501_916008891 小时前
没有 Mac 如何在 Windows 上创建 iOS 应用描述文件
android·macos·ios·小程序·uni-app·iphone·webview
Android系统攻城狮3 小时前
Android ALSA进阶之处理PCM的ioctl命令snd_pcm_lib_ioctl:用法实例(一百)
android·pcm·alsa·音频进阶
诸神黄昏EX12 小时前
Android Build系列专题【篇六:VINTF机制】
android
浪客川12 小时前
安卓日志工具类
android
csj5013 小时前
安卓基础之《(14)—数据存储(4)应用组件Application》
android