summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--api/system-current.txt4
-rw-r--r--core/jni/android_net_LocalSocketImpl.cpp174
-rw-r--r--services/core/java/com/android/server/am/ActivityManagerService.java2
-rw-r--r--telephony/java/android/telephony/ims/ImsStreamMediaProfile.java23
-rw-r--r--tests/utils/SleepUtils/AlarmService/Android.mk26
-rw-r--r--tests/utils/SleepUtils/AlarmService/AndroidManifest.xml31
-rw-r--r--tests/utils/SleepUtils/AlarmService/src/com/android/testing/alarmservice/Alarm.aidl23
-rw-r--r--tests/utils/SleepUtils/AlarmService/src/com/android/testing/alarmservice/AlarmImpl.java77
-rw-r--r--tests/utils/SleepUtils/AlarmService/src/com/android/testing/alarmservice/AlarmService.java52
-rw-r--r--tests/utils/SleepUtils/AlarmService/src/com/android/testing/alarmservice/WakeUpCall.java42
-rw-r--r--tests/utils/SleepUtils/AlarmService/src/com/android/testing/alarmservice/WakeUpController.java59
-rw-r--r--tests/utils/SleepUtils/Android.mk2
-rw-r--r--tests/utils/SleepUtils/README23
-rw-r--r--tests/utils/SleepUtils/SleepHelper/Android.mk29
-rw-r--r--tests/utils/SleepUtils/SleepHelper/AndroidManifest.xml21
-rw-r--r--tests/utils/SleepUtils/SleepHelper/src/com/android/testing/sleephelper/SetAlarm.java152
-rw-r--r--tests/utils/SleepUtils/WakeLoopService/Android.mk24
-rw-r--r--tests/utils/SleepUtils/WakeLoopService/AndroidManifest.xml32
-rw-r--r--tests/utils/SleepUtils/WakeLoopService/src/android/test/wakeuploop/FileUtil.java53
-rw-r--r--tests/utils/SleepUtils/WakeLoopService/src/android/test/wakeuploop/WakeLoopService.java98
-rw-r--r--tests/utils/SleepUtils/WakeLoopService/src/android/test/wakeuploop/WakeUpCall.java112
21 files changed, 63 insertions, 996 deletions
diff --git a/api/system-current.txt b/api/system-current.txt
index 7fcc6c0a924f..515daeee4ee9 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -7259,12 +7259,12 @@ package android.telephony.ims {
method public int describeContents();
method public int getAudioDirection();
method public int getAudioQuality();
- method public boolean getRttAudioSpeech();
method public int getRttMode();
method public int getVideoDirection();
method public int getVideoQuality();
+ method public boolean isReceivingRttAudio();
method public boolean isRttCall();
- method public void setRttAudioSpeech(boolean);
+ method public void setReceivingRttAudio(boolean);
method public void setRttMode(int);
method public void writeToParcel(android.os.Parcel, int);
field public static final int AUDIO_QUALITY_AMR = 1; // 0x1
diff --git a/core/jni/android_net_LocalSocketImpl.cpp b/core/jni/android_net_LocalSocketImpl.cpp
index a1f2377041e8..1163b860977d 100644
--- a/core/jni/android_net_LocalSocketImpl.cpp
+++ b/core/jni/android_net_LocalSocketImpl.cpp
@@ -33,14 +33,16 @@
#include <unistd.h>
#include <sys/ioctl.h>
+#include <android-base/cmsg.h>
+#include <android-base/macros.h>
#include <cutils/sockets.h>
#include <netinet/tcp.h>
#include <nativehelper/ScopedUtfChars.h>
-namespace android {
+using android::base::ReceiveFileDescriptorVector;
+using android::base::SendFileDescriptorVector;
-template <typename T>
-void UNUSED(T t) {}
+namespace android {
static jfieldID field_inboundFileDescriptors;
static jfieldID field_outboundFileDescriptors;
@@ -118,67 +120,6 @@ socket_bind_local (JNIEnv *env, jobject object, jobject fileDescriptor,
}
/**
- * Processes ancillary data, handling only
- * SCM_RIGHTS. Creates appropriate objects and sets appropriate
- * fields in the LocalSocketImpl object. Returns 0 on success
- * or -1 if an exception was thrown.
- */
-static int socket_process_cmsg(JNIEnv *env, jobject thisJ, struct msghdr * pMsg)
-{
- struct cmsghdr *cmsgptr;
-
- for (cmsgptr = CMSG_FIRSTHDR(pMsg);
- cmsgptr != NULL; cmsgptr = CMSG_NXTHDR(pMsg, cmsgptr)) {
-
- if (cmsgptr->cmsg_level != SOL_SOCKET) {
- continue;
- }
-
- if (cmsgptr->cmsg_type == SCM_RIGHTS) {
- int *pDescriptors = (int *)CMSG_DATA(cmsgptr);
- jobjectArray fdArray;
- int count
- = ((cmsgptr->cmsg_len - CMSG_LEN(0)) / sizeof(int));
-
- if (count < 0) {
- jniThrowException(env, "java/io/IOException",
- "invalid cmsg length");
- return -1;
- }
-
- fdArray = env->NewObjectArray(count, class_FileDescriptor, NULL);
-
- if (fdArray == NULL) {
- return -1;
- }
-
- for (int i = 0; i < count; i++) {
- jobject fdObject
- = jniCreateFileDescriptor(env, pDescriptors[i]);
-
- if (env->ExceptionCheck()) {
- return -1;
- }
-
- env->SetObjectArrayElement(fdArray, i, fdObject);
-
- if (env->ExceptionCheck()) {
- return -1;
- }
- }
-
- env->SetObjectField(thisJ, field_inboundFileDescriptors, fdArray);
-
- if (env->ExceptionCheck()) {
- return -1;
- }
- }
- }
-
- return 0;
-}
-
-/**
* Reads data from a socket into buf, processing any ancillary data
* and adding it to thisJ.
*
@@ -189,47 +130,48 @@ static ssize_t socket_read_all(JNIEnv *env, jobject thisJ, int fd,
void *buffer, size_t len)
{
ssize_t ret;
- struct msghdr msg;
- struct iovec iv;
- unsigned char *buf = (unsigned char *)buffer;
- // Enough buffer for a pile of fd's. We throw an exception if
- // this buffer is too small.
- struct cmsghdr cmsgbuf[2*sizeof(cmsghdr) + 0x100];
-
- memset(&msg, 0, sizeof(msg));
- memset(&iv, 0, sizeof(iv));
-
- iv.iov_base = buf;
- iv.iov_len = len;
+ std::vector<android::base::unique_fd> received_fds;
- msg.msg_iov = &iv;
- msg.msg_iovlen = 1;
- msg.msg_control = cmsgbuf;
- msg.msg_controllen = sizeof(cmsgbuf);
-
- ret = TEMP_FAILURE_RETRY(recvmsg(fd, &msg, MSG_NOSIGNAL | MSG_CMSG_CLOEXEC));
-
- if (ret < 0 && errno == EPIPE) {
- // Treat this as an end of stream
- return 0;
- }
+ ret = ReceiveFileDescriptorVector(fd, buffer, len, 64, &received_fds);
if (ret < 0) {
+ if (errno == EPIPE) {
+ // Treat this as an end of stream
+ return 0;
+ }
+
jniThrowIOException(env, errno);
return -1;
}
- if ((msg.msg_flags & (MSG_CTRUNC | MSG_OOB | MSG_ERRQUEUE)) != 0) {
- // To us, any of the above flags are a fatal error
+ if (received_fds.size() > 0) {
+ jobjectArray fdArray = env->NewObjectArray(received_fds.size(), class_FileDescriptor, NULL);
+
+ if (fdArray == NULL) {
+ // NewObjectArray has thrown.
+ return -1;
+ }
- jniThrowException(env, "java/io/IOException",
- "Unexpected error or truncation during recvmsg()");
+ for (size_t i = 0; i < received_fds.size(); i++) {
+ jobject fdObject = jniCreateFileDescriptor(env, received_fds[i].get());
- return -1;
- }
+ if (env->ExceptionCheck()) {
+ return -1;
+ }
+
+ env->SetObjectArrayElement(fdArray, i, fdObject);
+
+ if (env->ExceptionCheck()) {
+ return -1;
+ }
+ }
- if (ret >= 0) {
- socket_process_cmsg(env, thisJ, &msg);
+ for (auto &fd : received_fds) {
+ // The fds are stored in java.io.FileDescriptors now.
+ static_cast<void>(fd.release());
+ }
+
+ env->SetObjectField(thisJ, field_inboundFileDescriptors, fdArray);
}
return ret;
@@ -243,7 +185,6 @@ static ssize_t socket_read_all(JNIEnv *env, jobject thisJ, int fd,
static int socket_write_all(JNIEnv *env, jobject object, int fd,
void *buf, size_t len)
{
- ssize_t ret;
struct msghdr msg;
unsigned char *buffer = (unsigned char *)buf;
memset(&msg, 0, sizeof(msg));
@@ -256,14 +197,11 @@ static int socket_write_all(JNIEnv *env, jobject object, int fd,
return -1;
}
- struct cmsghdr *cmsg;
int countFds = outboundFds == NULL ? 0 : env->GetArrayLength(outboundFds);
- int fds[countFds];
- char msgbuf[CMSG_SPACE(countFds)];
+ std::vector<int> fds;
// Add any pending outbound file descriptors to the message
if (outboundFds != NULL) {
-
if (env->ExceptionCheck()) {
return -1;
}
@@ -274,47 +212,25 @@ static int socket_write_all(JNIEnv *env, jobject object, int fd,
return -1;
}
- fds[i] = jniGetFDFromFileDescriptor(env, fdObject);
+ fds.push_back(jniGetFDFromFileDescriptor(env, fdObject));
if (env->ExceptionCheck()) {
return -1;
}
}
-
- // See "man cmsg" really
- msg.msg_control = msgbuf;
- msg.msg_controllen = sizeof msgbuf;
- cmsg = CMSG_FIRSTHDR(&msg);
- cmsg->cmsg_level = SOL_SOCKET;
- cmsg->cmsg_type = SCM_RIGHTS;
- cmsg->cmsg_len = CMSG_LEN(sizeof fds);
- memcpy(CMSG_DATA(cmsg), fds, sizeof fds);
}
- // We only write our msg_control during the first write
- while (len > 0) {
- struct iovec iv;
- memset(&iv, 0, sizeof(iv));
-
- iv.iov_base = buffer;
- iv.iov_len = len;
-
- msg.msg_iov = &iv;
- msg.msg_iovlen = 1;
-
- do {
- ret = sendmsg(fd, &msg, MSG_NOSIGNAL);
- } while (ret < 0 && errno == EINTR);
+ ssize_t rc = SendFileDescriptorVector(fd, buffer, len, fds);
- if (ret < 0) {
+ while (rc != len) {
+ if (rc == -1) {
jniThrowIOException(env, errno);
return -1;
}
- buffer += ret;
- len -= ret;
+ buffer += rc;
+ len -= rc;
- // Wipes out any msg_control too
- memset(&msg, 0, sizeof(msg));
+ rc = send(fd, buffer, len, MSG_NOSIGNAL);
}
return 0;
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 0eec8e9cb717..e18f3740a969 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -2664,7 +2664,7 @@ public class ActivityManagerService extends IActivityManager.Stub
ProcessRecord proc;
int procState;
int statType;
- int pid;
+ int pid = -1;
long lastPssTime;
synchronized (ActivityManagerService.this) {
if (mPendingPssProcesses.size() <= 0) {
diff --git a/telephony/java/android/telephony/ims/ImsStreamMediaProfile.java b/telephony/java/android/telephony/ims/ImsStreamMediaProfile.java
index 837ef54a2f24..d11a0de24fb5 100644
--- a/telephony/java/android/telephony/ims/ImsStreamMediaProfile.java
+++ b/telephony/java/android/telephony/ims/ImsStreamMediaProfile.java
@@ -99,7 +99,7 @@ public final class ImsStreamMediaProfile implements Parcelable {
public int mRttMode;
// RTT Audio Speech Indicator
/** @hide */
- public boolean mHasRttAudioSpeech = false;
+ public boolean mIsReceivingRttAudio = false;
/** @hide */
public ImsStreamMediaProfile(Parcel in) {
@@ -201,7 +201,7 @@ public final class ImsStreamMediaProfile implements Parcelable {
", videoQuality=" + mVideoQuality +
", videoDirection=" + mVideoDirection +
", rttMode=" + mRttMode +
- ", hasRttAudioSpeech=" + mHasRttAudioSpeech + " }";
+ ", hasRttAudioSpeech=" + mIsReceivingRttAudio + " }";
}
@Override
@@ -216,7 +216,7 @@ public final class ImsStreamMediaProfile implements Parcelable {
out.writeInt(mVideoQuality);
out.writeInt(mVideoDirection);
out.writeInt(mRttMode);
- out.writeBoolean(mHasRttAudioSpeech);
+ out.writeBoolean(mIsReceivingRttAudio);
}
private void readFromParcel(Parcel in) {
@@ -225,7 +225,7 @@ public final class ImsStreamMediaProfile implements Parcelable {
mVideoQuality = in.readInt();
mVideoDirection = in.readInt();
mRttMode = in.readInt();
- mHasRttAudioSpeech = in.readBoolean();
+ mIsReceivingRttAudio = in.readBoolean();
}
public static final Creator<ImsStreamMediaProfile> CREATOR =
@@ -256,8 +256,12 @@ public final class ImsStreamMediaProfile implements Parcelable {
mRttMode = rttMode;
}
- public void setRttAudioSpeech(boolean audioOn) {
- mHasRttAudioSpeech = audioOn;
+ /**
+ * Sets whether the remote party is transmitting audio over the RTT call.
+ * @param audioOn true if audio is being received, false otherwise.
+ */
+ public void setReceivingRttAudio(boolean audioOn) {
+ mIsReceivingRttAudio = audioOn;
}
public int getAudioQuality() {
@@ -280,7 +284,10 @@ public final class ImsStreamMediaProfile implements Parcelable {
return mRttMode;
}
- public boolean getRttAudioSpeech() {
- return mHasRttAudioSpeech;
+ /**
+ * @return true if remote party is transmitting audio, false otherwise.
+ */
+ public boolean isReceivingRttAudio() {
+ return mIsReceivingRttAudio;
}
}
diff --git a/tests/utils/SleepUtils/AlarmService/Android.mk b/tests/utils/SleepUtils/AlarmService/Android.mk
deleted file mode 100644
index 9022f03b7cf2..000000000000
--- a/tests/utils/SleepUtils/AlarmService/Android.mk
+++ /dev/null
@@ -1,26 +0,0 @@
-#
-# Copyright (C) 2013 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-LOCAL_SRC_FILES += \
- src/com/android/testing/alarmservice/Alarm.aidl
-LOCAL_PACKAGE_NAME := SleepUtilsAlarmService
-LOCAL_SDK_VERSION := 7
-include $(BUILD_PACKAGE)
diff --git a/tests/utils/SleepUtils/AlarmService/AndroidManifest.xml b/tests/utils/SleepUtils/AlarmService/AndroidManifest.xml
deleted file mode 100644
index 1b6de39c91da..000000000000
--- a/tests/utils/SleepUtils/AlarmService/AndroidManifest.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2013 The Android Open Source Project Licensed under the
- Apache License, Version 2.0 (the "License"); you may not use this file except
- in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software distributed
- under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
- OR CONDITIONS OF ANY KIND, either express or implied. See the License for
- the specific language governing permissions and limitations under the License. -->
-
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.testing.alarmservice" >
-
- <uses-sdk android:minSdkVersion="7" />
- <uses-permission android:name="android.permission.WAKE_LOCK" />
-
- <application android:label="Sleep Utils Alarm Service">
- <service android:name=".AlarmService"
- android:label="Sleep Utils Alarm Service"
- android:exported="true"
- android:enabled="true">
- <intent-filter>
- <action android:name="com.android.testing.ALARM_SERVICE" />
- </intent-filter>
- </service>
- <receiver android:name=".WakeUpCall">
- <intent-filter>
- <action android:name="com.android.testing.alarmservice.WAKEUP" />
- </intent-filter>
- </receiver>
- </application>
-</manifest>
diff --git a/tests/utils/SleepUtils/AlarmService/src/com/android/testing/alarmservice/Alarm.aidl b/tests/utils/SleepUtils/AlarmService/src/com/android/testing/alarmservice/Alarm.aidl
deleted file mode 100644
index 62a8c4866f07..000000000000
--- a/tests/utils/SleepUtils/AlarmService/src/com/android/testing/alarmservice/Alarm.aidl
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.testing.alarmservice;
-
-interface Alarm {
- int prepare();
- int setAlarmAndWait(long timeoutMills);
- int done();
-} \ No newline at end of file
diff --git a/tests/utils/SleepUtils/AlarmService/src/com/android/testing/alarmservice/AlarmImpl.java b/tests/utils/SleepUtils/AlarmService/src/com/android/testing/alarmservice/AlarmImpl.java
deleted file mode 100644
index 122d55deb3e5..000000000000
--- a/tests/utils/SleepUtils/AlarmService/src/com/android/testing/alarmservice/AlarmImpl.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.testing.alarmservice;
-
-import android.app.AlarmManager;
-import android.app.PendingIntent;
-import android.content.Context;
-import android.content.Intent;
-import android.os.RemoteException;
-import android.os.SystemClock;
-import android.util.Log;
-
-import com.android.testing.alarmservice.Alarm.Stub;
-
-public class AlarmImpl extends Stub {
-
- private static final String LOG_TAG = AlarmImpl.class.getSimpleName();
-
- private Context mContext;
-
- public AlarmImpl(Context context) {
- super();
- mContext = context;
- }
-
- @Override
- public int prepare() throws RemoteException {
- WakeUpController.getController().getWakeLock().acquire();
- Log.d(LOG_TAG, "AlarmService prepared, wake lock acquired");
- return 0;
- }
-
- @Override
- public int setAlarmAndWait(long timeoutMills) throws RemoteException {
- // calculate when device should be waken up
- long atTime = SystemClock.elapsedRealtime() + timeoutMills;
- AlarmManager am = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
- Intent wakupIntent = new Intent(WakeUpCall.WAKEUP_CALL);
- PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, wakupIntent, 0);
- // set alarm, which will be delivered in form of the wakeupIntent
- am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, atTime, pi);
- Log.d(LOG_TAG, String.format("Alarm set: %d, giving up wake lock", atTime));
- Object lock = WakeUpController.getController().getWakeSync();
- // release wakelock and wait for the lock to be poked from the broadcast receiver
- WakeUpController.getController().getWakeLock().release();
- // does not really matter if device enters suspend before we start waiting on lock
- synchronized (lock) {
- try {
- lock.wait();
- } catch (InterruptedException e) {
- }
- }
- Log.d(LOG_TAG, String.format("Alarm triggered, done waiting"));
- return 0;
- }
-
- @Override
- public int done() throws RemoteException {
- WakeUpController.getController().getWakeLock().release();
- return 0;
- }
-
-}
diff --git a/tests/utils/SleepUtils/AlarmService/src/com/android/testing/alarmservice/AlarmService.java b/tests/utils/SleepUtils/AlarmService/src/com/android/testing/alarmservice/AlarmService.java
deleted file mode 100644
index 576a1cfcfbaf..000000000000
--- a/tests/utils/SleepUtils/AlarmService/src/com/android/testing/alarmservice/AlarmService.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.testing.alarmservice;
-
-import android.app.Service;
-import android.content.Context;
-import android.content.Intent;
-import android.os.IBinder;
-
-public class AlarmService extends Service {
-
- private AlarmImpl mAlarmImpl = null;
- static Context sContext;
-
- @Override
- public void onCreate() {
- super.onCreate();
- sContext = this;
- }
-
- @Override
- public IBinder onBind(Intent intent) {
- return getAlarmImpl();
- }
-
- private AlarmImpl getAlarmImpl() {
- if (mAlarmImpl == null) {
- mAlarmImpl = new AlarmImpl(this);
- }
- return mAlarmImpl;
- }
-
- @Override
- public void onDestroy() {
- sContext = null;
- super.onDestroy();
- }
-}
diff --git a/tests/utils/SleepUtils/AlarmService/src/com/android/testing/alarmservice/WakeUpCall.java b/tests/utils/SleepUtils/AlarmService/src/com/android/testing/alarmservice/WakeUpCall.java
deleted file mode 100644
index f4bb4dba4cda..000000000000
--- a/tests/utils/SleepUtils/AlarmService/src/com/android/testing/alarmservice/WakeUpCall.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.testing.alarmservice;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-
-/**
- * The receiver for the alarm we set
- *
- */
-public class WakeUpCall extends BroadcastReceiver {
-
- public static final String WAKEUP_CALL = "com.android.testing.alarmservice.WAKEUP";
-
- @Override
- public void onReceive(Context context, Intent intent) {
- // we acquire wakelock without release because user is supposed to manually release it
- WakeUpController.getController().getWakeLock().acquire();
- Object lock = WakeUpController.getController().getWakeSync();
- synchronized (lock) {
- // poke the lock so the service side can be woken from waiting on the lock
- lock.notifyAll();
- }
- }
-
-}
diff --git a/tests/utils/SleepUtils/AlarmService/src/com/android/testing/alarmservice/WakeUpController.java b/tests/utils/SleepUtils/AlarmService/src/com/android/testing/alarmservice/WakeUpController.java
deleted file mode 100644
index 478371f61f36..000000000000
--- a/tests/utils/SleepUtils/AlarmService/src/com/android/testing/alarmservice/WakeUpController.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.testing.alarmservice;
-
-import android.content.Context;
-import android.os.PowerManager;
-import android.os.PowerManager.WakeLock;
-import android.util.Log;
-
-/**
- * A singleton used for controlling and sharing of states/wakelocks
- *
- */
-public class WakeUpController {
-
- private static final String LOG_TAG = WakeUpController.class.getName();
- private static WakeUpController mController = null;
- private WakeLock mWakeLock = null;
- private Object mWakeSync = new Object();
-
- private WakeUpController() {
- Log.i(LOG_TAG, "Created instance: 0x" + Integer.toHexString(this.hashCode()));
- }
-
- public static synchronized WakeUpController getController() {
- if (mController == null) {
- mController = new WakeUpController();
- }
- return mController;
- }
-
- public WakeLock getWakeLock() {
- if (mWakeLock == null) {
- PowerManager pm =
- (PowerManager) AlarmService.sContext.getSystemService(Context.POWER_SERVICE);
- mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "testing-alarmservice");
- Log.i(LOG_TAG, "Create wakelock: 0x" + Integer.toHexString(mWakeLock.hashCode()));
- }
- return mWakeLock;
- }
-
- public Object getWakeSync() {
- return mWakeSync;
- }
-}
diff --git a/tests/utils/SleepUtils/Android.mk b/tests/utils/SleepUtils/Android.mk
deleted file mode 100644
index 0e65e2255c5b..000000000000
--- a/tests/utils/SleepUtils/Android.mk
+++ /dev/null
@@ -1,2 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(call all-makefiles-under, $(LOCAL_PATH))
diff --git a/tests/utils/SleepUtils/README b/tests/utils/SleepUtils/README
deleted file mode 100644
index bfe07da4a389..000000000000
--- a/tests/utils/SleepUtils/README
+++ /dev/null
@@ -1,23 +0,0 @@
-This folder contains utils to properly perform timed suspend and wakeup.
-
-AlarmService - a service that client can bind to and perform:
-1) holding wakelock (singleton to this service)
-2) setting alarm for a specified period and releasing the wakelock; service
- call will block until alarm has been triggered and the wakelock is held
-3) releasing the wakelock
-
-SleepHelper - a self instrumentation meant as a convenient way to trigger
-the service functions from command line. Corresponding to service function
-above, supported operations are:
-1) holding wakelock
-am instrument -w -e command prepare \
- com.android.testing.sleephelper/.SetAlarm
-
-2) setting alarm and wait til triggered
-am instrument -w -e command set_wait \
- -e param <time in ms> com.android.testing.sleephelper/.SetAlarm
-Note: for the function to work properly, "-w" parameter is required
-
-3) releasing wakelock
-am instrument -w -e command done \
- com.android.testing.sleephelper/.SetAlarm
diff --git a/tests/utils/SleepUtils/SleepHelper/Android.mk b/tests/utils/SleepUtils/SleepHelper/Android.mk
deleted file mode 100644
index f8267fd530ed..000000000000
--- a/tests/utils/SleepUtils/SleepHelper/Android.mk
+++ /dev/null
@@ -1,29 +0,0 @@
-#
-# Copyright (C) 2013 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-
-# Only compile source java files in this apk.
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-LOCAL_SRC_FILES += \
- ../AlarmService/src/com/android/testing/alarmservice/Alarm.aidl
-LOCAL_SDK_VERSION := 7
-LOCAL_PACKAGE_NAME := SleepUtilsSleepHelper
-
-include $(BUILD_PACKAGE)
diff --git a/tests/utils/SleepUtils/SleepHelper/AndroidManifest.xml b/tests/utils/SleepUtils/SleepHelper/AndroidManifest.xml
deleted file mode 100644
index 0f1d49185169..000000000000
--- a/tests/utils/SleepUtils/SleepHelper/AndroidManifest.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2013 The Android Open Source Project Licensed under the
- Apache License, Version 2.0 (the "License"); you may not use this file except
- in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software distributed
- under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
- OR CONDITIONS OF ANY KIND, either express or implied. See the License for
- the specific language governing permissions and limitations under the License. -->
-
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.testing.sleephelper">
-
- <uses-sdk android:minSdkVersion="7" />
- <instrumentation android:label="Sleep Helper"
- android:name="com.android.testing.sleephelper.SetAlarm"
- android:targetPackage="com.android.testing.sleephelper" />
-
- <application android:label="Sleep Utils Sleep Helper">
- <uses-library android:name="android.test.runner" />
- </application>
-</manifest>
diff --git a/tests/utils/SleepUtils/SleepHelper/src/com/android/testing/sleephelper/SetAlarm.java b/tests/utils/SleepUtils/SleepHelper/src/com/android/testing/sleephelper/SetAlarm.java
deleted file mode 100644
index b558741da908..000000000000
--- a/tests/utils/SleepUtils/SleepHelper/src/com/android/testing/sleephelper/SetAlarm.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.testing.sleephelper;
-
-import android.app.Activity;
-import android.app.Instrumentation;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.ServiceConnection;
-import android.os.Bundle;
-import android.os.Debug;
-import android.os.IBinder;
-import android.os.RemoteException;
-import android.util.Log;
-
-import com.android.testing.alarmservice.Alarm;
-
-public class SetAlarm extends Instrumentation {
-
- private static final String COMMAND = "command";
- private static final String PARAM = "param";
- private static final String CMD_PREPARE = "prepare";
- private static final String CMD_SET = "set_wait";
- private static final String CMD_DONE = "done";
- private static final String SERVICE_ACTION = "com.android.testing.ALARM_SERVICE";
- private static final String SERVICE_PKG = "com.android.testing.alarmservice";
- private static final String LOG_TAG = SetAlarm.class.getSimpleName();
-
- private Alarm mAlarmService = null;
- private Bundle mArgs = null;
- private String mCommand = null;
- private Intent mServceIntent = new Intent(SERVICE_ACTION).setPackage(SERVICE_PKG);
-
- private ServiceConnection mConn = new ServiceConnection() {
- @Override
- public void onServiceDisconnected(ComponentName name) {
- Log.d(LOG_TAG, "Service disconnected.");
- mAlarmService = null;
- errorFinish("service disconnected");
- }
-
- @Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- Log.d(LOG_TAG, "Service connected.");
- mAlarmService = Alarm.Stub.asInterface(service);
- handleCommands();
- }
- };
-
-
- private void handleCommands() {
- if (CMD_PREPARE.equals(mCommand)) {
- callPrepare();
- } else if (CMD_SET.equals(mCommand)) {
- String paramString = mArgs.getString(PARAM);
- if (paramString == null) {
- errorFinish("argument expected for alarm time");
- }
- long timeout = -1;
- try {
- timeout = Long.parseLong(paramString);
- } catch (NumberFormatException nfe) {
- errorFinish("a number argument is expected");
- }
- callSetAndWait(timeout);
- } else if (CMD_DONE.equals(mCommand)) {
- callDone();
- } else {
- errorFinish("Unrecognized command: " + mCommand);
- }
- finish(Activity.RESULT_OK, new Bundle());
- }
-
- @Override
- public void onCreate(Bundle arguments) {
- super.onCreate(arguments);
- mCommand = arguments.getString(COMMAND);
- if ("true".equals(arguments.getString("debug"))) {
- Debug.waitForDebugger();
- }
- if (mCommand == null) {
- errorFinish("No command specified");
- }
- mArgs = arguments;
- connectToAlarmService();
- }
-
- private void errorFinish(String msg) {
- Bundle ret = new Bundle();
- ret.putString("error", msg);
- finish(Activity.RESULT_CANCELED, ret);
- }
-
- private void connectToAlarmService() {
- // start the service with an intent, this ensures the service keeps running after unbind
- ComponentName cn = getContext().startService(mServceIntent);
- if (cn == null) {
- errorFinish("failed to start service");
- }
- if (!getContext().bindService(mServceIntent, mConn, Context.BIND_AUTO_CREATE)) {
- errorFinish("failed to bind service");
- }
- }
-
- private void callPrepare() {
- try {
- mAlarmService.prepare();
- } catch (RemoteException e) {
- errorFinish("RemoteExeption in prepare()");
- } finally {
- getContext().unbindService(mConn);
- }
- }
-
- private void callDone() {
- try {
- mAlarmService.done();
- } catch (RemoteException e) {
- errorFinish("RemoteExeption in prepare()");
- } finally {
- getContext().unbindService(mConn);
- }
- // explicitly stop the service (started in prepare()) so that the service is now free
- // to be reclaimed
- getContext().stopService(mServceIntent);
- }
-
- private void callSetAndWait(long timeoutMills) {
- try {
- mAlarmService.setAlarmAndWait(timeoutMills);
- } catch (RemoteException e) {
- errorFinish("RemoteExeption in setAlarmAndWait()");
- } finally {
- getContext().unbindService(mConn);
- }
- }
-}
diff --git a/tests/utils/SleepUtils/WakeLoopService/Android.mk b/tests/utils/SleepUtils/WakeLoopService/Android.mk
deleted file mode 100644
index a8a944b215d2..000000000000
--- a/tests/utils/SleepUtils/WakeLoopService/Android.mk
+++ /dev/null
@@ -1,24 +0,0 @@
-#
-# Copyright (C) 2014 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-LOCAL_PACKAGE_NAME := WakeupLoopService
-LOCAL_SDK_VERSION := 7
-include $(BUILD_PACKAGE)
diff --git a/tests/utils/SleepUtils/WakeLoopService/AndroidManifest.xml b/tests/utils/SleepUtils/WakeLoopService/AndroidManifest.xml
deleted file mode 100644
index a7028c4f671e..000000000000
--- a/tests/utils/SleepUtils/WakeLoopService/AndroidManifest.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2014 The Android Open Source Project Licensed under the
- Apache License, Version 2.0 (the "License"); you may not use this file except
- in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software distributed
- under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
- OR CONDITIONS OF ANY KIND, either express or implied. See the License for
- the specific language governing permissions and limitations under the License. -->
-
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="android.test.wakeuploop" >
-
- <uses-sdk android:minSdkVersion="7" />
- <uses-permission android:name="android.permission.WAKE_LOCK" />
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
-
- <application android:label="Auto Wakeup Loop">
- <service android:name=".WakeLoopService"
- android:label="Wakup Loop Service"
- android:exported="true"
- android:enabled="true">
- <intent-filter>
- <action android:name="android.test.wakeuploop.WAKEUP_SERVICE" />
- </intent-filter>
- </service>
- <receiver android:name=".WakeUpCall">
- <intent-filter>
- <action android:name="android.test.wakeuploop.WAKEUP" />
- </intent-filter>
- </receiver>
- </application>
-</manifest>
diff --git a/tests/utils/SleepUtils/WakeLoopService/src/android/test/wakeuploop/FileUtil.java b/tests/utils/SleepUtils/WakeLoopService/src/android/test/wakeuploop/FileUtil.java
deleted file mode 100644
index c8b075b4a90f..000000000000
--- a/tests/utils/SleepUtils/WakeLoopService/src/android/test/wakeuploop/FileUtil.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.test.wakeuploop;
-
-import android.util.Log;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-public class FileUtil {
-
- private static FileUtil sInst = null;
- private static DateFormat sDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
-
- private FileUtil() {};
-
- public static FileUtil get() {
- if (sInst == null) {
- sInst = new FileUtil();
- }
- return sInst;
- }
-
- public void writeDateToFile(File file) {
- try {
- FileOutputStream fos = new FileOutputStream(file);
- fos.write(sDateFormat.format(new Date()).getBytes());
- fos.write('\n');
- fos.flush();
- fos.close();
- } catch (IOException ioe) {
- Log.e("FileUtil", "exception writing date to file", ioe);
- }
- }
-}
diff --git a/tests/utils/SleepUtils/WakeLoopService/src/android/test/wakeuploop/WakeLoopService.java b/tests/utils/SleepUtils/WakeLoopService/src/android/test/wakeuploop/WakeLoopService.java
deleted file mode 100644
index 4f557b8786f4..000000000000
--- a/tests/utils/SleepUtils/WakeLoopService/src/android/test/wakeuploop/WakeLoopService.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.test.wakeuploop;
-
-import android.app.AlarmManager;
-import android.app.PendingIntent;
-import android.app.Service;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Environment;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.Message;
-import android.os.Messenger;
-import android.os.SystemClock;
-import android.util.Log;
-
-import java.io.File;
-
-public class WakeLoopService extends Service {
-
- private static final String LOG_TAG = WakeLoopService.class.getSimpleName();
- static final String WAKEUP_INTERNAL = "WAKEUP_INTERVAL";
- static final String MAX_LOOP = "MAX_LOOP";
- static final String STOP_CALLBACK = "STOP_CALLBACK";
- static final String THIS_LOOP = "THIS_LOOP";
- static final int MSG_STOP_SERVICE = 0xd1ed1e;
-
- private final Handler mHandler = new Handler() {
- public void handleMessage(Message msg) {
- if (msg.what == MSG_STOP_SERVICE) {
- stopSelf();
- } else {
- super.handleMessage(msg);
- }
- };
- };
-
- @Override
- public IBinder onBind(Intent intent) {
- // no binding, just start via intent
- return null;
- }
-
- @Override
- public int onStartCommand(Intent intent, int flags, int startId) {
- // get wakeup interval from intent
- long wakeupInterval = intent.getLongExtra(WAKEUP_INTERNAL, 0);
- long maxLoop = intent.getLongExtra(MAX_LOOP, 0);
-
- if (wakeupInterval == 0) {
- // stop and error
- Log.e(LOG_TAG, "No wakeup interval specified, not starting the service");
- stopSelf();
- return START_NOT_STICKY;
- }
- FileUtil.get().writeDateToFile(new File(Environment.getExternalStorageDirectory(),
- "wakeup-loop-start.txt"));
- Log.d(LOG_TAG, String.format("WakeLoop: STARTED interval = %d, total loop = %d",
- wakeupInterval, maxLoop));
- // calculate when device should be waken up
- long atTime = SystemClock.elapsedRealtime() + wakeupInterval;
- AlarmManager am = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
- Intent wakupIntent = new Intent(WakeUpCall.WAKEUP_CALL)
- .putExtra(WAKEUP_INTERNAL, wakeupInterval)
- .putExtra(MAX_LOOP, maxLoop)
- .putExtra(THIS_LOOP, 0L)
- .putExtra(STOP_CALLBACK, new Messenger(mHandler));
- PendingIntent pi = PendingIntent.getBroadcast(this, 0, wakupIntent,
- PendingIntent.FLAG_UPDATE_CURRENT);
- // set alarm, which will be delivered in form of the wakeupIntent
- am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, atTime, pi);
- return START_NOT_STICKY;
- }
-
- @Override
- public void onDestroy() {
- Log.d(LOG_TAG, "WakeLoop: STOPPED");
- // cancel alarms first
- Intent intent = new Intent(WakeUpCall.WAKEUP_CALL)
- .putExtra(WakeUpCall.CANCEL, "true");
- sendBroadcast(intent);
- }
-}
diff --git a/tests/utils/SleepUtils/WakeLoopService/src/android/test/wakeuploop/WakeUpCall.java b/tests/utils/SleepUtils/WakeLoopService/src/android/test/wakeuploop/WakeUpCall.java
deleted file mode 100644
index 8347bbf0c1c7..000000000000
--- a/tests/utils/SleepUtils/WakeLoopService/src/android/test/wakeuploop/WakeUpCall.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.test.wakeuploop;
-
-import android.app.AlarmManager;
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Environment;
-import android.os.Message;
-import android.os.Messenger;
-import android.os.PowerManager;
-import android.os.PowerManager.WakeLock;
-import android.os.RemoteException;
-import android.os.SystemClock;
-import android.util.Log;
-
-import java.io.File;
-
-/**
- * The receiver for the alarm we set
- *
- */
-public class WakeUpCall extends BroadcastReceiver {
- private static final String LOG_TAG = WakeUpCall.class.getSimpleName();
- static final String WAKEUP_CALL = "android.test.wakeuploop.WAKEUP";
- static final String CANCEL = "CANCEL";
-
- @Override
- public void onReceive(Context context, Intent intent) {
- AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
- boolean cancel = intent.hasExtra(CANCEL);
- if (!cancel) {
- long maxLoop = intent.getLongExtra(WakeLoopService.MAX_LOOP, 0);
- long wakeupInterval = intent.getLongExtra(WakeLoopService.WAKEUP_INTERNAL, 0);
- long thisLoop = intent.getLongExtra(WakeLoopService.THIS_LOOP, -1);
- Log.d(LOG_TAG, String.format("incoming: interval = %d, max loop = %d, this loop = %d",
- wakeupInterval, maxLoop, thisLoop));
- if (thisLoop == -1) {
- Log.e(LOG_TAG, "no valid loop count received, trying to stop service");
- stopService(intent);
- return;
- }
- if (wakeupInterval == 0) {
- Log.e(LOG_TAG, "no valid wakeup interval received, trying to stop service");
- stopService(intent);
- return;
- }
- thisLoop++;
- Log.d(LOG_TAG, String.format("WakeLoop - iteration %d of %d", thisLoop, maxLoop));
- if (thisLoop == maxLoop) {
- // when maxLoop is 0, we loop forever, so not checking that case
- // here
- Log.d(LOG_TAG, "reached max loop count, stopping service");
- stopService(intent);
- return;
- }
- screenOn(context);
- FileUtil.get().writeDateToFile(
- new File(Environment.getExternalStorageDirectory(), "wakeup-loop.txt"));
- // calculate when device should be waken up
- long atTime = SystemClock.elapsedRealtime() + wakeupInterval;
- intent.putExtra(WakeLoopService.THIS_LOOP, thisLoop);
- PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent,
- PendingIntent.FLAG_UPDATE_CURRENT);
- // set alarm, which will be delivered in form of the wakeupIntent
- am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, atTime, pi);
- } else {
- // cancel alarms
- Log.d(LOG_TAG, "cancelling future alarms on request");
- am.cancel(PendingIntent.getBroadcast(context, 0, intent, 0));
- }
- }
-
- private void stopService(Intent i) {
- Messenger msgr = i.getParcelableExtra(WakeLoopService.STOP_CALLBACK);
- if (msgr == null) {
- Log.e(LOG_TAG, "no stop service callback found, cannot stop");
- } else {
- Message msg = new Message();
- msg.what = WakeLoopService.MSG_STOP_SERVICE;
- try {
- msgr.send(msg);
- } catch (RemoteException e) {
- Log.e(LOG_TAG, "ignored remoted exception while attempting to stop service", e);
- }
- }
- }
-
- private void screenOn(Context context) {
- PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
- @SuppressWarnings("deprecation")
- WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK |
- PowerManager.ACQUIRE_CAUSES_WAKEUP, LOG_TAG);
- wl.acquire(500);
- }
-}