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

Commit c3950397 authored by Jack Yu's avatar Jack Yu Committed by Android (Google) Code Review
Browse files

Merge "Cleanup vendor class files" into sc-dev

parents 571c82ca d7b2f59c
Loading
Loading
Loading
Loading
+0 −175
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony.vendor;

import android.content.Context;
import android.os.AsyncResult;
import android.os.Message;
import android.telephony.PhoneNumberUtils;
import android.telephony.Rlog;
import android.telephony.ServiceState;
import android.telephony.SubscriptionManager;

import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.GsmCdmaPhone;
import com.android.internal.telephony.PhoneNotifier;
import com.android.internal.telephony.TelephonyComponentFactory;

public class VendorGsmCdmaPhone extends GsmCdmaPhone {
    private static final String LOG_TAG = "VendorGsmCdmaPhone";
    private static final int PROP_EVENT_START = EVENT_LAST;
    private static final int DEFAULT_PHONE_INDEX = 0;

    private boolean mIsPhoneReadySent = false;
    private boolean mIsPhoneReadyPending = false;
    private static int READY = 1;

    public VendorGsmCdmaPhone(Context context,
            CommandsInterface ci, PhoneNotifier notifier, int phoneId,
            int precisePhoneType, TelephonyComponentFactory telephonyComponentFactory) {
        this(context, ci, notifier, false, phoneId, precisePhoneType,
                telephonyComponentFactory);
    }

    public VendorGsmCdmaPhone(Context context,
            CommandsInterface ci, PhoneNotifier notifier, boolean unitTestMode, int phoneId,
            int precisePhoneType, TelephonyComponentFactory telephonyComponentFactory) {
        super(context, ci, notifier, unitTestMode, phoneId, precisePhoneType,
                telephonyComponentFactory);
        Rlog.d(LOG_TAG, "Constructor");
    }

    @Override
    protected void phoneObjectUpdater(int newVoiceTech) {
        super.phoneObjectUpdater(newVoiceTech);
    }

    @Override
    public boolean getCallForwardingIndicator() {
        if (!isCurrentSubValid()) {
            return false;
        }
        return super.getCallForwardingIndicator();
    }

    private boolean isCurrentSubValid() {
        boolean isUiccApplicationEnabled = true;
        // FIXME get the SubscriptionManager.UICC_APPLICATIONS_ENABLED value and use it above

        SubscriptionManager subscriptionManager = SubscriptionManager.from(mContext);

        Rlog.d(LOG_TAG, "ProvisionStatus: " + isUiccApplicationEnabled + " phone id:" + mPhoneId);
        return subscriptionManager.isActiveSubscriptionId(getSubId()) && isUiccApplicationEnabled;
    }

    public void fetchIMEI() {
            Rlog.d(LOG_TAG, "fetching device id");
            mCi.getDeviceIdentity(obtainMessage(EVENT_GET_DEVICE_IDENTITY_DONE));
    }

    @Override
    public void handleMessage(Message msg) {
        Rlog.d(LOG_TAG, "handleMessage: Event: " + msg.what);
        AsyncResult ar;
        switch(msg.what) {

            case EVENT_SIM_RECORDS_LOADED:
                if(isPhoneTypeGsm()) {
                    Rlog.d(LOG_TAG, "notify call forward indication, phone id:" + mPhoneId);
                    notifyCallForwardingIndicator();
                }

                super.handleMessage(msg);
                break;

            case EVENT_RADIO_AVAILABLE:
                mIsPhoneReadySent = false;
                super.handleMessage(msg);
                break;

            case EVENT_RIL_CONNECTED:
                mIsPhoneReadySent = false;
                super.handleMessage(msg);
                break;

            default: {
                super.handleMessage(msg);
            }

        }
    }

    // In DSDA, char 'D' is used as DTMF char for playing supervisory tone for G/W.
    // For CDMA, '#' is used. A, B, C & D are also supported as DTMF digits for G/W networks.
    @Override
    public void startDtmf(char c) {
        if (!(PhoneNumberUtils.is12Key(c) || (c == 'D'))) {
            Rlog.e(LOG_TAG, "startDtmf called with invalid character '" + c + "'");
        } else {
            if (isPhoneTypeCdma() && c == 'D') {
                c = '#';
            }
            mCi.startDtmf(c, null);
        }
    }

    // For CDMA sendBurstDtmf is used, if dtmf char is 'D' then it with '#'
    // since 'D' is used for SCH tone and for CDMA it has to be '#'.
    @Override
    public void sendBurstDtmf(String dtmfString, int on, int off, Message onComplete) {
        Character c = dtmfString.charAt(0);
        if(dtmfString.length() == 1 && c == 'D') {
            dtmfString = c.toString();
        }
        super.sendBurstDtmf(dtmfString, on, off, onComplete);
    }

    // When OOS occurs, IMS registration may be still available so that IMS service
    // state is also in-service, then reports in-service to upper layer.
    // Add a precondition to merge IMS service so that notifies proper service state
    // after IMS changes RAT.
    @Override
    public ServiceState getServiceState() {
        if (mSST == null || mSST.mSS.getState() != ServiceState.STATE_IN_SERVICE) {
            // Ensure UE has IMS service capability, then merge IMS service state.
            // Video enabled includes WIFI video
            final boolean isImsEnabled = mImsPhone != null && (mImsPhone.isVolteEnabled()
                    || mImsPhone.isVideoEnabled()
                    || mImsPhone.isWifiCallingEnabled());
            if (isImsEnabled) {
                return ServiceState.mergeServiceStates(
                        ((mSST == null) ? new ServiceState() : mSST.mSS),
                        mImsPhone.getServiceState());
            }
        }

        if (mSST != null) {
            return mSST.mSS;
        } else {
            // avoid potential NPE in EmergencyCallHelper during Phone switch
            return new ServiceState();
        }
    }

    private void logd(String msg) {
        Rlog.d(LOG_TAG, "[" + mPhoneId +" ] " + msg);
    }

    private void loge(String msg) {
        Rlog.e(LOG_TAG, "[" + mPhoneId +" ] " + msg);
    }
}
+0 −113
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony.vendor;

import android.content.Context;
import android.provider.Settings;
import android.telephony.SubscriptionInfo;
import android.telephony.TelephonyManager;
import android.util.Log;

import com.android.internal.telephony.GlobalSettingsHelper;
import com.android.internal.telephony.MultiSimSettingController;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.SubscriptionController;

import java.util.List;

/*
 * Extending VendorMultiSimSettingController to override default
 * behavior for mobile data
 */
public class VendorMultiSimSettingController extends MultiSimSettingController {

    private static final String LOG_TAG = "VendorMultiSimSettingController";

    public static MultiSimSettingController init(Context context, SubscriptionController sc) {
        synchronized (VendorMultiSimSettingController.class) {
            if (sInstance == null) {
                sInstance = new VendorMultiSimSettingController(context,
                        SubscriptionController.getInstance());
            } else {
                Log.wtf(LOG_TAG, "init() called multiple times!  sInstance = " + sInstance);
            }
        }
        return sInstance;
    }

    private VendorMultiSimSettingController(Context context, SubscriptionController sc) {
        super(context, sc);
    }

    public static VendorMultiSimSettingController getInstance() {
        return (VendorMultiSimSettingController)sInstance;
    }

    @Override
    protected void disableDataForNonDefaultNonOpportunisticSubscriptions() {
        log("disableDataForNonDefaultNonOpportunisticSubscriptions - do nothing");
    }

    protected synchronized void onUserDataEnabled(int subId, boolean enable) {
        log("onUserDataEnabled");
        // Make sure MOBILE_DATA of subscriptions in same group are synced.
        setUserDataEnabledForGroup(subId, enable);
    }

    /**
     * Make sure MOBILE_DATA of subscriptions in the same group with the subId
     * are synced.
     */
    @Override
    protected synchronized void setUserDataEnabledForGroup(int subId, boolean enable) {
        log("setUserDataEnabledForGroup subId " + subId + " enable " + enable);
        List<SubscriptionInfo> infoList = mSubController.getSubscriptionsInGroup(
                mSubController.getGroupUuid(subId), mContext.getOpPackageName(),
                null);

        if (infoList == null) return;

        for (SubscriptionInfo info : infoList) {
            int currentSubId = info.getSubscriptionId();
            if (currentSubId == subId) continue;
            // TODO: simplify when setUserDataEnabled becomes singleton
            if (mSubController.isActiveSubId(currentSubId)) {
                // For active subscription, call setUserDataEnabled through DataEnabledSettings.
                Phone phone = PhoneFactory.getPhone(mSubController.getPhoneId(currentSubId));
                if (phone != null) {
                    phone.getDataEnabledSettings().setDataEnabled(
                            TelephonyManager.DATA_ENABLED_REASON_USER, enable);
                }
            } else {
                // For inactive subscription, directly write into global settings.
                GlobalSettingsHelper.setBoolean(
                        mContext, Settings.Global.MOBILE_DATA, currentSubId, enable);
            }
        }
   }

   @Override
   protected void updateDefaults() {
        log("updateDefaults");

   }

    protected void log(String msg) {
        Log.d(LOG_TAG, msg);
    }
}
+0 −645

File deleted.

Preview size limit exceeded, changes collapsed.

+0 −94
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony.vendor;

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.AsyncResult;
import android.os.Message;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.TelephonyManager;

import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.GsmCdmaPhone;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.ServiceStateTracker;

public class VendorServiceStateTracker extends ServiceStateTracker {
    private static final String LOG_TAG = "VendorServiceStateTracker";
    private static final boolean DBG = true;
    private static final boolean VDBG = false;  // STOPSHIP if true
    private static final String ACTION_MANAGED_ROAMING_IND =
            "android.intent.action.ACTION_MANAGED_ROAMING_IND";

    public VendorServiceStateTracker(GsmCdmaPhone phone, CommandsInterface ci) {
        super(phone,ci);
    }

    @Override
    protected void handlePollStateResultMessage(int what, AsyncResult ar) {
        switch (what) {
            case EVENT_POLL_STATE_CS_CELLULAR_REGISTRATION: {
                super.handlePollStateResultMessage(what, ar);
                if (mPhone.isPhoneTypeGsm()) {
                    NetworkRegistrationInfo regStates = (NetworkRegistrationInfo) ar.result;
                    int regState = regStates.getRegistrationState();

                    if (regState == NetworkRegistrationInfo.REGISTRATION_STATE_DENIED) {
                        int rejCode = regStates.getRejectCause();
                        // Check if rejCode is "Persistent location update reject",
                        if (rejCode == 10) {
                            log(" Posting Managed roaming intent sub = "
                                    + mPhone.getSubId());
                            try {
                                Intent intent =
                                        new Intent(ACTION_MANAGED_ROAMING_IND);
                                // component would display Dialog to perform Manual scan
                                // if current Network selection Mode is Manual.
                                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY,
                                        mPhone.getSubId());
                                mPhone.getContext().startActivity(intent);
                            } catch (ActivityNotFoundException e) {
                                loge("unable to start activity: " + e);
                            }
                        }
                    }
                }
                break;
            }

            default:
                super.handlePollStateResultMessage(what, ar);
        }
    }

    @Override
    public void handleMessage(Message msg) {
        if (msg.what == EVENT_RADIO_STATE_CHANGED) {
            if (mPhone.mCi.getRadioState() == TelephonyManager.RADIO_POWER_OFF) {
                setPowerStateToDesired();
                log("Trigger as manual polling");
                pollState();
            } else {
                super.handleMessage(msg);
            }
        } else {
            super.handleMessage(msg);
        }
    }
}
+0 −96
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony.vendor;

import android.Manifest;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncResult;
import android.os.Handler;
import android.os.Message;
import android.os.Registrant;
import android.os.RegistrantList;
import android.os.SystemProperties;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.telephony.Rlog;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.Log;

import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.SubscriptionController;
import com.android.internal.telephony.Phone;

import java.util.Iterator;
import java.util.List;

/*
 * Extending SubscriptionController here:
 * To implement fall back of sms/data user preferred subId value to next
 * available subId when current preferred SIM deactivated or removed.
 */
public class VendorSubscriptionController extends SubscriptionController {
    static final String LOG_TAG = "VendorSubscriptionController";
    private static final boolean DBG = true;
    private static final boolean VDBG = Rlog.isLoggable(LOG_TAG, Log.VERBOSE);

    private static int sNumPhones;

    private static final int PROVISIONED = 1;
    private static final int NOT_PROVISIONED = 0;

    private TelecomManager mTelecomManager;
    private TelephonyManager mTelephonyManager;

    private RegistrantList mAddSubscriptionRecordRegistrants = new RegistrantList();

    private static final String SETTING_USER_PREF_DATA_SUB = "user_preferred_data_sub";

    public static VendorSubscriptionController init(Context c) {
        synchronized (VendorSubscriptionController.class) {
            if (sInstance == null) {
                sInstance = new VendorSubscriptionController(c);
            } else {
                Log.wtf(LOG_TAG, "init() called multiple times!  sInstance = " + sInstance);
            }
            return (VendorSubscriptionController)sInstance;
        }
    }

    public static VendorSubscriptionController getInstance() {
        if (sInstance == null) {
           Log.wtf(LOG_TAG, "getInstance null");
        }

        return (VendorSubscriptionController)sInstance;
    }

    protected VendorSubscriptionController(Context c) {
        super(c);

        mTelecomManager = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
        mTelephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
        sNumPhones = TelephonyManager.getDefault().getPhoneCount();
    }

}
Loading