Bug 7687 - Substitute package name in string literals
Summary: Substitute package name in string literals
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 4.2.x
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2012-10-05 10:49 UTC by Redth
Modified: 2012-11-02 04:21 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Redth 2012-10-05 10:49:10 UTC
I'm trying to improve the PushSharp client integration story, and one challenge I'm facing is that I need to use permissions and create permissions with names containing the actual package name of the application running.

Currently to do this, people who consume the PushSharp client library for GCM/C2DM using Mono for Android must manually edit their manifest xml.  There is already a [UsesPermission] attribute that could be used, however I'd really like to add this attribute to a base class in the library so the user doesn't have to worry about this.  The problem of course is that I don't know at compile time what the package name of their application will be.  The permission I'm trying to create and use MUST follow a specific pattern or GCM/C2DM to work which is: <PackageName>.permission.C2D_MESSAGE

Jon Pryor has suggested a hackish workaround would be to find and replace all @PACKAGE_NAME@ instances in string literals when generating the manifest file and replace it with the actual package name.  This would definitely solve the problem I'm trying to address, however it's a bit ugly of a solution on the Mono for Android side.

So bottom line is, I want to use something like this in my library:

[IntentFilter(new string[] { "com.google.android.gcm.intent.RETRY" }, Categories = new string[] { "@PACKAGE_NAME@" })]
public class GCMBroadcastReceiver

Comment 1 Atsushi Eno 2012-10-23 14:02:26 UTC
This would be useful and I'm for it. Though now I have mixed feeling of whether we should replace those special literals in AndroidManifest.xml or not (i.e. outside attributes).
People would expect that AndroidManifest.xml is passed to apk almost as plain as they wrote, when it is manually specified (instead of being represented as set of attributes in code). Also it is even possible that people may have their own way of replacing strings. On the other hand some people may think those escaped representation should also apply to AndroidManifest.xml, which is kind of valid assumption.

So far I'm inclined to apply the replace only to attributes (because it is easy).
Comment 2 Redth 2012-10-23 14:58:03 UTC
If this ends up being the case, can you please ensure you do this for all string fields in attributes that make sense?

For instance, in my example, it isn't just the permission name, but also the categories for the intentfilter, etc.
Comment 3 Atsushi Eno 2012-11-02 04:21:21 UTC
It is now implemented [master: f4e864c / 4.2: f7d0ccb]