Skip to content

Commit

Permalink
Convert to new data format on the fly
Browse files Browse the repository at this point in the history
  • Loading branch information
cylonid committed Oct 29, 2022
1 parent 74f5714 commit 5d45a14
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 20 deletions.
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,32 @@

## Download Options
[![IzzyOnDroid Download Badge](graphics/IzzyOnDroid.png)](https://apt.izzysoft.de/fdroid/index/apk/com.cylonid.nativealpha)
[![APK Download Badge](graphics/apk_badge.png)](https://github.com/cylonid/NativeAlphaForAndroid/releases/download/v1.2.0/NativeAlpha-standard-universal-release-v1.2.0.apk)
[![APK Download Badge](graphics/apk_badge.png)](https://github.com/cylonid/NativeAlphaForAndroid/releases/download/v1.3.0/NativeAlpha-standard-universal-release-v1.3.0.apk)
[![Google Play Download Badge](graphics/google_play.png)](https://play.google.com/store/apps/details?id=com.cylonid.nativealpha)
### Paid Download
[![Google Play Download Badge](graphics/google_play.png)](https://play.google.com/store/apps/details?id=com.cylonid.nativealpha.pro)

## Paid Features
* Sandbox containers: Web Apps are loaded in fully separated sandboxes, cookies or other data are not shared with other Web Apps
* Kiosk Mode: Fullscreen with menubars hidden
* Biometric Access Protection: For every Web App, you can enable access protection (Fingerprint + fallback to lockscreen PIN)
* Experimental "Force Dark Mode" also available for websites (configurable with respect to day-time)

## Latest Changes (v1.2.0)
* Support for mailto and tel hyperlinks
* Support for file picker dialogs
* Support for DRM-protected content
* Support for camera and microphone access
* Enhanced support for video playback
* Enabled for usage with non-internet addresses
* Color theme will from now on always follow system settings
## Latest Changes (v1.3.0)

* Resolved unusual going back behaviour on certain websites
* Added support for Google OAuth-enabled sites
* Context Menu: Long-press context menu with several options (Share, going back/forward, reload...)
* Added pinch-to-zoom setting
* Added option to freely set start URL of Web Apps to support non-standard URLs (expert settings)
* Build for x86 and x86_64 platform included
* Several bugfixes and general improvements

### Native Alpha Plus

* Biometric Access Protection: For every Web App, you can enable access protection (Fingerprint + fallback to lockscreen PIN)
* Further enhancements for Dark Mode


## FAQ
*Q: Why would I need this app if any mobile browser can do the same?*
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ android {
applicationId "com.cylonid.nativealpha"
minSdkVersion 26
targetSdkVersion 32
versionCode 1301
versionCode 1303
versionName "1.3.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
47 changes: 37 additions & 10 deletions app/src/main/java/com/cylonid/nativealpha/model/DataManager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.cylonid.nativealpha.model;

import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.util.Base64;
Expand Down Expand Up @@ -33,10 +32,14 @@

public class DataManager {

// Corresponds to app release version
private static final int LEGACY_DATA_FORMAT = 1000;

private static final String SHARED_PREF_KEY = "WEBSITEDATA";
private static final String INTRO_SCREENS = "com.cylonid.nativealpha.shownIntroScreens";
private static final String GENERAL_INFO = "com.cylonid.nativealpha.GENERAL_INFO";
public static final String EULA_ACCEPTED = "eulaAccepted";
public static final String LAST_SHOWN_UPDATE = "lastShownUpdate";
public static final String DATA_FORMAT = "dataFormat";

private static final String SHARED_PREF_LEGACY_KEY = "GLOBALSETTINGS";
private static final String shared_pref_max_id = "MAX_ID";
Expand Down Expand Up @@ -98,25 +101,33 @@ public void saveWebAppData() {
editor.apply();
}

public void setDataFormat(int dataFormat) {
getGeneralInfo().edit().putInt(DATA_FORMAT, dataFormat).apply();
}

public int getDataFormat() {
return getGeneralInfo().getInt(DATA_FORMAT, LEGACY_DATA_FORMAT);
}

public boolean getEulaData() {
return getIntroScreensData().getBoolean(EULA_ACCEPTED, false);
return getGeneralInfo().getBoolean(EULA_ACCEPTED, false);
}

public int getLastShownUpdate() {
return getIntroScreensData().getInt(LAST_SHOWN_UPDATE, 0);
return getGeneralInfo().getInt(LAST_SHOWN_UPDATE, 0);
}

public void setEulaData(boolean newValue) {
getIntroScreensData().edit().putBoolean(EULA_ACCEPTED, newValue).apply();
getGeneralInfo().edit().putBoolean(EULA_ACCEPTED, newValue).apply();
}

public void setLastShownUpdate(int newValue) {
getIntroScreensData().edit().putInt(LAST_SHOWN_UPDATE, newValue).apply();
getGeneralInfo().edit().putInt(LAST_SHOWN_UPDATE, newValue).apply();
}

private SharedPreferences getIntroScreensData() {
private SharedPreferences getGeneralInfo() {
Utility.Assert(App.getAppContext() != null, "App.getAppContext() null before saving sharedpref");
return App.getAppContext().getSharedPreferences(INTRO_SCREENS, MODE_PRIVATE);
return App.getAppContext().getSharedPreferences(GENERAL_INFO, MODE_PRIVATE);

}

Expand Down Expand Up @@ -144,14 +155,16 @@ public void loadAppData() {
appdata = App.getAppContext().getSharedPreferences(SHARED_PREF_KEY, MODE_PRIVATE);
//Webapp data
if (appdata.contains(shared_pref_webappdata)) {

GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(WebApp.class, new WebAppInstanceCreator());
Gson gson = gsonBuilder.create();
String json = appdata.getString(shared_pref_webappdata, "");
ArrayList<WebApp> new_websites = gson.fromJson(json, new TypeToken<ArrayList<WebApp>>() {}.getType());
int oldDataFormat = DataVersionConverter.getDataFormat(json);
String currentDataFormattedJson = this.checkDataFormat(oldDataFormat, json);
ArrayList<WebApp> new_websites = gson.fromJson(currentDataFormattedJson, new TypeToken<ArrayList<WebApp>>() {}.getType());
checkIfWebAppIdsCollide(websites, new_websites);
websites = new_websites;
if(oldDataFormat != DataVersionConverter.getDataFormat(currentDataFormattedJson)) this.saveWebAppData();
}

max_assigned_ID = appdata.getInt(shared_pref_max_id, max_assigned_ID);
Expand Down Expand Up @@ -332,6 +345,18 @@ else if (v instanceof String)
return result;
}

private String checkDataFormat(int dataFormat, String jsonInput) {
switch(dataFormat) {
case LEGACY_DATA_FORMAT:
String convertedInput = DataVersionConverter.convertToDataFormat(jsonInput, DataVersionConverter.getLegacyTo1300Map());
this.setDataFormat(1300);
return convertedInput;
default:
case 1300: // Current data format => corresponding to app release version
return jsonInput;
}
}

public WebApp getSuccessor(int i) {
int INVALID = websites.size();
int neighbor = i;
Expand Down Expand Up @@ -368,5 +393,7 @@ public WebApp getPredecessor(int i) {
// else
// return websites.get(websites.size() - 1);
}


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.cylonid.nativealpha.model;

import android.service.autofill.DateValueSanitizer;

import java.util.HashMap;
import java.util.Map;

public class DataVersionConverter {

public static String convertToDataFormat(String input, Map<String, String> map) {
for (Map.Entry<String, String> entry : map.entrySet()) {
input = input.replace(DataVersionConverter.formatAsJsonKey(entry.getKey()), DataVersionConverter.formatAsJsonKey(entry.getValue()));
}
return input;
}

public static int getDataFormat(String input) {
if(input.contains(DataVersionConverter.formatAsJsonKey("base_url"))) return 1000;
if(input.contains(DataVersionConverter.formatAsJsonKey("baseUrl"))) return 1300;

return 0;
}
private static String formatAsJsonKey(String key) {
return "\"" + key + "\":";
}

public static Map<String, String> getLegacyTo1300Map() {
Map<String, String> map = new HashMap<>();
map.put("base_url","baseUrl");
map.put("override_global_settings","isOverrideGlobalSettings");
map.put("open_url_external","isOpenUrlExternal");
map.put("allow_cookies","isAllowCookies");
map.put("allow_third_p_cookies","isAllowThirdPartyCookies");
map.put("restore_page","isRestorePage");
map.put("allow_js","isAllowJs");
map.put("active_entry","isActiveEntry");
map.put("request_desktop","isRequestDesktop");
map.put("clear_cache","isClearCache");
map.put("use_adblock","isUseAdblock");
map.put("send_savedata_request","isSendSavedataRequest");
map.put("block_images","isBlockImages");
map.put("allow_http","isAllowHttp");
map.put("allow_location_access","isAllowLocationAccess");
map.put("user_agent","userAgent");
map.put("use_custom_user_agent","isUseCustomUserAgent");
map.put("autoreload","isAutoreload");
map.put("time_autoreload","timeAutoreload");
map.put("force_dark_mode","isForceDarkMode");
map.put("use_timespan_dark_mode","isUseTimespanDarkMode");
map.put("timespan_dark_mode_begin","timespanDarkModeBegin");
map.put("timespan_dark_mode_end","timespanDarkModeEnd");
map.put("ignore_ssl_errors","isIgnoreSslErrors");
map.put("show_expert_settings","isShowExpertSettings");
map.put("safe_browsing","isSafeBrowsing");
map.put("block_third_party_requests","isBlockThirdPartyRequests");
map.put("container_id","containerId");
map.put("use_container","isUseContainer");
map.put("drm_allowed","isDrmAllowed");
map.put("show_fullscreen","isShowFullscreen");
map.put("keep_awake","isKeepAwake");
map.put("camera_permission","isCameraPermission");
map.put("microphone_permission","isMicrophonePermission");
return map;
}
}

0 comments on commit 5d45a14

Please sign in to comment.