summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeepak Kundra <deepakkundra@gmail.com>2016-06-02 07:23:28 (GMT)
committerDeepak Kundra <deepakkundra@gmail.com>2016-06-02 07:25:51 (GMT)
commit2015d27a6cb3bb04620f6b3e8b7d077f706df52c (patch)
treef94d58d88c30ca7fa9eb9357b54abde4e3d233a4
parenteb998df357e17e279cf0968431ef3f962f2d880b (diff)
downloadandroid_packages_apps_CellBroadcastReceiver-2015d27a6cb3bb04620f6b3e8b7d077f706df52c.zip
android_packages_apps_CellBroadcastReceiver-2015d27a6cb3bb04620f6b3e8b7d077f706df52c.tar.gz
android_packages_apps_CellBroadcastReceiver-2015d27a6cb3bb04620f6b3e8b7d077f706df52c.tar.bz2
Do not let system keys bypass alert
Issue-id:FEIJ-507 Change-Id: I276280515a13a263eadff631c823849491049e67
-rw-r--r--AndroidManifest.xml1
-rw-r--r--src/com/android/cellbroadcastreceiver/CellBroadcastAlertDialog.java3
-rw-r--r--src/com/android/cellbroadcastreceiver/CellBroadcastAlertFullScreen.java35
-rw-r--r--src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java5
4 files changed, 37 insertions, 7 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 740562c..3a7886d 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -30,6 +30,7 @@
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
<uses-permission android:name="android.permission.MANAGE_USERS" />
+ <uses-permission android:name="android.permission.PREVENT_SYSTEM_KEYS" />
<application android:name="CellBroadcastReceiverApp"
android:label="@string/app_label"
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertDialog.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertDialog.java
index f250928..e4dc93b 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertDialog.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertDialog.java
@@ -22,6 +22,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.telephony.CellBroadcastMessage;
+import android.util.Log;
/**
* Custom alert dialog with optional flashing warning icon.
@@ -29,6 +30,7 @@ import android.telephony.CellBroadcastMessage;
* Keyguard handling based on {@code AlarmAlert} class from DeskClock app.
*/
public class CellBroadcastAlertDialog extends CellBroadcastAlertFullScreen {
+ private static final String TAG = "CellBroadcastAlertDialog";
private BroadcastReceiver mScreenOffReceiver;
@@ -43,6 +45,7 @@ public class CellBroadcastAlertDialog extends CellBroadcastAlertFullScreen {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
+ Log.d(TAG, "Alert Dialog Created");
// 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 alert.
if (CellBroadcastConfigService.isEmergencyAlertMessage(getLatestMessage())) {
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertFullScreen.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertFullScreen.java
index 26d5643..8110e1e 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertFullScreen.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertFullScreen.java
@@ -83,6 +83,9 @@ public class CellBroadcastAlertFullScreen extends Activity {
/** Handler to add and remove screen on flags for emergency alerts. */
private final ScreenOffHandler mScreenOffHandler = new ScreenOffHandler();
+ /** Duration of alert if set to 0 then do not allow system keys to dismiss the alert. */
+ private int mDuration = 1;
+
/**
* Animation handler for the flashing warning icon (emergency alerts only).
*/
@@ -182,6 +185,13 @@ public class CellBroadcastAlertFullScreen extends Activity {
/** Package local constructor (called from outer class). */
ScreenOffHandler() {}
+ /** Add screen on window flags. */
+ void keepScreenOn() {
+ addWindowFlags();
+ addSystemKeyFlag();
+ Log.d(TAG, "added FLAG_KEEP_SCREEN_ON & PRIVATE_FLAG_PREVENT_SYSTEM_KEYS");
+ }
+
/** Add screen on window flags and queue a delayed message to remove them later. */
void startScreenOnTimer() {
addWindowFlags();
@@ -203,6 +213,11 @@ public class CellBroadcastAlertFullScreen extends Activity {
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
+ /** Set the system keys flag. */
+ private void addSystemKeyFlag() {
+ getWindow().addPrivateFlags(WindowManager.LayoutParams.PRIVATE_FLAG_PREVENT_SYSTEM_KEYS);
+ }
+
/** Clear the screen on window flags. */
private void clearWindowFlags() {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
@@ -269,15 +284,15 @@ public class CellBroadcastAlertFullScreen extends Activity {
// Get message list from saved Bundle or from Intent.
if (savedInstanceState != null) {
- Log.d(TAG, "onCreate getting message list from saved instance state");
+ Log.d(TAG, "onCreate getting message list from saved instance state, Duration=" + mDuration);
mMessageList = savedInstanceState.getParcelableArrayList(
CellBroadcastMessage.SMS_CB_MESSAGE_EXTRA);
} else {
- Log.d(TAG, "onCreate getting message list from intent");
Intent intent = getIntent();
mMessageList = intent.getParcelableArrayListExtra(
CellBroadcastMessage.SMS_CB_MESSAGE_EXTRA);
-
+ mDuration = intent.getIntExtra(CellBroadcastAlertAudio.ALERT_AUDIO_DURATION_EXTRA, 1);
+ Log.d(TAG, "onCreate getting message list from intent, Duration=" + mDuration);
// If we were started from a notification, dismiss it.
clearNotification(intent);
}
@@ -295,8 +310,13 @@ public class CellBroadcastAlertFullScreen extends Activity {
if (CellBroadcastConfigService.isEmergencyAlertMessage(message) &&
(savedInstanceState != null ||
!getIntent().getBooleanExtra(SCREEN_OFF_EXTRA, false))) {
- Log.d(TAG, "onCreate setting screen on timer for emergency alert");
- mScreenOffHandler.startScreenOnTimer();
+ if (mDuration == 0) {
+ Log.d(TAG, "onCreate keep screen on for emergency alert");
+ mScreenOffHandler.keepScreenOn();
+ } else {
+ Log.d(TAG, "onCreate setting screen on timer for emergency alert");
+ mScreenOffHandler.startScreenOnTimer();
+ }
}
updateAlertText(message);
@@ -462,6 +482,10 @@ public class CellBroadcastAlertFullScreen extends Activity {
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
+ if (mDuration == 0) {
+ Log.d(TAG, "Override all key events till the Alert Dialog is not dismissed");
+ return true;
+ }
CellBroadcastMessage message = getLatestMessage();
if (message != null && !message.isEtwsMessage()) {
switch (event.getKeyCode()) {
@@ -488,6 +512,7 @@ public class CellBroadcastAlertFullScreen extends Activity {
*/
@Override
public void onBackPressed() {
+ Log.d(TAG, "Override back key events till the Alert Dialog is not dismissed");
// ignored
}
}
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java
index d2f8394..8607217 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java
@@ -394,8 +394,8 @@ public class CellBroadcastAlertService extends Service {
// Decide which activity to start based on the state of the keyguard.
Class c = CellBroadcastAlertDialog.class;
KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
- if (km.inKeyguardRestrictedInputMode()) {
- // Use the full screen activity for security.
+ if (km.inKeyguardRestrictedInputMode() || duration == 0) {
+ // Use the full screen activity for security and local gov law's.
c = CellBroadcastAlertFullScreen.class;
}
@@ -404,6 +404,7 @@ public class CellBroadcastAlertService extends Service {
Intent alertDialogIntent = createDisplayMessageIntent(this, c, messageList);
alertDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ alertDialogIntent.putExtra(CellBroadcastAlertAudio.ALERT_AUDIO_DURATION_EXTRA, duration);
startActivity(alertDialogIntent);
}