Skip to content

Commit

Permalink
Merge pull request #211 from SecUSo/remove-api-keys
Browse files Browse the repository at this point in the history
Remove api keys and updates to API 3.0
  • Loading branch information
coderPaddyS authored May 27, 2024
2 parents 027bdd8 + ad51832 commit 80aaef9
Show file tree
Hide file tree
Showing 20 changed files with 102 additions and 106 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- name: Run unit tests
run: ./gradlew test
- name: Android Test Report
Expand Down Expand Up @@ -46,9 +46,9 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- name: Build debug APK
run: ./gradlew assembleDebug
29 changes: 21 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ def keysFile = rootProject.file('keys.properties')

android {

compileSdkVersion 32
compileSdk 34
namespace "org.secuso.privacyfriendlyweather"

defaultConfig {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
applicationId "org.secuso.privacyfriendlyweather"
minSdkVersion 17
targetSdkVersion 32
versionCode 17
versionName "3.1.1"
targetSdkVersion 34
versionCode 18
versionName "3.1.2"
multiDexEnabled = true

if (keysFile.exists()) {
def keys = new Properties()
Expand All @@ -29,12 +31,16 @@ android {
i++
}

if (keyString == "") {
keyString = null
}

buildConfigField "String[]", "DEFAULT_API_KEYS", "{" + keyString + "}"
} else {
buildConfigField "String[]", "DEFAULT_API_KEYS", "{null}"
}

buildConfigField "String", "BASE_URL", "\"https://api.openweathermap.org/data/2.5/\""
buildConfigField "String", "BASE_URL", "\"https://api.openweathermap.org/data/3.0/\""

javaCompileOptions {
annotationProcessorOptions {
Expand Down Expand Up @@ -62,6 +68,10 @@ android {
}
}

buildFeatures {
buildConfig true
}

buildTypes {
release {
minifyEnabled false
Expand Down Expand Up @@ -97,12 +107,15 @@ dependencies {
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.readystatesoftware.sqliteasset:sqliteassethelper:2.0.1'

implementation 'androidx.room:room-runtime:2.4.3'
annotationProcessor 'androidx.room:room-compiler:2.4.3'
androidTestImplementation 'androidx.room:room-testing:2.4.3'
implementation 'androidx.room:room-runtime:2.6.1'
annotationProcessor 'androidx.room:room-compiler:2.6.1'
androidTestImplementation 'androidx.room:room-testing:2.6.1'

def work_version = "2.7.1"
implementation "androidx.work:work-runtime:$work_version"
implementation "androidx.work:work-runtime-ktx:$work_version"
androidTestImplementation "androidx.work:work-testing:$work_version"

def multidex_version = "2.0.1"
implementation("androidx.multidex:multidex:$multidex_version")
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package org.secuso.privacyfriendlyweather;

import android.app.Application;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.multidex.MultiDexApplication;
import androidx.work.Configuration;

import org.secuso.privacyfriendlybackup.api.pfa.BackupManager;
import org.secuso.privacyfriendlyweather.backup.BackupCreator;
import org.secuso.privacyfriendlyweather.backup.BackupRestorer;


public class PFAWeatherApplication extends Application implements Configuration.Provider {
public class PFAWeatherApplication extends MultiDexApplication implements Configuration.Provider {

@Override
public void onCreate() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.secuso.privacyfriendlyweather.activities;

import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.method.LinkMovementMethod;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand All @@ -19,6 +22,7 @@
import org.secuso.privacyfriendlyweather.database.data.CurrentWeatherData;
import org.secuso.privacyfriendlyweather.database.data.Forecast;
import org.secuso.privacyfriendlyweather.database.data.WeekForecast;
import org.secuso.privacyfriendlyweather.preferences.AppPreferencesManager;
import org.secuso.privacyfriendlyweather.ui.updater.IUpdateableCityUI;
import org.secuso.privacyfriendlyweather.ui.updater.ViewUpdater;
import org.secuso.privacyfriendlyweather.ui.viewPager.WeatherPagerAdapter;
Expand All @@ -27,6 +31,7 @@

public class ForecastCityActivity extends BaseActivity implements IUpdateableCityUI {
private WeatherPagerAdapter pagerAdapter;
private AppPreferencesManager appPreferencesManager;

private MenuItem refreshActionButton;
private MenuItem rainviewerButton;
Expand Down Expand Up @@ -73,7 +78,6 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_forecast_city);
overridePendingTransition(0, 0);

//cityId = getIntent().getIntExtra("cityId", -1); //done in onResume

initResources();
Expand Down Expand Up @@ -113,6 +117,20 @@ public void onPageScrollStateChanged(int state) {}
}
}

@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);

if (appPreferencesManager.getOWMApiKey(this).equals(getString(R.string.settings_API_key_default))) {
TextView textView = new AlertDialog.Builder(this).setTitle(getString(R.string.dialog_app_api_deprecation_title))
.setMessage(R.string.dialog_app_api_deprecation_description)
.setNeutralButton(android.R.string.ok, null)
.show()
.findViewById(android.R.id.message);
textView.setMovementMethod(LinkMovementMethod.getInstance());
}
}

public void updatePageTitle() {
if (getSupportActionBar() != null && pagerAdapter.getCount() > 0) {
getSupportActionBar().setTitle(pagerAdapter.getPageTitleForActionBar(viewPager.getCurrentItem()));
Expand All @@ -129,6 +147,7 @@ private void initResources() {
viewPager = findViewById(R.id.viewPager);
pagerAdapter = new WeatherPagerAdapter(this, getSupportFragmentManager());
noCityText = findViewById(R.id.noCitySelectedText);
appPreferencesManager = new AppPreferencesManager(PreferenceManager.getDefaultSharedPreferences(this));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

public class BackupCreator implements IBackupCreator {
@Override
public void writeBackup(@NotNull Context context, @NotNull OutputStream outputStream) {
public boolean writeBackup(@NotNull Context context, @NotNull OutputStream outputStream) {
// lock application, so no changes can be made as long as this backup is created
// depending on the size of the application - this could take a bit

Expand Down Expand Up @@ -85,6 +85,6 @@ public void writeBackup(@NotNull Context context, @NotNull OutputStream outputSt
}

Log.d("PFA BackupCreator", "Backup created successfully");

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -248,30 +248,6 @@ public boolean usingPersonalKey(Context context) {
}

public String getOWMApiKey(Context context) {
String noKeyString = context.getString(R.string.settings_API_key_default);
String prefValue = preferences.getString("API_key_value", noKeyString);
if (!prefValue.equals(noKeyString)) {
return prefValue;
} else {
String availableKeysString = preferences.getString("availble_keys", "");
List<String> availableKeys = new ArrayList<>(Arrays.asList(availableKeysString.split(",")));

SharedPreferences.Editor editor = preferences.edit();

if(availableKeys.isEmpty() || availableKeysString.isEmpty()) {
// fill list with shuffled keys
availableKeys = new ArrayList<>(Arrays.asList(BuildConfig.DEFAULT_API_KEYS));
Collections.shuffle(availableKeys);
}

// get result and remove from possible keys
String result = availableKeys.get(0);
availableKeys.remove(result);
editor.putString("availble_keys", String.join(",", availableKeys)).commit();

return result;
}
return preferences.getString("API_key_value", context.getString(R.string.settings_API_key_default));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,7 @@ public static void updateView(Context context, AppWidgetManager appWidgetManager

Intent intent = new Intent(context, ForecastCityActivity.class);
intent.putExtra("cityId", city.getCityId());
PendingIntent pendingIntent;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_IMMUTABLE);
} else {
pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, 0);
}
PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_IMMUTABLE);

views.setOnClickPendingIntent(R.id.widget1day_layout, pendingIntent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,7 @@ public static void updateView(Context context, AppWidgetManager appWidgetManager

Intent intent = new Intent(context, ForecastCityActivity.class);
intent.putExtra("cityId", city.getCityId());
PendingIntent pendingIntent;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_IMMUTABLE);
} else {
pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, 0);
}
PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_IMMUTABLE);

views.setOnClickPendingIntent(R.id.widget5day_layout, pendingIntent);
// Instruct the widget manager to update the widget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,8 @@ public static void updateView(Context context, AppWidgetManager appWidgetManager

Intent intent = new Intent(context, ForecastCityActivity.class);
intent.putExtra("cityId", city.getCityId());
PendingIntent pendingIntent;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_IMMUTABLE);
} else {
pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, 0);
}
PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_IMMUTABLE);


views.setOnClickPendingIntent(R.id.widget1day_layout, pendingIntent);
// Instruct the widget manager to update the widget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,7 @@ public static void updateView(Context context, AppWidgetManager appWidgetManager

Intent intent = new Intent(context, ForecastCityActivity.class);
intent.putExtra("cityId", city.getCityId());
PendingIntent pendingIntent;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_IMMUTABLE);
} else {
pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, 0);
}
PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_IMMUTABLE);

views.setOnClickPendingIntent(R.id.widget3day_layout, pendingIntent);

Expand Down
10 changes: 9 additions & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
<string name="settings_API_key_default">Es wurde kein API Key bereitgestellt</string>
<string name="settings_confirm_content_API_key_reset">Wirklich den standard API Key wiederherstellen?</string>
<string name="settings_confirm_title_API_key_reset">API Key zurücksetzen</string>
<string name="settings_description_API">Privacy Friendly Wetter erhält die Wetterdaten von dem freien Service openweathermap.org. Dieser Service ist auf 1000 Anfragen pro Tag beschränkt. Sie könnten ihren eigenen API Key registrieren, um ihre eigenen 1000 Anfragen pro Tag zu bekommen. Andernfalls werden die Anfragen zwischen allen Benutzern von Privacy Friendly Wetter geteilt.</string>
<string name="settings_description_API">Privacy Friendly Wetter erhält die Wetterdaten von dem freien Service openweathermap.org. Dieser Service ist auf 1000 Anfragen pro Tag beschränkt. Sie müssen ihren eigenen API Key registrieren, um ihre 1000 Anfragen pro Tag zu bekommen.</string>
<string name="settings_interval_summary">Setzen Sie das Interval der automatischen Updates</string>
<string name="settings_intervals">Intervalle</string>
<string name="settings_title_API">API Schlüssel</string>
Expand Down Expand Up @@ -204,4 +204,12 @@
<string name="help_permission_bindservice_description">Die Wetter-App ermöglicht Backups mit unserer Privacy Friendly Backup-App. Um diese Funktionalität zu aktivieren, wird die Berechtigung zum Verbinden mit Diensten benötigt.</string>
<string name="owm_about">Wetterdaten zur Verfügung gestellt von:</string>
<string name="owm_logo_copyright">"Das OpenWeatherMap Logo ist lizensiert unter\n<a href="https://creativecommons.org/licenses/by-sa/3.0/deed.en">Creative Commons BY-SA.</a>"</string>
<string name="dialog_app_api_deprecation_title">App-Veraltung und API-Änderungen</string>
<string name="dialog_app_api_deprecation_description">
Am 1. Juni 2024 deaktiviert Open Weather seine alte API, daher sind die alten API-Schlüssel nicht mehr verwendbar.
Da die Privacy Friendly Weather App veraltet ist, werden wir uns nicht an API-Änderungen anpassen und die App wird nicht wie erwartet funktionieren.

Wenn Sie diese App weiterhin verwenden möchten, besorgen Sie sich Ihren eigenen API-Schlüssel, indem Sie der <a href="https://openweathermap.org/appid">OpenWeather-Anweisung</a> folgen.
Nachdem Sie Ihren API-Schlüssel erhalten haben, legen Sie ihn in den Einstellungen fest.
</string>
</resources>
5 changes: 4 additions & 1 deletion app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
<string name="settings_API_key_default">Nessuna chiave API fornita</string>
<string name="settings_confirm_content_API_key_reset">Volete davvero ripristinare la chiave API di default?</string>
<string name="settings_confirm_title_API_key_reset">Reimpostare la chiave API</string>
<string name="settings_description_API">Privacy Friendly Weather riceve i dati meteo dal servizio gratuito openweathermap.org. Questo servizio è limitato a 1000 richieste al giorno. È possibile registrare la propria chiave API per ottenere le proprie 1000 richieste al giorno. In caso contrario, le richieste sono condivise tra tutti gli utenti di Privacy Friendly Weather.</string>
<string name="settings_description_API">Privacy Friendly Weather riceve i dati dal servizio gratuito di openweathermap.org. Questo servizio è limitato a 1000 chiamate al giorno. Devi registrare gratuitamente la tua chiave API per ricevere le tue 1000 chiamate.</string>
<string name="settings_interval_summary">Impostare l\'intervallo di aggiornamento automatico</string>
<string name="settings_intervals">Intervalli</string>
<string name="settings_title_API">API Chiave</string>
Expand Down Expand Up @@ -203,4 +203,7 @@
<string name="help_permission_bindservice_description">L\'app meteo abilita i backup con la nostra app Privacy Friendly Backup. Per abilitare questa funzionalità, è necessario il permesso di legarsi ai servizi.</string>
<string name="owm_about">Dati meteo forniti da:</string>
<string name="owm_logo_copyright">"Il logo di OpenWeatherMap è concesso in licenza sotto\n<a href="https://creativecommons.org/licenses/by-sa/3.0/deed.en">la licenza Creative Commons BY-SA.</a>"</string>
<string name="dialog_app_api_deprecation_title">Deprecazione dell\'app e modifiche all\'API</string>
<string name="dialog_app_api_deprecation_description">Dal 1 giugno 2024 Open Weather disattiva la sua vecchia API, pertanto le vecchie chiavi API non sono più utilizzabili. \n Poiché l\'app Meteo rispettosa della privacy è deprecata, non ci adatteremo ad alcuna modifica dell\'API e l\'app non funzionerà come previsto. Se vuoi continuare a utilizzare questa app, ottieni la tua chiave API seguendo le <a href="https://openweathermap.org/appid">istruzioni OpenWeather</a>. Dopo aver ottenuto la chiave API, impostala nelle impostazioni.
</string>
</resources>
10 changes: 9 additions & 1 deletion app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
<string name="settings_API_key_default">No API Key provided</string>
<string name="settings_confirm_content_API_key_reset">Do you really want to reset to the default API key?</string>
<string name="settings_confirm_title_API_key_reset">Reset API key</string>
<string name="settings_description_API">Privacy Friendly Weather receives data from the free service of openweathermap.org. This service is limited to 1000 calls per day. You could register your own API key for free to get your own 1000 calls. Otherwise, calls are shared between all users of Privacy Friendly Weather.</string>
<string name="settings_description_API">Privacy Friendly Weather receives data from the free service of openweathermap.org. This service is limited to 1000 calls per day. You have to register your own API key for free to get your 1000 calls.</string>
<string name="settings_interval_summary">Set the interval of automatic updates</string>
<string name="settings_intervals">Intervals</string>
<string name="settings_title_API">API Key</string>
Expand Down Expand Up @@ -257,5 +257,13 @@
<string name="help_permission_bindservice_description">The weather app enables backups with our Privacy Friendly Backup app. To enable this functionality, the permission to bind with services is needed.</string>
<string name="owm_about">Weather data provided by:</string>
<string name="owm_logo_copyright">"OpenWeatherMap logo is licensed under\n<a href="https://creativecommons.org/licenses/by-sa/3.0/deed.en">Creative Commons BY-SA license.</a>"</string>
<string name="dialog_app_api_deprecation_title">アプリの非推奨と API の変更</string>
<string name="dialog_app_api_deprecation_description">
2024 年 6 月 1 日に、Open Weather は古い API を非アクティブ化するため、古い API キーは使用できなくなります。
プライバシー フレンドリーな天気アプリは廃止されるため、API の変更に対応できず、アプリは期待どおりに機能しません。

このアプリを引き続き使用する場合は、<a href="https://openweathermap.org/appid">OpenWeather の手順</a>に従って独自の API キーを取得してください。
APIキーを取得したら、設定でAPIキーを設定します。
</string>

</resources>
Loading

0 comments on commit 80aaef9

Please sign in to comment.