Loading core/java/android/provider/Settings.java +7 −0 Original line number Diff line number Diff line Loading @@ -3053,6 +3053,12 @@ public final class Settings { */ public static final String QUIET_HOURS_HAPTIC = "quiet_hours_haptic"; /** * Whether to remove the system sounds during quiet hours. * @hide */ public static final String QUIET_HOURS_SYSTEM = "quiet_hours_system"; /** * Whether to remove the vibration from outgoing notifications during quiet hours. * @hide Loading Loading @@ -3407,6 +3413,7 @@ public final class Settings { QUIET_HOURS_START, QUIET_HOURS_END, QUIET_HOURS_MUTE, QUIET_HOURS_SYSTEM, QUIET_HOURS_STILL, QUIET_HOURS_DIM, SYSTEM_PROFILES_ENABLED, Loading core/java/com/android/internal/util/cm/QuietHoursUtils.java 0 → 100644 +48 −0 Original line number Diff line number Diff line /* * Copyright (C) 2013 The CyanogenMod 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.internal.util.cm; import android.content.Context; import android.provider.Settings; import java.util.Calendar; public class QuietHoursUtils { public static boolean inQuietHours(Context context, String option) { boolean quietHoursEnabled = Settings.System.getInt(context.getContentResolver(), Settings.System.QUIET_HOURS_ENABLED, 0) != 0; int quietHoursStart = Settings.System.getInt(context.getContentResolver(), Settings.System.QUIET_HOURS_START, 0); int quietHoursEnd = Settings.System.getInt(context.getContentResolver(), Settings.System.QUIET_HOURS_END, 0); boolean quietHoursOption = Settings.System.getInt(context.getContentResolver(), option, 0) != 0; if (quietHoursEnabled && quietHoursOption && (quietHoursStart != quietHoursEnd)) { // Get the date in "quiet hours" format. Calendar calendar = Calendar.getInstance(); int minutes = calendar.get(Calendar.HOUR_OF_DAY) * 60 + calendar.get(Calendar.MINUTE); if (quietHoursEnd < quietHoursStart) { // Starts at night, ends in the morning. return (minutes > quietHoursStart) || (minutes < quietHoursEnd); } else { return (minutes > quietHoursStart) && (minutes < quietHoursEnd); } } return false; } } media/java/android/media/AudioManager.java +6 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,8 @@ import android.view.VolumePanel; import java.util.HashMap; import com.android.internal.util.cm.QuietHoursUtils; /** * AudioManager provides access to volume and ringer mode control. * <p> Loading Loading @@ -1794,6 +1796,10 @@ public class AudioManager { return; } if (QuietHoursUtils.inQuietHours(mContext, Settings.System.QUIET_HOURS_SYSTEM)) { return; } if (!querySoundEffectsEnabled()) { return; } Loading packages/Keyguard/src/com/android/keyguard/KeyguardViewMediator.java +5 −1 Original line number Diff line number Diff line Loading @@ -57,9 +57,9 @@ import android.view.WindowManager; import android.view.WindowManagerPolicy; import com.android.internal.telephony.IccCardConstants; import com.android.internal.util.cm.QuietHoursUtils; import com.android.internal.widget.LockPatternUtils; /** * Mediates requests related to the keyguard. This includes queries about the * state of the keyguard, power management events that effect whether the keyguard Loading Loading @@ -1177,6 +1177,10 @@ public class KeyguardViewMediator { return; } if (QuietHoursUtils.inQuietHours(mContext, Settings.System.QUIET_HOURS_SYSTEM)) { return; } final ContentResolver cr = mContext.getContentResolver(); if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) { final int whichSound = locked Loading services/java/com/android/server/BatteryService.java +2 −20 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.server; import android.os.BatteryStats; import com.android.internal.app.IBatteryStats; import com.android.internal.util.cm.QuietHoursUtils; import com.android.server.am.BatteryStatsService; import android.app.ActivityManagerNative; Loading Loading @@ -51,7 +52,6 @@ import java.io.FileDescriptor; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.Calendar; /** * <p>BatteryService monitors the charging status, and charge level of the device Loading Loading @@ -150,7 +150,6 @@ public final class BatteryService extends Binder { private boolean mQuietHoursEnabled = false; private int mQuietHoursStart = 0; private int mQuietHoursEnd = 0; private boolean mQuietHoursDim = true; public BatteryService(Context context, LightsService lights) { mContext = context; Loading Loading @@ -738,7 +737,7 @@ public final class BatteryService extends Binder { if (!mLightEnabled) { // No lights if explicitly disabled mBatteryLight.turnOff(); } else if (inQuietHours() && mQuietHoursDim) { } else if (QuietHoursUtils.inQuietHours(mContext, Settings.System.QUIET_HOURS_DIM)) { if (mLedPulseEnabled && level < mLowBatteryWarningLevel && status != BatteryManager.BATTERY_STATUS_CHARGING) { // The battery is low, the device is not charging and the low battery pulse Loading Loading @@ -857,26 +856,9 @@ public final class BatteryService extends Binder { Settings.System.QUIET_HOURS_START, 0, UserHandle.USER_CURRENT_OR_SELF); mQuietHoursEnd = Settings.System.getIntForUser(resolver, Settings.System.QUIET_HOURS_END, 0, UserHandle.USER_CURRENT_OR_SELF); mQuietHoursDim = Settings.System.getIntForUser(resolver, Settings.System.QUIET_HOURS_DIM, 0, UserHandle.USER_CURRENT_OR_SELF) != 0; updateLedPulse(); } } private boolean inQuietHours() { if (mQuietHoursEnabled && (mQuietHoursStart != mQuietHoursEnd)) { // Get the date in "quiet hours" format. Calendar calendar = Calendar.getInstance(); int minutes = calendar.get(Calendar.HOUR_OF_DAY) * 60 + calendar.get(Calendar.MINUTE); if (mQuietHoursEnd < mQuietHoursStart) { // Starts at night, ends in the morning. return (minutes > mQuietHoursStart) || (minutes < mQuietHoursEnd); } else { return (minutes > mQuietHoursStart) && (minutes < mQuietHoursEnd); } } return false; } } Loading
core/java/android/provider/Settings.java +7 −0 Original line number Diff line number Diff line Loading @@ -3053,6 +3053,12 @@ public final class Settings { */ public static final String QUIET_HOURS_HAPTIC = "quiet_hours_haptic"; /** * Whether to remove the system sounds during quiet hours. * @hide */ public static final String QUIET_HOURS_SYSTEM = "quiet_hours_system"; /** * Whether to remove the vibration from outgoing notifications during quiet hours. * @hide Loading Loading @@ -3407,6 +3413,7 @@ public final class Settings { QUIET_HOURS_START, QUIET_HOURS_END, QUIET_HOURS_MUTE, QUIET_HOURS_SYSTEM, QUIET_HOURS_STILL, QUIET_HOURS_DIM, SYSTEM_PROFILES_ENABLED, Loading
core/java/com/android/internal/util/cm/QuietHoursUtils.java 0 → 100644 +48 −0 Original line number Diff line number Diff line /* * Copyright (C) 2013 The CyanogenMod 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.internal.util.cm; import android.content.Context; import android.provider.Settings; import java.util.Calendar; public class QuietHoursUtils { public static boolean inQuietHours(Context context, String option) { boolean quietHoursEnabled = Settings.System.getInt(context.getContentResolver(), Settings.System.QUIET_HOURS_ENABLED, 0) != 0; int quietHoursStart = Settings.System.getInt(context.getContentResolver(), Settings.System.QUIET_HOURS_START, 0); int quietHoursEnd = Settings.System.getInt(context.getContentResolver(), Settings.System.QUIET_HOURS_END, 0); boolean quietHoursOption = Settings.System.getInt(context.getContentResolver(), option, 0) != 0; if (quietHoursEnabled && quietHoursOption && (quietHoursStart != quietHoursEnd)) { // Get the date in "quiet hours" format. Calendar calendar = Calendar.getInstance(); int minutes = calendar.get(Calendar.HOUR_OF_DAY) * 60 + calendar.get(Calendar.MINUTE); if (quietHoursEnd < quietHoursStart) { // Starts at night, ends in the morning. return (minutes > quietHoursStart) || (minutes < quietHoursEnd); } else { return (minutes > quietHoursStart) && (minutes < quietHoursEnd); } } return false; } }
media/java/android/media/AudioManager.java +6 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,8 @@ import android.view.VolumePanel; import java.util.HashMap; import com.android.internal.util.cm.QuietHoursUtils; /** * AudioManager provides access to volume and ringer mode control. * <p> Loading Loading @@ -1794,6 +1796,10 @@ public class AudioManager { return; } if (QuietHoursUtils.inQuietHours(mContext, Settings.System.QUIET_HOURS_SYSTEM)) { return; } if (!querySoundEffectsEnabled()) { return; } Loading
packages/Keyguard/src/com/android/keyguard/KeyguardViewMediator.java +5 −1 Original line number Diff line number Diff line Loading @@ -57,9 +57,9 @@ import android.view.WindowManager; import android.view.WindowManagerPolicy; import com.android.internal.telephony.IccCardConstants; import com.android.internal.util.cm.QuietHoursUtils; import com.android.internal.widget.LockPatternUtils; /** * Mediates requests related to the keyguard. This includes queries about the * state of the keyguard, power management events that effect whether the keyguard Loading Loading @@ -1177,6 +1177,10 @@ public class KeyguardViewMediator { return; } if (QuietHoursUtils.inQuietHours(mContext, Settings.System.QUIET_HOURS_SYSTEM)) { return; } final ContentResolver cr = mContext.getContentResolver(); if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) { final int whichSound = locked Loading
services/java/com/android/server/BatteryService.java +2 −20 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.server; import android.os.BatteryStats; import com.android.internal.app.IBatteryStats; import com.android.internal.util.cm.QuietHoursUtils; import com.android.server.am.BatteryStatsService; import android.app.ActivityManagerNative; Loading Loading @@ -51,7 +52,6 @@ import java.io.FileDescriptor; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.Calendar; /** * <p>BatteryService monitors the charging status, and charge level of the device Loading Loading @@ -150,7 +150,6 @@ public final class BatteryService extends Binder { private boolean mQuietHoursEnabled = false; private int mQuietHoursStart = 0; private int mQuietHoursEnd = 0; private boolean mQuietHoursDim = true; public BatteryService(Context context, LightsService lights) { mContext = context; Loading Loading @@ -738,7 +737,7 @@ public final class BatteryService extends Binder { if (!mLightEnabled) { // No lights if explicitly disabled mBatteryLight.turnOff(); } else if (inQuietHours() && mQuietHoursDim) { } else if (QuietHoursUtils.inQuietHours(mContext, Settings.System.QUIET_HOURS_DIM)) { if (mLedPulseEnabled && level < mLowBatteryWarningLevel && status != BatteryManager.BATTERY_STATUS_CHARGING) { // The battery is low, the device is not charging and the low battery pulse Loading Loading @@ -857,26 +856,9 @@ public final class BatteryService extends Binder { Settings.System.QUIET_HOURS_START, 0, UserHandle.USER_CURRENT_OR_SELF); mQuietHoursEnd = Settings.System.getIntForUser(resolver, Settings.System.QUIET_HOURS_END, 0, UserHandle.USER_CURRENT_OR_SELF); mQuietHoursDim = Settings.System.getIntForUser(resolver, Settings.System.QUIET_HOURS_DIM, 0, UserHandle.USER_CURRENT_OR_SELF) != 0; updateLedPulse(); } } private boolean inQuietHours() { if (mQuietHoursEnabled && (mQuietHoursStart != mQuietHoursEnd)) { // Get the date in "quiet hours" format. Calendar calendar = Calendar.getInstance(); int minutes = calendar.get(Calendar.HOUR_OF_DAY) * 60 + calendar.get(Calendar.MINUTE); if (mQuietHoursEnd < mQuietHoursStart) { // Starts at night, ends in the morning. return (minutes > mQuietHoursStart) || (minutes < mQuietHoursEnd); } else { return (minutes > mQuietHoursStart) && (minutes < mQuietHoursEnd); } } return false; } }