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

Unverified Commit ba7525b3 authored by ExactExampl's avatar ExactExampl Committed by Michael Bestas
Browse files

telephony: introduce a stub SubscriptionController



This is a completely standalone alternative to SubscriptionController
that was replaced with SubscriptionManagerService in commit
c97b4ba2

The reason for this is some older ims packages still need it, as seen
in sargo/bonito ims' getSubId() method:
SubscriptionController.getInstance().getSubIdUsingPhoneId(this.mPhoneId)

The logic behind this implementation is to mock getSubIdUsingPhoneId
method with similar getSubId() method from SubscriptionManagerService
and fit the usage of SubscriptionController in the ims by restoring
getInstance() function as well.

Co-authored-by: default avatarEnesSastim <sastimenes@gmail.com>
Change-Id: I1fdd7e00144b76e49ae721d18187ced6467cf28d
parent 8ed557df
Loading
Loading
Loading
Loading
+58 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 PixelBuildsROM
 *
 * 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.telephony.SubscriptionManager;
import android.util.Log;

import com.android.internal.telephony.subscription.SubscriptionManagerService;

public class SubscriptionController {
    private static final String LOG_TAG = "SubscriptionController";
    protected static SubscriptionController sInstance = null;

    public static SubscriptionController getInstance() {
        // Lazy init happens once, whenever getInstance() is invoked for the first time
        if (sInstance == null) {
            synchronized (SubscriptionController.class) {
                if (sInstance == null) {
                    Log.v(LOG_TAG, "getInstance() was invoked for the first time, "
                            + "initializing the stub SubscriptionController");
                    sInstance = new SubscriptionController();
                }
            }
        }
        return sInstance;
    }

    /**
     * @return The subscription manager service instance.
     */
    public SubscriptionManagerService getSubscriptionManagerService() {
        return SubscriptionManagerService.getInstance();
    }

    public int getSubIdUsingPhoneId(int phoneId) {
        SubscriptionManagerService subscriptionManagerService = getSubscriptionManagerService();
        int subId = subscriptionManagerService.getSubId(phoneId);
        Integer subIdObj = subId;
        if (subIdObj == null) {
            return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
        }
        return subId;
    }
}