OSDN Git Service

Update SubscriptionManager API as per API council.
authorWink Saville <wink@google.com>
Tue, 11 Nov 2014 16:37:56 +0000 (08:37 -0800)
committerWink Saville <wink@google.com>
Tue, 11 Nov 2014 16:37:56 +0000 (08:37 -0800)
bug: 17575308
Change-Id: Ib39a60e4f75981a466e9d606ec627756efad018d

src/com/android/bluetooth/hfp/HeadsetPhoneState.java

index a0b23c4..df52967 100644 (file)
@@ -20,6 +20,7 @@ import android.content.Context;
 import android.telephony.PhoneStateListener;
 import android.telephony.ServiceState;
 import android.telephony.SignalStrength;
+import android.telephony.SubscriptionListener;
 import android.telephony.TelephonyManager;
 import android.telephony.SubscriptionManager;
 import android.content.IntentFilter;
@@ -37,7 +38,7 @@ import android.bluetooth.BluetoothDevice;
 // All methods in this class are not thread safe, donot call them from
 // multiple threads. Call them from the HeadsetPhoneStateMachine message
 // handler only.
-class HeadsetPhoneState extends BroadcastReceiver{
+class HeadsetPhoneState {
     private static final String TAG = "HeadsetPhoneState";
 
     private HeadsetStateMachine mStateMachine;
@@ -78,36 +79,34 @@ class HeadsetPhoneState extends BroadcastReceiver{
 
     private PhoneStateListener mPhoneStateListener = null;
 
+    private final SubscriptionListener mSubscriptionListener = new SubscriptionListener() {
+        @Override
+        public void onSubscriptionInfoChanged() {
+            listenForPhoneState(false);
+            listenForPhoneState(true);
+        }
+    };
+
     HeadsetPhoneState(Context context, HeadsetStateMachine stateMachine) {
         mStateMachine = stateMachine;
         mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
-
-        IntentFilter filter = new IntentFilter();
-        filter.addAction(TelephonyIntents.ACTION_SUBINFO_RECORD_UPDATED);
-
         mContext = context;
-        mContext.registerReceiver(this, filter);
 
+        // Register for SubscriptionInfo list changes which is guaranteed
+        // to invoke onSubscriptionInfoChanged and which in turns calls
+        // loadInBackgroud.
+        SubscriptionManager.register(mContext, mSubscriptionListener,
+                SubscriptionListener.LISTEN_SUBSCRIPTION_INFO_LIST_CHANGED);
     }
 
     public void cleanup() {
-        mContext.unregisterReceiver(this);
         listenForPhoneState(false);
+        SubscriptionManager.unregister(mContext, mSubscriptionListener);
+
         mTelephonyManager = null;
         mStateMachine = null;
     }
 
-    @Override
-    public void onReceive(Context context, Intent intent) {
-        final String action = intent.getAction();
-        Log.d(TAG, "onReceive, intent action = " + action);
-
-        if (action.equals(TelephonyIntents.ACTION_SUBINFO_RECORD_UPDATED)) {
-            listenForPhoneState(false);
-            listenForPhoneState(true);
-        }
-    }
-
     void listenForPhoneState(boolean start) {
 
         mSlcReady = start;