From a997fcd73c374b1b360dc667035c4aaa8eb81885 Mon Sep 17 00:00:00 2001 From: stom79 Date: Sat, 9 Dec 2017 18:16:20 +0100 Subject: [PATCH] Removes Safetynet library --- app/build.gradle | 5 +- .../activities/MainActivity.java | 4 - .../mastodon/activities/BaseMainActivity.java | 2 - ...eLoginActivity.java => LoginActivity.java} | 14 ++- .../activities/MainActivity.java} | 18 ++-- .../activities/LoginActivity.java | 82 ------------------ .../activities/MainActivity.java | 85 ------------------- 7 files changed, 18 insertions(+), 192 deletions(-) rename app/src/main/java/fr/gouv/etalab/mastodon/activities/{BaseLoginActivity.java => LoginActivity.java} (96%) rename app/src/{fdroid/java/fr.gouv.etalab.mastodon/activities/LoginActivity.java => playstore/java/fr.gouv.etalab.mastodon/activities/MainActivity.java} (77%) delete mode 100644 app/src/safetynet/java/fr.gouv.etalab.mastodon/activities/LoginActivity.java delete mode 100644 app/src/safetynet/java/fr.gouv.etalab.mastodon/activities/MainActivity.java diff --git a/app/build.gradle b/app/build.gradle index 7f01cf3a5..97e9dbf83 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -21,7 +21,7 @@ android { productFlavors { fdroid { } - safetynet { + playstore { } } } @@ -44,6 +44,5 @@ dependencies { implementation 'org.jsoup:jsoup:1.10.3' implementation 'com.github.stom79:country-picker-android:1.2.0' implementation 'com.github.stom79:mytransl:1.2' - safetynetImplementation 'com.google.android.gms:play-services-safetynet:11.6.2' - safetynetImplementation 'io.github.kobakei:ratethisapp:1.2.0' + playstoreImplementation 'io.github.kobakei:ratethisapp:1.2.0' } diff --git a/app/src/fdroid/java/fr.gouv.etalab.mastodon/activities/MainActivity.java b/app/src/fdroid/java/fr.gouv.etalab.mastodon/activities/MainActivity.java index b706ac1cb..fcd637a97 100644 --- a/app/src/fdroid/java/fr.gouv.etalab.mastodon/activities/MainActivity.java +++ b/app/src/fdroid/java/fr.gouv.etalab.mastodon/activities/MainActivity.java @@ -16,10 +16,6 @@ package fr.gouv.etalab.mastodon.activities; public class MainActivity extends BaseMainActivity { - @Override - protected void installProviders() { - // do nothing - } @Override protected void rateThisApp() { diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java index 5bca23f44..d1a61f6c8 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java @@ -151,7 +151,6 @@ public abstract class BaseMainActivity extends AppCompatActivity final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); - installProviders(); final int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); if( theme == Helper.THEME_LIGHT){ @@ -853,7 +852,6 @@ public abstract class BaseMainActivity extends AppCompatActivity new RetrieveInstanceAsyncTask(getApplicationContext(), BaseMainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } - protected abstract void installProviders(); protected abstract void rateThisApp(); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseLoginActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/LoginActivity.java similarity index 96% rename from app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseLoginActivity.java rename to app/src/main/java/fr/gouv/etalab/mastodon/activities/LoginActivity.java index 7f8fc59e0..b420385c7 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseLoginActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/LoginActivity.java @@ -56,7 +56,7 @@ import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor; * Login activity class which handles the connection */ -public abstract class BaseLoginActivity extends AppCompatActivity { +public class LoginActivity extends AppCompatActivity { private String client_id; private String client_secret; @@ -71,7 +71,6 @@ public abstract class BaseLoginActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - installProviders(); SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); if( theme == Helper.THEME_LIGHT){ @@ -133,9 +132,9 @@ public abstract class BaseLoginActivity extends AppCompatActivity { } login_instance.setAdapter(null); ArrayAdapter adapter = - new ArrayAdapter<>(BaseLoginActivity.this, android.R.layout.simple_list_item_1, instances); + new ArrayAdapter<>(LoginActivity.this, android.R.layout.simple_list_item_1, instances); login_instance.setAdapter(adapter); - if( login_instance.hasFocus() && !BaseLoginActivity.this.isFinishing()) + if( login_instance.hasFocus() && !LoginActivity.this.isFinishing()) login_instance.showDropDown(); } catch (JSONException ignored) {isLoadingInstance = false;} @@ -178,7 +177,6 @@ public abstract class BaseLoginActivity extends AppCompatActivity { }); } - protected abstract void installProviders(); @Override protected void onResume(){ @@ -196,7 +194,7 @@ public abstract class BaseLoginActivity extends AppCompatActivity { try { instance = URLEncoder.encode(login_instance.getText().toString().trim(), "utf-8"); } catch (UnsupportedEncodingException e) { - Toast.makeText(BaseLoginActivity.this,R.string.client_error, Toast.LENGTH_LONG).show(); + Toast.makeText(LoginActivity.this,R.string.client_error, Toast.LENGTH_LONG).show(); } final String action = "/api/v1/apps"; final HashMap parameters = new HashMap<>(); @@ -227,7 +225,7 @@ public abstract class BaseLoginActivity extends AppCompatActivity { connectionButton.setEnabled(true); login_two_step.setVisibility(View.VISIBLE); if( client_id_for_webview){ - Intent i = new Intent(BaseLoginActivity.this, WebviewConnectActivity.class); + Intent i = new Intent(LoginActivity.this, WebviewConnectActivity.class); i.putExtra("instance", instance); startActivity(i); } @@ -278,7 +276,7 @@ public abstract class BaseLoginActivity extends AppCompatActivity { editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token); editor.apply(); //Update the account with the token; - new UpdateAccountInfoAsyncTask(BaseLoginActivity.this, token, instance).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new UpdateAccountInfoAsyncTask(LoginActivity.this, token, instance).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } catch (JSONException ignored) {} } }); diff --git a/app/src/fdroid/java/fr.gouv.etalab.mastodon/activities/LoginActivity.java b/app/src/playstore/java/fr.gouv.etalab.mastodon/activities/MainActivity.java similarity index 77% rename from app/src/fdroid/java/fr.gouv.etalab.mastodon/activities/LoginActivity.java rename to app/src/playstore/java/fr.gouv.etalab.mastodon/activities/MainActivity.java index 613d225ba..eca35c05f 100644 --- a/app/src/fdroid/java/fr.gouv.etalab.mastodon/activities/LoginActivity.java +++ b/app/src/playstore/java/fr.gouv.etalab.mastodon/activities/MainActivity.java @@ -14,14 +14,16 @@ * see . */ package fr.gouv.etalab.mastodon.activities; -/** - * Created by Thomas on 23/04/2017. - * Login activity class which handles the connection - */ -public class LoginActivity extends BaseLoginActivity { +import com.kobakei.ratethisapp.RateThisApp; + + +public class MainActivity extends BaseMainActivity { + @Override - protected void installProviders() { - // do nothing + protected void rateThisApp() { + RateThisApp.onCreate(this); + RateThisApp.showRateDialogIfNeeded(this); } -} \ No newline at end of file + +} diff --git a/app/src/safetynet/java/fr.gouv.etalab.mastodon/activities/LoginActivity.java b/app/src/safetynet/java/fr.gouv.etalab.mastodon/activities/LoginActivity.java deleted file mode 100644 index dd0897d91..000000000 --- a/app/src/safetynet/java/fr.gouv.etalab.mastodon/activities/LoginActivity.java +++ /dev/null @@ -1,82 +0,0 @@ -/* Copyright 2017 Thomas Schneider - * - * This file is a part of Mastalab - * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation; either version 3 of the - * License, or (at your option) any later version. - * - * Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even - * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. - * - * You should have received a copy of the GNU General Public License along with Mastalab; if not, - * see . */ -package fr.gouv.etalab.mastodon.activities; - -import android.content.DialogInterface; -import android.content.Intent; - -import com.google.android.gms.common.GooglePlayServicesUtil; -import com.google.android.gms.security.ProviderInstaller; - - -/** - * Created by Thomas on 23/04/2017. - * Login activity class which handles the connection - */ - -public class LoginActivity extends BaseLoginActivity implements ProviderInstaller.ProviderInstallListener { - - private static final int ERROR_DIALOG_REQUEST_CODE = 97; - - @Override - protected void installProviders() { - ProviderInstaller.installIfNeededAsync(this, this); - } - - @Override - public void onProviderInstalled() { - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, - Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (requestCode == ERROR_DIALOG_REQUEST_CODE) { - // Adding a fragment via GooglePlayServicesUtil.showErrorDialogFragment - // before the instance state is restored throws an error. So instead, - // set a flag here, which will cause the fragment to delay until - // onPostResume. - } - } - - - @Override - public void onProviderInstallFailed(int errorCode, Intent recoveryIntent) { - if (GooglePlayServicesUtil.isUserRecoverableError(errorCode)) { - // Recoverable error. Show a dialog prompting the user to - // install/update/enable Google Play services. - GooglePlayServicesUtil.showErrorDialogFragment( - errorCode, - this, - 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 is not available. - onProviderInstallerNotAvailable(); - } - } - - private void onProviderInstallerNotAvailable() { - // This is reached if the provider cannot be updated for some reason. - // App should consider all HTTP communication to be vulnerable, and take - // appropriate action. - } -} \ No newline at end of file diff --git a/app/src/safetynet/java/fr.gouv.etalab.mastodon/activities/MainActivity.java b/app/src/safetynet/java/fr.gouv.etalab.mastodon/activities/MainActivity.java deleted file mode 100644 index 5254030ee..000000000 --- a/app/src/safetynet/java/fr.gouv.etalab.mastodon/activities/MainActivity.java +++ /dev/null @@ -1,85 +0,0 @@ -/* Copyright 2017 Thomas Schneider - * - * This file is a part of Mastalab - * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation; either version 3 of the - * License, or (at your option) any later version. - * - * Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even - * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. - * - * You should have received a copy of the GNU General Public License along with Mastalab; if not, - * see . */ -package fr.gouv.etalab.mastodon.activities; - -import android.content.DialogInterface; -import android.content.Intent; - -import com.google.android.gms.common.GooglePlayServicesUtil; -import com.google.android.gms.security.ProviderInstaller; -import com.kobakei.ratethisapp.RateThisApp; - - -public class MainActivity extends BaseMainActivity - implements ProviderInstaller.ProviderInstallListener { - private static final int ERROR_DIALOG_REQUEST_CODE = 97; - - @Override - protected void rateThisApp() { - RateThisApp.onCreate(this); - RateThisApp.showRateDialogIfNeeded(this); - } - - @Override - protected void installProviders() { - ProviderInstaller.installIfNeededAsync(this, this); - } - - @Override - public void onProviderInstalled() { - - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, - Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (requestCode == ERROR_DIALOG_REQUEST_CODE) { - // Adding a fragment via GooglePlayServicesUtil.showErrorDialogFragment - // before the instance state is restored throws an error. So instead, - // set a flag here, which will cause the fragment to delay until - // onPostResume. - } - } - - - @Override - public void onProviderInstallFailed(int errorCode, Intent recoveryIntent) { - if (GooglePlayServicesUtil.isUserRecoverableError(errorCode)) { - // Recoverable error. Show a dialog prompting the user to - // install/update/enable Google Play services. - GooglePlayServicesUtil.showErrorDialogFragment( - errorCode, - this, - 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 is not available. - onProviderInstallerNotAvailable(); - } - } - - private void onProviderInstallerNotAvailable() { - // This is reached if the provider cannot be updated for some reason. - // App should consider all HTTP communication to be vulnerable, and take - // appropriate action. - } -}