Skip to content
This repository was archived by the owner on Apr 15, 2021. It is now read-only.

Somehow, it doesn't work for Android #2

Open
ghuang0207 opened this issue Aug 21, 2017 · 26 comments
Open

Somehow, it doesn't work for Android #2

ghuang0207 opened this issue Aug 21, 2017 · 26 comments

Comments

@ghuang0207
Copy link

I am using ionic2 with your plugin. We are using airwatch in our enterprise.

We published our code to Google Play, set as internal access only. We saw an error message "This app doesn't support app configuration", when we tried to enable "Send Application Configuration" from the airwatch console. ( the same exact code works for iOS).

Also I checked my config.xml file, the version is: ~1.0.1 Does that matter? I tried to do:
cordova plugin rmv cordova-plugin-emm-app-config and
cordova plugin add cordova-plugin-emm-app-config
but I still get version 1.0.1.. I even tried cordova plugin add [email protected]

Could anyone please help me?
We have been running out all the solutions...

Thank you
George

@lpchanora
Copy link
Contributor

Hi George,

1.0.1 or 1.0.2 shouldn't make any difference. 1.0.2 only added some extra description and contains no bug fix or new feature. However, you can update to 1.0.2 by first removing it:
cordova plugin remove cordova-plugin-emm-app-config

The command is "remove", not "rmv".

As for the error message, sounds like it's coming from the Airwatch Console when you try to enable the "Application Configuration" setting, is that correct? If that's the case, it shouldn't be caused by the app itself. It's probably related to the app settings in AirWatch. You may want to contact AirWatch to see what's causing that error message.

Thanks,
Leon

@lpchanora
Copy link
Contributor

Closing this issue since this doesn't appear to be a problem with the plugin itself.

@theaccordance
Copy link

Having the same issue as well, and my suspicion leans towards it being the plugin. Reviewing the Google documentation for Setting up Managed Configurations, it appears there should be additional properties injected into the AndroidManifest.xml file?

@theaccordance
Copy link

If I'm reading the Android documentation correctly for configuring an application for managed configurations, the plugin needs to do the following to enable the functionality:

  1. Add a property to platforms/android/AndroidManifest.xml within the <application> block:

<meta-data android:name="android.content.APP_RESTRICTIONS" android:resource="@xml/app_restrictions" />

  1. Add a XML file which defines the properties exposed via AppConfig: platforms/android/res/xml/app_restrictions.xml

As far as I can tell looking at the plugin, it's doing neither. My suspicion is supported by the fact that we don't define anything in Cordova's config.xml file to even define the restrictions, which is something I have to do for other plugins like Deeplinks.

@lpchanora
Copy link
Contributor

@theaccordance Thanks for the comments. Are you also getting error message from AirWatch console?

We had it working with AirWatch without the need to define any restriction. We will investigate to see if there are cases where restrictions may be needed.

@ghuang0207
Copy link
Author

Hi Leon,

Thank you for the message!! Yes, we are getting the error message from AirWatch console.
We did contact AirWatch, but they kept saying the problem is in the plugin....

Is it possible you can give us some direction where the setting/configuration part we can check in Airwatch console?

George

@lpchanora
Copy link
Contributor

Hi George @ghuang0207 ,

I'm not sure exactly what to check. I would think AirWatch should know since apparently they are checking for something when they throw the error message. Is your apk file uploaded directly to AirWatch, or do you have it in another app store like Google Play and provide a link in AirWatch?

Another poster has just commented on this issue. Maybe you can try adding the restriction property and file and see if that solves the problem?

Thanks,
Leon

@theaccordance
Copy link

@lpchanora Can't speak for Airwatch, my Android woes relating to this plugin are coming from my Mobile Iron customers

@MrTechGadget
Copy link

I think @theaccordance is onto something, the Documentation from google clearly states

"To provide externally managed configurations:
Declare the managed configurations in your app manifest. Doing so allows the enterprise administrator to read the app's configurations through Google Play APIs."

That leads me to believe that AirWatch, or Mobile Iron is using the Google Play APIs to check for the keys that can be set. If the app has not correctly declared those in the application manifest it will not be able to read them.

Should be fairly easy to test this by manually adding this data to the manifest to check. If that fixes it, it shouldn't be that hard to add functionality to the plugin to write this data programmatically when built.

@ghuang0207
Copy link
Author

@audioeng I think your are right AirWatch asked us to deploy apk through Google Play ( a must )..

@ghuang0207
Copy link
Author

To Leon @lpchanora ,

We deployed our APKs to AirWatch through Google Play.

George

@theaccordance
Copy link

theaccordance commented Aug 31, 2017

Here's a patch I'm testing: #3

The PR itself is not ready for merge, the changes I'm showing need to be optimized further to function as a proper plugin.

What the patch is doing:

  • Adding a property to AndroidManifest.xml
  • Adding a string property for each key to res/values/strings.xml
  • Adding a new xml file app_restrictions.xml to res/xml/

I'll report back in after I hear from my customers

@ghuang0207
Copy link
Author

To @theaccordance Joe, Thank you very much for all the help!

Actually all we need was just for Airwatch to send us "EnrollmentUser" key and value (string). But I don't know how to configure the app_restrictions.xml to do that. Or can I not set any restriction for the app?

platforms/android/res/xml/app_restrictions.xml

@theaccordance
Copy link

@ghuang0207 https://developer.android.com/work/managed-configurations.html if you want context on the code changes I've shared in the PR. Keep in mind, that's not the final solution to fix the plugin, probably better to look at it as a POC currently. I'm still waiting for feedback from my customers if this addresses the problem they're having configuring our app with Mobile Iron.

Assuming my changes fix the problem, then the next step is to refactor my solution so the custom configurations are defined in your project's config.xml file, and revising the documentation accordingly.

@theaccordance
Copy link

The patch so far looks promising. One of my colleagues tested our revised build against an AirWatch demo & can now see config options for our Android App:
screen shot 2017-08-31 at 7 54 27 pm

I still don't have confirmation yet that the app is able to read the values provided through the MDM provider, but we're hopeful that the scope is just limited to the missing properties for AndroidManifest & the Restrictions doc.

I spent some time last night reviewing the user-defined data that still needs to be abstracted from the plugin, and I'm considering the following solution:

  1. The user (developer implementing the plugin) will be responsible for creating their own app_restrictions.xml file. Documentation will need to be updated accordingly.
<?xml version="1.0" encoding="utf-8"?>
<restrictions xmlns:android="http://schemas.android.com/apk/res/android">
    <restriction
            android:key="KEY1"
            android:title="KEY 1 NAME"
            android:description="@string/appconfig_key1"
            android:restrictionType="string" />

    <restriction
            android:key="KEY2"
            android:title="KEY 2 NAME"
            android:description="@string/appconfig_key2"
            android:restrictionType="bool"
            android:defaultValue="false" />
</restrictions>
  1. The user will save this file somewhere in their project, and reference it in the config.xml file using a variable APPCONFIG_RESTRICTIONS:
<plugin name="cordova-plugin-emm-app-config">
    <variable name="APPCONFIG_RESTRICTIONS" value="path/to/app_restrictions.xml" />
</plugin>
  1. The plugin will add a hook that when executed:
  • Parses the config.xml file & obtains the path reference
  • Copies the file to $PROJECT_ROOT/platforms/android/res/xml/app_restrictions.xml

The parsing is by far the most difficult part of this solution, but thankfully Ionic Plugin Deeplinks already has done this and is serving an excellent reference.

Let me know your thoughts, I hope to have this completed sometime next week.

@ghuang0207
Copy link
Author

To @theaccordance: This is great! Thank you very much, and I think this new plugin will help many ionic developers in the future. I have a question though:

We would like to obtain the keyname: EnrollmentUser from AirWatch, so should I add that into the restrictions.xml file as well? Like below?

<?xml version="1.0" encoding="utf-8"?>
<restrictions xmlns:android="http://schemas.android.com/apk/res/android">
    <restriction
            android:key="EnrollmentUser"
            android:title="EnrollmentUser"
            android:description="@string/EnrollmentUser"
            android:restrictionType="string" />

    </restrictions>

However, I also notice that, we can add any key and value from the AirWatch Console. This has been making a lot of confusion... Is there a way I can do in the restrictions.xml file to allow whatever key/value added from AirWatch console?

Again, thank you for your help..

George

@theaccordance
Copy link

theaccordance commented Sep 5, 2017

@ghraml ignore @string references and use string literals instead. The @string is a reference to another xml file for android and I don't have a personal need to localize the restrictions file yet.

As far as your question about the restrictions file - I can't answer. I'm just a guy who knows his way around a cordova project, read the manual (the link I provided you earlier), and uses moments like this to give back to the open source community. You'll need to talk to someone more versed with Android & Airwatch on that.

@theaccordance
Copy link

theaccordance commented Sep 15, 2017

Just got word that the patch is working for our customers, so I'll finish revising our patch into a workable PR for the plugin. Probably be a couple weeks until I complete this, the downside of open source is that it generally has to take a back seat on the priority list.

If anyone wants to pick up where I've left off, I'll be more than happy to clarify spec on what's left.

@lpchanora would it be possible to at least keep this issue open until we've finalized the PR & it's been accepted? It'll make it easier for others to find

@lpchanora
Copy link
Contributor

@theaccordance Thanks for sharing the result. I will keep the issue open.

@lpchanora lpchanora reopened this Sep 15, 2017
@MrTechGadget
Copy link

@theaccordance Great! I haven't had time to test out your changes, but they look good as far as I can tell and I like your proposal to require the user to make their own app_restrictions.xml file.
I think the documentation should include a sample like you have in this thread.

Looking forward to a workable PR, I should have some time to test it when you have it ready!

Thanks!

@bhutchison
Copy link

bhutchison commented Oct 3, 2017

Has there been any progress on this? I am trying to incorporate the fix described above and still receiving an empty _appconfig object. Not sure about step 3 mentioned by theaccordance.

Im trying to add a server url from Airwatch.

@theaccordance
Copy link

I haven't finalized the solution so it's release-worthy, and it'll probably be at least a week until I have the capacity to do so myself - unfortunate reality of open source. You can take a look at the open PR i have submitted and engineer your own shim in the meantime.

I'll see if I can recruit someone internally to help get it across the finish line sooner, I do know some of them are looking for ways to contribute to open source in general.

@bhutchison
Copy link

Ok thank you. Yes I have edited the plugin.xml and added an app_restrictions.xml under /src/android/ as well as platforms/android/res/xml . Not sure what else I am missing. My understanding is that the plugin should now add the necessary entry to the AndroidManifest, pointing to the restrictions available. Still when debugging my EmmAppConfig _appconfig is returning empty. I am using Cordova, not sure if that changes anything though.

@lpchanora
Copy link
Contributor

lpchanora commented Oct 4, 2017

Hi @bhutchison , this plugin has not been updated to look at plugin.xml as proposed by @theaccordance . However, if the issue is just a missing app_restrictions.xml, you don't really need an updated plugin. You can just manually modify AndroidManifest.xml to add a <meta-data> element in the <application> element that points to your app_restrictions.xml:

<meta-data android:name="android.content.APP_RESTRICTIONS" android:resource="@xml/app_restrictions" />

For more information, please refer to:
https://developer.android.com/work/managed-configurations.html#define-configuration

@bhutchison
Copy link

bhutchison commented Oct 5, 2017

Thank you @lpchanora. I have followed these steps but still not seeing any key values. If anyone has this working I would be interested to see your configuration and use of the plugin. Im wondering if its something to do with my Airwatch config.

@MrTechGadget
Copy link

MrTechGadget commented Oct 5, 2017 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants