diff options
| author | Joey Hewitt <joey@joeyhewitt.com> | 2017-09-02 00:20:46 -0700 |
|---|---|---|
| committer | Joey Hewitt <joey@joeyhewitt.com> | 2017-09-02 01:51:51 -0700 |
| commit | cf97f506fe48245a82f463db53162a67911894cb (patch) | |
| tree | e052f2cecdd16a271d63eb87f4f0128ededaf1a7 | |
| parent | 9fc5a8093936a20b75d5a83ce39f7a57747cdece (diff) | |
| download | frameworks_opt_telephony_ril_ofono-cf97f506fe48245a82f463db53162a67911894cb.tar.gz frameworks_opt_telephony_ril_ofono-cf97f506fe48245a82f463db53162a67911894cb.tar.bz2 frameworks_opt_telephony_ril_ofono-cf97f506fe48245a82f463db53162a67911894cb.zip | |
notifications cleanup
* Removed unnecessary cross-thread posting (Messages will find their own way to their thread)
* Centralize logging of notifications and facade Android's RegistrantList under my own
| -rw-r--r-- | src/java/net/scintill/ril_ofono/CallModule.java | 10 | ||||
| -rw-r--r-- | src/java/net/scintill/ril_ofono/DataConnModule.java | 5 | ||||
| -rw-r--r-- | src/java/net/scintill/ril_ofono/ModemModule.java | 24 | ||||
| -rw-r--r-- | src/java/net/scintill/ril_ofono/RilOfono.java | 44 | ||||
| -rw-r--r-- | src/java/net/scintill/ril_ofono/RilWrapper.java | 28 | ||||
| -rw-r--r-- | src/java/net/scintill/ril_ofono/SimModule.java | 6 | ||||
| -rw-r--r-- | src/java/net/scintill/ril_ofono/SmsModule.java | 10 | ||||
| -rw-r--r-- | src/java/net/scintill/ril_ofono/SupplementaryServicesModule.java | 4 |
8 files changed, 58 insertions, 73 deletions
diff --git a/src/java/net/scintill/ril_ofono/CallModule.java b/src/java/net/scintill/ril_ofono/CallModule.java index b1939ea..24e5186 100644 --- a/src/java/net/scintill/ril_ofono/CallModule.java +++ b/src/java/net/scintill/ril_ofono/CallModule.java @@ -19,7 +19,6 @@ package net.scintill.ril_ofono; -import android.os.RegistrantList; import android.telephony.PhoneNumberUtils; import android.telephony.Rlog; @@ -44,9 +43,10 @@ import java.util.concurrent.ConcurrentLinkedQueue; import static com.android.internal.telephony.CommandException.Error.GENERIC_FAILURE; import static com.android.internal.telephony.CommandException.Error.MODE_NOT_SUPPORTED; import static com.android.internal.telephony.CommandException.Error.NO_SUCH_ELEMENT; +import static net.scintill.ril_ofono.RilOfono.RegistrantList; +import static net.scintill.ril_ofono.RilOfono.notifyResultAndLog; import static net.scintill.ril_ofono.RilOfono.privExc; import static net.scintill.ril_ofono.RilOfono.privStr; -import static net.scintill.ril_ofono.RilOfono.runOnMainThread; import static net.scintill.ril_ofono.RilOfono.runOnMainThreadDebounced; /*package*/ class CallModule extends PropManager { @@ -115,7 +115,7 @@ import static net.scintill.ril_ofono.RilOfono.runOnMainThreadDebounced; newCallProps.put(PROPNAME_CALL_INDEX, new Variant<>(mAvailableCallIndices.remove())); putOrMerge2dProps(mCallsProps, callPath, newCallProps); - runOnMainThread(mFnNotifyCallStateChanged); + notifyResultAndLog("call state - added", mCallStateRegistrants, null, false); } public void handle(VoiceCall.PropertyChanged s) { @@ -129,7 +129,7 @@ import static net.scintill.ril_ofono.RilOfono.runOnMainThreadDebounced; int callIndex = getProp(mCallsProps.get(callPath), PROPNAME_CALL_INDEX, -1); mCallsProps.remove(callPath); if (callIndex != -1) mAvailableCallIndices.add(callIndex); - runOnMainThread(mFnNotifyCallStateChanged); + notifyResultAndLog("call state - removed", mCallStateRegistrants, null, false); } private String getDbusPathForCallIndex(int i) { @@ -243,7 +243,7 @@ import static net.scintill.ril_ofono.RilOfono.runOnMainThreadDebounced; final DebouncedRunnable mFnNotifyCallStateChanged = new DebouncedRunnable() { @Override public void run() { - mCallStateRegistrants.notifyResult(null); + notifyResultAndLog("call state", mCallStateRegistrants, null, false); } }; diff --git a/src/java/net/scintill/ril_ofono/DataConnModule.java b/src/java/net/scintill/ril_ofono/DataConnModule.java index eb59c26..d78649b 100644 --- a/src/java/net/scintill/ril_ofono/DataConnModule.java +++ b/src/java/net/scintill/ril_ofono/DataConnModule.java @@ -19,7 +19,6 @@ package net.scintill.ril_ofono; -import android.os.RegistrantList; import android.telephony.Rlog; import android.text.TextUtils; @@ -46,6 +45,8 @@ import java.util.Map; import static com.android.internal.telephony.CommandException.Error.MODE_NOT_SUPPORTED; import static com.android.internal.telephony.CommandException.Error.NO_SUCH_ELEMENT; import static com.android.internal.telephony.CommandException.Error.REQUEST_NOT_SUPPORTED; +import static net.scintill.ril_ofono.RilOfono.RegistrantList; +import static net.scintill.ril_ofono.RilOfono.notifyResultAndLog; import static net.scintill.ril_ofono.RilOfono.privStr; import static net.scintill.ril_ofono.RilOfono.runOnMainThreadDebounced; @@ -233,7 +234,7 @@ import static net.scintill.ril_ofono.RilOfono.runOnMainThreadDebounced; public void run() { Object calls = getDataCallListImpl(); Rlog.d(TAG, "notify dataNetworkState "+privStr(calls)); - mDataNetworkStateRegistrants.notifyResult(calls); + notifyResultAndLog("data netstate", mDataNetworkStateRegistrants, calls, true); } }; diff --git a/src/java/net/scintill/ril_ofono/ModemModule.java b/src/java/net/scintill/ril_ofono/ModemModule.java index 22591d7..dc8b13c 100644 --- a/src/java/net/scintill/ril_ofono/ModemModule.java +++ b/src/java/net/scintill/ril_ofono/ModemModule.java @@ -19,7 +19,6 @@ package net.scintill.ril_ofono; -import android.os.RegistrantList; import android.telephony.Rlog; import android.telephony.SignalStrength; @@ -47,7 +46,8 @@ import static android.telephony.ServiceState.RIL_RADIO_TECHNOLOGY_UMTS; import static android.telephony.ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN; import static com.android.internal.telephony.CommandException.Error.GENERIC_FAILURE; import static com.android.internal.telephony.CommandsInterface.RadioState; -import static net.scintill.ril_ofono.RilOfono.runOnMainThread; +import static net.scintill.ril_ofono.RilOfono.RegistrantList; +import static net.scintill.ril_ofono.RilOfono.notifyResultAndLog; import static net.scintill.ril_ofono.RilOfono.runOnMainThreadDebounced; /*package*/ class ModemModule extends PropManager { @@ -163,23 +163,13 @@ import static net.scintill.ril_ofono.RilOfono.runOnMainThreadDebounced; protected void onPropChange(Modem modem, String name, Variant value) { if (name.equals("Online")) { final boolean online = (Boolean) value.getValue(); - runOnMainThread(new Runnable() { - @Override - public void run() { - RilOfono.sInstance.setRadioState(online ? RadioState.RADIO_ON : RadioState.RADIO_OFF); - } - }); + RilOfono.sInstance.setRadioState(online ? RadioState.RADIO_ON : RadioState.RADIO_OFF); } } protected void onPropChange(NetworkRegistration netReg, String name, Variant value) { if (name.equals("Strength")) { - runOnMainThread(new Runnable() { - @Override - public void run() { - mSignalStrengthRegistrants.notifyResult(getSignalStrength()); - } - }); + notifyResultAndLog("signal strength", mSignalStrengthRegistrants, getSignalStrength(), false); } else { runOnMainThreadDebounced(mFnNotifyNetworkChanged, 350); } @@ -189,10 +179,8 @@ import static net.scintill.ril_ofono.RilOfono.runOnMainThreadDebounced; final DebouncedRunnable mFnNotifyNetworkChanged = new DebouncedRunnable() { @Override public void run() { - Rlog.d(TAG, "notify voiceNetworkState"); - mVoiceNetworkStateRegistrants.notifyRegistrants(); - Rlog.d(TAG, "notify voiceRadioTechChanged"); - mVoiceRadioTechChangedRegistrants.notifyResult(getVoiceRadioTechnologyAsyncResult()); + notifyResultAndLog("voice netstate", mVoiceNetworkStateRegistrants, null, false); + notifyResultAndLog("voice radiotech changed", mVoiceRadioTechChangedRegistrants, getVoiceRadioTechnologyAsyncResult(), false); } }; diff --git a/src/java/net/scintill/ril_ofono/RilOfono.java b/src/java/net/scintill/ril_ofono/RilOfono.java index 63c96e8..65fda79 100644 --- a/src/java/net/scintill/ril_ofono/RilOfono.java +++ b/src/java/net/scintill/ril_ofono/RilOfono.java @@ -121,27 +121,18 @@ public class RilOfono implements RilInterface { } /*package*/ void onModemAvail() { - mMainHandler.post(new Runnable() { - @Override - public void run() { - // see RIL.java for RIL_UNSOL_RIL_CONNECTED - mRilWrapper.setRadioPower(false, cbToMsg(new Handler.Callback() { - @Override - public boolean handleMessage(Message msg) { - AsyncResult ar = (AsyncResult) msg.obj; - if (ar.exception == null) { - setRadioState(RadioState.RADIO_OFF); - } else { - setRadioState(RadioState.RADIO_UNAVAILABLE); - Rlog.e(TAG, "onModemAvail: setRadioPower(false) returned an exception", ar.exception); - } - return true; - } - })); - Rlog.d(TAG, "notifyRegistrantsRilConnectionChanged"); - mRilWrapper.updateRilConnection(RIL_VERSION); - } - }); + // RIL.java for RIL_UNSOL_RIL_CONNECTED does this + try { + setRadioPower(false); + } catch (Throwable t) { + setRadioState(RadioState.RADIO_UNAVAILABLE); + Rlog.e(TAG, "onModemAvail: setRadioPower(false) threw an exception", t); + return; + } + + setRadioState(RadioState.RADIO_OFF); + + mRilWrapper.updateRilConnection(RIL_VERSION); // TODO call VoiceManager GetCalls() ? oFono docs on that method suggest you should at startup } @@ -917,8 +908,9 @@ public class RilOfono implements RilInterface { } } - private Message cbToMsg(Handler.Callback cb) { - return new Handler(cb).obtainMessage(); + /*package*/ static void notifyResultAndLog(String logSuffix, RegistrantList list, Object result, boolean priv) { + Rlog.i(TAG, "notify "+logSuffix+" "+(priv ? privStr("") : toDebugString(result))); + list.notifyResult(result); } private static void postDebounced(Handler h, DebouncedRunnable r, long delayMillis) { @@ -934,10 +926,8 @@ public class RilOfono implements RilInterface { sInstance.mDbusHandler.post(r); } - /*package*/ static void runOnMainThread(Runnable r) { - sInstance.mMainHandler.post(r); - } - + // We often won't care much what thread it runs on, but in order to use a Handler, I guess we need + // to specify a thread. /*package*/ static void runOnMainThreadDebounced(DebouncedRunnable r, long delayMillis) { postDebounced(sInstance.mMainHandler, r, delayMillis); } diff --git a/src/java/net/scintill/ril_ofono/RilWrapper.java b/src/java/net/scintill/ril_ofono/RilWrapper.java index 056eb91..a2b441b 100644 --- a/src/java/net/scintill/ril_ofono/RilWrapper.java +++ b/src/java/net/scintill/ril_ofono/RilWrapper.java @@ -21,7 +21,6 @@ package net.scintill.ril_ofono; import android.content.Context; import android.os.Registrant; -import android.os.RegistrantList; import android.telephony.Rlog; import com.android.internal.telephony.BaseCommands; @@ -31,6 +30,7 @@ import java.lang.reflect.Field; import static com.android.internal.telephony.CommandException.Error.GENERIC_FAILURE; import static com.android.internal.telephony.RILConstants.NO_PHONE; +import static net.scintill.ril_ofono.RilOfono.notifyResultAndLog; import static net.scintill.ril_ofono.RilOfono.privExc; import static net.scintill.ril_ofono.RilOfono.respondExc; import static net.scintill.ril_ofono.RilOfono.runOnDbusThread; @@ -51,7 +51,7 @@ public final class RilWrapper extends BaseCommands { /*package*/ void updateRilConnection(int version) { this.mRilVersion = version; if (mRilConnectedRegistrants != null) { - mRilConnectedRegistrants.notifyResult(version); + notifyResultAndLog("ril connected", mRilConnectedRegistrants, version, false); } } @@ -84,12 +84,13 @@ public final class RilWrapper extends BaseCommands { // Promote some members to package visibility /////////////////////////// - /*package*/ android.os.RegistrantList - mVoiceNetworkStateRegistrants = super.mVoiceNetworkStateRegistrants, - mIccStatusChangedRegistrants = super.mIccStatusChangedRegistrants, - mVoiceRadioTechChangedRegistrants = super.mVoiceRadioTechChangedRegistrants, - mCallStateRegistrants = super.mCallStateRegistrants, - mDataNetworkStateRegistrants = super.mDataNetworkStateRegistrants; + /*package*/ RilOfono.RegistrantList + mVoiceNetworkStateRegistrants = new RegistrantListAndroidTypeWrapper(super.mVoiceNetworkStateRegistrants), + mIccStatusChangedRegistrants = new RegistrantListAndroidTypeWrapper(super.mIccStatusChangedRegistrants), + mVoiceRadioTechChangedRegistrants = new RegistrantListAndroidTypeWrapper(super.mVoiceRadioTechChangedRegistrants), + mCallStateRegistrants = new RegistrantListAndroidTypeWrapper(super.mCallStateRegistrants), + mDataNetworkStateRegistrants = new RegistrantListAndroidTypeWrapper(super.mDataNetworkStateRegistrants), + mRilConnectedRegistrants = new RegistrantListAndroidTypeWrapper(super.mRilConnectedRegistrants); /*package*/ void setRadioStateHelper(RadioState newState) { setRadioState(newState); @@ -125,6 +126,17 @@ public final class RilWrapper extends BaseCommands { } } + class RegistrantListAndroidTypeWrapper implements RilOfono.RegistrantList { + android.os.RegistrantList mList; + RegistrantListAndroidTypeWrapper(android.os.RegistrantList list) { + mList = list; + } + @Override + public void notifyResult(Object result) { + mList.notifyResult(result); + } + } + private static void respondOk(String caller, android.os.Message msg, Object ret) { if (ret == RETURN_LATER) { Rlog.v(TAG, caller+" will return later"); diff --git a/src/java/net/scintill/ril_ofono/SimModule.java b/src/java/net/scintill/ril_ofono/SimModule.java index 6c5f061..8559b64 100644 --- a/src/java/net/scintill/ril_ofono/SimModule.java +++ b/src/java/net/scintill/ril_ofono/SimModule.java @@ -19,7 +19,6 @@ package net.scintill.ril_ofono; -import android.os.RegistrantList; import android.telephony.Rlog; import com.android.internal.telephony.CommandException; @@ -35,6 +34,8 @@ import java.util.HashMap; import java.util.Map; import static com.android.internal.telephony.CommandException.Error.GENERIC_FAILURE; +import static net.scintill.ril_ofono.RilOfono.RegistrantList; +import static net.scintill.ril_ofono.RilOfono.notifyResultAndLog; import static net.scintill.ril_ofono.RilOfono.runOnMainThreadDebounced; /*package*/ class SimModule extends PropManager { @@ -125,8 +126,7 @@ import static net.scintill.ril_ofono.RilOfono.runOnMainThreadDebounced; private DebouncedRunnable mFnNotifySimChanged = new DebouncedRunnable() { @Override public void run() { - Rlog.d(TAG, "notify iccStatusChanged"); - mIccStatusChangedRegistrants.notifyRegistrants(); + notifyResultAndLog("icc status", mIccStatusChangedRegistrants, null, false); } }; diff --git a/src/java/net/scintill/ril_ofono/SmsModule.java b/src/java/net/scintill/ril_ofono/SmsModule.java index 8857407..80f3ff3 100644 --- a/src/java/net/scintill/ril_ofono/SmsModule.java +++ b/src/java/net/scintill/ril_ofono/SmsModule.java @@ -36,11 +36,11 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import static com.android.internal.telephony.CommandException.Error.GENERIC_FAILURE; +import static net.scintill.ril_ofono.RilOfono.notifyResultAndLog; import static net.scintill.ril_ofono.RilOfono.privExc; import static net.scintill.ril_ofono.RilOfono.privStr; import static net.scintill.ril_ofono.RilOfono.respondExc; import static net.scintill.ril_ofono.RilOfono.respondOk; -import static net.scintill.ril_ofono.RilOfono.runOnMainThread; /*package*/ class SmsModule { @@ -114,13 +114,7 @@ import static net.scintill.ril_ofono.RilOfono.runOnMainThread; throw new IllegalArgumentException("Null returned from parser"); } - final SmsMessage fmsg = msg; - runOnMainThread(new Runnable() { - @Override - public void run() { - mSmsRegistrants.notifyResult(fmsg); - } - }); + notifyResultAndLog("sms", mSmsRegistrants, msg, true); } catch (Throwable t) { Rlog.e(TAG, "Error handling incoming PDU "+privStr(IccUtils.bytesToHexString(s.pdu)+" tpdu_len="+s.tpdu_len), privExc(t)); } diff --git a/src/java/net/scintill/ril_ofono/SupplementaryServicesModule.java b/src/java/net/scintill/ril_ofono/SupplementaryServicesModule.java index f8ac028..f72ce28 100644 --- a/src/java/net/scintill/ril_ofono/SupplementaryServicesModule.java +++ b/src/java/net/scintill/ril_ofono/SupplementaryServicesModule.java @@ -45,9 +45,9 @@ import static com.android.internal.telephony.CommandsInterface.USSD_MODE_NOT_SUP // TODO do on a separate thread? oFono docs seem to imply this will block everything anyway Pair<String, Variant> ussdResponse = mSupplSvcs.Initiate(ussdString); if (!ussdResponse.a.equals("USSD")) { - mUSSDRegistrants.notifyResult(new String[]{""+USSD_MODE_NOT_SUPPORTED, null}); + RilOfono.notifyResultAndLog("ussd n/a", mUSSDRegistrants, new String[]{""+USSD_MODE_NOT_SUPPORTED, null}, false); } else { - mUSSDRegistrants.notifyResult(new String[]{""+USSD_MODE_NOTIFY, (String) ussdResponse.b.getValue()}); + RilOfono.notifyResultAndLog("ussd", mUSSDRegistrants, new String[]{""+USSD_MODE_NOTIFY, (String) ussdResponse.b.getValue()}, true); } return null; } |
