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

Commit 708f9982 authored by Santos Cordon's avatar Santos Cordon Committed by Android Git Automerger
Browse files

am 1a67c738: am 8afd76dc: Merge "(Telecom-system part 1) Move global state...

am 1a67c738: am 8afd76dc: Merge "(Telecom-system part 1) Move global state from TelecomApp to TelecomGlobals." into lmp-mr1-dev

* commit '1a67c738':
  (Telecom-system part 1) Move global state from TelecomApp to TelecomGlobals.
parents 815c8415 1a67c738
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -851,8 +851,11 @@ public final class BluetoothPhoneService extends Service {
     * phone account for PhoneAccount.SCHEME_TEL.
     */
    private PhoneAccount getBestPhoneAccount() {
        TelecomApp app = (TelecomApp) getApplication();
        PhoneAccountRegistrar registry = app.getPhoneAccountRegistrar();
        PhoneAccountRegistrar registry = TelecomGlobals.getInstance().getPhoneAccountRegistrar();
        if (registry == null) {
            return null;
        }

        Call call = getCallsManager().getForegroundCall();

        PhoneAccount account = null;
+1 −64
Original line number Diff line number Diff line
@@ -17,82 +17,19 @@
package com.android.server.telecom;

import android.app.Application;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.os.UserManager;

/**
 * Top-level Application class for Telecom.
 */
public final class TelecomApp extends Application {
    private static final IntentFilter USER_SWITCHED_FILTER =
            new IntentFilter(Intent.ACTION_USER_SWITCHED);

    /**
     * The Telecom service implementation.
     */
    private TelecomServiceImpl mTelecomService;

    /**
     * Missed call notifier. Exists here so that the instance can be shared with
     * {@link TelecomBroadcastReceiver}.
     */
    private MissedCallNotifier mMissedCallNotifier;

    /**
     * Maintains the list of registered {@link android.telecom.PhoneAccountHandle}s.
     */
    private PhoneAccountRegistrar mPhoneAccountRegistrar;

    /**
     * The calls manager for the Telecom service.
     */
    private CallsManager mCallsManager;

    private final BroadcastReceiver mUserSwitchedReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            int userHandleId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
            UserHandle currentUserHandle = new UserHandle(userHandleId);
            mPhoneAccountRegistrar.setCurrentUserHandle(currentUserHandle);
        }
    };

    /** {@inheritDoc} */
    @Override
    public void onCreate() {
        super.onCreate();

        if (UserHandle.myUserId() == UserHandle.USER_OWNER) {
            // Note: This style of initialization mimics what will be performed once Telecom is
            // moved
            // to run in the system service. The emphasis is on ensuring that initialization of all
            // telecom classes happens in one place without relying on Singleton initialization.
            mMissedCallNotifier = new MissedCallNotifier(this);
            mPhoneAccountRegistrar = new PhoneAccountRegistrar(this);

            mCallsManager = new CallsManager(this, mMissedCallNotifier, mPhoneAccountRegistrar);
            CallsManager.initialize(mCallsManager);

            mTelecomService = new TelecomServiceImpl(mMissedCallNotifier, mPhoneAccountRegistrar,
                    mCallsManager, this);
            ServiceManager.addService(Context.TELECOM_SERVICE, mTelecomService);

            // Start the BluetoothPhoneService
            BluetoothPhoneService.start(this);
        }
        registerReceiver(mUserSwitchedReceiver, USER_SWITCHED_FILTER);
            TelecomGlobals.getInstance().initialize(this);
        }

    MissedCallNotifier getMissedCallNotifier() {
        return mMissedCallNotifier;
    }

    PhoneAccountRegistrar getPhoneAccountRegistrar() {
        return mPhoneAccountRegistrar;
    }
}
+109 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 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.server.telecom;

import android.app.Application;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.ServiceManager;
import android.os.UserHandle;

/**
 * Top-level Application class for Telecom.
 */
public final class TelecomGlobals {
    private static final String TAG = TelecomGlobals.class.getSimpleName();

    private static final IntentFilter USER_SWITCHED_FILTER =
            new IntentFilter(Intent.ACTION_USER_SWITCHED);

    private static final TelecomGlobals INSTANCE = new TelecomGlobals();

    /**
     * The Telecom service implementation.
     */
    private TelecomServiceImpl mTelecomService;

    /**
     * Missed call notifier. Exists here so that the instance can be shared with
     * {@link TelecomBroadcastReceiver}.
     */
    private MissedCallNotifier mMissedCallNotifier;

    /**
     * Maintains the list of registered {@link android.telecom.PhoneAccountHandle}s.
     */
    private PhoneAccountRegistrar mPhoneAccountRegistrar;

    /**
     * The calls manager for the Telecom service.
     */
    private CallsManager mCallsManager;

    /**
     * The application context.
     */
    private Context mContext;

    private final BroadcastReceiver mUserSwitchedReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            int userHandleId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
            UserHandle currentUserHandle = new UserHandle(userHandleId);
            mPhoneAccountRegistrar.setCurrentUserHandle(currentUserHandle);
        }
    };

    static TelecomGlobals getInstance() {
        return INSTANCE;
    }

    void initialize(Context context) {
        if (mContext != null) {
            Log.e(TAG, null, "Attempting to intialize TelecomGlobals a second time.");
            return;
        } else {
            Log.i(TAG, "TelecomGlobals initializing");
        }
        mContext = context;

        mMissedCallNotifier = new MissedCallNotifier(mContext);
        mPhoneAccountRegistrar = new PhoneAccountRegistrar(mContext);

        mCallsManager = new CallsManager(mContext, mMissedCallNotifier, mPhoneAccountRegistrar);
        CallsManager.initialize(mCallsManager);

        mTelecomService = new TelecomServiceImpl(mMissedCallNotifier, mPhoneAccountRegistrar,
                mCallsManager, mContext);
        ServiceManager.addService(Context.TELECOM_SERVICE, mTelecomService);

        // Start the BluetoothPhoneService
        BluetoothPhoneService.start(mContext);

        mContext.registerReceiver(mUserSwitchedReceiver, USER_SWITCHED_FILTER);
    }

    MissedCallNotifier getMissedCallNotifier() {
        return mMissedCallNotifier;
    }

    PhoneAccountRegistrar getPhoneAccountRegistrar() {
        return mPhoneAccountRegistrar;
    }
}