From f0f7e5e14be3c39c798e024377ac21d876ff7e67 Mon Sep 17 00:00:00 2001 From: Fyodor Ryzhov <53872073+Feodor0090@users.noreply.github.com> Date: Mon, 11 Sep 2023 00:23:14 +0300 Subject: [PATCH 1/8] Create interface to avoid direct type links --- src/mahomaps/map/ILocationAPI.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/mahomaps/map/ILocationAPI.java diff --git a/src/mahomaps/map/ILocationAPI.java b/src/mahomaps/map/ILocationAPI.java new file mode 100644 index 0000000..c7f44a6 --- /dev/null +++ b/src/mahomaps/map/ILocationAPI.java @@ -0,0 +1,12 @@ +package mahomaps.map; + +interface ILocationAPI { + + void setThread(GeoUpdateThread geoUpdateThread); + + void setupListener(); + + double[] getLastKnownCoordinates(); + + void resetProvider() throws Exception; +} \ No newline at end of file From 42fc38fb2392a76e7038bc02462b1540670ce534 Mon Sep 17 00:00:00 2001 From: Fyodor Ryzhov <53872073+Feodor0090@users.noreply.github.com> Date: Mon, 11 Sep 2023 00:26:25 +0300 Subject: [PATCH 2/8] Move locationapi to standalone class --- src/mahomaps/map/GeoUpdateThread.java | 141 +----------------------- src/mahomaps/map/LocationAPI.java | 149 ++++++++++++++++++++++++++ 2 files changed, 151 insertions(+), 139 deletions(-) create mode 100644 src/mahomaps/map/LocationAPI.java diff --git a/src/mahomaps/map/GeoUpdateThread.java b/src/mahomaps/map/GeoUpdateThread.java index bbc984d..3db9aa1 100644 --- a/src/mahomaps/map/GeoUpdateThread.java +++ b/src/mahomaps/map/GeoUpdateThread.java @@ -2,12 +2,6 @@ import java.util.Vector; -import javax.microedition.location.Coordinates; -import javax.microedition.location.Location; -import javax.microedition.location.LocationListener; -import javax.microedition.location.LocationProvider; - -import mahomaps.MahoMapsApp; import mahomaps.screens.MapCanvas; public class GeoUpdateThread extends Thread { @@ -20,7 +14,7 @@ public class GeoUpdateThread extends Thread { * Состояние получения геопозиции. Одно из state-значений. */ public int state; - private LocationAPI locationAPI; + private ILocationAPI locationAPI; public boolean loop = true; public long lastUpdateTime = System.currentTimeMillis(); public String method = null; @@ -40,6 +34,7 @@ public void run() { Class.forName("javax.microedition.location.LocationProvider"); try { locationAPI = new LocationAPI(); + locationAPI.setThread(this); } catch (Exception e) { state = e.toString().indexOf("LocationException") != -1 ? STATE_UNAVAILABLE : STATE_UNSUPPORTED; e.printStackTrace(); @@ -151,136 +146,4 @@ public boolean DrawPoint() { public final static int STATE_OK = 2; public final static int[] states = new int[] { 93, 93, 94, 88, 95, 96 }; - - // для безопасных вызовов - class LocationAPI { - public LocationProvider locationProvider; - - public LocationAPI() throws Exception { - locationProvider = LocationProvider.getInstance(null); - } - - public double[] getLastKnownCoordinates() { - Location location = LocationProvider.getLastKnownLocation(); - if (location == null || !location.isValid()) - return null; - Coordinates coordinates = location.getQualifiedCoordinates(); - if (coordinates == null) - return null; - return new double[] { coordinates.getLatitude(), coordinates.getLongitude() }; - } - - public void setupListener() { - locationProvider.setLocationListener(new LocationAPIListener(), 5, 5, 5); - } - - public void resetProvider() throws Exception { - System.out.println("resetProvider"); - Thread.sleep(5000); - LocationProvider old = locationProvider; - try { - locationProvider = LocationProvider.getInstance(null); - old.setLocationListener(null, 0, 0, 0); - setupListener(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - class LocationAPIListener implements LocationListener { - - public void locationUpdated(LocationProvider provider, Location location) { - // определение кол-ва спутников - String nmea = location.getExtraInfo("application/X-jsr179-location-nmea"); - if (nmea != null) { - String[] sequence = split(nmea, '$'); - int s1 = -1; - int s2 = -1; - for (int i = sequence.length - 1; i >= 0; i--) { - String[] sentence = split(sequence[i], ','); - if (sentence[0].endsWith("GGA")) { - try { - s1 = Integer.parseInt(sentence[7]); - } catch (Exception e) { - s1 = -1; - } - s2 = Math.max(s2, s1); - } else if (sentence[0].endsWith("GSV")) { - try { - s2 = Math.max(s2, Integer.parseInt(sentence[3])); - } catch (Exception e) { - } - } - } - sattelites = s1; - totalSattelitesInView = s2; - } else { - totalSattelitesInView = sattelites = -1; - } - String s = ""; - int t = location.getLocationMethod(); - if ((t & Location.MTE_SATELLITE) == Location.MTE_SATELLITE) { - s = "GPS"; - } - if ((t & Location.MTE_TIMEDIFFERENCE) == Location.MTE_TIMEDIFFERENCE) { - s += "TD"; - } - if ((t & Location.MTE_TIMEOFARRIVAL) == Location.MTE_TIMEOFARRIVAL) { - s += "TOA"; - } - if ((t & Location.MTE_CELLID) == Location.MTE_CELLID) { - s += "CID"; - } - if ((t & Location.MTE_SHORTRANGE) == Location.MTE_SHORTRANGE) { - s += "SR"; - } - if ((t & Location.MTE_ANGLEOFARRIVAL) == Location.MTE_ANGLEOFARRIVAL) { - s += "AOA"; - } - if ((t & Location.MTA_ASSISTED) == Location.MTA_ASSISTED) { - s = "A" + s; - } else if ((t & Location.MTA_UNASSISTED) == Location.MTA_UNASSISTED) { - s = "U" + s; - } - if ((t & Location.MTY_TERMINALBASED) == Location.MTY_TERMINALBASED) { - s = "TB " + s; - } - if ((t & Location.MTY_NETWORKBASED) == Location.MTY_NETWORKBASED) { - s = "NB " + s; - } - method = s.length() == 0 ? null : s; - if (location.isValid()) { - Coordinates coordinates = location.getQualifiedCoordinates(); - if (coordinates.getLatitude() != 0 && coordinates.getLongitude() != 0) { - if (!vibrated) { - try { - MahoMapsApp.display.vibrate(100); - } catch (Exception e) { - } - vibrated = true; - } - positionPoint.lat = coordinates.getLatitude(); - positionPoint.lon = coordinates.getLongitude(); - positionPoint.color = Geopoint.COLOR_RED; - state = STATE_OK; - lastUpdateTime = System.currentTimeMillis(); - MahoMapsApp.GetCanvas().requestRepaint(); - } else { - state = STATE_UNAVAILABLE; - } - } - updateCount++; - } - - public void providerStateChanged(LocationProvider provider, int newState) { - if (newState != LocationProvider.AVAILABLE) { - state = STATE_OK_PENDING; - } - // на случай если изменился провайдер - if (newState == LocationProvider.OUT_OF_SERVICE) { - restart(); - } - } - } - } } diff --git a/src/mahomaps/map/LocationAPI.java b/src/mahomaps/map/LocationAPI.java new file mode 100644 index 0000000..83641ac --- /dev/null +++ b/src/mahomaps/map/LocationAPI.java @@ -0,0 +1,149 @@ +package mahomaps.map; + +import javax.microedition.location.Coordinates; +import javax.microedition.location.Location; +import javax.microedition.location.LocationListener; +import javax.microedition.location.LocationProvider; + +import mahomaps.MahoMapsApp; + +// для безопасных вызовов +class LocationAPI implements ILocationAPI { + + /** + * Geo thread, where this api will work. + */ + private GeoUpdateThread geoUpdateThread; + public LocationProvider locationProvider; + + public LocationAPI() throws Exception { + locationProvider = LocationProvider.getInstance(null); + } + + public void setThread(GeoUpdateThread geoUpdateThread) { + this.geoUpdateThread = geoUpdateThread; + } + + public double[] getLastKnownCoordinates() { + Location location = LocationProvider.getLastKnownLocation(); + if (location == null || !location.isValid()) + return null; + Coordinates coordinates = location.getQualifiedCoordinates(); + if (coordinates == null) + return null; + return new double[] { coordinates.getLatitude(), coordinates.getLongitude() }; + } + + public void setupListener() { + locationProvider.setLocationListener(new LocationAPIListener(), 5, 5, 5); + } + + public void resetProvider() throws Exception { + System.out.println("resetProvider"); + Thread.sleep(5000); + LocationProvider old = locationProvider; + try { + locationProvider = LocationProvider.getInstance(null); + old.setLocationListener(null, 0, 0, 0); + setupListener(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + class LocationAPIListener implements LocationListener { + + public void locationUpdated(LocationProvider provider, Location location) { + // определение кол-ва спутников + String nmea = location.getExtraInfo("application/X-jsr179-location-nmea"); + if (nmea != null) { + String[] sequence = GeoUpdateThread.split(nmea, '$'); + int s1 = -1; + int s2 = -1; + for (int i = sequence.length - 1; i >= 0; i--) { + String[] sentence = GeoUpdateThread.split(sequence[i], ','); + if (sentence[0].endsWith("GGA")) { + try { + s1 = Integer.parseInt(sentence[7]); + } catch (Exception e) { + s1 = -1; + } + s2 = Math.max(s2, s1); + } else if (sentence[0].endsWith("GSV")) { + try { + s2 = Math.max(s2, Integer.parseInt(sentence[3])); + } catch (Exception e) { + } + } + } + geoUpdateThread.sattelites = s1; + geoUpdateThread.totalSattelitesInView = s2; + } else { + geoUpdateThread.totalSattelitesInView = geoUpdateThread.sattelites = -1; + } + String s = ""; + int t = location.getLocationMethod(); + if ((t & Location.MTE_SATELLITE) == Location.MTE_SATELLITE) { + s = "GPS"; + } + if ((t & Location.MTE_TIMEDIFFERENCE) == Location.MTE_TIMEDIFFERENCE) { + s += "TD"; + } + if ((t & Location.MTE_TIMEOFARRIVAL) == Location.MTE_TIMEOFARRIVAL) { + s += "TOA"; + } + if ((t & Location.MTE_CELLID) == Location.MTE_CELLID) { + s += "CID"; + } + if ((t & Location.MTE_SHORTRANGE) == Location.MTE_SHORTRANGE) { + s += "SR"; + } + if ((t & Location.MTE_ANGLEOFARRIVAL) == Location.MTE_ANGLEOFARRIVAL) { + s += "AOA"; + } + if ((t & Location.MTA_ASSISTED) == Location.MTA_ASSISTED) { + s = "A" + s; + } else if ((t & Location.MTA_UNASSISTED) == Location.MTA_UNASSISTED) { + s = "U" + s; + } + if ((t & Location.MTY_TERMINALBASED) == Location.MTY_TERMINALBASED) { + s = "TB " + s; + } + if ((t & Location.MTY_NETWORKBASED) == Location.MTY_NETWORKBASED) { + s = "NB " + s; + } + geoUpdateThread.method = s.length() == 0 ? null : s; + if (location.isValid()) { + Coordinates coordinates = location.getQualifiedCoordinates(); + if (coordinates.getLatitude() != 0 && coordinates.getLongitude() != 0) { + if (!geoUpdateThread.vibrated) { + try { + MahoMapsApp.display.vibrate(100); + } catch (Exception e) { + } + geoUpdateThread.vibrated = true; + } + geoUpdateThread.positionPoint.lat = coordinates.getLatitude(); + geoUpdateThread.positionPoint.lon = coordinates.getLongitude(); + geoUpdateThread.positionPoint.color = Geopoint.COLOR_RED; + geoUpdateThread.state = GeoUpdateThread.STATE_OK; + geoUpdateThread.lastUpdateTime = System.currentTimeMillis(); + MahoMapsApp.GetCanvas().requestRepaint(); + } else { + geoUpdateThread.state = GeoUpdateThread.STATE_UNAVAILABLE; + } + } + geoUpdateThread.updateCount++; + } + + public void providerStateChanged(LocationProvider provider, int newState) { + if (newState != LocationProvider.AVAILABLE) { + geoUpdateThread.state = GeoUpdateThread.STATE_OK_PENDING; + } + // на случай если изменился провайдер + if (newState == LocationProvider.OUT_OF_SERVICE) { + geoUpdateThread.restart(); + } + } + } +} \ No newline at end of file From 6c11518a52191be0486d805ef2c483bf32992031 Mon Sep 17 00:00:00 2001 From: Fyodor Ryzhov <53872073+Feodor0090@users.noreply.github.com> Date: Mon, 11 Sep 2023 00:27:36 +0300 Subject: [PATCH 3/8] Create location api via reflection --- src/mahomaps/map/GeoUpdateThread.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mahomaps/map/GeoUpdateThread.java b/src/mahomaps/map/GeoUpdateThread.java index 3db9aa1..7912e35 100644 --- a/src/mahomaps/map/GeoUpdateThread.java +++ b/src/mahomaps/map/GeoUpdateThread.java @@ -33,7 +33,7 @@ public void run() { try { Class.forName("javax.microedition.location.LocationProvider"); try { - locationAPI = new LocationAPI(); + locationAPI = (ILocationAPI) Class.forName("mahomaps.map.LocationAPI").newInstance(); locationAPI.setThread(this); } catch (Exception e) { state = e.toString().indexOf("LocationException") != -1 ? STATE_UNAVAILABLE : STATE_UNSUPPORTED; From 8fb005ca0ec5ce9e65bcefd546ef216633e548f5 Mon Sep 17 00:00:00 2001 From: Fyodor Ryzhov <53872073+Feodor0090@users.noreply.github.com> Date: Mon, 11 Sep 2023 00:34:00 +0300 Subject: [PATCH 4/8] Delete location classes from package --- build.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/build.sh b/build.sh index 8660c47..5e9700d 100755 --- a/build.sh +++ b/build.sh @@ -96,6 +96,16 @@ fi echo "Build done!" ./${APP}.jar +echo "Removing location classes..." +rm ./classes/mahomaps/map/LocationAPI* + +echo "Jaring preverified class files..." +${JAR} cmf ${MANIFEST} ${APP}_no_geo.jar -C ./classes . + +if [ -d ${RES} ] ; then + ${JAR} uf ${APP}_no_geo.jar -C ${RES} . +fi + echo Optimizing ${APP} chmod +x ${PROGUARD} touch cf.cfg From f85bdd6ade59dd0202e5c659b3fa218844ee752f Mon Sep 17 00:00:00 2001 From: Fyodor Ryzhov <53872073+Feodor0090@users.noreply.github.com> Date: Mon, 11 Sep 2023 00:34:11 +0300 Subject: [PATCH 5/8] Make CI upload no_geo jars --- .github/workflows/build.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5aba66b..8062747 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,6 +24,11 @@ jobs: with: name: obf.zip path: ${{ github.workspace }}/mm_v1_obf.jar + - name: Upload no_geo jar + uses: actions/upload-artifact@v2 + with: + name: obf.zip + path: ${{ github.workspace }}/mm_v1_no_geo.jar - name: Upload obf mappings uses: actions/upload-artifact@v2 with: From ca8f77e6915cfa540c3ccf70c8e014b321b8aea9 Mon Sep 17 00:00:00 2001 From: Fyodor Ryzhov <53872073+Feodor0090@users.noreply.github.com> Date: Mon, 11 Sep 2023 00:37:05 +0300 Subject: [PATCH 6/8] Forbid `LocationAPI` obfuscation --- proguard.basecfg | 1 + 1 file changed, 1 insertion(+) diff --git a/proguard.basecfg b/proguard.basecfg index b97f8b0..375d389 100644 --- a/proguard.basecfg +++ b/proguard.basecfg @@ -27,4 +27,5 @@ } -keep public class * extends javax.microedition.midlet.MIDlet +-keep public class * extends mahomaps.map.ILocationAPI From 72d8423d2d1460a2c76c966c92c212fe73c26a9f Mon Sep 17 00:00:00 2001 From: Fyodor Ryzhov <53872073+Feodor0090@users.noreply.github.com> Date: Mon, 11 Sep 2023 00:40:53 +0300 Subject: [PATCH 7/8] Fix name conflict --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8062747..db53079 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,7 +27,7 @@ jobs: - name: Upload no_geo jar uses: actions/upload-artifact@v2 with: - name: obf.zip + name: base_no_geo.zip path: ${{ github.workspace }}/mm_v1_no_geo.jar - name: Upload obf mappings uses: actions/upload-artifact@v2 From 26089a3b2774d1e7b108725d922bfb93bbaf3524 Mon Sep 17 00:00:00 2001 From: Arman Jussupgaliyev <43963888+shinovon@users.noreply.github.com> Date: Wed, 13 Sep 2023 19:54:42 +0500 Subject: [PATCH 8/8] Fix proguard config --- proguard.basecfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proguard.basecfg b/proguard.basecfg index 375d389..8205638 100644 --- a/proguard.basecfg +++ b/proguard.basecfg @@ -27,5 +27,5 @@ } -keep public class * extends javax.microedition.midlet.MIDlet --keep public class * extends mahomaps.map.ILocationAPI +-keep class * extends mahomaps.map.ILocationAPI