summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/com/android/settings/sim/SimBootReceiver.java103
1 files changed, 37 insertions, 66 deletions
diff --git a/src/com/android/settings/sim/SimBootReceiver.java b/src/com/android/settings/sim/SimBootReceiver.java
index 1564711..10f8f00 100644
--- a/src/com/android/settings/sim/SimBootReceiver.java
+++ b/src/com/android/settings/sim/SimBootReceiver.java
@@ -24,8 +24,6 @@ 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.provider.Settings;
import android.support.v4.app.NotificationCompat;
@@ -40,12 +38,8 @@ import java.util.List;
public class SimBootReceiver extends BroadcastReceiver {
private static final String TAG = "SimBootReceiver";
- 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;
private SubscriptionManager mSubscriptionManager;
@@ -55,9 +49,6 @@ public class SimBootReceiver extends BroadcastReceiver {
mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
mContext = context;
mSubscriptionManager = SubscriptionManager.from(mContext);
- mSharedPreferences = mContext.getSharedPreferences(SHARED_PREFERENCES_NAME,
- Context.MODE_PRIVATE);
-
mSubscriptionManager.addOnSubscriptionsChangedListener(mSubscriptionListener);
}
@@ -75,80 +66,60 @@ public class SimBootReceiver extends BroadcastReceiver {
return;
}
- for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
- if (TelephonyManager.getDefault().hasIccCard(i)) {
- numSIMsDetected++;
- }
+ // Cancel any previous notifications
+ cancelNotification(mContext);
+
+ // Clear defaults for any subscriptions which no longer exist
+ mSubscriptionManager.clearDefaultsForInactiveSubIds();
+
+ boolean dataSelected = SubscriptionManager.isUsableSubIdValue(
+ SubscriptionManager.getDefaultDataSubId());
+ boolean smsSelected = SubscriptionManager.isUsableSubIdValue(
+ SubscriptionManager.getDefaultSmsSubId());
+
+ // If data and sms defaults are selected, dont show notification (Calls default is optional)
+ if (dataSelected && smsSelected) {
+ 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
List<SubscriptionInfo> sil = mSubscriptionManager.getActiveSubscriptionInfoList();
// if numSIMsDetected is 2, sil.size may be 1 because of another subInfo hasn't been loaded yet,
// then we should wait all subInfo is loaded(sil.size() == numSIMsDetected), then we can clear the
// subinfo which no longer exist and show the notification if needed
if (sil == null || sil.size() < 1) {
return;
- } else if (sil.size() == numSIMsDetected) {
- // Cancel any previous notifications
- cancelNotification(mContext);
- // Clear defaults for any subscriptions which no longer exist
- mSubscriptionManager.clearDefaultsForInactiveSubIds();
- boolean dataSelected = SubscriptionManager.isUsableSubIdValue(
- SubscriptionManager.getDefaultDataSubId());
- boolean smsSelected = SubscriptionManager.isUsableSubIdValue(
- SubscriptionManager.getDefaultSmsSubId());
- // If data and sms defaults are selected, dont show notification (Calls default is optional)
- if (dataSelected && smsSelected) {
- return;
- }
-
- for (int i = 0; i < numSlots; i++) {
- final SubscriptionInfo sir = Utils.findRecordBySlotId(mContext, i);
- final String key = SLOT_PREFIX+i;
- final int lastSubId = getLastSubId(key);
-
- if (sir != null) {
- numSIMsDetected++;
- final int currentSubId = sir.getSubscriptionId();
- if (lastSubId != currentSubId) {
- createNotification(mContext);
- setLastSubId(key, currentSubId);
- notificationSent = true;
- }
- lastSIMSlotDetected = i;
- } else if (lastSubId != SLOT_EMPTY) {
- createNotification(mContext);
- setLastSubId(key, SLOT_EMPTY);
- notificationSent = true;
- }
- }
-
- if (notificationSent) {
- Intent intent = new Intent(mContext, SimDialogActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- if (numSIMsDetected == 1) {
+ } else {
+ // Create a notification to tell the user that some defaults are missing
+ createNotification(mContext);
+
+ if (sil.size() == 1) {
+ // If there is only one subscription, ask if user wants to use if for everything
+ Intent intent = new Intent(mContext, SimDialogActivity.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(SimDialogActivity.DIALOG_TYPE_KEY, SimDialogActivity.PREFERRED_PICK);
- intent.putExtra(SimDialogActivity.PREFERRED_SIM, lastSIMSlotDetected);
- } else {
- intent.putExtra(SimDialogActivity.DIALOG_TYPE_KEY, SimDialogActivity.DEFAULT_DATA_PICK);
+ intent.putExtra(SimDialogActivity.PREFERRED_SIM, sil.get(0).getSimSlotIndex());
+ mContext.startActivity(intent);
+ } else if (!dataSelected) {
+ // TODO(sanketpadawe): This should not be shown if the user is looking at the
+ // SimSettings page - its just annoying
+ // If there are mulitple, ensure they pick default data
+ Intent intent = new Intent(mContext, SimDialogActivity.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.putExtra(SimDialogActivity.DIALOG_TYPE_KEY, SimDialogActivity.DATA_PICK);
+ mContext.startActivity(intent);
}
- mContext.startActivity(intent);
}
- }
- }
-
- 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();
+ // TODO(sanketpadawe): This notification should not be dissmissable by the user
NotificationCompat.Builder builder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_sim_card_alert_white_48dp)