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

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

Merge "ForegroundServiceDidNotStartInTimeException now has..." into sc-v2-dev

parents cfcfa223 45f4b4aa
Loading
Loading
Loading
Loading
+23 −6
Original line number Diff line number Diff line
@@ -1294,8 +1294,11 @@ public final class ActivityThread extends ClientTransactionHandler
        }

        @Override
        public void scheduleCrash(String msg, int typeId) {
            sendMessage(H.SCHEDULE_CRASH, msg, typeId);
        public void scheduleCrash(String msg, int typeId, @Nullable Bundle extras) {
            SomeArgs args = SomeArgs.obtain();
            args.arg1 = msg;
            args.arg2 = extras;
            sendMessage(H.SCHEDULE_CRASH, args, typeId);
        }

        public void dumpActivity(ParcelFileDescriptor pfd, IBinder activitytoken,
@@ -1925,11 +1928,11 @@ public final class ActivityThread extends ClientTransactionHandler
        }
    }

    private void throwRemoteServiceException(String message, int typeId) {
    private void throwRemoteServiceException(String message, int typeId, @Nullable Bundle extras) {
        // Use a switch to ensure all the type IDs are unique.
        switch (typeId) {
            case ForegroundServiceDidNotStartInTimeException.TYPE_ID:
                throw new ForegroundServiceDidNotStartInTimeException(message);
                throw generateForegroundServiceDidNotStartInTimeException(message, extras);

            case CannotDeliverBroadcastException.TYPE_ID:
                throw new CannotDeliverBroadcastException(message);
@@ -1952,6 +1955,15 @@ public final class ActivityThread extends ClientTransactionHandler
        }
    }

    private ForegroundServiceDidNotStartInTimeException
            generateForegroundServiceDidNotStartInTimeException(String message, Bundle extras) {
        final String serviceClassName =
                ForegroundServiceDidNotStartInTimeException.getServiceClassNameFromExtras(extras);
        final Exception inner = (serviceClassName == null) ? null
                : Service.getStartForegroundServiceStackTrace(serviceClassName);
        throw new ForegroundServiceDidNotStartInTimeException(message, inner);
    }

    class H extends Handler {
        public static final int BIND_APPLICATION        = 110;
        @UnsupportedAppUsage
@@ -2169,9 +2181,14 @@ public final class ActivityThread extends ClientTransactionHandler
                    handleDispatchPackageBroadcast(msg.arg1, (String[])msg.obj);
                    Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
                    break;
                case SCHEDULE_CRASH:
                    throwRemoteServiceException((String) msg.obj, msg.arg1);
                case SCHEDULE_CRASH: {
                    SomeArgs args = (SomeArgs) msg.obj;
                    String message = (String) args.arg1;
                    Bundle extras = (Bundle) args.arg2;
                    args.recycle();
                    throwRemoteServiceException(message, msg.arg1, extras);
                    break;
                }
                case DUMP_HEAP:
                    handleDumpHeap((DumpHeapData) msg.obj);
                    break;
+8 −0
Original line number Diff line number Diff line
@@ -1862,6 +1862,14 @@ class ContextImpl extends Context {
                            "Not allowed to start service " + service + ": " + cn.getClassName());
                }
            }
            // If we started a foreground service in the same package, remember the stack trace.
            if (cn != null && requireForeground) {
                if (cn.getPackageName().equals(getOpPackageName())) {
                    Service.setStartForegroundServiceStackTrace(cn.getClassName(),
                            new StackTrace("Last startServiceCommon() call for this service was "
                                    + "made here"));
                }
            }
            return cn;
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
+2 −0
Original line number Diff line number Diff line
@@ -321,6 +321,8 @@ interface IActivityManager {
    boolean isTopActivityImmersive();
    void crashApplicationWithType(int uid, int initialPid, in String packageName, int userId,
            in String message, boolean force, int exceptionTypeId);
    void crashApplicationWithTypeWithExtras(int uid, int initialPid, in String packageName,
            int userId, in String message, boolean force, int exceptionTypeId, in Bundle extras);
    /** @deprecated -- use getProviderMimeTypeAsync */
    @UnsupportedAppUsage(maxTargetSdk = 29, publicAlternatives =
            "Use {@link android.content.ContentResolver#getType} public API instead.")
+1 −1
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ oneway interface IApplicationThread {
    void scheduleOnNewActivityOptions(IBinder token, in Bundle options);
    void scheduleSuicide();
    void dispatchPackageBroadcast(int cmd, in String[] packages);
    void scheduleCrash(in String msg, int typeId);
    void scheduleCrash(in String msg, int typeId, in Bundle extras);
    void dumpHeap(boolean managed, boolean mallocInfo, boolean runGc, in String path,
            in ParcelFileDescriptor fd, in RemoteCallback finishCallback);
    void dumpActivity(in ParcelFileDescriptor fd, IBinder servicetoken, in String prefix,
+23 −2
Original line number Diff line number Diff line
@@ -16,6 +16,10 @@

package android.app;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.ComponentName;
import android.os.Bundle;
import android.util.AndroidRuntimeException;

/**
@@ -33,6 +37,10 @@ public class RemoteServiceException extends AndroidRuntimeException {
        super(msg);
    }

    public RemoteServiceException(String msg, Throwable cause) {
        super(msg, cause);
    }

    /**
     * Exception used to crash an app process when it didn't call {@link Service#startForeground}
     * in time after the service was started with
@@ -44,8 +52,21 @@ public class RemoteServiceException extends AndroidRuntimeException {
        /** The type ID passed to {@link IApplicationThread#scheduleCrash}. */
        public static final int TYPE_ID = 1;

        public ForegroundServiceDidNotStartInTimeException(String msg) {
            super(msg);
        private static final String KEY_SERVICE_CLASS_NAME = "serviceclassname";

        public ForegroundServiceDidNotStartInTimeException(String msg, Throwable cause) {
            super(msg, cause);
        }

        public static Bundle createExtrasForService(@NonNull ComponentName service) {
            Bundle b = new Bundle();
            b.putString(KEY_SERVICE_CLASS_NAME, service.getClassName());
            return b;
        }

        @Nullable
        public static String getServiceClassNameFromExtras(@Nullable Bundle extras) {
            return (extras == null) ? null : extras.getString(KEY_SERVICE_CLASS_NAME);
        }
    }

Loading