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

Commit 21f77806 authored by Christopher Tate's avatar Christopher Tate
Browse files

Enable background restrictions

Apps that target O+ are always subject to background restrictions.
Legacy apps' background restriction is subject to the OP_RUN_IN_BACKGROUND
app op.

Apps with these properties are exempted from background restrictions:
  - persistent process
  - currently on the idle battery whitelist
  - global whitelist for things like bluetooth services

Bug 30953212

Change-Id: Ib444829a2d222125f64ff19e8218823fa78373f9
parent b7a77d24
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -5435,6 +5435,7 @@ package android.app {
    method public boolean removeAutomaticZenRule(java.lang.String);
    method public final void setInterruptionFilter(int);
    method public void setNotificationPolicy(android.app.NotificationManager.Policy);
    method public android.content.ComponentName startServiceInForeground(android.content.Intent, int, android.app.Notification);
    method public boolean updateAutomaticZenRule(java.lang.String, android.app.AutomaticZenRule);
    field public static final java.lang.String ACTION_INTERRUPTION_FILTER_CHANGED = "android.app.action.INTERRUPTION_FILTER_CHANGED";
    field public static final java.lang.String ACTION_NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED = "android.app.action.NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED";
@@ -38971,6 +38972,7 @@ package android.test.mock {
    method public void startIntentSender(android.content.IntentSender, android.content.Intent, int, int, int) throws android.content.IntentSender.SendIntentException;
    method public void startIntentSender(android.content.IntentSender, android.content.Intent, int, int, int, android.os.Bundle) throws android.content.IntentSender.SendIntentException;
    method public android.content.ComponentName startService(android.content.Intent);
    method public android.content.ComponentName startServiceInForeground(android.content.Intent, int, android.app.Notification);
    method public boolean stopService(android.content.Intent);
    method public void unbindService(android.content.ServiceConnection);
    method public void unregisterReceiver(android.content.BroadcastReceiver);
+2 −0
Original line number Diff line number Diff line
@@ -5620,6 +5620,7 @@ package android.app {
    method public boolean removeAutomaticZenRule(java.lang.String);
    method public final void setInterruptionFilter(int);
    method public void setNotificationPolicy(android.app.NotificationManager.Policy);
    method public android.content.ComponentName startServiceInForeground(android.content.Intent, int, android.app.Notification);
    method public boolean updateAutomaticZenRule(java.lang.String, android.app.AutomaticZenRule);
    field public static final java.lang.String ACTION_INTERRUPTION_FILTER_CHANGED = "android.app.action.INTERRUPTION_FILTER_CHANGED";
    field public static final java.lang.String ACTION_NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED = "android.app.action.NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED";
@@ -42219,6 +42220,7 @@ package android.test.mock {
    method public void startIntentSender(android.content.IntentSender, android.content.Intent, int, int, int) throws android.content.IntentSender.SendIntentException;
    method public void startIntentSender(android.content.IntentSender, android.content.Intent, int, int, int, android.os.Bundle) throws android.content.IntentSender.SendIntentException;
    method public android.content.ComponentName startService(android.content.Intent);
    method public android.content.ComponentName startServiceInForeground(android.content.Intent, int, android.app.Notification);
    method public boolean stopService(android.content.Intent);
    method public void unbindService(android.content.ServiceConnection);
    method public void unregisterReceiver(android.content.BroadcastReceiver);
+2 −0
Original line number Diff line number Diff line
@@ -5446,6 +5446,7 @@ package android.app {
    method public boolean removeAutomaticZenRule(java.lang.String);
    method public final void setInterruptionFilter(int);
    method public void setNotificationPolicy(android.app.NotificationManager.Policy);
    method public android.content.ComponentName startServiceInForeground(android.content.Intent, int, android.app.Notification);
    method public boolean updateAutomaticZenRule(java.lang.String, android.app.AutomaticZenRule);
    field public static final java.lang.String ACTION_INTERRUPTION_FILTER_CHANGED = "android.app.action.INTERRUPTION_FILTER_CHANGED";
    field public static final java.lang.String ACTION_NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED = "android.app.action.NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED";
@@ -39091,6 +39092,7 @@ package android.test.mock {
    method public void startIntentSender(android.content.IntentSender, android.content.Intent, int, int, int) throws android.content.IntentSender.SendIntentException;
    method public void startIntentSender(android.content.IntentSender, android.content.Intent, int, int, int, android.os.Bundle) throws android.content.IntentSender.SendIntentException;
    method public android.content.ComponentName startService(android.content.Intent);
    method public android.content.ComponentName startServiceInForeground(android.content.Intent, int, android.app.Notification);
    method public boolean stopService(android.content.Intent);
    method public void unbindService(android.content.ServiceConnection);
    method public void unregisterReceiver(android.content.BroadcastReceiver);
+19 −4
Original line number Diff line number Diff line
@@ -1385,7 +1385,14 @@ class ContextImpl extends Context {
    @Override
    public ComponentName startService(Intent service) {
        warnIfCallingFromSystemProcess();
        return startServiceCommon(service, mUser);
        return startServiceCommon(service, -1, null, mUser);
    }

    @Override
    public ComponentName startServiceInForeground(Intent service,
            int id, Notification notification) {
        warnIfCallingFromSystemProcess();
        return startServiceCommon(service, id, notification, mUser);
    }

    @Override
@@ -1396,16 +1403,24 @@ class ContextImpl extends Context {

    @Override
    public ComponentName startServiceAsUser(Intent service, UserHandle user) {
        return startServiceCommon(service, user);
        return startServiceCommon(service, -1, null, user);
    }

    private ComponentName startServiceCommon(Intent service, UserHandle user) {
    @Override
    public ComponentName startServiceInForegroundAsUser(Intent service,
            int id, Notification notification, UserHandle user) {
        return startServiceCommon(service, id, notification, user);
    }

    private ComponentName startServiceCommon(Intent service, int id, Notification notification,
            UserHandle user) {
        try {
            validateServiceIntent(service);
            service.prepareToLeaveProcess(this);
            ComponentName cn = ActivityManager.getService().startService(
                mMainThread.getApplicationThread(), service, service.resolveTypeIfNeeded(
                            getContentResolver()), getOpPackageName(), user.getIdentifier());
                            getContentResolver()), id, notification, getOpPackageName(),
                            user.getIdentifier());
            if (cn != null) {
                if (cn.getPackageName().equals("!")) {
                    throw new SecurityException(
+2 −1
Original line number Diff line number Diff line
@@ -128,7 +128,8 @@ interface IActivityManager {
    void finishSubActivity(in IBinder token, in String resultWho, int requestCode);
    PendingIntent getRunningServiceControlPanel(in ComponentName service);
    ComponentName startService(in IApplicationThread caller, in Intent service,
            in String resolvedType, in String callingPackage, int userId);
            in String resolvedType, int id, in Notification notification,
            in String callingPackage, int userId);
    int stopService(in IApplicationThread caller, in Intent service,
            in String resolvedType, int userId);
    int bindService(in IApplicationThread caller, in IBinder token, in Intent service,
Loading