blob: da3aaf1e6708417d59883bd932978f0e6683c6dc [file] [log] [blame]
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chromecast.base;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
/**
* Java implementations of SystemTimeChangeNotifierAndroid functionality.
* Forwards TIME_SET intent to native SystemTimeChangeNotifierAndroid.
*/
@JNINamespace("chromecast")
public final class SystemTimeChangeNotifierAndroid {
private BroadcastReceiver mTimeChangeObserver;
@CalledByNative
private static SystemTimeChangeNotifierAndroid create() {
return new SystemTimeChangeNotifierAndroid();
}
private SystemTimeChangeNotifierAndroid() {}
@CalledByNative
private void initializeFromNative(final long nativeSystemTimeChangeNotifier) {
// Listen to TIME_SET intent.
mTimeChangeObserver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
nativeOnTimeChanged(nativeSystemTimeChangeNotifier);
}
};
IntentFilter filter = new IntentFilter(Intent.ACTION_TIME_CHANGED);
ContextUtils.getApplicationContext().registerReceiver(mTimeChangeObserver, filter);
}
@CalledByNative private void finalizeFromNative() {
ContextUtils.getApplicationContext().unregisterReceiver(mTimeChangeObserver);
mTimeChangeObserver = null;
}
private native void nativeOnTimeChanged(long nativeSystemTimeChangeNotifierAndroid);
}