From 63f7bc87d8b5ec3c9fb6b48ecd4d66607aa1e7a4 Mon Sep 17 00:00:00 2001 From: PauloftheWest Date: Thu, 30 Oct 2014 08:01:30 -0700 Subject: [PATCH] Created Multi-SIM notifications. + On Multi-SIM devices a notificaiton will pop up when a SIM card is added, removed, or replaced. + The notification informs the user there has been a change in SIMs and they can tap the notification to go SIM Card Settings. Bug: 18293625 Change-Id: Iad1e5e0cf469e7bdfc43b2c18dd0586d042bb784 --- AndroidManifest.xml | 7 + .../ic_sim_card_alert_white_48dp.png | Bin 0 -> 412 bytes .../ic_sim_card_alert_white_48dp.png | Bin 0 -> 321 bytes .../ic_sim_card_alert_white_48dp.png | Bin 0 -> 516 bytes .../ic_sim_card_alert_white_48dp.png | Bin 0 -> 718 bytes .../ic_sim_card_alert_white_48dp.png | Bin 0 -> 931 bytes res/values/colors.xml | 2 + res/values/strings.xml | 4 + .../android/settings/sim/SimBootReceiver.java | 142 ++++++++++++++++++ src/com/android/settings/sim/SimSettings.java | 3 +- 10 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 res/drawable-hdpi/ic_sim_card_alert_white_48dp.png create mode 100644 res/drawable-mdpi/ic_sim_card_alert_white_48dp.png create mode 100644 res/drawable-xhdpi/ic_sim_card_alert_white_48dp.png create mode 100644 res/drawable-xxhdpi/ic_sim_card_alert_white_48dp.png create mode 100644 res/drawable-xxxhdpi/ic_sim_card_alert_white_48dp.png create mode 100644 src/com/android/settings/sim/SimBootReceiver.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index a800b4bcf71..99bb4837689 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -66,6 +66,7 @@ + @@ -1988,6 +1989,12 @@ + + + + + + I(3)EF2VS{N990fib~ zFff!FFfhDIU|_JC!N4G1FlSew4N!t9$=lt9;eUJonf*W>XMsm#F#`j)FbFd;%$g&? zz`!Wt>EalYaqsQTgT79I0<91KuZ`Qn>TR$?F@yJ*m_~!>Lgp6-B*c$xy_O)nLBWCh z0@I^s8kSbp78%d^{<=n166v!xa`EwJ(9m~xV{p~#XkKzP?K!xIY4JVqem6#Lw}HYpPv#o3GGfdbzZ z!Qz}RW?M}Zj(BkPg<8|HJKI@%EBsh^D|5M5&AjCK=uBnDnv?lI9_h7yKJqMO?f+jh xv)I1ueCic;O53i&{;O4e^FKv4$&$haw$Ep-XI$rZDI6GR44$rjF6*2UngFOnn6Ll< literal 0 HcmV?d00001 diff --git a/res/drawable-mdpi/ic_sim_card_alert_white_48dp.png b/res/drawable-mdpi/ic_sim_card_alert_white_48dp.png new file mode 100644 index 0000000000000000000000000000000000000000..18cd7f9c671dc02793c01f25d7854ae4fcd53909 GIT binary patch literal 321 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA0wn)(8}a}tg=CK)Uj~LMH3o);76yi2K%s^g z3=E|}g|8AA7_4S6Fo+k-*%fF5lweBoc6VX;-`;;_Kaj^+;1OBOz`!jG!i)^F=12eq zcY3-whD02Gd&7{A(NU!RV}7gTe~DWM4foQ`lO literal 0 HcmV?d00001 diff --git a/res/drawable-xhdpi/ic_sim_card_alert_white_48dp.png b/res/drawable-xhdpi/ic_sim_card_alert_white_48dp.png new file mode 100644 index 0000000000000000000000000000000000000000..6d983b726275ba2b23733b82cf8e55b8526c2209 GIT binary patch literal 516 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD0wg^q?%xcg6p}rHd>I(3)EF2VS{N990fib~ zFff!FFfhDIU|_JC!N4G1FlSew4N!t9$=lt9;eUJonf*W>XMsm#F#`j)FbFd;%$g&? zz`$7J>EaktaqI2vgT99iM2>yb7Y*9Q#=PYX!*RY#hA;RuTy+k0zG)B;dK9$L&EiSn z35IRL)^!K|Kb5PuzrFFPMyAjH-DXTc!xin_qJs-6&*J>etnI3N=LrgExjwB)GjZsj!)^#EQxunsCW5yaBWLe{+aCe{-zny z5-Oi%>SwvJns55_vHRT-zDN3uJ38#;AE^9`X_)=vGeh5_^Nc&X=JOSZ*^55VtCKpA z_(!DS^pB4W%ReSF<~=^nD094@aYvtgvD}R6gbc2`?dCvVBLfBhSkc{^4Z+U-u>N~v z%zL+)P9OybDjPIGK@9>cSbwaWl^?E& zV8!L+t^eLTeSBQUl=XGZZLW{;B^>&SvsX-guwZk})03YCgzcZ2ubJDo>+;rHkGP+^ n?wxmNvbyL2KOT_z^@1OmE%)-wJ*81J8N~N=^>bP0l+XkKXbj8L literal 0 HcmV?d00001 diff --git a/res/drawable-xxhdpi/ic_sim_card_alert_white_48dp.png b/res/drawable-xxhdpi/ic_sim_card_alert_white_48dp.png new file mode 100644 index 0000000000000000000000000000000000000000..6c8dd1fffa117d49651bad411aad094fde72e7cb GIT binary patch literal 718 zcmeAS@N?(olHy`uVBq!ia0vp^6F``Q1xWh(YZ(J6g=CK)Uj~LMH3o);76yi2K%s^g z3=E|P3=FRl7#OT(FffQ0%-I!a1C(G&@^*J&_}|`tWO>_%)r1c48n{Iv*t(u zRk(S&IEGZ*dVAMCYf7L<+sE{fEt`17X0dpm)jHy2KEWq>D(?}sNnYB5EZtMC9g-+v zWIL&sl$q$kks)q<{Nd&qhx}%o|9Q?<-R3>pyQjzh7Wp9jVJD$Z}Oayb0?&)FX4d4*A&8k5rJ&CmI~kSoB3-{CmlZ_$QZAI@}c z`!#1##DX%L&)sGDAGd1=tGd4nqg#AY@5a00s(<_(VUa$?9NQYM%WVJmC77PmykY$R|Enyy zr=M&Xqh{E9u6w@PGOj6VX8rfR7n^P7U+2uo{P!g2-I>=cTTJUG&3XEG&iSV-Tg>Y> zomsmxrYUNUy=UGz<^@-OPHwhj*kWD3>Hfd&g43VXXD{5Ie3c>h{Ct(}Y5I+K!;E+U-ExEvc*7ng_VYJW&srh^S*6;5PEC23a=-1#q0Ui-B?U&DgXP(0_ zT>&GeUBFt_Co*7 zr}XE>)Pz-$)e`JufylKUVdv|EJW4{Q1xP_MIu3wmsH;r};7K z`QN!GsDu}3n-@>`TXW-&>>;(~k9orIKf}&b7Z2xG S7XJVSHiM_DpUXO@geCx(F@C53 literal 0 HcmV?d00001 diff --git a/res/values/colors.xml b/res/values/colors.xml index 9e3161dc9fe..a5abbbe501c 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -72,4 +72,6 @@ #ff7fcac3 #ffe0e0e0 + @*android:color/material_deep_teal_500 + diff --git a/res/values/strings.xml b/res/values/strings.xml index f6f4d5af059..415c4c9f75a 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -5548,6 +5548,10 @@ Disabling Network Name Broadcast will prevent automatic connection to hidden networks. %1$d dBm %2$d asu + + SIM cards changed. + + Touch to set up Preferred SIM for diff --git a/src/com/android/settings/sim/SimBootReceiver.java b/src/com/android/settings/sim/SimBootReceiver.java new file mode 100644 index 00000000000..2d9d15e728e --- /dev/null +++ b/src/com/android/settings/sim/SimBootReceiver.java @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2014 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.settings.sim; + +import com.android.settings.R; +import com.android.settings.Settings.SimSettingsActivity; + +import java.util.List; + +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.SharedPreferences.Editor; +import android.content.res.Resources; +import android.support.v4.app.NotificationCompat; +import android.telephony.SubscriptionInfo; +import android.telephony.SubscriptionListener; +import android.telephony.SubscriptionManager; +import android.telephony.TelephonyManager; +import android.util.Log; + +import com.android.settings.Utils; + +public class SimBootReceiver extends BroadcastReceiver { + private static final int SLOT_EMPTY = -1; + private static final int NOTIFICATION_ID = 1; + private static final String SHARED_PREFERENCES_NAME = "sim_state"; + private static final String SLOT_PREFIX = "sim_slot_"; + + private SharedPreferences mSharedPreferences = null; + private TelephonyManager mTelephonyManager; + private Context mContext; + + @Override + public void onReceive(Context context, Intent intent) { + mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); + mContext = context; + mSharedPreferences = mContext.getSharedPreferences(SHARED_PREFERENCES_NAME, + Context.MODE_PRIVATE); + + SubscriptionManager.register(mContext, mSubscriptionListener, + SubscriptionListener.LISTEN_SUBSCRIPTION_INFO_LIST_CHANGED); + } + + private void detectChangeAndNotify() { + final int numSlots = mTelephonyManager.getSimCount(); + + // Do not create notifications on single SIM devices. + if (numSlots < 2) { + return; + } + + // We wait until SubscriptionManager returns a valid list of Subscription informations + // by checking if the list is empty. + // This is not completely correct, but works for most cases. + // See Bug: 18377252 + if (SubscriptionManager.getActiveSubscriptionInfoList().size() < 1) { + return; + } + + for (int i = 0; i < numSlots; i++) { + final SubscriptionInfo sir = Utils.findRecordBySlotId(i); + final String key = SLOT_PREFIX+i; + final int lastSubId = getLastSubId(key); + + if (sir != null) { + final int currentSubId = sir.getSubscriptionId(); + if (lastSubId != currentSubId) { + createNotification(mContext); + setLastSubId(key, currentSubId); + } + } else if (lastSubId != SLOT_EMPTY) { + createNotification(mContext); + setLastSubId(key, SLOT_EMPTY); + } + } + } + + private int getLastSubId(String strSlotId) { + return mSharedPreferences.getInt(strSlotId, SLOT_EMPTY); + } + + private void setLastSubId(String strSlotId, int value) { + Editor editor = mSharedPreferences.edit(); + editor.putInt(strSlotId, value); + editor.commit(); + } + + private void createNotification(Context context){ + final Resources resources = context.getResources(); + + NotificationCompat.Builder builder = + new NotificationCompat.Builder(context) + .setSmallIcon(R.drawable.ic_sim_card_alert_white_48dp) + .setColor(resources.getColor(R.color.sim_noitification)) + .setContentTitle(resources.getString(R.string.sim_notification_title)) + .setContentText(resources.getString(R.string.sim_notification_summary)); + Intent resultIntent = new Intent(context, SimSettingsActivity.class); + resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + PendingIntent resultPendingIntent = + PendingIntent.getActivity( + context, + 0, + resultIntent, + PendingIntent.FLAG_CANCEL_CURRENT + ); + builder.setContentIntent(resultPendingIntent); + NotificationManager notificationManager = + (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.notify(NOTIFICATION_ID, builder.build()); + } + + public static void cancelNotification(Context context) { + NotificationManager notificationManager = + (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.cancel(NOTIFICATION_ID); + } + + private final SubscriptionListener mSubscriptionListener = new SubscriptionListener() { + @Override + public void onSubscriptionInfoChanged() { + detectChangeAndNotify(); + } + }; +} diff --git a/src/com/android/settings/sim/SimSettings.java b/src/com/android/settings/sim/SimSettings.java index 6de0cc10f2a..273d64c1d1f 100644 --- a/src/com/android/settings/sim/SimSettings.java +++ b/src/com/android/settings/sim/SimSettings.java @@ -131,6 +131,8 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable createPreferences(); updateAllOptions(); + + SimBootReceiver.cancelNotification(getActivity()); } private void createPreferences() { @@ -583,5 +585,4 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable return result; } }; - }