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

Commit cbaccfa5 authored by Makoto Onuki's avatar Makoto Onuki Committed by Android (Google) Code Review
Browse files

Merge "Merge "Use different exceptions for different crash reasons" into...

Merge "Merge "Use different exceptions for different crash reasons" into sc-v2-dev am: 5dcf36ad am: abdd86b2"
parents 90a7d0e3 543acbc3
Loading
Loading
Loading
Loading
+25 −3
Original line number Diff line number Diff line
@@ -41,6 +41,12 @@ import android.annotation.ElapsedRealtimeLong;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UptimeMillisLong;
import android.app.RemoteServiceException.BadForegroundServiceNotificationException;
import android.app.RemoteServiceException.CannotDeliverBroadcastException;
import android.app.RemoteServiceException.CannotPostForegroundServiceNotificationException;
import android.app.RemoteServiceException.CrashedByAdbException;
import android.app.RemoteServiceException.ForegroundServiceDidNotStartInTimeException;
import android.app.RemoteServiceException.MissingRequestPasswordComplexityPermissionException;
import android.app.assist.AssistContent;
import android.app.assist.AssistStructure;
import android.app.backup.BackupAgent;
@@ -1929,11 +1935,27 @@ public final class ActivityThread extends ClientTransactionHandler
    private void throwRemoteServiceException(String message, int typeId) {
        // Use a switch to ensure all the type IDs are unique.
        switch (typeId) {
            case ForegroundServiceDidNotStartInTimeException.TYPE_ID: // 1
            case ForegroundServiceDidNotStartInTimeException.TYPE_ID:
                throw new ForegroundServiceDidNotStartInTimeException(message);
            case RemoteServiceException.TYPE_ID: // 0

            case CannotDeliverBroadcastException.TYPE_ID:
                throw new CannotDeliverBroadcastException(message);

            case CannotPostForegroundServiceNotificationException.TYPE_ID:
                throw new CannotPostForegroundServiceNotificationException(message);

            case BadForegroundServiceNotificationException.TYPE_ID:
                throw new BadForegroundServiceNotificationException(message);

            case MissingRequestPasswordComplexityPermissionException.TYPE_ID:
                throw new MissingRequestPasswordComplexityPermissionException(message);

            case CrashedByAdbException.TYPE_ID:
                throw new CrashedByAdbException(message);

            default:
                throw new RemoteServiceException(message);
                throw new RemoteServiceException(message
                        + " (with unwknown typeId:" + typeId + ")");
        }
    }

+0 −33
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.app;

/**
 * Exception used to crash an app process when it didn't call {@link Service#startForeground}
 * in time after the service was started with
 * {@link android.content.Context#startForegroundService}.
 *
 * @hide
 */
public class ForegroundServiceDidNotStartInTimeException extends RemoteServiceException {
    /** The type ID passed to {@link IApplicationThread#scheduleCrash}. */
    public static final int TYPE_ID = 1;

    public ForegroundServiceDidNotStartInTimeException(String msg) {
        super(msg);
    }
}
+0 −2
Original line number Diff line number Diff line
@@ -330,8 +330,6 @@ interface IActivityManager {
    void handleApplicationStrictModeViolation(in IBinder app, int penaltyMask,
            in StrictMode.ViolationInfo crashInfo);
    boolean isTopActivityImmersive();
    void crashApplication(int uid, int initialPid, in String packageName, int userId,
            in String message, boolean force);
    void crashApplicationWithType(int uid, int initialPid, in String packageName, int userId,
            in String message, boolean force, int exceptionTypeId);
    /** @deprecated -- use getProviderMimeTypeAsync */
+96 −7
Original line number Diff line number Diff line
@@ -19,20 +19,109 @@ package android.app;
import android.util.AndroidRuntimeException;

/**
 * Exception used by {@link ActivityThread} to crash an app process.
 * Exception used by {@link ActivityThread} to crash an app process for an unknown cause.
 * An exception of this class is no longer supposed to be thrown. Instead, we use fine-grained
 * sub-exceptions.
 *
 * Subclasses must be registered in
 * {@link android.app.ActivityThread#throwRemoteServiceException(java.lang.String, int)}.
 *
 * @hide
 */
public class RemoteServiceException extends AndroidRuntimeException {
    public RemoteServiceException(String msg) {
        super(msg);
    }

    /**
     * The type ID passed to {@link IApplicationThread#scheduleCrash}.
     * Exception used to crash an app process when it didn't call {@link Service#startForeground}
     * in time after the service was started with
     * {@link android.content.Context#startForegroundService}.
     *
     * Assign a unique ID to each subclass. See the above method for the numbers that are already
     * taken.
     * @hide
     */
    public static final int TYPE_ID = 0;
    public static class ForegroundServiceDidNotStartInTimeException extends RemoteServiceException {
        /** The type ID passed to {@link IApplicationThread#scheduleCrash}. */
        public static final int TYPE_ID = 1;

    public RemoteServiceException(String msg) {
        public ForegroundServiceDidNotStartInTimeException(String msg) {
            super(msg);
        }
    }

    /**
     * Exception used to crash an app process when the system received a RemoteException
     * while delivering a broadcast to an app process.
     *
     * @hide
     */
    public static class CannotDeliverBroadcastException extends RemoteServiceException {
        /** The type ID passed to {@link IApplicationThread#scheduleCrash}. */
        public static final int TYPE_ID = 2;

        public CannotDeliverBroadcastException(String msg) {
            super(msg);
        }
    }

    /**
     * Exception used to crash an app process when the system received a RemoteException
     * while posting a notification of a foreground service.
     *
     * @hide
     */
    public static class CannotPostForegroundServiceNotificationException
            extends RemoteServiceException {
        /** The type ID passed to {@link IApplicationThread#scheduleCrash}. */
        public static final int TYPE_ID = 3;

        public CannotPostForegroundServiceNotificationException(String msg) {
            super(msg);
        }
    }

    /**
     * Exception used to crash an app process when the system finds an error in a foreground service
     * notification.
     *
     * @hide
     */
    public static class BadForegroundServiceNotificationException extends RemoteServiceException {
        /** The type ID passed to {@link IApplicationThread#scheduleCrash}. */
        public static final int TYPE_ID = 4;

        public BadForegroundServiceNotificationException(String msg) {
            super(msg);
        }
    }

    /**
     * Exception used to crash an app process when it calls a setting activity that requires
     * the {@code REQUEST_PASSWORD_COMPLEXITY} permission.
     *
     * @hide
     */
    public static class MissingRequestPasswordComplexityPermissionException
            extends RemoteServiceException {
        /** The type ID passed to {@link IApplicationThread#scheduleCrash}. */
        public static final int TYPE_ID = 5;

        public MissingRequestPasswordComplexityPermissionException(String msg) {
            super(msg);
        }
    }

    /**
     * Exception used to crash an app process by {@code adb shell am crash}.
     *
     * @hide
     */
    public static class CrashedByAdbException extends RemoteServiceException {
        /** The type ID passed to {@link IApplicationThread#scheduleCrash}. */
        public static final int TYPE_ID = 6;

        public CrashedByAdbException(String msg) {
            super(msg);
        }
    }
}
+4 −4
Original line number Diff line number Diff line
@@ -87,7 +87,6 @@ import android.app.ActivityManagerInternal.ServiceNotificationPolicy;
import android.app.ActivityThread;
import android.app.AppGlobals;
import android.app.AppOpsManager;
import android.app.ForegroundServiceDidNotStartInTimeException;
import android.app.ForegroundServiceStartNotAllowedException;
import android.app.IApplicationThread;
import android.app.IForegroundServiceObserver;
@@ -95,6 +94,7 @@ import android.app.IServiceConnection;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.RemoteServiceException.ForegroundServiceDidNotStartInTimeException;
import android.app.Service;
import android.app.ServiceStartArgs;
import android.app.admin.DevicePolicyEventLogger;
@@ -1293,7 +1293,7 @@ public final class ActiveServices {
    }

    void killMisbehavingService(ServiceRecord r,
            int appUid, int appPid, String localPackageName) {
            int appUid, int appPid, String localPackageName, int exceptionTypeId) {
        synchronized (mAm) {
            if (!r.destroying) {
                // This service is still alive, stop it.
@@ -1307,8 +1307,8 @@ public final class ActiveServices {
                    stopServiceLocked(found, false);
                }
            }
            mAm.crashApplication(appUid, appPid, localPackageName, -1,
                    "Bad notification for startForeground", true /*force*/);
            mAm.crashApplicationWithType(appUid, appPid, localPackageName, -1,
                    "Bad notification for startForeground", true /*force*/, exceptionTypeId);
        }
    }

Loading