Skip to content

Commit

Permalink
Add use of s2msp compatibility API (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
frimtec authored May 7, 2023
1 parent 1fe068e commit d07f7c4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ SDK is 33 (Android 13-Tiramisu) and the minimal SDK is 26 (Android 8.0-Oreo).
* [SlideToAct][slide-to-act]
* [preferencex-android][preferencex-android]
* [Secure-SMS-Proxy API][secure-sms-proxy-api]
* [semver4j][semver4j]

## Devices compatibility
* [Devices compatibility][devices-compatibility]
Expand Down Expand Up @@ -292,3 +293,4 @@ You can send an email to [[email protected]](mailto:[email protected]) or [open an iss
[preferencex-android]: https://github.com/takisoft/preferencex-android
[secure-sms-proxy-api]: https://github.com/frimtec/secure-sms-proxy
[lokalise]: https://lokalise.com/
[semver4j]: https://github.com/vdurmont/semver4j
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: "de.mannodermaus.android-junit5"
apply plugin: 'jacoco'

// Third party library versions
def secure_sms_proxy_api_version = '2.7.0'
def secure_sms_proxy_api_version = '2.7.0-compatapi.2'
def android_billingclient_version = '5.2.0'
def slidetoact_version = '0.10.0'
def takisoft_preferencex_version = '1.1.0'
Expand Down Expand Up @@ -63,6 +63,7 @@ dependencies {
implementation "androidx.work:work-runtime:$work_version"
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.android.material:material:1.8.0'
implementation 'com.vdurmont:semver4j:3.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.code.gson:gson:2.10.1'
implementation "com.ncorti:slidetoact:$slidetoact_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.github.frimtec.android.pikettassist.R;
import com.github.frimtec.android.pikettassist.state.ApplicationState;
import com.github.frimtec.android.securesmsproxyapi.SecureSmsProxyFacade.Installation;
import com.github.frimtec.android.securesmsproxyapi.SecureSmsProxyFacade.Installation.AppCompatibility;

class SmsAdapterState extends State {

Expand All @@ -50,32 +51,52 @@ class SmsAdapterState extends State {
}

private static State.TrafficLight getSmsAdapterState(StateContext stateContext, boolean smsAdapterSmsPermission) {
if (stateContext.isSmsAdapterMissing() || !smsAdapterSmsPermission || stateContext.isOperationsCenterPhoneNumbersBlocked()) {
AppCompatibility compatibility = getAppCompatibility(stateContext);
if (!compatibility.isSupported() || !smsAdapterSmsPermission || stateContext.isOperationsCenterPhoneNumbersBlocked()) {
return RED;
} else if (stateContext.isSmsAdapterVersionOutdated()) {
} else if (compatibility == AppCompatibility.UPDATE_RECOMMENDED) {
return YELLOW;
} else {
return GREEN;
}
}

private static AppCompatibility getAppCompatibility(StateContext stateContext) {
return stateContext.getSmsAdapterInstallation().getAppCompatibility();
}

private static String getSmsAdapterValue(StateContext stateContext, boolean smsAdapterSmsPermission) {
if (stateContext.isSmsAdapterMissing()) {
return stateContext.getString(R.string.state_fragment_sms_adapter_not_installed);
} else if (!smsAdapterSmsPermission) {
switch (getAppCompatibility(stateContext)) {
case NOT_INSTALLED:
return stateContext.getString(R.string.state_fragment_sms_adapter_not_installed);
case NOT_YET_SUPPORTED:
return "Not yet supported" + "\n" + getVersionUpdate(stateContext);
case NO_MORE_SUPPORTED:
return stateContext.getString(R.string.state_fragment_s2msp_requires_update) + "\n" + getVersionUpdate(stateContext);
case UPDATE_RECOMMENDED:
return "Update recommended\n" + getVersionUpdate(stateContext);
}
if (!smsAdapterSmsPermission) {
return stateContext.getString(R.string.state_fragment_sms_adapter_no_sms_permissions);
} else if (stateContext.isOperationsCenterPhoneNumbersBlocked()) {
return stateContext.getString(R.string.state_fragment_phone_numbers_blocked);
} else if (stateContext.isSmsAdapterVersionOutdated()) {
return stateContext.getString(R.string.state_fragment_s2msp_requires_update);
} else {
return "S2MSP V" + stateContext.getSmsAdapterInstallation().getAppVersion().orElse("?.?");
return "S2MSP V" + getAppVersion(stateContext);
}
}

private static String getAppVersion(StateContext stateContext) {
return stateContext.getSmsAdapterInstallation().getAppVersion().orElse("?.?");
}

private static String getVersionUpdate(StateContext stateContext) {
return String.format("Version %s -> %s", getAppVersion(stateContext), stateContext.getSmsAdapterInstallation().getApiVersion());
}

@Override
public void onClickAction(Context context) {
if (stateContext.isSmsAdapterMissing()) {
AppCompatibility appCompatibility = getAppCompatibility(stateContext);
if (appCompatibility == AppCompatibility.NOT_INSTALLED) {
openDownloadDialog(context, R.string.permission_sms_text, R.string.permission_sms_title, stateContext.getSmsAdapterInstallation());
return;
}
Expand All @@ -84,7 +105,7 @@ public void onClickAction(Context context) {
stateContext.registerPhoneNumberOnSmsAdapter();
return;
}
if (stateContext.isSmsAdapterVersionOutdated()) {
if (appCompatibility == AppCompatibility.UPDATE_RECOMMENDED || appCompatibility == AppCompatibility.NO_MORE_SUPPORTED) {
openDownloadDialog(context, R.string.permission_sms_update_text, R.string.permission_sms_update_title, stateContext.getSmsAdapterInstallation());
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ class StateContext {
private final boolean operationsCenterPhoneNumbersBlocked;

private final Installation smsAdapterInstallation;
private final boolean smsAdapterMissing;
private final boolean smsAdapterVersionOutdated;
private final boolean smsAdapterPermissionsGranted;

private final SignalLevel signalStrengthLevel;
Expand All @@ -59,8 +57,6 @@ class StateContext {
Runnable closeAlertAction,
Runnable showDonationDialogAction,
Installation smsAdapterInstallation,
boolean smsAdapterMissing,
boolean smsAdapterVersionOutdated,
boolean smsAdapterPermissionsGranted,
ShiftState shiftState,
String pikettStateDuration,
Expand All @@ -82,8 +78,6 @@ class StateContext {
this.closeAlertAction = closeAlertAction;
this.showDonationDialogAction = showDonationDialogAction;
this.smsAdapterInstallation = smsAdapterInstallation;
this.smsAdapterMissing = smsAdapterMissing;
this.smsAdapterVersionOutdated = smsAdapterVersionOutdated;
this.smsAdapterPermissionsGranted = smsAdapterPermissionsGranted;
this.shiftState = shiftState;
this.pikettStateDuration = pikettStateDuration;
Expand Down Expand Up @@ -130,14 +124,6 @@ Installation getSmsAdapterInstallation() {
return smsAdapterInstallation;
}

boolean isSmsAdapterMissing() {
return smsAdapterMissing;
}

boolean isSmsAdapterVersionOutdated() {
return smsAdapterVersionOutdated;
}

boolean isSmsAdapterPermissionsGranted() {
return smsAdapterPermissionsGranted;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,6 @@ private void regularStates(List<State> states) {
() -> this.alertService.closeAlert(),
() -> this.billingAccess.showDonationDialog(),
smsAdapterInstallation,
!smsAdapterInstallation.getAppVersion().isPresent(),
smsAdapterInstallation.getAppVersion().isPresent() && smsAdapterInstallation.getApiVersion().compareTo(smsAdapterInstallation.getAppVersion().get()) > 0,
s2msp.areSmsPermissionsGranted(),
shiftState,
currentOrNextShift.map(shift -> toDuration(pikettStateManuallyOn, shiftState, shift, now, prePostRunTime)).orElse(""),
Expand Down

0 comments on commit d07f7c4

Please sign in to comment.