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

Commit ab0d28c6 authored by Paul Sliwowski's avatar Paul Sliwowski
Browse files

Refactor alarm manager code to use new Instance table.

Change-Id: If0ef94f68383ebfcb4a0af697671c7854f33383d
parent 8fd10c34
Loading
Loading
Loading
Loading
+8 −33
Original line number Diff line number Diff line
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.android.deskclock"
        android:versionCode="300" android:versionName="3.0.0">
        android:versionCode="301" android:versionName="3.0.0">

    <original-package android:name="com.android.alarmclock" />
    <original-package android:name="com.android.deskclock" />
@@ -75,20 +75,9 @@
            </intent-filter>
        </activity>

        <activity android:name="AlarmAlert"
                android:excludeFromRecents="true"
                android:theme="@android:style/Theme.Holo"
                android:launchMode="singleInstance"
                android:taskAffinity=""
                android:configChanges="orientation|screenSize|keyboardHidden|keyboard|navigation"/>

        <!-- This activity is basically the same as AlarmAlert
             but full-screen so that it can turn the display on. -->
        <activity android:name="AlarmAlertFullScreen"
        <activity android:name=".alarms.AlarmActivity"
                android:excludeFromRecents="true"
                android:theme="@style/AlarmAlertFullScreenTheme"
                android:launchMode="singleInstance"
                android:taskAffinity=""
                android:windowSoftInputMode="stateHidden"
                android:showOnLockScreen="true"
                android:configChanges="orientation|screenSize|keyboardHidden|keyboard|navigation"/>
@@ -99,15 +88,14 @@
                android:theme="@style/ScreensaverActivityTheme"
                android:configChanges="orientation|screenSize|keyboardHidden|keyboard" />

        <receiver android:name="AlarmReceiver"
        <receiver android:name=".alarms.AlarmStateManager"
                  android:exported="false">
            <intent-filter>
                <action android:name="com.android.deskclock.ALARM_ALERT" />
                <action android:name="alarm_killed" />
                <action android:name="cancel_snooze" />
            </intent-filter>
        </receiver>

        <service android:name=".alarms.AlarmService"
                 android:exported="false">
        </service>

        <activity android:name="HandleApiCalls"
                android:theme="@android:style/Theme.NoDisplay"
                android:excludeFromRecents="true"
@@ -131,19 +119,6 @@
            android:exported="true">
        </activity-alias>

        <!-- This service receives the same intent as AlarmReceiver but it does
             not respond to the same broadcast. The AlarmReceiver will receive
             the alert broadcast and will start this service with the same
             intent. The service plays the alarm alert and vibrates the device.
             This allows the alert to continue playing even if another activity
             causes the AlarmAlert activity to pause. -->
        <service android:name="AlarmKlaxon"
                android:exported="false"
                android:description="@string/alarm_klaxon_service_desc">
            <intent-filter>
                <action android:name="com.android.deskclock.ALARM_ALERT" />
            </intent-filter>
        </service>

        <receiver android:name="AlarmInitReceiver">
            <intent-filter>
+9 −0
Original line number Diff line number Diff line
@@ -82,6 +82,9 @@
    <!-- Button labels on the alarm dialog: Dismiss -->
    <string name="alarm_alert_dismiss_text">Dismiss</string>

    <!-- Button labels on the pre-dismiss alarm notifications: Dismiss now -->
    <string name="alarm_alert_dismiss_now_text">Dismiss Now</string>

    <!-- Alarm Alert screen: this message is shown after an alarm rung
         unattended for a number of minutes.  It tells the user that
         the alarm has been silenced.-->
@@ -98,6 +101,12 @@
    <!-- Text to appear inside a notification while an alarm is snoozing. -->
    <string name="alarm_alert_snooze_until">Snoozing until <xliff:g id="time">%s</xliff:g></string>

    <!-- Text to appear in the notification title while an alarm is about to go off. -->
    <string name="alarm_alert_predismiss_title">Upcoming alarm</string>

    <!-- Text to appear in when trying to view a missed alarm that has been deleted -->
    <string name="missed_alarm_has_been_deleted">Your missed alarm has been deleted</string>

    <!-- 0: nothing
         1: days
         2:      hours
+3 −3
Original line number Diff line number Diff line
@@ -31,9 +31,9 @@ import android.view.View;
import android.widget.RemoteViews;
import android.widget.RemoteViewsService.RemoteViewsFactory;

import com.android.deskclock.Alarms;
import com.android.deskclock.R;
import com.android.deskclock.Utils;
import com.android.deskclock.alarms.AlarmNotifications;
import com.android.deskclock.worldclock.Cities;
import com.android.deskclock.worldclock.CityObj;
import com.android.deskclock.worldclock.WorldClockAdapter;
@@ -206,7 +206,7 @@ public class DigitalWidgetViewsFactory extends BroadcastReceiver implements Remo
        filter.addAction(Utils.ACTION_ON_QUARTER_HOUR);
        filter.addAction(Intent.ACTION_TIME_CHANGED);
        filter.addAction(Intent.ACTION_LOCALE_CHANGED);
        filter.addAction(Alarms.NEXT_ALARM_TIME_SET);
        filter.addAction(AlarmNotifications.SYSTEM_ALARM_CHANGE_ACTION);
        filter.addAction(Cities.WORLDCLOCK_UPDATE_INTENT);
        Log.v(TAG, "DigitalWidget register receiver");
        mContext.registerReceiver(this, filter);
@@ -245,7 +245,7 @@ public class DigitalWidgetViewsFactory extends BroadcastReceiver implements Remo
        if (action == null || widgetManager == null) {
            return;
        }
        if (action.equals(Alarms.NEXT_ALARM_TIME_SET)) {
        if (action.equals(AlarmNotifications.SYSTEM_ALARM_CHANGE_ACTION)) {
            // Update the next alarm text view
            RemoteViews widget =
                    new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);
+0 −111
Original line number Diff line number Diff line
/*
 * Copyright (C) 2007 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.deskclock;

import android.app.KeyguardManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;

/**
 * Full screen alarm alert: pops visible indicator and plays alarm tone. This
 * activity shows the alert as a dialog.
 */
public class AlarmAlert extends AlarmAlertFullScreen {

    // If we try to check the keyguard more than 5 times, just launch the full
    // screen activity.
    private int mKeyguardRetryCount;
    private final int MAX_KEYGUARD_CHECKS = 5;

    private final Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            handleScreenOff((KeyguardManager) msg.obj);
        }
    };

    private final BroadcastReceiver mScreenOffReceiver =
            new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
                    KeyguardManager km =
                            (KeyguardManager) context.getSystemService(
                            Context.KEYGUARD_SERVICE);
                    handleScreenOff(km);
                }
            };

    @Override
    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        /* Disable custom title, this will already be shown as a dialog */
    //    findViewById(R.id.topPanel).setVisibility(View.GONE);

        // Listen for the screen turning off so that when the screen comes back
        // on, the user does not need to unlock the phone to dismiss the alarm.
        registerReceiver(mScreenOffReceiver,
                new IntentFilter(Intent.ACTION_SCREEN_OFF));
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        unregisterReceiver(mScreenOffReceiver);
        // Remove any of the keyguard messages just in case
        mHandler.removeMessages(0);
    }

    @Override
    public void onBackPressed() {
        finish();
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.alarm_alert;
    }

    private boolean checkRetryCount() {
        if (mKeyguardRetryCount++ >= MAX_KEYGUARD_CHECKS) {
            Log.e("Tried to read keyguard status too many times, bailing...");
            return false;
        }
        return true;
    }

    private void handleScreenOff(final KeyguardManager km) {
        if (!km.inKeyguardRestrictedInputMode() && checkRetryCount()) {
            if (checkRetryCount()) {
                mHandler.sendMessageDelayed(mHandler.obtainMessage(0, km), 500);
            }
        } else {
            // Launch the full screen activity but do not turn the screen on.
            Intent i = new Intent(this, AlarmAlertFullScreen.class);
            i.putExtra(Alarms.ALARM_INTENT_EXTRA, mAlarm);
            i.putExtra(SCREEN_OFF, true);
            startActivity(i);
            finish();
        }
    }
}
+7 −9
Original line number Diff line number Diff line
@@ -20,20 +20,18 @@ import android.content.Context;
import android.os.PowerManager;

/**
 * Hold a wakelock that can be acquired in the AlarmReceiver and
 * released in the AlarmAlert activity
 * Utility class to hold wake lock in app.
 */
class AlarmAlertWakeLock {
public class AlarmAlertWakeLock {

    private static PowerManager.WakeLock sCpuWakeLock;

    static PowerManager.WakeLock createPartialWakeLock(Context context) {
        PowerManager pm =
                (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    public static PowerManager.WakeLock createPartialWakeLock(Context context) {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        return pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Log.LOGTAG);
    }

    static void acquireCpuWakeLock(Context context) {
    public static void acquireCpuWakeLock(Context context) {
        if (sCpuWakeLock != null) {
            return;
        }
@@ -42,7 +40,7 @@ class AlarmAlertWakeLock {
        sCpuWakeLock.acquire();
    }

    static void acquireScreenCpuWakeLock(Context context) {
    public static void acquireScreenCpuWakeLock(Context context) {
        if (sCpuWakeLock != null) {
            return;
        }
@@ -52,7 +50,7 @@ class AlarmAlertWakeLock {
        sCpuWakeLock.acquire();
    }

    static void releaseCpuLock() {
    public static void releaseCpuLock() {
        if (sCpuWakeLock != null) {
            sCpuWakeLock.release();
            sCpuWakeLock = null;
Loading