From a91e9809c1a9cf962a3ac03687615a77b91eff2c Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 12 Nov 2019 14:45:45 +0200 Subject: [PATCH] Fix connected apps aidl layers visibility --- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 17 ++++-- .../net/osmand/aidl/OsmandAidlService.java | 9 ++- .../net/osmand/aidl/OsmandAidlServiceV2.java | 9 ++- .../net/osmand/plus/views/AidlMapLayer.java | 60 ++++++++++++------- 4 files changed, 63 insertions(+), 32 deletions(-) diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 84e0cbc7c1..ca36576aa5 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -143,6 +143,7 @@ public class OsmandAidlApi { private static final String AIDL_SEARCH_LON = "aidl_search_lon"; private static final String AIDL_OBJECT_ID = "aidl_object_id"; + private static final String AIDL_PACKAGE_NAME = "aidl_package_name"; private static final String AIDL_ADD_MAP_WIDGET = "aidl_add_map_widget"; private static final String AIDL_REMOVE_MAP_WIDGET = "aidl_remove_map_widget"; @@ -415,14 +416,15 @@ public class OsmandAidlApi { public void onReceive(Context context, Intent intent) { MapActivity mapActivity = mapActivityRef.get(); String layerId = intent.getStringExtra(AIDL_OBJECT_ID); - if (mapActivity != null && layerId != null) { + String packName = intent.getStringExtra(AIDL_PACKAGE_NAME); + if (mapActivity != null && packName != null && layerId != null) { AidlMapLayerWrapper layer = layers.get(layerId); if (layer != null) { OsmandMapLayer mapLayer = mapLayers.get(layerId); if (mapLayer != null) { mapActivity.getMapView().removeLayer(mapLayer); } - mapLayer = new AidlMapLayer(mapActivity, layer); + mapLayer = new AidlMapLayer(mapActivity, layer, packName); mapActivity.getMapView().addLayer(mapLayer, layer.getZOrder()); mapLayers.put(layerId, mapLayer); } @@ -839,10 +841,14 @@ public class OsmandAidlApi { public void registerMapLayers(MapActivity mapActivity) { for (AidlMapLayerWrapper layer : layers.values()) { OsmandMapLayer mapLayer = mapLayers.get(layer.getId()); + String packName = ""; if (mapLayer != null) { + if (mapLayer instanceof AidlMapLayer) { + packName = ((AidlMapLayer) mapLayer).getPackName(); + } mapActivity.getMapView().removeLayer(mapLayer); } - mapLayer = new AidlMapLayer(mapActivity, layer); + mapLayer = new AidlMapLayer(mapActivity, layer, packName); mapActivity.getMapView().addLayer(mapLayer, layer.getZOrder()); mapLayers.put(layer.getId(), mapLayer); } @@ -1093,7 +1099,7 @@ public class OsmandAidlApi { } } - boolean addMapLayer(AidlMapLayerWrapper layer) { + boolean addMapLayer(String packName, AidlMapLayerWrapper layer) { if (layer != null) { if (layers.containsKey(layer.getId())) { updateMapLayer(layer); @@ -1102,6 +1108,7 @@ public class OsmandAidlApi { Intent intent = new Intent(); intent.setAction(AIDL_ADD_MAP_LAYER); intent.putExtra(AIDL_OBJECT_ID, layer.getId()); + intent.putExtra(AIDL_PACKAGE_NAME, packName); app.sendBroadcast(intent); } refreshMap(); @@ -1833,7 +1840,7 @@ public class OsmandAidlApi { return saveConnectedApps(selectedAppMode, connectedApps); } - boolean isAppEnabled(@NonNull String pack) { + public boolean isAppEnabled(@NonNull String pack) { ConnectedApp app = connectedApps.get(pack); if (app == null) { app = new ConnectedApp(pack, true); diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index fe4896f73c..f19e6126a1 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -121,7 +121,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { private OsmandAidlApi getApi(String reason) { LOG.info("Request AIDL API for " + reason); OsmandAidlApi api = getApp().getAidlApi(); - String pack = getApp().getPackageManager().getNameForUid(Binder.getCallingUid()); + String pack = getCallingAppPackName(); if (pack != null && !pack.equals(getApp().getPackageName()) && !api.isAppEnabled(pack)) { return null; } @@ -158,6 +158,10 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { mHandlerThread.quit(); } + private String getCallingAppPackName() { + return getApp().getPackageManager().getNameForUid(Binder.getCallingUid()); + } + private long getCallbackId() { return aidlCallbackId.get(); } @@ -449,7 +453,8 @@ public class OsmandAidlService extends Service implements AidlCallbackListener { public boolean addMapLayer(AddMapLayerParams params) { try { OsmandAidlApi api = getApi("addMapLayer"); - return params != null && api != null && api.addMapLayer(new AidlMapLayerWrapper(params.getLayer())); + String pack = getCallingAppPackName(); + return params != null && api != null && api.addMapLayer(pack, new AidlMapLayerWrapper(params.getLayer())); } catch (Exception e) { handleException(e); return false; diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java index 728c1a0553..1654136fb5 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java @@ -122,7 +122,7 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener private OsmandAidlApi getApi(String reason) { LOG.info("Request AIDL API V2 for " + reason); OsmandAidlApi api = getApp().getAidlApi(); - String pack = getApp().getPackageManager().getNameForUid(Binder.getCallingUid()); + String pack = getCallingAppPackName(); if (pack != null && !pack.equals(getApp().getPackageName()) && !api.isAppEnabled(pack)) { return null; } @@ -159,6 +159,10 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener mHandlerThread.quit(); } + private String getCallingAppPackName() { + return getApp().getPackageManager().getNameForUid(Binder.getCallingUid()); + } + private long getCallbackId() { return aidlCallbackId.get(); } @@ -449,7 +453,8 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener public boolean addMapLayer(AddMapLayerParams params) { try { OsmandAidlApi api = getApi("addMapLayer"); - return params != null && api != null && api.addMapLayer(new AidlMapLayerWrapper(params.getLayer())); + String pack = getCallingAppPackName(); + return params != null && api != null && api.addMapLayer(pack, new AidlMapLayerWrapper(params.getLayer())); } catch (Exception e) { handleException(e); return false; diff --git a/OsmAnd/src/net/osmand/plus/views/AidlMapLayer.java b/OsmAnd/src/net/osmand/plus/views/AidlMapLayer.java index 270581e5dd..509cbeb98e 100644 --- a/OsmAnd/src/net/osmand/plus/views/AidlMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/AidlMapLayer.java @@ -51,6 +51,7 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider private final MapActivity map; private OsmandMapTileView view; + private String packName; private AidlMapLayerWrapper aidlLayer; private Paint pointInnerCircle; @@ -77,9 +78,10 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider private Set imageRequests = new HashSet<>(); private List displayedPoints = new ArrayList<>(); - public AidlMapLayer(MapActivity map, AidlMapLayerWrapper aidlLayer) { + public AidlMapLayer(MapActivity map, AidlMapLayerWrapper aidlLayer, String packName) { this.map = map; this.aidlLayer = aidlLayer; + this.packName = packName; } @Override @@ -137,34 +139,36 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider displayedPoints.clear(); imageRequests.clear(); - canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY()); + if (isAppEnabled()) { + canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY()); - String selectedPointId = getSelectedContextMenuPointId(); - for (AidlMapPointWrapper point : aidlLayer.getPoints()) { - LatLon l = point.getLocation(); - if (l != null) { - int x = (int) tileBox.getPixXFromLatLon(l.getLatitude(), l.getLongitude()); - int y = (int) tileBox.getPixYFromLatLon(l.getLatitude(), l.getLongitude()); - if (tileBox.containsPoint(x, y, bigIconSize)) { - Bitmap image = null; - if (pointsType != PointsType.STANDARD) { - String imageUri = point.getParams().get(AMapPoint.POINT_IMAGE_URI_PARAM); - if (!TextUtils.isEmpty(imageUri)) { - image = pointImages.get(imageUri); - if (image == null) { - imageRequests.add(imageUri); + String selectedPointId = getSelectedContextMenuPointId(); + for (AidlMapPointWrapper point : aidlLayer.getPoints()) { + LatLon l = point.getLocation(); + if (l != null) { + int x = (int) tileBox.getPixXFromLatLon(l.getLatitude(), l.getLongitude()); + int y = (int) tileBox.getPixYFromLatLon(l.getLatitude(), l.getLongitude()); + if (tileBox.containsPoint(x, y, bigIconSize)) { + Bitmap image = null; + if (pointsType != PointsType.STANDARD) { + String imageUri = point.getParams().get(AMapPoint.POINT_IMAGE_URI_PARAM); + if (!TextUtils.isEmpty(imageUri)) { + image = pointImages.get(imageUri); + if (image == null) { + imageRequests.add(imageUri); + } } } + displayedPoints.add(point); + boolean selected = selectedPointId != null && selectedPointId.equals(point.getId()); + drawPoint(canvas, x, y, tileBox, point, image, selected); } - displayedPoints.add(point); - boolean selected = selectedPointId != null && selectedPointId.equals(point.getId()); - drawPoint(canvas, x, y, tileBox, point, image, selected); } } - } - if (imageRequests.size() > 0) { - executeTaskInBackground(new PointImageReaderTask(this), imageRequests.toArray(new String[imageRequests.size()])); + if (imageRequests.size() > 0) { + executeTaskInBackground(new PointImageReaderTask(this), imageRequests.toArray(new String[imageRequests.size()])); + } } mapTextLayer.putData(this, displayedPoints); } @@ -230,6 +234,14 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider return Boolean.parseBoolean(point.getParams().get(AMapPoint.POINT_STALE_LOC_PARAM)); } + private boolean isAppEnabled() { + return map.getMyApplication().getAidlApi().isAppEnabled(packName); + } + + public String getPackName() { + return packName; + } + @Override public void destroyLayer() { } @@ -261,7 +273,9 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider @Override public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List o, boolean unknownLocation) { - getFromPoint(tileBox, point, o); + if (isAppEnabled()) { + getFromPoint(tileBox, point, o); + } } @Override