-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #455 from Chooloo/fix/ussd
Added Mmi and secret codes options to dialer #164
- Loading branch information
Showing
15 changed files
with
135 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
...lib/src/main/java/com/chooloo/www/chooloolib/interactor/call/CallNavigationsInteractor.kt
This file was deleted.
Oops, something went wrong.
49 changes: 0 additions & 49 deletions
49
...src/main/java/com/chooloo/www/chooloolib/interactor/call/CallNavigationsInteractorImpl.kt
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
chooloolib/src/main/java/com/chooloo/www/chooloolib/interactor/telecom/TelecomInteractor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.chooloo.www.chooloolib.interactor.telecom | ||
|
||
import com.chooloo.www.chooloolib.interactor.base.BaseInteractor | ||
import com.chooloo.www.chooloolib.model.SimAccount | ||
|
||
interface TelecomInteractor : BaseInteractor<TelecomInteractor.Listener> { | ||
interface Listener {} | ||
|
||
fun handleMmi(code: String): Boolean | ||
fun handleSecretCode(code: String): Boolean | ||
fun handleSpecialChars(code: String): Boolean | ||
fun callVoicemail() | ||
fun callNumber(number: String, simAccount: SimAccount? = null) | ||
} |
63 changes: 63 additions & 0 deletions
63
...olib/src/main/java/com/chooloo/www/chooloolib/interactor/telecom/TelecomInteractorImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.chooloo.www.chooloolib.interactor.telecom | ||
|
||
import android.Manifest | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.net.Uri | ||
import android.os.Build | ||
import android.os.Bundle | ||
import android.provider.VoicemailContract | ||
import android.telecom.PhoneAccount | ||
import android.telecom.TelecomManager | ||
import android.telephony.TelephonyManager | ||
import androidx.annotation.RequiresPermission | ||
import com.chooloo.www.chooloolib.model.SimAccount | ||
import com.chooloo.www.chooloolib.util.CallUtils | ||
import com.chooloo.www.chooloolib.util.PhoneNumberUtils | ||
import com.chooloo.www.chooloolib.util.baseobservable.BaseObservable | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class TelecomInteractorImpl @Inject constructor( | ||
private val telecomManager: TelecomManager, | ||
private val telephonyManager: TelephonyManager, | ||
@ApplicationContext private val context: Context | ||
) : BaseObservable<TelecomInteractor.Listener>(), TelecomInteractor { | ||
private val SECRET_CODE_ACTION = "android.provider.Telephony.SECRET_CODE" | ||
|
||
override fun handleMmi(code: String) = telecomManager.handleMmi(code) | ||
|
||
override fun handleSecretCode(code: String): Boolean { | ||
if (!PhoneNumberUtils.isSecretCode(code)) { | ||
return false; | ||
} | ||
|
||
val secretCode: String = code.substring(4, code.length - 4) | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
telephonyManager.sendDialerSpecialCode(secretCode) | ||
} else { | ||
// System service call is not supported pre-O, so must use a broadcast for N-. | ||
val intent = Intent(SECRET_CODE_ACTION, Uri.parse("android_secret_code://$secretCode")) | ||
context.sendBroadcast(intent) | ||
} | ||
return true; | ||
} | ||
|
||
override fun handleSpecialChars(code: String) = handleMmi(code) || handleSecretCode(code) | ||
|
||
@RequiresPermission(Manifest.permission.CALL_PHONE) | ||
override fun callVoicemail() { | ||
telecomManager.placeCall(Uri.fromParts(PhoneAccount.SCHEME_VOICEMAIL, "", null), Bundle()) | ||
} | ||
|
||
@RequiresPermission(allOf = [Manifest.permission.READ_PHONE_STATE, Manifest.permission.CALL_PHONE]) | ||
override fun callNumber(number: String, simAccount: SimAccount?) { | ||
val extras = Bundle() | ||
simAccount?.phoneAccountHandle?.let { | ||
extras.putParcelable(VoicemailContract.EXTRA_PHONE_ACCOUNT_HANDLE, it) | ||
} | ||
telecomManager.placeCall(CallUtils.getCallURI(number), extras) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
chooloolib/src/main/java/com/chooloo/www/chooloolib/util/CallUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.chooloo.www.chooloolib.util | ||
|
||
import android.net.Uri | ||
import android.telecom.PhoneAccount | ||
|
||
object CallUtils { | ||
fun getCallURI(number: String) = if (PhoneNumberUtils.isUri(number)) { | ||
Uri.fromParts(PhoneAccount.SCHEME_SIP, number, null); | ||
} else { | ||
Uri.fromParts(PhoneAccount.SCHEME_TEL, number, null); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
chooloolib/src/main/java/com/chooloo/www/chooloolib/util/PhoneNumberUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.chooloo.www.chooloolib.util | ||
|
||
|
||
object PhoneNumberUtils { | ||
fun isMmi(number: String) = | ||
(number.startsWith("**04") || number.startsWith("**05")) && number.endsWith("#") | ||
|
||
fun isUri(number: String?) = | ||
number != null && (number.contains("@") || number.contains("%40")) | ||
|
||
fun isSecretCode(number: String) = | ||
number.length > 8 && number.startsWith("*#*#") && number.endsWith("#*#*") | ||
} |
Oops, something went wrong.