Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit afdc9841 authored by kaiyiz's avatar kaiyiz
Browse files

SystemUI: Enhancement for DDS switch on quick setting panel

1. Start an AsyncTask to set default data subscription to avoid ANR while
switching DDS in status bar continuously.
2. Make the DDS switch button grayed out while changing subscription.
3. Hide APN switch button if DDS is set to non default subscription.

CRs-Fixed: 677798

Change-Id: I36de2fa45921fb123ab24d94696fba3fe4d48656
parent 4646b94d
Loading
Loading
Loading
Loading
+56 −9
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri;
import android.net.ConnectivityManager;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.SystemProperties;
import android.provider.Settings;
@@ -353,11 +354,14 @@ class ExtQuickSettingsModel extends QuickSettingsModel {

        public void startObserving() {
            final ContentResolver cr = mContext.getContentResolver();
            cr.registerContentObserver(Telephony.Carriers.CONTENT_URI, true, this);;
            cr.registerContentObserver(Telephony.Carriers.CONTENT_URI, true, this);
            cr.registerContentObserver(Settings.Global.getUriFor(
                    Settings.Global.MULTI_SIM_DEFAULT_DATA_CALL_SUBSCRIPTION),
                    false, this, mUserTracker.getCurrentUserId());
        }
    };

    private final ApnObserver mApnObserver;
    private ApnObserver mApnObserver;
    private QuickSettingsTileView mApnTile;
    private RefreshCallback mApnCallback;
    private ApnState mApnState = new ApnState();
@@ -453,10 +457,10 @@ class ExtQuickSettingsModel extends QuickSettingsModel {
    public ExtQuickSettingsModel(Context context) {
        super(context);
        mContext = context;
        mApnObserver = new ApnObserver(mHandler);

        // APN switcher
        if (mContext.getResources().getBoolean(R.bool.config_showApnSwitch)) {
            mApnObserver = new ApnObserver(mHandler);
            mApnObserver.startObserving();
            // Register the receiver to handle the sim state changed event.
            // And caused by if we open the airplane mode, we couldn't receive the sim state
@@ -576,6 +580,19 @@ class ExtQuickSettingsModel extends QuickSettingsModel {
        refreshApnTile();
    }
    void refreshApnTile() {
        int dataSub = MSimConstants.DEFAULT_SUBSCRIPTION;
        if (MSimTelephonyManager.getDefault().isMultiSimEnabled()) {
            MSimTelephonyManager msimTM = (MSimTelephonyManager)
                    mContext.getSystemService(Context.MSIM_TELEPHONY_SERVICE);
            dataSub = msimTM.getDefaultDataSubscription();
        }
        // Hide APN switch button if DDS is set to non default subscription
        if (dataSub != MSimConstants.DEFAULT_SUBSCRIPTION) {
            mApnState.enabled = false;
        } else {
            mApnState.enabled = hasIccCard() && !isAirplaneModeOn();
        }

        if (mApnTile != null && mApnCallback != null) {
            Resources res = mContext.getResources();
            if (mApnState.enabled) {
@@ -657,6 +674,7 @@ class ExtQuickSettingsModel extends QuickSettingsModel {
    private QuickSettingsTileView mDdsTile;
    private RefreshCallback mDdsCallback;
    private State mDdsState = new State();
    private AsyncTask switchDdsAsyncTask = null;
    protected void addDdsTile(QuickSettingsTileView view, RefreshCallback cb) {
        mDdsTile = view;
        mDdsCallback = cb;
@@ -683,13 +701,42 @@ class ExtQuickSettingsModel extends QuickSettingsModel {

    void switchDdsToNext() {
        Log.d(DDS_TAG, "switchDdsToNext");
        if (MSimTelephonyManager.getDefault().isMultiSimEnabled()) {
        if (!MSimTelephonyManager.getDefault().isMultiSimEnabled()) {
            return;
        }
        if (switchDdsAsyncTask != null &&
                switchDdsAsyncTask.getStatus() != AsyncTask.Status.FINISHED) {
            Log.d(DDS_TAG, "Dds switch in progress!");
            return;
        }
        switchDdsAsyncTask = new AsyncTask<Void, Void, Void>() {
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                // Make DDS switch grayed out and while changing subscription
                if (mDdsTile != null) {
                    mDdsTile.setAlpha(0.5f);
                    mDdsTile.setEnabled(false);
                }
            }
            @Override
            protected Void doInBackground(Void... params) {
                MSimTelephonyManager msimTM = (MSimTelephonyManager)
                        mContext.getSystemService(Context.MSIM_TELEPHONY_SERVICE);
                int dataSub = msimTM.getDefaultDataSubscription();
                int phoneCount = msimTM.getPhoneCount();
                msimTM.setDefaultDataSubscription((dataSub+1)%phoneCount);
                return null;
            }
            @Override
            protected void onPostExecute(Void result) {
                super.onPostExecute(result);
                if (mDdsTile != null) {
                    mDdsTile.setAlpha(1f);
                    mDdsTile.setEnabled(true);
                }
            }
        }.execute();
    }

    private void updateDds() {