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

Commit 4cadfe8c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Throw when automatic watching expected but missing" into sc-dev

parents 57406e2f 41162b58
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -1449,21 +1449,21 @@ public class PackageManagerService extends IPackageManager.Stub
    /** Token for keys in mPendingEnableRollback. */
    private int mPendingEnableRollbackToken = 0;
    @Watched
    @Watched(manual = true)
    volatile boolean mSystemReady;
    @Watched
    @Watched(manual = true)
    private volatile boolean mSafeMode;
    volatile boolean mHasSystemUidErrors;
    @Watched
    private final WatchedSparseBooleanArray mWebInstantAppsDisabled =
            new WatchedSparseBooleanArray();
    @Watched
    @Watched(manual = true)
    private ApplicationInfo mAndroidApplication;
    @Watched
    @Watched(manual = true)
    final ActivityInfo mResolveActivity = new ActivityInfo();
    final ResolveInfo mResolveInfo = new ResolveInfo();
    @Watched
    @Watched(manual = true)
    private ComponentName mResolveComponentName;
    AndroidPackage mPlatformPackage;
    ComponentName mCustomResolverComponentName;
@@ -1479,9 +1479,9 @@ public class PackageManagerService extends IPackageManager.Stub
    final ComponentName mInstantAppResolverSettingsComponent;
    /** Activity used to install instant applications */
    @Watched
    @Watched(manual = true)
    private ActivityInfo mInstantAppInstallerActivity;
    @Watched
    @Watched(manual = true)
    private final ResolveInfo mInstantAppInstallerInfo = new ResolveInfo();
    private final Map<String, Pair<PackageInstalledInfo, IPackageInstallObserver2>>
+15 −12
Original line number Diff line number Diff line
@@ -73,7 +73,8 @@ public interface Watchable {
            return;
        }
        for (Field f : base.getClass().getDeclaredFields()) {
            if (f.getAnnotation(Watched.class) != null) {
            final Watched annotation = f.getAnnotation(Watched.class);
            if (annotation != null) {
                final String fn = base.getClass().getName() + "." + f.getName();
                try {
                    f.setAccessible(true);
@@ -81,25 +82,27 @@ public interface Watchable {
                    if (o instanceof Watchable) {
                        Watchable attr = (Watchable) (o);
                        if (attr != null && !attr.isRegisteredObserver(observer)) {
                            if (logOnly) {
                                Log.e("Watchable", fn + " missing an observer");
                            } else {
                                throw new RuntimeException("Watchable " + fn
                                                           + " missing an observer");
                            }
                            handleVerifyError("Watchable " + fn + " missing an observer", logOnly);
                        }
                    } else if (!annotation.manual()) {
                        handleVerifyError("@Watched annotated field " + fn + " is not a watchable"
                                + " type and is not flagged for manual watching.", logOnly);
                    }
                } catch (IllegalAccessException e) {
                    // The field is protected; ignore it.  Other exceptions that may be thrown by
                    // Field.get() are allowed to roll up.
                    if (logOnly) {
                        Log.e("Watchable", fn + " not visible");
                    } else {
                        throw new RuntimeException("Watchable " + fn + " not visible");
                    handleVerifyError("Watchable " + fn + " not visible", logOnly);
                }
            }
        }
    }

    static void handleVerifyError(String errorMessage, boolean logOnly) {
        if (logOnly) {
            Log.e("Watchable", errorMessage);
        } else {
            throw new RuntimeException(errorMessage);
        }
    }

    /**
+2 −0
Original line number Diff line number Diff line
@@ -29,4 +29,6 @@ import java.lang.annotation.Target;
@Target({ ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
public @interface Watched {
    /** true if the annotated field is manually tracked */
    boolean manual() default false;
}