1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.content.browser;
7 import android.content.BroadcastReceiver;
8 import android.content.Context;
9 import android.content.Intent;
10 import android.content.IntentFilter;
11 import android.util.Log;
13 import org.chromium.base.CalledByNative;
14 import org.chromium.base.JNINamespace;
17 * Android implementation details for content::TimeZoneMonitorAndroid.
19 @JNINamespace("content")
20 class TimeZoneMonitor {
21 private static final String TAG = "TimeZoneMonitor";
23 private final Context mAppContext;
24 private final IntentFilter mFilter = new IntentFilter(Intent.ACTION_TIMEZONE_CHANGED);
25 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
27 public void onReceive(Context context, Intent intent) {
28 if (!intent.getAction().equals(Intent.ACTION_TIMEZONE_CHANGED)) {
29 Log.e(TAG, "unexpected intent");
33 nativeTimeZoneChangedFromJava(mNativePtr);
37 private long mNativePtr;
40 * Start listening for intents.
41 * @param nativePtr The native content::TimeZoneMonitorAndroid to notify of time zone changes.
43 private TimeZoneMonitor(Context context, long nativePtr) {
44 mAppContext = context.getApplicationContext();
45 mNativePtr = nativePtr;
46 mAppContext.registerReceiver(mBroadcastReceiver, mFilter);
50 static TimeZoneMonitor getInstance(Context context, long nativePtr) {
51 return new TimeZoneMonitor(context, nativePtr);
55 * Stop listening for intents.
59 mAppContext.unregisterReceiver(mBroadcastReceiver);
64 * Native JNI call to content::TimeZoneMonitorAndroid::TimeZoneChanged.
65 * See content/browser/time_zone_monitor_android.cc.
67 private native void nativeTimeZoneChangedFromJava(long nativeTimeZoneMonitorAndroid);