Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confirm security provider is up to date #146

Open
whaber opened this issue Aug 27, 2020 · 0 comments
Open

Confirm security provider is up to date #146

whaber opened this issue Aug 27, 2020 · 0 comments
Labels
enhancement New feature or request security

Comments

@whaber
Copy link
Contributor

whaber commented Aug 27, 2020

The Google Play services provide an ProviderInstaller.installIfNeeded() method that will ensure that the device that is secured against vulnerabilities and that the Security Provider is up to date.
Leverage this method in order to perform the check during the App's startup; the following cases need to be handled:
• If the device's Provider is successfully updated (or is already up-to-date), the method will return normally.
• If the device's Google Play services library is out of date, the method will throw an GooglePlayServicesRepairableException. The App can then catch this exception and show the user an appropriate dialog box to update Google Play services.
• If an error occurs, the method will throw a GooglePlayServicesNotAvailableException to indicate that it is unable to update the Provider. The App can then catch the exception and choose an appropriate course of action.
Secure Code

Add the following method to your top/first activity:

public void providerInstallerCheck(Context context) {
    try {
        // Checking if the ProviderInstaller is installed and updated
        ProviderInstaller.installIfNeeded(context);
        Toast.makeText(context, "Provider installed and updated!", Toast.LENGTH_LONG).show();
    } catch (GooglePlayServicesRepairableException e) {
        /* If the ProviderInstaller is installed but not updated
        A popup asks the user to do a manual update of the Google Play Services
         */
        e.printStackTrace();
        GooglePlayServicesUtil.showErrorNotification(e.getConnectionStatusCode(), context);
        Toast.makeText(context, "Provider it outdated. Please update your Google Play Service"
                , Toast.LENGTH_LONG).show();

    } catch (GooglePlayServicesNotAvailableException e) {
        e.printStackTrace();

        /* If the ProviderInstaller is not installed but not updated
        A popup redirects the user to the Google Play Services page on the Google PlayStore
        and let the user download them.
         */
        Dialog dialog = GooglePlayServicesUtil
                .getErrorDialog(e.errorCode, this,
                        REQUEST_GOOGLE_PLAY_SERVICES_DOWNLOAD);

        dialog.setCancelable(false);
        dialog.show();
    }
}

@whaber whaber added enhancement New feature or request security labels Aug 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request security
Projects
None yet
Development

No branches or pull requests

1 participant