Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 994b5ad7 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Fix issue #72116995: Add permission guarding Service#startForeground

Now requires permission if targeting P.

Note that this is a separate permission from the existing one
that is required for instant apps to use foreground services.  The
reason for this is that their semantics are different (the instant
apps permission is associated with an app op for control over what
the app is allowed, while the regular app permission is just a
normal permission that is always granted and only there for
auditing of apps), and there are probably going to be cases where
a developer will want to use a foreground service in the full
version of their app but not as an instant app.

Bug: 72116995
Test: atest CtsAppTestCases
Change-Id: If5a79e7ed5ab9e0edc77410315eb4d2df8ac850b
parent 00be1979
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ package android {
    field public static final java.lang.String DUMP = "android.permission.DUMP";
    field public static final java.lang.String EXPAND_STATUS_BAR = "android.permission.EXPAND_STATUS_BAR";
    field public static final java.lang.String FACTORY_TEST = "android.permission.FACTORY_TEST";
    field public static final java.lang.String FOREGROUND_SERVICE = "android.permission.FOREGROUND_SERVICE";
    field public static final java.lang.String GET_ACCOUNTS = "android.permission.GET_ACCOUNTS";
    field public static final java.lang.String GET_ACCOUNTS_PRIVILEGED = "android.permission.GET_ACCOUNTS_PRIVILEGED";
    field public static final java.lang.String GET_PACKAGE_SIZE = "android.permission.GET_PACKAGE_SIZE";
+4 −8
Original line number Diff line number Diff line
@@ -471,14 +471,6 @@ public abstract class Service extends ContextWrapper implements ComponentCallbac
     * {@link #onStart} and returns either {@link #START_STICKY}
     * or {@link #START_STICKY_COMPATIBILITY}.
     * 
     * <p>If you need your application to run on platform versions prior to API
     * level 5, you can use the following model to handle the older {@link #onStart}
     * callback in that case.  The <code>handleCommand</code> method is implemented by
     * you as appropriate:
     * 
     * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/ForegroundService.java
     *   start_compatibility}
     *
     * <p class="caution">Note that the system calls this on your
     * service's main thread.  A service's main thread is the same
     * thread where UI operations take place for Activities running in the
@@ -687,6 +679,10 @@ public abstract class Service extends ContextWrapper implements ComponentCallbac
     * {@link #startService(Intent)} first to tell the system it should keep the service running,
     * and then use this method to tell it to keep it running harder.</p>
     *
     * <p>Apps targeting API {@link android.os.Build.VERSION_CODES#P} or later must request
     * the permission {@link android.Manifest.permission#FOREGROUND_SERVICE} in order to use
     * this API.</p>
     *
     * @param id The identifier for this notification as per
     * {@link NotificationManager#notify(int, Notification)
     * NotificationManager.notify(int, Notification)}; must not be 0.
+8 −0
Original line number Diff line number Diff line
@@ -894,6 +894,14 @@ public class Build {

        /**
         * P.
         *
         * <p>Applications targeting this or a later release will get these
         * new changes in behavior:</p>
         * <ul>
         * <li>{@link android.app.Service#startForeground Service.startForeground} requires
         * that apps hold the permission
         * {@link android.Manifest.permission#FOREGROUND_SERVICE}.</li>
         * </ul>
         */
        public static final int P = CUR_DEVELOPMENT; // STOPSHIP Replace with the real version.
    }
+9 −0
Original line number Diff line number Diff line
@@ -3717,6 +3717,15 @@
    <permission android:name="android.permission.INSTANT_APP_FOREGROUND_SERVICE"
        android:protectionLevel="signature|development|instant|appop" />

    <!-- Allows a regular application to use {@link android.app.Service#startForeground
         Service.startForeground}.
         <p>Protection level: normal
    -->
    <permission android:name="android.permission.FOREGROUND_SERVICE"
        android:description="@string/permdesc_foregroundService"
        android:label="@string/permlab_foregroundService"
        android:protectionLevel="normal|instant" />

    <!-- @hide Allows system components to access all app shortcuts. -->
    <permission android:name="android.permission.ACCESS_SHORTCUTS"
        android:protectionLevel="signature" />
+5 −0
Original line number Diff line number Diff line
@@ -915,6 +915,11 @@
    <string name="permdesc_persistentActivity" product="tv">Allows the app to make parts of itself persistent in memory.  This can limit memory available to other apps slowing down the TV.</string>
    <string name="permdesc_persistentActivity" product="default">Allows the app to make parts of itself persistent in memory.  This can limit memory available to other apps slowing down the phone.</string>

    <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
    <string name="permlab_foregroundService">run foreground service</string>
    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
    <string name="permdesc_foregroundService">Allows the app to make use of foreground services.</string>

    <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
    <string name="permlab_getPackageSize">measure app storage space</string>
    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
Loading