[packages/apps/Settings] Revert "Setting: fix the SIM notification"

This reverts commit ccd9a42c78359b01f7ee6bf7ef6799041ab04947.
This commit is contained in:
Firefly
2015-08-05 09:27:02 +08:00
committed by djw
parent bb5e27954e
commit c0e9740e48
3 changed files with 56 additions and 36 deletions

View File

@ -2127,9 +2127,6 @@
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.ACTION_SUBINFO_RECORD_UPDATED" />
</intent-filter>
</receiver>
<provider

View File

@ -24,6 +24,8 @@ 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;
@ -31,37 +33,35 @@ import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener;
import com.android.internal.telephony.TelephonyIntents;
import com.android.settings.Utils;
import android.util.Log;
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 static final int NOTIFICATION_ID_SIM_DISABLED = 2;
private SharedPreferences mSharedPreferences = null;
private TelephonyManager mTelephonyManager;
private Context mContext;
private SubscriptionManager mSubscriptionManager;
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "onReceive " + intent);
String action = intent.getAction();
mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
mContext = context;
mSubscriptionManager = SubscriptionManager.from(mContext);
if(Intent.ACTION_BOOT_COMPLETED.equals(action)) {
mSubscriptionManager.addOnSubscriptionsChangedListener(mSubscriptionListener);
if(anySimDisabled()) {
createSimDisabledNotification(mContext);
}
} else if(TelephonyIntents.ACTION_SUBINFO_RECORD_UPDATED.equals(action)) {
detectChangeAndNotify();
mSharedPreferences = mContext.getSharedPreferences(SHARED_PREFERENCES_NAME,
Context.MODE_PRIVATE);
mSubscriptionManager.addOnSubscriptionsChangedListener(mSubscriptionListener);
if(anySimDisabled()) {
createSimDisabledNotification(mContext);
}
}
@ -105,26 +105,49 @@ public class SimBootReceiver extends BroadcastReceiver {
return;
}
// Create a notification to tell the user that some defaults are missing
createNotification(mContext);
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 (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, 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.DEFAULT_DATA_PICK);
mContext.startActivity(intent);
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) {
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);
}
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){
@ -161,7 +184,7 @@ public class SimBootReceiver extends BroadcastReceiver {
new OnSubscriptionsChangedListener() {
@Override
public void onSubscriptionsChanged() {
//detectChangeAndNotify();
detectChangeAndNotify();
}
};
private void createSimDisabledNotification(Context context) {

View File

@ -329,7 +329,7 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
// FIXME: b/18385348, needs to handle null from getActiveSubscriptionInfoList
if (DBG) log("[onResme] mSubInfoList=" + mSubInfoList);
//updateAvailableSubInfos();
updateAvailableSubInfos();
if (getActivity() != null) {
final IntentFilter filter = new IntentFilter(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
@ -340,7 +340,6 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
getActivity().registerReceiver(mReceiver, filter);
}
updatePreferences();
updateAllOptions();
}
@ -836,7 +835,8 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (DBG) log("receive action=" + action);
if (TelephonyIntents.ACTION_SUBINFO_RECORD_UPDATED.equals(action)
if (TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(action)
|| TelephonyIntents.ACTION_SUBINFO_RECORD_UPDATED.equals(action)
|| TelephonyIntents.ACTION_SUBINFO_CONTENT_CHANGE.equals(action)) {
mHandler.removeMessages(MESSAGE_UPDATE_VIEW);
mHandler.sendEmptyMessage(MESSAGE_UPDATE_VIEW);