Skip to content

Instantly share code, notes, and snippets.

@CedricGatay
Created August 16, 2010 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CedricGatay/527099 to your computer and use it in GitHub Desktop.
Save CedricGatay/527099 to your computer and use it in GitHub Desktop.
diff --git a/src/com/android/phone/NotificationMgr.java b/src/com/android/phone/NotificationMgr.java
index c335b02..887be30 100644
--- a/src/com/android/phone/NotificationMgr.java
+++ b/src/com/android/phone/NotificationMgr.java
@@ -31,6 +31,7 @@ import android.media.AudioManager;
import android.net.Uri;
import android.os.IBinder;
import android.os.SystemClock;
+import android.os.SystemProperties;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.provider.CallLog.Calls;
@@ -49,6 +50,12 @@ import com.android.internal.telephony.Connection;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneBase;
+import android.preference.PreferenceManager;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+
+
/**
* NotificationManager-related utility code for the Phone app.
*/
@@ -85,6 +92,8 @@ public class NotificationMgr implements CallerInfoAsyncQuery.OnQueryCompleteList
private IBinder mSpeakerphoneIcon;
private IBinder mMuteIcon;
+private CallFeaturesSetting mSettings;
+
// used to track the missed call counter, default to 0.
private int mNumberMissedCalls = 0;
@@ -107,6 +116,7 @@ public class NotificationMgr implements CallerInfoAsyncQuery.OnQueryCompleteList
NotificationMgr(Context context) {
mContext = context;
+mSettings = CallFeaturesSetting.getInstance(PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()));
mNotificationMgr = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
@@ -365,9 +375,12 @@ public class NotificationMgr implements CallerInfoAsyncQuery.OnQueryCompleteList
* Configures a Notification to emit the blinky green message-waiting/
* missed-call signal.
*/
- private static void configureLedNotification(Notification note) {
- note.flags |= Notification.FLAG_SHOW_LIGHTS;
- note.defaults |= Notification.DEFAULT_LIGHTS;
+ private void configureLedNotification(Notification note) {
+// note.flags |= Notification.FLAG_SHOW_LIGHTS;
+// note.ledARGB = 0xff00ffff;
+// note.ledOnMS = 500;
+// note.ledOffMS = 2000;
+ mLiquidLEDHack.setLEDEnabled(true);
}
/**
@@ -412,15 +425,15 @@ public class NotificationMgr implements CallerInfoAsyncQuery.OnQueryCompleteList
final Intent intent = PhoneApp.createCallLogIntent();
// make the notification
- Notification note = new Notification(
+ Notification note = new Notification(mContext, // context
android.R.drawable.stat_notify_missed_call, // icon
mContext.getString(R.string.notification_missedCallTicker, callName), // tickerText
- date // when
+ date, // when
+ mContext.getText(titleResId), // expandedTitle
+ expandedText, // expandedText
+ intent // contentIntent
);
- note.setLatestEventInfo(mContext, mContext.getText(titleResId), expandedText,
- PendingIntent.getActivity(mContext, 0, intent, 0));
-
- configureLedNotification(note);
+ if (mSettings.mLedNotify) configureLedNotification(note);
mNotificationMgr.notify(MISSED_CALL_NOTIFICATION, note);
}
@@ -428,6 +441,7 @@ public class NotificationMgr implements CallerInfoAsyncQuery.OnQueryCompleteList
// reset the number of missed calls to 0.
mNumberMissedCalls = 0;
mNotificationMgr.cancel(MISSED_CALL_NOTIFICATION);
+ mLiquidLEDHack.setLEDEnabled(false);
}
void notifySpeakerphone() {
@@ -596,7 +610,11 @@ public class NotificationMgr implements CallerInfoAsyncQuery.OnQueryCompleteList
expandedViewLine1 = mContext.getString(R.string.notification_on_hold);
} else {
// Format string with a "%s" where the current call time should go.
+if (callDurationMsec > 0) {
expandedViewLine1 = mContext.getString(R.string.notification_ongoing_call_format);
+} else {
+ expandedViewLine1 = mContext.getString(R.string.notification_ongoing_calling_format);
+}
}
if (DBG) log("- Updating expanded view: line 1 '" + expandedViewLine1 + "'");
@@ -781,8 +799,7 @@ public class NotificationMgr implements CallerInfoAsyncQuery.OnQueryCompleteList
pendingIntent // contentIntent
);
notification.defaults |= Notification.DEFAULT_SOUND;
- notification.flags |= Notification.FLAG_NO_CLEAR;
- configureLedNotification(notification);
+ if (mSettings.mLedNotify) configureLedNotification(notification);
mNotificationMgr.notify(VOICEMAIL_NOTIFICATION, notification);
} else {
mNotificationMgr.cancel(VOICEMAIL_NOTIFICATION);
@@ -816,17 +833,17 @@ public class NotificationMgr implements CallerInfoAsyncQuery.OnQueryCompleteList
intent.setClassName("com.android.phone",
"com.android.phone.CallFeaturesSetting");
-
notification = new Notification(
- android.R.drawable.stat_sys_phone_call_forward, // icon
+ mContext, // context
+ android.R.drawable.stat_sys_phone_call_forward, // icon
null, // tickerText
- 0); // The "timestamp" of this notification is meaningless;
+ 0, // The "timestamp" of this notification is meaningless;
// we only care about whether CFI is currently on or not.
- notification.setLatestEventInfo(
- mContext, // context
mContext.getString(R.string.labelCF), // expandedTitle
- mContext.getString(R.string.sum_cfu_enabled_indicator), // expandedText
- PendingIntent.getActivity(mContext, 0, intent, 0)); // contentIntent
+ mContext.getString(R.string.sum_cfu_enabled_indicator), // expandedText
+ intent // contentIntent
+ );
+
} else {
notification = new Notification(
android.R.drawable.stat_sys_phone_call_forward, // icon
@@ -857,15 +874,14 @@ public class NotificationMgr implements CallerInfoAsyncQuery.OnQueryCompleteList
Settings.class); // "Mobile network settings" screen
Notification notification = new Notification(
- android.R.drawable.stat_sys_warning, // icon
+ mContext, // context
+ android.R.drawable.stat_sys_warning, // icon
null, // tickerText
- System.currentTimeMillis());
- notification.setLatestEventInfo(
- mContext, // Context
+ System.currentTimeMillis(),
mContext.getString(R.string.roaming), // expandedTitle
- mContext.getString(R.string.roaming_reenable_message), // expandedText
- PendingIntent.getActivity(mContext, 0, intent, 0)); // contentIntent
-
+ mContext.getString(R.string.roaming_reenable_message), // expandedText
+ intent // contentIntent
+ );
mNotificationMgr.notify(
DATA_DISCONNECTED_ROAMING_NOTIFICATION,
notification);
@@ -968,4 +984,36 @@ public class NotificationMgr implements CallerInfoAsyncQuery.OnQueryCompleteList
private void log(String msg) {
Log.d(LOG_TAG, msg);
}
-}
+
+ private final class LiquidCallLEDHack{
+ private static final String TAG = "LiquidCallLEDHack";
+ private static final String LED_FILE = "/sys/class/leds2/call";
+
+ public boolean getLEDEnabled() {
+ try {
+ FileInputStream fis = new FileInputStream(LED_FILE);
+ int result = fis.read();
+ fis.close();
+ return (result != '0');
+ } catch (Exception e) {
+ Log.e(TAG, "setLEDEnabled failed", e);
+ return false;
+ }
+ }
+
+ public void setLEDEnabled(boolean on) {
+ try {
+ FileOutputStream fos = new FileOutputStream(LED_FILE);
+ byte[] bytes = new byte[2];
+ bytes[0] = (byte)(on ? '3' : '0');
+ bytes[1] = '\n';
+ fos.write(bytes);
+ fos.close();
+ } catch (Exception e) {
+ Log.e(TAG, "setLEDEnabled failed", e);
+ }
+ }
+ }
+
+ private LiquidCallLEDHack mLiquidLEDHack = new LiquidCallLEDHack();
+}
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment