About how to set the default number of sms center number center, a huge question mark, solve!

Posted by bazza84 on Sun, 12 Jul 2020 18:24:47 +0200

For beginners, android 4.4 doesn't know how the default number for SMS centers is set, but now it's a rule to write a short summary of what you see every day, so let's just tell it!


First I found a place to set the SMS center number on the display of the control:

Filename: SimSettingPreferenceActivity.java

    @Override
    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        mPhoneId = this.getIntent().getIntExtra(Phone.PHONE_ID, TelephonyManager.getDefaultPhoneId());
        mTelephonyManager = MmsApp.getApplication().getTelephonyManager(mPhoneId);
        if (MessageUtils.OS_DEBUG) {
        Log.d(TAG, "onCreate() -->> Start activity for phoneId = " + mPhoneId);
        }
        addPreferencesFromResource(R.xml.setting_sim_preferences);
        createResource();
        ActionBar actionBar = getActionBar();
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE
                | ActionBar.DISPLAY_HOME_AS_UP);
        setMessagePreferences();
        //modify for Bug 620828 begin
        mSoftKeyPanel=new SoftKeyPanel(this);
        mSoftKeyPanel.setCaption(null,getString(R.string.menu_select), getString(R.string.menu_back));
        //modify for Bug 620828 end
    private void createResource() {
        mManageSimPref = findPreference("pref_key_manage_sim_messages");
        mSmsDeliveryReportPref = (CheckBoxPreference) findPreference("pref_key_sms_delivery_reports");
        mStoreSmsOnSim = (CheckBoxPreference) findPreference("pref_key_store_sms_on_sim");
        mMmsDeliveryReportPref = (CheckBoxPreference)findPreference("pref_key_mms_delivery_reports");
        mMmsReadReportPref = (CheckBoxPreference)findPreference("pref_key_mms_read_reports");
        mSmscPref = findPreference("pref_key_sim_smsc");
        mMmsAutoCheckPref = (CheckBoxPreference)findPreference("pref_key_mms_auto_retrieval");
        mMmsDuringPref = (CheckBoxPreference)findPreference("pref_key_mms_retrieval_during_roaming");
        mMmsValidityPref = (ListPreference)findPreference("pref_key_mms_validity_input_sim");
        mMmsValidityPref.setOnPreferenceChangeListener(this);
        mSmsValidityPref = (ListPreference)findPreference("pref_key_sms_validity");
        mSmsValidityPref.setOnPreferenceChangeListener(this);

        mMmsPriorityPref = (ListPreference)findPreference("pref_key_mms_priority");
        mMmsPriorityPref.setOnPreferenceChangeListener(this);
    }
 private void setMessagePreferences() {
..........................
        if (isMultiSim && isValidPhoneId(mPhoneId)) {
            mSmscPref.setTitle(getString(R.string.pref_title_manage_simx_smsc, mPhoneId+1));
            mSmscPref.setSummary(getSmscString(mPhoneId));

        } else {
            mSmscPref.setSummary(getSmscString(-1));
        }

.......................
}

    private String getSmscString(int phoneId) {
        String smscStr = "";
        // SPRD: Modify for bug261680 @{
        TelephonyManager telephonyManager;
        if (phoneId == -1) {
            telephonyManager = MmsApp.getApplication().getTelephonyManager();
        } else {
            telephonyManager = MmsApp.getApplication().getTelephonyManager(phoneId);
        }
        if (!mSupportOrange) {
            smscStr = telephonyManager.getSmsc();  //SMS Center Number Default Access
            if ((smscStr == null || smscStr.equals("") || smscStr.equals("refresh error"))
                    && isCMCCSim(phoneId)) {
                smscStr = CMCC_DEFAULT_SMSC;
            }
        }else{
            SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(SimSettingPreferenceActivity.this);
            if (TelephonyManager.isMultiSim()) {
                smscStr = sharedPreferences.getString(
                        SimSettingPreferenceActivity.SMS_CENTER_ACTIVATED_STR_SIMX[phoneId], "");
            } else {
                smscStr = sharedPreferences.getString(
                                SimSettingPreferenceActivity.SMS_CENTER_ACTIVATED_STR, "");
            }
        }
        // @}

        return smscStr;
    }

stay TelephonyManager.java Medium:

    public String getSmsc() {
        try {
            return getISprdTelephony().getSmsc(); //The getISprdTelephone method returns aISprdTelephony.aidlService, implementationGetISprdTelephony.aidlThe class of is: SprdPhoneInterfaceManger.java
        } catch (RemoteException ex) {
            return null;
        } catch (NullPointerException ex) {
            return null;
        }
    }

In spdPHoneInterfaceManager.javaTo really get Smsc:

    public String getSmsc() {
        enforceModifyPermission();
        final GetSetSMSC getSMSC = new GetSetSMSC(mPhone, null);
        getSMSC.start();
        return getSMSC.getSmsc();
    }

    public boolean setSmsc(String smscAddr) {
        enforceModifyPermission();
        final GetSetSMSC getSMSC = new GetSetSMSC(mPhone, smscAddr);
        getSMSC.start();
        return getSMSC.setSmsc();
    }

    private static class GetSetSMSC extends Thread {

        private final Phone mPhone;
        private final String mSmscStr;
        private boolean mDone = false;
        private String mResult;
        private boolean bResult = false;

        private Handler mHandler;

        // For async handler to identify request type
        private static final int QUERY_SMSC_DONE = 100;
        private static final int UPDATE_SMSC_DONE = 101;

        public GetSetSMSC(Phone phone, String SmscStr) {
            mPhone = phone;
            mSmscStr = SmscStr;
        }

        @Override
        public void run() {
            Looper.prepare();
            synchronized (GetSetSMSC.this) {
                mHandler = new Handler() {
                    @Override
                    public void handleMessage(Message msg) {
                        AsyncResult ar = (AsyncResult) msg.obj;
                        switch (msg.what) {
                            case QUERY_SMSC_DONE:
                                Log.d(LOG_TAG, "[smsc]QUERY_SMSC_DONE");
                                synchronized (GetSetSMSC.this) {
                                    if (ar.exception == null) {
                                        mResult = (String)ar.result;
                                    } else {
                                        mResult = "refresh error";
                                    }
                                    mDone = true;
                                    GetSetSMSC.this.notifyAll();
                                }
                                getLooper().quit();
                                break;
                            case UPDATE_SMSC_DONE:
                                Log.d(LOG_TAG, "[smsc]UPDATE_SMSC_DONE");
                                synchronized (GetSetSMSC.this) {
                                    bResult = (ar.exception == null);
                                    mDone = true;
                                    GetSetSMSC.this.notifyAll();
                                }
                                getLooper().quit();
                                break;
                        }
                    }
                };
                GetSetSMSC.this.notifyAll();
            }
            Looper.loop();
        }

        synchronized String getSmsc() {

            while (mHandler == null) {
                try {
                    wait();
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
            }

            mPhone.getSmscAddress(mHandler.obtainMessage(QUERY_SMSC_DONE));

            while (!mDone) {
                try {
                    Log.d(LOG_TAG, "[smsc]wait get for done");
                    wait();
                } catch (InterruptedException e) {
                    // Restore the interrupted status
                    Thread.currentThread().interrupt();
                }
            }
            Log.d(LOG_TAG, "[smsc]get done");
            return mResult;
        }

        synchronized boolean setSmsc() {

            while (mHandler == null) {
                try {
                    wait();
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
            }

            mPhone.setSmscAddress(mSmscStr, mHandler.obtainMessage(UPDATE_SMSC_DONE));

            while (!mDone) {
                try {
                    Log.d(LOG_TAG, "[smsc]wait set for done");
                    wait();
                } catch (InterruptedException e) {
                    // Restore the interrupted status
                    Thread.currentThread().interrupt();
                }
            }
            Log.d(LOG_TAG, "[smsc]set done. result = "+bResult);
            return bResult;
        }
    }

When I finally get here, I don't have any idea. My idea is that setSmsAddress() will be set by default and UPDATE_will be notified at the end when the startup is initialized.SMSC_DONE,

Last sent to RIL. Last sent to getSmscAddress in getSmsc().MHandler.obtainMessage(QUERY_SMSC_DONE) to get an mResult of String type.

However, the code global search setSmscAddress did not find relevant and important settings, which were automatically retrieved from the SIM card???Or is my idea wrong?

Topics: Java Android xml