title: Enable communication between two Android apps via custom permissions
body: <p>One of my Android applications needs some features that are "dangerous" when it comes to permissions. They require some permissions such as "Internet access" which are critical in combination with private data.</p>
  
  <p>This is why I want to create a separate "Add-on", i.e. a second app that provides these permission-critical features. So if users want them, they can install the add-on, but the main app will still work without those permissions.</p>
  
  <p>Using a <code>sharedUserId</code> would obviously be the easiest solution, but adding this afterwards, when lots of users use the app already, could cause serious problems. Wouldn't this mean that the app can't access its own data any longer?</p>
  
  <p>So I have to choose another approach. ContentProviders are something that I try to avoid, because they're too complex for this simple need in my opinion.</p>
  
  <p>I thought custom permissions could solve the issue. Can they? I've added the following permission declaration to both the main app as well as the add-on as a child to the <code>manifest</code> tag in <code>AndroidManifest.xml</code>:</p>
  
  <pre><code>&lt;permission
      android:name="com.my.package.ADDON"
      android:label="@string/permission_title"
      android:description="@string/permission_description"
      android:permissionGroup="android.permission-group.PERSONAL_INFO"
      android:protectionLevel="signature" /&gt;
  </code></pre>
  
  <p>Furthermore, both manifest files have got this part now:</p>
  
  <pre><code>&lt;uses-permission android:name="com.my.package.ADDON"&gt;&lt;/uses-permission&gt;
  </code></pre>
  
  <p>The add-on app includes an <code>IntentService</code> that has the following attribute now:</p>
  
  <pre><code>android:permission="com.my.package.ADDON"
  </code></pre>
  
  <p>Shouldn't this do the job so that I can call the add-on's <code>IntentService</code> from my main app via this code?</p>
  
  <pre><code>Intent addonIntent = new Intent();
  addonIntent.setClassName("com.my.package", "com.my.package.MyService");
  startService(addonIntent);
  </code></pre>
  
  <p>Unfortunately, this call always fails with the following exception:</p>
  
  <pre><code>E/AndroidRuntime(16721): java.lang.SecurityException: Not allowed to start service Intent { cmp=com.mypackage.addon/.MyService } without permission com.mypackage.permission.ADDON
  </code></pre>
  
  <p>What did I do wrong? Thank you very much in advance!</p>
  
  <p><strong>Addition #1 - Add-on manifest:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
        android:versionCode="1"
        android:versionName="1.0"
        package="com.mypackage.addon"&gt;
      &lt;uses-sdk android:minSdkVersion="8" /&gt;
      &lt;permission
          android:name="com.mypackage.permission.ADDON"
          android:label="@string/permission_title"
          android:description="@string/permission_description"
          android:permissionGroup="android.permission-group.PERSONAL_INFO"
          android:protectionLevel="signature" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"&gt;&lt;/uses-permission&gt;
      &lt;uses-permission android:name="android.permission.INTERNET"&gt;&lt;/uses-permission&gt;
  &lt;application
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:permission="com.mypackage.permission.ADDON"
      android:exported="true"&gt;
      &lt;service
          android:enabled="true"
          android:name=".MyService" /&gt;
  &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p><strong>Addition #2 - main app manifest:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
        android:versionCode="1"
        android:versionName="1.0"
        package="com.mypackage.mainapp"&gt;
      &lt;uses-sdk android:minSdkVersion="8" /&gt;
      &lt;permission
          android:name="com.mypackage.permission.ADDON"
          android:label="@string/permission_title"
          android:description="@string/permission_description"
          android:permissionGroup="android.permission-group.PERSONAL_INFO"
          android:protectionLevel="signature" /&gt;
      &lt;uses-permission android:name="com.mypackage.permission.ADDON"&gt;&lt;/uses-permission&gt;
  &lt;application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:name="MyApp"&gt;
      &lt;activity android:name=".MainActivity" android:launchMode="singleTask" android:label="@string/app_name"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>