Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 548170a6 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Remove unused tests/utils/SleepUtils"

parents e051b0c9 aef4b828
Loading
Loading
Loading
Loading
+0 −26
Original line number Diff line number Diff line
#
# 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)
+0 −31
Original line number Diff line number Diff line
<?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>
+0 −23
Original line number Diff line number Diff line
/*
 * 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
+0 −77
Original line number Diff line number Diff line
/*
 * 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;
    }

}
+0 −52
Original line number Diff line number Diff line
/*
 * 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();
    }
}
Loading