PorcessPendingMessagesAction queues one message for sending/downloading associated with a subscription triggering current action at a time. And the ConnectivityUtil also works based on subscriptions so that pending messages can be processed regardless of other phones' state in multi-sim case. It includes cleanup code as well. Test: Manual Change-Id: Id6b4f4a0aa6a3291e7a4d8a5d3f0fbb9db3c5b86 Signed-off-by: Taesu Lee <taesu82.lee@samsung.com>
98 lines
3.5 KiB
Java
98 lines
3.5 KiB
Java
/*
|
|
* 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.messaging.util;
|
|
|
|
import android.content.Context;
|
|
import android.telephony.PhoneStateListener;
|
|
import android.telephony.ServiceState;
|
|
import android.telephony.TelephonyManager;
|
|
|
|
import com.android.messaging.datamodel.data.ParticipantData;
|
|
|
|
public class ConnectivityUtil {
|
|
// Assume not connected until informed differently
|
|
private volatile int mCurrentServiceState = ServiceState.STATE_POWER_OFF;
|
|
|
|
private final TelephonyManager mTelephonyManager;
|
|
|
|
private ConnectivityListener mListener;
|
|
|
|
public interface ConnectivityListener {
|
|
public void onPhoneStateChanged(int serviceState);
|
|
}
|
|
|
|
public ConnectivityUtil(final Context context) {
|
|
mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
|
}
|
|
|
|
public ConnectivityUtil(final Context context, final int subId) {
|
|
mTelephonyManager =
|
|
((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE))
|
|
.createForSubscriptionId(subId);
|
|
}
|
|
|
|
public int getCurrentServiceState() {
|
|
return mCurrentServiceState;
|
|
}
|
|
|
|
private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
|
|
@Override
|
|
public void onServiceStateChanged(final ServiceState serviceState) {
|
|
if (mCurrentServiceState != serviceState.getState()) {
|
|
mCurrentServiceState = serviceState.getState();
|
|
onPhoneStateChanged(mCurrentServiceState);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onDataConnectionStateChanged(final int state) {
|
|
mCurrentServiceState = (state == TelephonyManager.DATA_DISCONNECTED) ?
|
|
ServiceState.STATE_OUT_OF_SERVICE : ServiceState.STATE_IN_SERVICE;
|
|
}
|
|
};
|
|
|
|
private void onPhoneStateChanged(final int serviceState) {
|
|
final ConnectivityListener listener = mListener;
|
|
if (listener != null) {
|
|
listener.onPhoneStateChanged(serviceState);
|
|
}
|
|
}
|
|
|
|
public void register(final ConnectivityListener listener) {
|
|
Assert.isTrue(mListener == null || mListener == listener);
|
|
if (mListener == null) {
|
|
if (mTelephonyManager != null) {
|
|
mCurrentServiceState = (PhoneUtils.getDefault().isAirplaneModeOn() ?
|
|
ServiceState.STATE_POWER_OFF : ServiceState.STATE_IN_SERVICE);
|
|
mTelephonyManager.listen(mPhoneStateListener,
|
|
PhoneStateListener.LISTEN_SERVICE_STATE);
|
|
}
|
|
}
|
|
mListener = listener;
|
|
}
|
|
|
|
public void unregister() {
|
|
if (mListener != null) {
|
|
if (mTelephonyManager != null) {
|
|
mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
|
|
mCurrentServiceState = ServiceState.STATE_POWER_OFF;
|
|
}
|
|
}
|
|
mListener = null;
|
|
}
|
|
}
|