forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1172740 - Implement Android HAL backend for alarms. r=snorp
- Loading branch information
Showing
11 changed files
with
239 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "Hal.h" | ||
#include "AndroidBridge.h" | ||
|
||
#include "GeneratedJNINatives.h" | ||
|
||
using namespace mozilla::hal; | ||
|
||
namespace mozilla { | ||
|
||
class AlarmReceiver : public widget::AlarmReceiver::Natives<AlarmReceiver> | ||
{ | ||
private: | ||
AlarmReceiver(); | ||
|
||
public: | ||
static void NotifyAlarmFired() { | ||
nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([=]() { | ||
hal::NotifyAlarmFired(); | ||
}); | ||
NS_DispatchToMainThread(runnable); | ||
} | ||
}; | ||
|
||
namespace hal_impl { | ||
|
||
bool | ||
EnableAlarm() | ||
{ | ||
AlarmReceiver::Init(); | ||
return true; | ||
} | ||
|
||
void | ||
DisableAlarm() | ||
{ | ||
widget::GeckoAppShell::DisableAlarm(); | ||
} | ||
|
||
bool | ||
SetAlarm(int32_t aSeconds, int32_t aNanoseconds) | ||
{ | ||
return widget::GeckoAppShell::SetAlarm(aSeconds, aNanoseconds); | ||
} | ||
|
||
} // hal_impl | ||
} // mozilla |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.gecko; | ||
|
||
import org.mozilla.gecko.annotation.WrapForJNI; | ||
|
||
import android.app.IntentService; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.BroadcastReceiver; | ||
import android.os.PowerManager; | ||
import android.os.PowerManager.WakeLock; | ||
import android.util.Log; | ||
|
||
import java.util.Timer; | ||
import java.util.TimerTask; | ||
|
||
public class AlarmReceiver extends BroadcastReceiver { | ||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
PowerManager powerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); | ||
final WakeLock wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "GeckoAlarm"); | ||
wakeLock.acquire(); | ||
|
||
AlarmReceiver.notifyAlarmFired(); | ||
TimerTask releaseLockTask = new TimerTask() { | ||
@Override | ||
public void run() { | ||
wakeLock.release(); | ||
} | ||
}; | ||
Timer timer = new Timer(); | ||
// 5 seconds ought to be enough for anybody | ||
timer.schedule(releaseLockTask, 5*1000); | ||
} | ||
|
||
@WrapForJNI | ||
private static native void notifyAlarmFired(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -381,10 +381,13 @@ | |
</receiver> | ||
|
||
<service android:name="org.mozilla.gecko.Restarter" | ||
android:exported="false" | ||
android:process="@[email protected]"> | ||
android:exported="false" | ||
android:process="@[email protected]"> | ||
</service> | ||
|
||
<receiver android:name="org.mozilla.gecko.AlarmReceiver" > | ||
</receiver> | ||
|
||
#include ../services/manifests/FxAccountAndroidManifest_activities.xml.in | ||
#include ../services/manifests/HealthReportAndroidManifest_activities.xml.in | ||
#include ../services/manifests/SyncAndroidManifest_activities.xml.in | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters