[Settings] Fix unable to accessing Fi

1. Get subscription ID from intent
2. Application context for proxy SubscriptionManager (since this is singleton)

Bug: 144172733
Test: Manual
Change-Id: I2f49d55da3380adeb40e8ff9414057113cb4ac35
This commit is contained in:
Bonian Chen
2019-11-19 19:36:19 +08:00
parent 345dc2bf3a
commit 6317a112ea
3 changed files with 25 additions and 11 deletions

View File

@@ -24,6 +24,7 @@ import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
@@ -37,6 +38,8 @@ import java.util.List;
public abstract class ActiveSubsciptionsListener public abstract class ActiveSubsciptionsListener
extends SubscriptionManager.OnSubscriptionsChangedListener { extends SubscriptionManager.OnSubscriptionsChangedListener {
private static final String TAG = "ActiveSubsciptions";
/** /**
* Constructor * Constructor
* *
@@ -155,6 +158,18 @@ public abstract class ActiveSubsciptionsListener
} }
mIsCachedDataAvailable = mIsMonitoringDataChange; mIsCachedDataAvailable = mIsMonitoringDataChange;
mCachedActiveSubscriptionInfo = getSubscriptionManager().getActiveSubscriptionInfoList(); mCachedActiveSubscriptionInfo = getSubscriptionManager().getActiveSubscriptionInfoList();
if ((mCachedActiveSubscriptionInfo == null)
|| (mCachedActiveSubscriptionInfo.size() <= 0)) {
Log.d(TAG, "active subscriptions: " + mCachedActiveSubscriptionInfo);
} else {
final StringBuilder logString = new StringBuilder("active subscriptions:");
for (SubscriptionInfo subInfo : mCachedActiveSubscriptionInfo) {
logString.append(" " + subInfo.getSubscriptionId());
}
Log.d(TAG, logString.toString());
}
return mCachedActiveSubscriptionInfo; return mCachedActiveSubscriptionInfo;
} }
@@ -246,7 +261,10 @@ public abstract class ActiveSubsciptionsListener
} }
private boolean clearCachedSubId(int subId) { private boolean clearCachedSubId(int subId) {
if ((!mIsCachedDataAvailable) || (mCachedActiveSubscriptionInfo == null)) { if (!mIsCachedDataAvailable) {
return false;
}
if (mCachedActiveSubscriptionInfo == null) {
return false; return false;
} }
for (SubscriptionInfo subInfo : mCachedActiveSubscriptionInfo) { for (SubscriptionInfo subInfo : mCachedActiveSubscriptionInfo) {

View File

@@ -35,8 +35,7 @@ import java.util.List;
/** /**
* A proxy to the subscription manager * A proxy to the subscription manager
*/ */
public class ProxySubscriptionManager extends SubscriptionManager.OnSubscriptionsChangedListener public class ProxySubscriptionManager implements LifecycleObserver {
implements LifecycleObserver {
/** /**
* Interface for monitor active subscriptions list changing * Interface for monitor active subscriptions list changing
@@ -65,7 +64,7 @@ public class ProxySubscriptionManager extends SubscriptionManager.OnSubscription
if (sSingleton != null) { if (sSingleton != null) {
return sSingleton; return sSingleton;
} }
sSingleton = new ProxySubscriptionManager(context); sSingleton = new ProxySubscriptionManager(context.getApplicationContext());
return sSingleton; return sSingleton;
} }
@@ -110,12 +109,6 @@ public class ProxySubscriptionManager extends SubscriptionManager.OnSubscription
} }
} }
@Override
public void onSubscriptionsChanged() {
clearCache();
notifyAllListeners();
}
/** /**
* Lifecycle for data within proxy * Lifecycle for data within proxy
* *

View File

@@ -89,9 +89,12 @@ public class MobileNetworkActivity extends SettingsBaseActivity
mProxySubscriptionMgr.setLifecycle(getLifecycle()); mProxySubscriptionMgr.setLifecycle(getLifecycle());
mProxySubscriptionMgr.addActiveSubscriptionsListener(this); mProxySubscriptionMgr.addActiveSubscriptionsListener(this);
final Intent startIntent = getIntent();
mCurSubscriptionId = savedInstanceState != null mCurSubscriptionId = savedInstanceState != null
? savedInstanceState.getInt(Settings.EXTRA_SUB_ID, SUB_ID_NULL) ? savedInstanceState.getInt(Settings.EXTRA_SUB_ID, SUB_ID_NULL)
: SUB_ID_NULL; : ((startIntent != null)
? startIntent.getIntExtra(Settings.EXTRA_SUB_ID, SUB_ID_NULL)
: SUB_ID_NULL);
final SubscriptionInfo subscription = getSubscription(); final SubscriptionInfo subscription = getSubscription();
updateTitleAndNavigation(subscription); updateTitleAndNavigation(subscription);