Skip to content

Commit

Permalink
Fix: update the Security provider via Google Play Services
Browse files Browse the repository at this point in the history
  • Loading branch information
georgipavlov-7DIGIT committed Feb 15, 2024
1 parent edbaab9 commit 446fbbb
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,112 @@
package org.unicef.ecar.usupport;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;

import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.security.ProviderInstaller;

import expo.modules.ReactActivityDelegateWrapper;

public class MainActivity extends ReactActivity {
public class MainActivity extends ReactActivity
implements ProviderInstaller.ProviderInstallListener {

private static final int ERROR_DIALOG_REQUEST_CODE = 1;
private boolean retryProviderInstall;


@Override
protected void onCreate(Bundle savedInstanceState) {
// Set the theme to AppTheme BEFORE onCreate to support
// coloring the background, status bar, and navigation bar.
// This is required for expo-splash-screen.
setTheme(R.style.AppTheme);
super.onCreate(null);
ProviderInstaller.installIfNeededAsync(this, this);
}

/**
* This method is called if updating fails. The error code indicates
* whether the error is recoverable.
*/
public void onProviderInstallFailed(int errorCode, Intent recoveryIntent) {
GoogleApiAvailability availability = GoogleApiAvailability.getInstance();
if (availability.isUserResolvableError(errorCode)) {
// Recoverable error. Show a dialog prompting the user to
// install/update/enable Google Play services.
availability.showErrorDialogFragment(
this,
errorCode,
ERROR_DIALOG_REQUEST_CODE,
new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
// The user chose not to take the recovery action.
onProviderInstallerNotAvailable();
}
});
} else {
// Google Play services isn't available.
onProviderInstallerNotAvailable();
}
}

@Override
public void onProviderInstalled() {
// Handle the success of the provider installation
// You might not need to do anything here, but the method must exist.
}

@Override
public void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == ERROR_DIALOG_REQUEST_CODE) {
// Adding a fragment via GoogleApiAvailability.showErrorDialogFragment
// before the instance state is restored throws an error. So instead,
// set a flag here, which causes the fragment to delay until
// onPostResume.
retryProviderInstall = true;
}
}

/**
* On resume, check whether a flag indicates that the provider needs to be
* reinstalled.
*/
@Override
protected void onPostResume() {
super.onPostResume();
if (retryProviderInstall) {
// It's safe to retry installation.
ProviderInstaller.installIfNeededAsync(this, this);
}
retryProviderInstall = false;
}

private void onProviderInstallerNotAvailable() {
// This is reached if the provider can't be updated for some reason.
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.provider_install_failed_title));
builder.setMessage(getString(R.string.provider_install_failed_message));

builder.setPositiveButton(getString(R.string.ok_button), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// User clicked OK button.
finish(); // Close the app or navigate accordingly
}
});

// Create and show the AlertDialog
AlertDialog dialog = builder.create();
dialog.show();
}

/**
Expand Down
9 changes: 9 additions & 0 deletions android/app/src/main/res/values-kk/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml
version="1.0"
encoding="UTF-8"
standalone="yes"
?>
<resources>
<!-- Below line is handled by '@expo/configure-splash-screen' command and it's discouraged to modify it manually -->
<color name="splashscreen_background">#54CFD9</color>
</resources>
4 changes: 4 additions & 0 deletions android/app/src/main/res/values-kk/ic_launcher_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#7372F9</color>
</resources>
10 changes: 10 additions & 0 deletions android/app/src/main/res/values-kk/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<resources>
<!-- Below line is handled by '@expo/configure-splash-screen' command and it's discouraged to modify it manually -->
<string name="expo_splash_screen_resize_mode" translatable="false">cover</string>
<string name="app_name">uSupport</string>
<string moduleConfig="true" name="CodePushDeploymentKey">@string/CODEPUSH_ANDROID_DEPLOYMENT_KEY</string>
<string name="provider_install_failed_title">Қамтамасыз етушіні орнату сәтсіз аяқталды</string>
<string name="provider_install_failed_message">Қауіпсіздік қамтамасыз етушісі орнатылмады. Жаңартусыз жалғастыра алмайсыз.</string>
<string name="ok_button">Жарайды</string>

</resources>
18 changes: 18 additions & 0 deletions android/app/src/main/res/values-kk/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:textColor">@android:color/black</item>
<item name="android:editTextStyle">@style/ResetEditText</item>
<item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
<item name="android:windowDisablePreview">true</item>
</style>
<style name="ResetEditText" parent="@android:style/Widget.EditText">
<item name="android:padding">0dp</item>
<item name="android:textColorHint">#c8c8c8</item>
<item name="android:textColor">@android:color/black</item>
</style>
<style name="Theme.App.SplashScreen" parent="AppTheme">
<!-- Below line is handled by '@expo/configure-splash-screen' command and it's discouraged to modify it manually -->
<!-- Customize your splash screen theme here -->
<item name="android:windowBackground">@drawable/splashscreen</item>
</style>
</resources>
9 changes: 9 additions & 0 deletions android/app/src/main/res/values-ru/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml
version="1.0"
encoding="UTF-8"
standalone="yes"
?>
<resources>
<!-- Below line is handled by '@expo/configure-splash-screen' command and it's discouraged to modify it manually -->
<color name="splashscreen_background">#54CFD9</color>
</resources>
4 changes: 4 additions & 0 deletions android/app/src/main/res/values-ru/ic_launcher_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#7372F9</color>
</resources>
10 changes: 10 additions & 0 deletions android/app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<resources>
<!-- Below line is handled by '@expo/configure-splash-screen' command and it's discouraged to modify it manually -->
<string name="expo_splash_screen_resize_mode" translatable="false">cover</string>
<string name="app_name">uSupport</string>
<string moduleConfig="true" name="CodePushDeploymentKey">@string/CODEPUSH_ANDROID_DEPLOYMENT_KEY</string>
<string name="provider_install_failed_title">Ошибка установки провайдера</string>
<string name="provider_install_failed_message">Провайдер безопасности не может быть установлен. Вы не можете продолжить без обновления.</string>
<string name="ok_button">ОК</string>

</resources>
18 changes: 18 additions & 0 deletions android/app/src/main/res/values-ru/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:textColor">@android:color/black</item>
<item name="android:editTextStyle">@style/ResetEditText</item>
<item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
<item name="android:windowDisablePreview">true</item>
</style>
<style name="ResetEditText" parent="@android:style/Widget.EditText">
<item name="android:padding">0dp</item>
<item name="android:textColorHint">#c8c8c8</item>
<item name="android:textColor">@android:color/black</item>
</style>
<style name="Theme.App.SplashScreen" parent="AppTheme">
<!-- Below line is handled by '@expo/configure-splash-screen' command and it's discouraged to modify it manually -->
<!-- Customize your splash screen theme here -->
<item name="android:windowBackground">@drawable/splashscreen</item>
</style>
</resources>
5 changes: 4 additions & 1 deletion android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<resources>
<!-- Below line is handled by '@expo/configure-splash-screen' command and it's discouraged to modify it manually -->
<string name="expo_splash_screen_resize_mode" translatable="false">cover</string>
<string name="app_name">USupport</string>
<string name="app_name">uSupport</string>
<string moduleConfig="true" name="CodePushDeploymentKey">@string/CODEPUSH_ANDROID_DEPLOYMENT_KEY</string>
<string name="provider_install_failed_title">Provider Installation Failed</string>
<string name="provider_install_failed_message">The security provider could not be installed. You cannot proceed without updating.</string>
<string name="ok_button">OK</string>
</resources>

0 comments on commit 446fbbb

Please sign in to comment.