Fix connected apps aidl layers visibility

This commit is contained in:
Chumva 2019-11-12 14:45:45 +02:00
parent ac1ddcae11
commit a91e9809c1
4 changed files with 63 additions and 32 deletions

View file

@ -143,6 +143,7 @@ public class OsmandAidlApi {
private static final String AIDL_SEARCH_LON = "aidl_search_lon"; 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_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_ADD_MAP_WIDGET = "aidl_add_map_widget";
private static final String AIDL_REMOVE_MAP_WIDGET = "aidl_remove_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) { public void onReceive(Context context, Intent intent) {
MapActivity mapActivity = mapActivityRef.get(); MapActivity mapActivity = mapActivityRef.get();
String layerId = intent.getStringExtra(AIDL_OBJECT_ID); 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); AidlMapLayerWrapper layer = layers.get(layerId);
if (layer != null) { if (layer != null) {
OsmandMapLayer mapLayer = mapLayers.get(layerId); OsmandMapLayer mapLayer = mapLayers.get(layerId);
if (mapLayer != null) { if (mapLayer != null) {
mapActivity.getMapView().removeLayer(mapLayer); mapActivity.getMapView().removeLayer(mapLayer);
} }
mapLayer = new AidlMapLayer(mapActivity, layer); mapLayer = new AidlMapLayer(mapActivity, layer, packName);
mapActivity.getMapView().addLayer(mapLayer, layer.getZOrder()); mapActivity.getMapView().addLayer(mapLayer, layer.getZOrder());
mapLayers.put(layerId, mapLayer); mapLayers.put(layerId, mapLayer);
} }
@ -839,10 +841,14 @@ public class OsmandAidlApi {
public void registerMapLayers(MapActivity mapActivity) { public void registerMapLayers(MapActivity mapActivity) {
for (AidlMapLayerWrapper layer : layers.values()) { for (AidlMapLayerWrapper layer : layers.values()) {
OsmandMapLayer mapLayer = mapLayers.get(layer.getId()); OsmandMapLayer mapLayer = mapLayers.get(layer.getId());
String packName = "";
if (mapLayer != null) { if (mapLayer != null) {
if (mapLayer instanceof AidlMapLayer) {
packName = ((AidlMapLayer) mapLayer).getPackName();
}
mapActivity.getMapView().removeLayer(mapLayer); mapActivity.getMapView().removeLayer(mapLayer);
} }
mapLayer = new AidlMapLayer(mapActivity, layer); mapLayer = new AidlMapLayer(mapActivity, layer, packName);
mapActivity.getMapView().addLayer(mapLayer, layer.getZOrder()); mapActivity.getMapView().addLayer(mapLayer, layer.getZOrder());
mapLayers.put(layer.getId(), mapLayer); 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 (layer != null) {
if (layers.containsKey(layer.getId())) { if (layers.containsKey(layer.getId())) {
updateMapLayer(layer); updateMapLayer(layer);
@ -1102,6 +1108,7 @@ public class OsmandAidlApi {
Intent intent = new Intent(); Intent intent = new Intent();
intent.setAction(AIDL_ADD_MAP_LAYER); intent.setAction(AIDL_ADD_MAP_LAYER);
intent.putExtra(AIDL_OBJECT_ID, layer.getId()); intent.putExtra(AIDL_OBJECT_ID, layer.getId());
intent.putExtra(AIDL_PACKAGE_NAME, packName);
app.sendBroadcast(intent); app.sendBroadcast(intent);
} }
refreshMap(); refreshMap();
@ -1833,7 +1840,7 @@ public class OsmandAidlApi {
return saveConnectedApps(selectedAppMode, connectedApps); return saveConnectedApps(selectedAppMode, connectedApps);
} }
boolean isAppEnabled(@NonNull String pack) { public boolean isAppEnabled(@NonNull String pack) {
ConnectedApp app = connectedApps.get(pack); ConnectedApp app = connectedApps.get(pack);
if (app == null) { if (app == null) {
app = new ConnectedApp(pack, true); app = new ConnectedApp(pack, true);

View file

@ -121,7 +121,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
private OsmandAidlApi getApi(String reason) { private OsmandAidlApi getApi(String reason) {
LOG.info("Request AIDL API for " + reason); LOG.info("Request AIDL API for " + reason);
OsmandAidlApi api = getApp().getAidlApi(); OsmandAidlApi api = getApp().getAidlApi();
String pack = getApp().getPackageManager().getNameForUid(Binder.getCallingUid()); String pack = getCallingAppPackName();
if (pack != null && !pack.equals(getApp().getPackageName()) && !api.isAppEnabled(pack)) { if (pack != null && !pack.equals(getApp().getPackageName()) && !api.isAppEnabled(pack)) {
return null; return null;
} }
@ -158,6 +158,10 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
mHandlerThread.quit(); mHandlerThread.quit();
} }
private String getCallingAppPackName() {
return getApp().getPackageManager().getNameForUid(Binder.getCallingUid());
}
private long getCallbackId() { private long getCallbackId() {
return aidlCallbackId.get(); return aidlCallbackId.get();
} }
@ -449,7 +453,8 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
public boolean addMapLayer(AddMapLayerParams params) { public boolean addMapLayer(AddMapLayerParams params) {
try { try {
OsmandAidlApi api = getApi("addMapLayer"); 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) { } catch (Exception e) {
handleException(e); handleException(e);
return false; return false;

View file

@ -122,7 +122,7 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
private OsmandAidlApi getApi(String reason) { private OsmandAidlApi getApi(String reason) {
LOG.info("Request AIDL API V2 for " + reason); LOG.info("Request AIDL API V2 for " + reason);
OsmandAidlApi api = getApp().getAidlApi(); OsmandAidlApi api = getApp().getAidlApi();
String pack = getApp().getPackageManager().getNameForUid(Binder.getCallingUid()); String pack = getCallingAppPackName();
if (pack != null && !pack.equals(getApp().getPackageName()) && !api.isAppEnabled(pack)) { if (pack != null && !pack.equals(getApp().getPackageName()) && !api.isAppEnabled(pack)) {
return null; return null;
} }
@ -159,6 +159,10 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
mHandlerThread.quit(); mHandlerThread.quit();
} }
private String getCallingAppPackName() {
return getApp().getPackageManager().getNameForUid(Binder.getCallingUid());
}
private long getCallbackId() { private long getCallbackId() {
return aidlCallbackId.get(); return aidlCallbackId.get();
} }
@ -449,7 +453,8 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
public boolean addMapLayer(AddMapLayerParams params) { public boolean addMapLayer(AddMapLayerParams params) {
try { try {
OsmandAidlApi api = getApi("addMapLayer"); 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) { } catch (Exception e) {
handleException(e); handleException(e);
return false; return false;

View file

@ -51,6 +51,7 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider
private final MapActivity map; private final MapActivity map;
private OsmandMapTileView view; private OsmandMapTileView view;
private String packName;
private AidlMapLayerWrapper aidlLayer; private AidlMapLayerWrapper aidlLayer;
private Paint pointInnerCircle; private Paint pointInnerCircle;
@ -77,9 +78,10 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider
private Set<String> imageRequests = new HashSet<>(); private Set<String> imageRequests = new HashSet<>();
private List<AidlMapPointWrapper> displayedPoints = new ArrayList<>(); private List<AidlMapPointWrapper> displayedPoints = new ArrayList<>();
public AidlMapLayer(MapActivity map, AidlMapLayerWrapper aidlLayer) { public AidlMapLayer(MapActivity map, AidlMapLayerWrapper aidlLayer, String packName) {
this.map = map; this.map = map;
this.aidlLayer = aidlLayer; this.aidlLayer = aidlLayer;
this.packName = packName;
} }
@Override @Override
@ -137,34 +139,36 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider
displayedPoints.clear(); displayedPoints.clear();
imageRequests.clear(); imageRequests.clear();
canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY()); if (isAppEnabled()) {
canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
String selectedPointId = getSelectedContextMenuPointId(); String selectedPointId = getSelectedContextMenuPointId();
for (AidlMapPointWrapper point : aidlLayer.getPoints()) { for (AidlMapPointWrapper point : aidlLayer.getPoints()) {
LatLon l = point.getLocation(); LatLon l = point.getLocation();
if (l != null) { if (l != null) {
int x = (int) tileBox.getPixXFromLatLon(l.getLatitude(), l.getLongitude()); int x = (int) tileBox.getPixXFromLatLon(l.getLatitude(), l.getLongitude());
int y = (int) tileBox.getPixYFromLatLon(l.getLatitude(), l.getLongitude()); int y = (int) tileBox.getPixYFromLatLon(l.getLatitude(), l.getLongitude());
if (tileBox.containsPoint(x, y, bigIconSize)) { if (tileBox.containsPoint(x, y, bigIconSize)) {
Bitmap image = null; Bitmap image = null;
if (pointsType != PointsType.STANDARD) { if (pointsType != PointsType.STANDARD) {
String imageUri = point.getParams().get(AMapPoint.POINT_IMAGE_URI_PARAM); String imageUri = point.getParams().get(AMapPoint.POINT_IMAGE_URI_PARAM);
if (!TextUtils.isEmpty(imageUri)) { if (!TextUtils.isEmpty(imageUri)) {
image = pointImages.get(imageUri); image = pointImages.get(imageUri);
if (image == null) { if (image == null) {
imageRequests.add(imageUri); 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) { if (imageRequests.size() > 0) {
executeTaskInBackground(new PointImageReaderTask(this), imageRequests.toArray(new String[imageRequests.size()])); executeTaskInBackground(new PointImageReaderTask(this), imageRequests.toArray(new String[imageRequests.size()]));
}
} }
mapTextLayer.putData(this, displayedPoints); 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)); 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 @Override
public void destroyLayer() { public void destroyLayer() {
} }
@ -261,7 +273,9 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider
@Override @Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o, boolean unknownLocation) { public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o, boolean unknownLocation) {
getFromPoint(tileBox, point, o); if (isAppEnabled()) {
getFromPoint(tileBox, point, o);
}
} }
@Override @Override