现象
使用系统接口设置时间生效,查看rtc也设置成功。但是重启后时间为首次开机的时间.
分析
多次测试后发现,设置时间在第一次开机时系统显示的时间之后,重启后时间设置生效;设置在之前,则会还原成第一次系统开机时显示的时间。
所以怀疑时,系统在开机的时候做了时间有效检测.查看AlarmManagerService.java后发现系统会用当前时间和编译固件的时间做对比,如果早于编译时间则使用编译时间为当前时间。
frameworks/base/apex/jobscheduler/service/java/com/android/server/alarm/AlarmManagerService.java文章来源:https://www.toymoban.com/news/detail-665539.html
@Override
public void onStart() {
mInjector.init();
mMetricsHelper = new MetricsHelper(getContext(), mLock);
mListenerDeathRecipient = new IBinder.DeathRecipient() {
@Override
public void binderDied() {
}
@Override
public void binderDied(IBinder who) {
final IAlarmListener listener = IAlarmListener.Stub.asInterface(who);
removeImpl(null, listener);
}
};
synchronized (mLock) {
mHandler = new AlarmHandler();
mConstants = new Constants();
mAlarmStore = mConstants.LAZY_BATCHING ? new LazyAlarmStore()
: new BatchingAlarmStore();
mAlarmStore.setAlarmClockRemovalListener(mAlarmClockUpdater);
mAppWakeupHistory = new AppWakeupHistory(Constants.DEFAULT_APP_STANDBY_WINDOW);
mAllowWhileIdleHistory = new AppWakeupHistory(INTERVAL_HOUR);
mAllowWhileIdleCompatHistory = new AppWakeupHistory(INTERVAL_HOUR);
mNextWakeup = mNextNonWakeup = 0;
// We have to set current TimeZone info to kernel
// because kernel doesn't keep this after reboot
setTimeZoneImpl(SystemProperties.get(TIMEZONE_PROPERTY));
// Ensure that we're booting with a halfway sensible current time. Use the
// most recent of Build.TIME, the root file system's timestamp, and the
// value of the ro.build.date.utc system property (which is in seconds).
final long systemBuildTime = Long.max(
1000L * SystemProperties.getLong("ro.build.date.utc", -1L),
Long.max(Environment.getRootDirectory().lastModified(), Build.TIME));
if (mInjector.getCurrentTimeMillis() < systemBuildTime) {
Slog.i(TAG, "Current time only " + mInjector.getCurrentTimeMillis()
+ ", advancing to build time " + systemBuildTime);
mInjector.setKernelTime(systemBuildTime);
}
mPackageManagerInternal = LocalServices.getService(PackageManagerInternal.class);
...
...
}
解决办法
屏蔽此处的时间检验即可或者向客户说明情况文章来源地址https://www.toymoban.com/news/detail-665539.html
if (mInjector.getCurrentTimeMillis() < systemBuildTime) {
Slog.i(TAG, "Current time only " + mInjector.getCurrentTimeMillis()
+ ", advancing to build time " + systemBuildTime);
mInjector.setKernelTime(systemBuildTime);
}
到了这里,关于Android AlarmManagerService-设置系统时间无效的问题的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!