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

Commit 235e00fe authored by Chen Xu's avatar Chen Xu Committed by Hall Liu
Browse files

non-mainline telephony related AIDL refactor/decoupling

1. decouple IOnSubscriptionChangedListener AIDL from telephonyMainline

2. other refactor. moving APIs which will not be included in
telephony mainline to frameworks/base/core/java/android/telephony.
Moving internal classes like AIDL which will not be included in
telephony mainline to
framework/base/core/java/com/android/internal/telephony

3. remove subscriptionMonitor which can be easily replaced with
SubscriptionManager.addOnSubscriptionChangedListener API

Bug: 140908357
Test: Build & unit test
Change-Id: I89c77ae7f006437e954af0d42491217a9f24b64d
Merged-In: I89c77ae7f006437e954af0d42491217a9f24b64d
parent 52fcae96
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -24,7 +24,7 @@ import android.net.NetworkCapabilities;
import android.os.Bundle;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManager;
import android.os.telephony.TelephonyRegistryManager;
import android.telephony.TelephonyRegistryManager;
import android.telephony.Annotation.DataFailureCause;
import android.telephony.Annotation.DataFailureCause;
import android.telephony.Annotation.RadioPowerState;
import android.telephony.Annotation.RadioPowerState;
import android.telephony.Annotation.SrvccState;
import android.telephony.Annotation.SrvccState;
+1 −14
Original line number Original line Diff line number Diff line
@@ -87,7 +87,6 @@ public class PhoneFactory {
    static private Context sContext;
    static private Context sContext;
    static private PhoneConfigurationManager sPhoneConfigurationManager;
    static private PhoneConfigurationManager sPhoneConfigurationManager;
    static private PhoneSwitcher sPhoneSwitcher;
    static private PhoneSwitcher sPhoneSwitcher;
    static private SubscriptionMonitor sSubscriptionMonitor;
    static private TelephonyNetworkFactory[] sTelephonyNetworkFactories;
    static private TelephonyNetworkFactory[] sTelephonyNetworkFactories;
    static private ImsResolver sImsResolver;
    static private ImsResolver sImsResolver;
    static private NotificationChannelController sNotificationChannelController;
    static private NotificationChannelController sNotificationChannelController;
@@ -250,8 +249,6 @@ public class PhoneFactory {
                ITelephonyRegistry tr = ITelephonyRegistry.Stub.asInterface(
                ITelephonyRegistry tr = ITelephonyRegistry.Stub.asInterface(
                        ServiceManager.getService("telephony.registry"));
                        ServiceManager.getService("telephony.registry"));


                sSubscriptionMonitor = new SubscriptionMonitor(tr, sContext, sc, numPhones);

                sPhoneConfigurationManager = PhoneConfigurationManager.init(sContext);
                sPhoneConfigurationManager = PhoneConfigurationManager.init(sContext);


                sCellularNetworkValidator = CellularNetworkValidator.make(sContext);
                sCellularNetworkValidator = CellularNetworkValidator.make(sContext);
@@ -271,7 +268,7 @@ public class PhoneFactory {


                for (int i = 0; i < numPhones; i++) {
                for (int i = 0; i < numPhones; i++) {
                    sTelephonyNetworkFactories[i] = new TelephonyNetworkFactory(
                    sTelephonyNetworkFactories[i] = new TelephonyNetworkFactory(
                            sSubscriptionMonitor, Looper.myLooper(), sPhones[i]);
                            Looper.myLooper(), sPhones[i]);
                }
                }
            }
            }
        }
        }
@@ -538,16 +535,6 @@ public class PhoneFactory {
        pw.decreaseIndent();
        pw.decreaseIndent();
        pw.println("++++++++++++++++++++++++++++++++");
        pw.println("++++++++++++++++++++++++++++++++");


        pw.println("SubscriptionMonitor:");
        pw.increaseIndent();
        try {
            sSubscriptionMonitor.dump(fd, pw, args);
        } catch (Exception e) {
            e.printStackTrace();
        }
        pw.decreaseIndent();
        pw.println("++++++++++++++++++++++++++++++++");

        pw.println("UiccController:");
        pw.println("UiccController:");
        pw.increaseIndent();
        pw.increaseIndent();
        try {
        try {
+14 −17
Original line number Original line Diff line number Diff line
@@ -53,6 +53,7 @@ import android.telephony.PhoneStateListener;
import android.telephony.Rlog;
import android.telephony.Rlog;
import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyRegistryManager;
import android.telephony.data.ApnSetting;
import android.telephony.data.ApnSetting;
import android.util.LocalLog;
import android.util.LocalLog;


@@ -64,6 +65,7 @@ import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.DataSwi
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.OnDemandDataSwitch;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyEvent.OnDemandDataSwitch;
import com.android.internal.util.IndentingPrintWriter;
import com.android.internal.util.IndentingPrintWriter;



import java.io.FileDescriptor;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.ArrayList;
@@ -293,7 +295,7 @@ public class PhoneSwitcher extends Handler {
            CommandsInterface[] cis, Phone[] phones) {
            CommandsInterface[] cis, Phone[] phones) {
        if (sPhoneSwitcher == null) {
        if (sPhoneSwitcher == null) {
            sPhoneSwitcher = new PhoneSwitcher(maxActivePhones, numPhones, context,
            sPhoneSwitcher = new PhoneSwitcher(maxActivePhones, numPhones, context,
                    subscriptionController, looper, tr, cis, phones);
                    subscriptionController, looper, cis, phones);
        }
        }


        return sPhoneSwitcher;
        return sPhoneSwitcher;
@@ -346,7 +348,7 @@ public class PhoneSwitcher extends Handler {


    @VisibleForTesting
    @VisibleForTesting
    public PhoneSwitcher(int maxActivePhones, int numPhones, Context context,
    public PhoneSwitcher(int maxActivePhones, int numPhones, Context context,
            SubscriptionController subscriptionController, Looper looper, ITelephonyRegistry tr,
            SubscriptionController subscriptionController, Looper looper,
            CommandsInterface[] cis, Phone[] phones) {
            CommandsInterface[] cis, Phone[] phones) {
        super(looper);
        super(looper);
        mContext = context;
        mContext = context;
@@ -392,11 +394,10 @@ public class PhoneSwitcher extends Handler {
            mCommandsInterfaces[0].registerForAvailable(this, EVENT_RADIO_AVAILABLE, null);
            mCommandsInterfaces[0].registerForAvailable(this, EVENT_RADIO_AVAILABLE, null);
        }
        }


        try {
        TelephonyRegistryManager telephonyRegistryManager = (TelephonyRegistryManager)
            tr.addOnSubscriptionsChangedListener(context.getOpPackageName(),
                context.getSystemService(Context.TELEPHONY_REGISTRY_SERVICE);
                    mSubscriptionsChangedListener);
        telephonyRegistryManager.addOnSubscriptionsChangedListener(
        } catch (RemoteException e) {
                mSubscriptionsChangedListener, mSubscriptionsChangedListener.getHandlerExecutor());
        }


        mConnectivityManager =
        mConnectivityManager =
            (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
@@ -438,8 +439,8 @@ public class PhoneSwitcher extends Handler {
        }
        }
    };
    };


    private final IOnSubscriptionsChangedListener mSubscriptionsChangedListener =
    private final SubscriptionManager.OnSubscriptionsChangedListener mSubscriptionsChangedListener =
            new IOnSubscriptionsChangedListener.Stub() {
            new SubscriptionManager.OnSubscriptionsChangedListener() {
        @Override
        @Override
        public void onSubscriptionsChanged() {
        public void onSubscriptionsChanged() {
            Message msg = PhoneSwitcher.this.obtainMessage(EVENT_SUBSCRIPTION_CHANGED);
            Message msg = PhoneSwitcher.this.obtainMessage(EVENT_SUBSCRIPTION_CHANGED);
@@ -1301,14 +1302,10 @@ public class PhoneSwitcher extends Handler {
     * See {@link PhoneStateListener#LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE}.
     * See {@link PhoneStateListener#LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE}.
     */
     */
    private void notifyPreferredDataSubIdChanged() {
    private void notifyPreferredDataSubIdChanged() {
        ITelephonyRegistry tr = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService(
        TelephonyRegistryManager telephonyRegistryManager = (TelephonyRegistryManager) mContext
                "telephony.registry"));
                .getSystemService(Context.TELEPHONY_REGISTRY_SERVICE);
        try {
        log("notifyPreferredDataSubIdChanged to " + mPreferredDataSubId);
        log("notifyPreferredDataSubIdChanged to " + mPreferredDataSubId);
            tr.notifyActiveDataSubIdChanged(mPreferredDataSubId);
        telephonyRegistryManager.notifyActiveDataSubIdChanged(mPreferredDataSubId);
        } catch (RemoteException ex) {
            // Should never happen because its always available.
        }
    }
    }


    /**
    /**
+0 −133
Original line number Original line Diff line number Diff line
/*
* Copyright (C) 2015 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;

import android.content.Context;
import android.os.Handler;
import android.os.Registrant;
import android.os.RegistrantList;
import android.os.RemoteException;
import android.telephony.Rlog;
import android.util.LocalLog;

import com.android.internal.annotations.VisibleForTesting;

import java.io.FileDescriptor;
import java.io.PrintWriter;

/**
 * Utility singleton to monitor subscription changes and help people act on them.
 * Uses Registrant model to post messages to handlers.
 *
 */
public class SubscriptionMonitor {

    private final RegistrantList mSubscriptionsChangedRegistrants[];

    private final SubscriptionController mSubscriptionController;
    private final Context mContext;

    private final int mPhoneSubId[];

    private final Object mLock = new Object();

    private final static boolean VDBG = true;
    private final static String LOG_TAG = "SubscriptionMonitor";

    private final static int MAX_LOGLINES = 100;
    private final LocalLog mLocalLog = new LocalLog(MAX_LOGLINES);

    public SubscriptionMonitor(ITelephonyRegistry tr, Context context,
            SubscriptionController subscriptionController, int numPhones) {
        mSubscriptionController = subscriptionController;
        mContext = context;

        mSubscriptionsChangedRegistrants = new RegistrantList[numPhones];
        mPhoneSubId = new int[numPhones];

        for (int phoneId = 0; phoneId < numPhones; phoneId++) {
            mSubscriptionsChangedRegistrants[phoneId] = new RegistrantList();
            mPhoneSubId[phoneId] = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
        }

        try {
            tr.addOnSubscriptionsChangedListener(context.getOpPackageName(),
                    mSubscriptionsChangedListener);
        } catch (RemoteException e) {
        }
    }

    @VisibleForTesting
    public SubscriptionMonitor() {
        mSubscriptionsChangedRegistrants = null;
        mSubscriptionController = null;
        mContext = null;
        mPhoneSubId = null;
    }

    private final IOnSubscriptionsChangedListener mSubscriptionsChangedListener =
            new IOnSubscriptionsChangedListener.Stub() {
        @Override
        public void onSubscriptionsChanged() {
            synchronized (mLock) {
                for (int phoneId = 0; phoneId < mPhoneSubId.length; phoneId++) {
                    final int newSubId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
                    final int oldSubId = mPhoneSubId[phoneId];
                    if (oldSubId != newSubId) {
                        log("Phone[" + phoneId + "] subId changed " + oldSubId + "->" + newSubId
                                + ", " + mSubscriptionsChangedRegistrants[phoneId].size()
                                + " registrants");
                        mPhoneSubId[phoneId] = newSubId;
                        mSubscriptionsChangedRegistrants[phoneId].notifyRegistrants();
                    }
                }
            }
        }
    };

    public void registerForSubscriptionChanged(int phoneId, Handler h, int what, Object o) {
        if (invalidPhoneId(phoneId)) {
            throw new IllegalArgumentException("Invalid PhoneId");
        }
        Registrant r = new Registrant(h, what, o);
        mSubscriptionsChangedRegistrants[phoneId].add(r);
        r.notifyRegistrant();
    }

    public void unregisterForSubscriptionChanged(int phoneId, Handler h) {
        if (invalidPhoneId(phoneId)) {
            throw new IllegalArgumentException("Invalid PhoneId");
        }
        mSubscriptionsChangedRegistrants[phoneId].remove(h);
    }

    private boolean invalidPhoneId(int phoneId) {
        if (phoneId >= 0 && phoneId < mPhoneSubId.length) return false;
        return true;
    }

    private void log(String s) {
        Rlog.d(LOG_TAG, s);
        mLocalLog.log(s);
    }

    public void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
        synchronized (mLock) {
            mLocalLog.dump(fd, printWriter, args);
        }
    }
}
+18 −9
Original line number Original line Diff line number Diff line
@@ -30,13 +30,15 @@ import android.os.Message;
import android.telephony.AccessNetworkConstants;
import android.telephony.AccessNetworkConstants;
import android.telephony.Annotation.ApnType;
import android.telephony.Annotation.ApnType;
import android.telephony.Rlog;
import android.telephony.Rlog;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.data.ApnSetting;
import android.telephony.data.ApnSetting;
import android.util.LocalLog;
import android.util.LocalLog;


import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneSwitcher;
import com.android.internal.telephony.PhoneSwitcher;
import com.android.internal.telephony.SubscriptionController;
import com.android.internal.telephony.SubscriptionController;
import com.android.internal.telephony.SubscriptionMonitor;
import com.android.internal.telephony.dataconnection.DcTracker.ReleaseNetworkType;
import com.android.internal.telephony.dataconnection.DcTracker.ReleaseNetworkType;
import com.android.internal.telephony.dataconnection.DcTracker.RequestNetworkType;
import com.android.internal.telephony.dataconnection.DcTracker.RequestNetworkType;
import com.android.internal.telephony.dataconnection.TransportManager.HandoverParams;
import com.android.internal.telephony.dataconnection.TransportManager.HandoverParams;
@@ -60,7 +62,8 @@ public class TelephonyNetworkFactory extends NetworkFactory {
    private static final int TELEPHONY_NETWORK_SCORE = 50;
    private static final int TELEPHONY_NETWORK_SCORE = 50;


    private static final int EVENT_ACTIVE_PHONE_SWITCH              = 1;
    private static final int EVENT_ACTIVE_PHONE_SWITCH              = 1;
    private static final int EVENT_SUBSCRIPTION_CHANGED             = 2;
    @VisibleForTesting
    public static final int EVENT_SUBSCRIPTION_CHANGED              = 2;
    private static final int EVENT_NETWORK_REQUEST                  = 3;
    private static final int EVENT_NETWORK_REQUEST                  = 3;
    private static final int EVENT_NETWORK_RELEASE                  = 4;
    private static final int EVENT_NETWORK_RELEASE                  = 4;
    private static final int EVENT_DATA_HANDOVER_NEEDED             = 5;
    private static final int EVENT_DATA_HANDOVER_NEEDED             = 5;
@@ -68,7 +71,6 @@ public class TelephonyNetworkFactory extends NetworkFactory {


    private final PhoneSwitcher mPhoneSwitcher;
    private final PhoneSwitcher mPhoneSwitcher;
    private final SubscriptionController mSubscriptionController;
    private final SubscriptionController mSubscriptionController;
    private final SubscriptionMonitor mSubscriptionMonitor;
    private final LocalLog mLocalLog = new LocalLog(REQUEST_LOG_SIZE);
    private final LocalLog mLocalLog = new LocalLog(REQUEST_LOG_SIZE);


    // Key: network request. Value: the transport of DcTracker it applies to,
    // Key: network request. Value: the transport of DcTracker it applies to,
@@ -83,11 +85,11 @@ public class TelephonyNetworkFactory extends NetworkFactory {


    private int mSubscriptionId;
    private int mSubscriptionId;


    private final Handler mInternalHandler;
    @VisibleForTesting
    public final Handler mInternalHandler;




    public TelephonyNetworkFactory(SubscriptionMonitor subscriptionMonitor, Looper looper,
    public TelephonyNetworkFactory(Looper looper, Phone phone) {
                                   Phone phone) {
        super(looper, phone.getContext(), "TelephonyNetworkFactory[" + phone.getPhoneId()
        super(looper, phone.getContext(), "TelephonyNetworkFactory[" + phone.getPhoneId()
                + "]", null);
                + "]", null);
        mPhone = phone;
        mPhone = phone;
@@ -100,7 +102,6 @@ public class TelephonyNetworkFactory extends NetworkFactory {
        setScoreFilter(TELEPHONY_NETWORK_SCORE);
        setScoreFilter(TELEPHONY_NETWORK_SCORE);


        mPhoneSwitcher = PhoneSwitcher.getInstance();
        mPhoneSwitcher = PhoneSwitcher.getInstance();
        mSubscriptionMonitor = subscriptionMonitor;
        LOG_TAG = "TelephonyNetworkFactory[" + mPhone.getPhoneId() + "]";
        LOG_TAG = "TelephonyNetworkFactory[" + mPhone.getPhoneId() + "]";


        mPhoneSwitcher.registerForActivePhoneSwitch(mInternalHandler, EVENT_ACTIVE_PHONE_SWITCH,
        mPhoneSwitcher.registerForActivePhoneSwitch(mInternalHandler, EVENT_ACTIVE_PHONE_SWITCH,
@@ -109,12 +110,20 @@ public class TelephonyNetworkFactory extends NetworkFactory {
                EVENT_DATA_HANDOVER_NEEDED);
                EVENT_DATA_HANDOVER_NEEDED);


        mSubscriptionId = INVALID_SUBSCRIPTION_ID;
        mSubscriptionId = INVALID_SUBSCRIPTION_ID;
        mSubscriptionMonitor.registerForSubscriptionChanged(mPhone.getPhoneId(), mInternalHandler,
        SubscriptionManager.from(mPhone.getContext()).addOnSubscriptionsChangedListener(
                EVENT_SUBSCRIPTION_CHANGED, null);
                mSubscriptionsChangedListener);


        register();
        register();
    }
    }


    private final SubscriptionManager.OnSubscriptionsChangedListener mSubscriptionsChangedListener =
            new SubscriptionManager.OnSubscriptionsChangedListener() {
                @Override
                public void onSubscriptionsChanged() {
                    mInternalHandler.sendEmptyMessage(EVENT_SUBSCRIPTION_CHANGED);
                }
            };

    private NetworkCapabilities makeNetworkFilter(SubscriptionController subscriptionController,
    private NetworkCapabilities makeNetworkFilter(SubscriptionController subscriptionController,
            int phoneId) {
            int phoneId) {
        final int subscriptionId = subscriptionController.getSubIdUsingPhoneId(phoneId);
        final int subscriptionId = subscriptionController.getSubIdUsingPhoneId(phoneId);
Loading