diff options
| author | Stephen Bird <sbird@cyngn.com> | 2015-08-18 18:48:34 -0700 |
|---|---|---|
| committer | doc HD <doc.divxm@gmail.com> | 2015-08-22 01:46:32 +0300 |
| commit | 418963b1915f18a58224806a04871d6824533dd6 (patch) | |
| tree | f64a486ddd50db0a17dd44563cf88788da687120 | |
| parent | 695e16fbbe8bb72210cc103410448acfaa1e6db5 (diff) | |
QuickMessage: Make useful on lockscreen
Previously, the 'wake and unlock' feature would do
horrible things like disabling the keyguard and never
enabling it. This caused a bunch of different issues.
The Activity would also wake the screen with a wakelock that
never ended. This wakes the phone using the windowmanager flag.
Ticket(s): QRDL-1022 & QRDL-1000
Change-Id: Id53e70f38a3af0fab74016a29abbe7c7693de9c1
| -rw-r--r-- | res/values/cm_strings.xml | 2 | ||||
| -rw-r--r-- | res/values/styles.xml | 1 | ||||
| -rw-r--r-- | src/com/android/mms/quickmessage/ClearAllReceiver.java | 72 | ||||
| -rw-r--r-- | src/com/android/mms/quickmessage/ManageKeyguard.java | 53 | ||||
| -rw-r--r-- | src/com/android/mms/quickmessage/ManageWakeLock.java | 84 | ||||
| -rwxr-xr-x | src/com/android/mms/quickmessage/QmTextWatcher.java | 6 | ||||
| -rw-r--r-- | src/com/android/mms/quickmessage/QuickMessagePopup.java | 71 | ||||
| -rw-r--r-- | src/com/android/mms/ui/ComposeMessageActivityNoLockScreen.java | 10 |
8 files changed, 21 insertions, 278 deletions
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml index 84df6673..cc062120 100644 --- a/res/values/cm_strings.xml +++ b/res/values/cm_strings.xml @@ -22,7 +22,7 @@ <string name="pref_quickmessage_title">Show QuickMessage</string> <string name="pref_quickmessage_summary">Automatically open the QuickMessage pop-up for incoming SMS messages</string> <string name="pref_wake_unlock_title">Wake and unlock</string> - <string name="pref_wake_unlock_summary">Wake and unlock device on incoming message (insecure lock screens only)</string> + <string name="pref_wake_unlock_summary">Wake the device and display the QuickMessage box</string> <string name="pref_close_all_title">Close all</string> <string name="pref_close_all_summary">Close button closes all messages</string> <string name="pref_dark_theme_title">Use dark theme</string> diff --git a/res/values/styles.xml b/res/values/styles.xml index ef12a2ec..661e6fc3 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -117,5 +117,6 @@ <style name="Theme.QMPopUp" parent="android:Theme.Material.Dialog"> <item name="android:alertDialogTheme">@android:style/Theme.Material.Light.Dialog</item> + <item name="android:windowTranslucentStatus">true</item> </style> </resources> diff --git a/src/com/android/mms/quickmessage/ClearAllReceiver.java b/src/com/android/mms/quickmessage/ClearAllReceiver.java deleted file mode 100644 index 52f355cb..00000000 --- a/src/com/android/mms/quickmessage/ClearAllReceiver.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2012 Adam K - * Modifications Copyright (C) 2012 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.mms.quickmessage; - -import android.app.AlarmManager; -import android.app.PendingIntent; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; - -/** - * This class provides an easy way to clear held WakeLocks and re-enable the - * Keyguard (either immediately or scheduled in the future). - */ -public class ClearAllReceiver extends BroadcastReceiver { - private static String LOG_TAG = "ManageKeyguard"; - - @Override - public void onReceive(Context context, Intent intent) { - clearAll(); - } - - public static synchronized void clearAll() { - clearAll(true); - } - - public static synchronized void clearAll(boolean reenableKeyguard) { - if (reenableKeyguard) { - ManageKeyguard.reenableKeyguard(); - } - ManageWakeLock.releaseAll(); - } - - private static PendingIntent getPendingIntent(Context context) { - return PendingIntent.getBroadcast( - context, 0, new Intent(context, ClearAllReceiver.class), 0); - } - - /** - * Schedules a Broadcast to this receiver for some time in the future (timeout). Used in the - * case the user doesn't notice the pop-up and the phone should go back to sleep - */ - public static synchronized void setCancel(Context context, int timeout) { - removeCancel(context); - AlarmManager myAM = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); - myAM.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (timeout * 1000), - getPendingIntent(context)); - } - - /** - * Cancels the scheduled Broadcast to this receiver - */ - public static synchronized void removeCancel(Context context) { - AlarmManager myAM = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); - myAM.cancel(getPendingIntent(context)); - } -} diff --git a/src/com/android/mms/quickmessage/ManageKeyguard.java b/src/com/android/mms/quickmessage/ManageKeyguard.java deleted file mode 100644 index cede39c5..00000000 --- a/src/com/android/mms/quickmessage/ManageKeyguard.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2012 Adam K - * Modifications Copyright (C) 2012 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.mms.quickmessage; - -import android.app.KeyguardManager; -import android.app.KeyguardManager.KeyguardLock; -import android.app.KeyguardManager.OnKeyguardExitResult; -import android.content.Context; -import com.android.mms.MmsApp; - -public class ManageKeyguard { - private static String LOGTAG = "ManageKeyguard"; - private static KeyguardManager sKeyguardManager = null; - private static KeyguardLock sKeyguardLock = null; - - public static synchronized void initialize() { - Context context = MmsApp.getApplication(); - if (sKeyguardManager == null) { - sKeyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); - } - } - - public static synchronized void disableKeyguard() { - initialize(); - - if (sKeyguardLock == null) { - sKeyguardLock = sKeyguardManager.newKeyguardLock(LOGTAG); - } - sKeyguardLock.disableKeyguard(); - } - - public static synchronized void reenableKeyguard() { - if (sKeyguardLock != null) { - sKeyguardLock.reenableKeyguard(); - sKeyguardLock = null; - } - } -} diff --git a/src/com/android/mms/quickmessage/ManageWakeLock.java b/src/com/android/mms/quickmessage/ManageWakeLock.java deleted file mode 100644 index 23f13ee6..00000000 --- a/src/com/android/mms/quickmessage/ManageWakeLock.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) 2012 Adam K - * Modifications Copyright (C) 2012 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.mms.quickmessage; - -import android.content.Context; -import android.os.PowerManager; - -public class ManageWakeLock { - private static String LOG_TAG = "ManageWakelock"; - - private static volatile PowerManager.WakeLock sWakeLock = null; - private static volatile PowerManager.WakeLock sPartialWakeLock = null; - private static final int TIMEOUT = 30; - - public static synchronized void acquireFull(Context context) { - if (sWakeLock != null) { - return; - } - - ManageKeyguard.disableKeyguard(); - - PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); - sWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK - | PowerManager.ACQUIRE_CAUSES_WAKEUP, LOG_TAG + ".full"); - sWakeLock.setReferenceCounted(false); - sWakeLock.acquire(); - - // Set a receiver to remove all locks in "timeout" seconds - ClearAllReceiver.setCancel(context, TIMEOUT); - } - - public static synchronized void pokeWakeLock(Context context) { - if (sWakeLock == null) { - return; - } - // Reset the receiver to remove all locks in "timeout" seconds - ClearAllReceiver.setCancel(context, TIMEOUT); - } - - public static synchronized void acquirePartial(Context mContext) { - if (sPartialWakeLock != null) { - return; - } - - PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); - sPartialWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, LOG_TAG + ".partial"); - sPartialWakeLock.setReferenceCounted(false); - sPartialWakeLock.acquire(300000); // set timeout to 5 mins - } - - public static synchronized void releaseFull() { - if (sWakeLock != null) { - sWakeLock.release(); - sWakeLock = null; - } - } - - public static synchronized void releasePartial() { - if (sPartialWakeLock != null && sPartialWakeLock.isHeld()) { - sPartialWakeLock.release(); - sPartialWakeLock = null; - } - } - - public static synchronized void releaseAll() { - releaseFull(); - releasePartial(); - } -}
\ No newline at end of file diff --git a/src/com/android/mms/quickmessage/QmTextWatcher.java b/src/com/android/mms/quickmessage/QmTextWatcher.java index e82917ba..e85f0206 100755 --- a/src/com/android/mms/quickmessage/QmTextWatcher.java +++ b/src/com/android/mms/quickmessage/QmTextWatcher.java @@ -61,12 +61,6 @@ public class QmTextWatcher implements TextWatcher { s = mUnicodeFilter.filter(s); } getQuickReplyCounterText(s, mTextView, mSendButton); - - // For performance, we will only poke the wakelock on the 1st and every 20th keystroke - if (s.length() == 1 || s.length() % 20 == 0) { - // If there is no active wakelock this will not do anything - ManageWakeLock.pokeWakeLock(mContext); - } } public static void getQuickReplyCounterText(CharSequence s, TextView textView, diff --git a/src/com/android/mms/quickmessage/QuickMessagePopup.java b/src/com/android/mms/quickmessage/QuickMessagePopup.java index a91a0a72..c10efec1 100644 --- a/src/com/android/mms/quickmessage/QuickMessagePopup.java +++ b/src/com/android/mms/quickmessage/QuickMessagePopup.java @@ -18,16 +18,13 @@ package com.android.mms.quickmessage; import android.app.Activity; import android.app.AlertDialog; -import android.app.KeyguardManager; import android.app.NotificationManager; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; -import android.content.res.Configuration; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Parcelable; -import android.os.PowerManager; import android.preference.PreferenceManager; import android.provider.ContactsContract.Profile; import android.support.v4.view.PagerAdapter; @@ -42,7 +39,6 @@ import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; -import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; import android.view.inputmethod.EditorInfo; @@ -59,11 +55,11 @@ import com.android.internal.telephony.util.BlacklistUtils; import com.android.mms.MmsConfig; import com.android.mms.R; import com.android.mms.data.Contact; -import com.android.mms.data.ContactList; import com.android.mms.data.Conversation; import com.android.mms.transaction.MessagingNotification; import com.android.mms.transaction.MessagingNotification.NotificationInfo; import com.android.mms.transaction.SmsMessageSender; +import com.android.mms.ui.ComposeMessageActivityNoLockScreen; import com.android.mms.ui.MessageUtils; import com.android.mms.ui.MessagingPreferenceActivity; import com.android.mms.util.SmileyParser; @@ -71,9 +67,7 @@ import com.android.mms.util.UnicodeFilter; import com.google.android.mms.MmsException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Iterator; -import java.util.List; public class QuickMessagePopup extends Activity { private static final String LOG_TAG = "QuickMessagePopup"; @@ -104,9 +98,6 @@ public class QuickMessagePopup extends Activity { // General items private Drawable mDefaultContactImage; - private boolean mScreenUnlocked = false; - private KeyguardManager mKeyguardManager = null; - private PowerManager mPowerManager; // Message list items private ArrayList<QuickMessage> mMessageList; @@ -134,8 +125,6 @@ public class QuickMessagePopup extends Activity { // Initialise the message list and other variables mMessageList = new ArrayList<QuickMessage>(); mDefaultContactImage = getResources().getDrawable(R.drawable.ic_contact_picture); - mPowerManager = (PowerManager) getSystemService(POWER_SERVICE); - mKeyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE); // Get the preferences SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); @@ -147,6 +136,12 @@ public class QuickMessagePopup extends Activity { // Set the window features and layout requestWindowFeature(Window.FEATURE_NO_TITLE); + if (mWakeAndUnlock) { + getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + } setContentView(R.layout.dialog_quickmessage); // Turn on the Options Menu @@ -205,25 +200,18 @@ public class QuickMessagePopup extends Activity { mViewButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - // Override the re-lock if the screen was unlocked - if (mScreenUnlocked) { - // Cancel the receiver that will clear the wake locks - ClearAllReceiver.removeCancel(getApplicationContext()); - ClearAllReceiver.clearAll(false); - mScreenUnlocked = false; - } - // Trigger the view intent mCurrentQm = mMessageList.get(mCurrentPage); Intent vi = mCurrentQm.getViewIntent(); if (vi != null) { mCurrentQm.saveReplyText(); + vi.setClass(getApplicationContext(), ComposeMessageActivityNoLockScreen.class); vi.putExtra("sms_body", mCurrentQm.getReplyText()); - startActivity(vi); + + clearNotification(true); + finish(); } - clearNotification(false); - finish(); } }); } @@ -288,30 +276,6 @@ public class QuickMessagePopup extends Activity { } @Override - public void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - } - - @Override - protected void onResume() { - super.onResume(); - - // Unlock the screen if needed - unlockScreen(); - } - - @Override - protected void onStop() { - super.onStop(); - - if (mScreenUnlocked) { - // Cancel the receiver that will clear the wake locks - ClearAllReceiver.removeCancel(getApplicationContext()); - ClearAllReceiver.clearAll(true); - } - } - - @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); @@ -387,19 +351,6 @@ public class QuickMessagePopup extends Activity { } /** - * If 'Wake and unlock' is enabled, this method will unlock the screen - */ - private void unlockScreen() { - // See if the lock screen should be disabled - if (!mWakeAndUnlock) { - return; - } - - ManageWakeLock.acquireFull(this); - mScreenUnlocked = true; - } - - /** * Update the page indicator counter to show the currently selected visible page number */ public void updateMessageCounter() { diff --git a/src/com/android/mms/ui/ComposeMessageActivityNoLockScreen.java b/src/com/android/mms/ui/ComposeMessageActivityNoLockScreen.java index b69d4e42..b4753154 100644 --- a/src/com/android/mms/ui/ComposeMessageActivityNoLockScreen.java +++ b/src/com/android/mms/ui/ComposeMessageActivityNoLockScreen.java @@ -25,8 +25,14 @@ import android.view.WindowManager; public class ComposeMessageActivityNoLockScreen extends ComposeMessageActivity { @Override protected void onCreate(Bundle savedInstanceState) { - getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | - WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); super.onCreate(savedInstanceState); } + + @Override + protected void onPause() { + // when the lockscreendismissed composemesssage pauses, kill it + super.onPause(); + finish(); + } } |
