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

Commit 1bf1952d authored by Harshit Mahajan's avatar Harshit Mahajan
Browse files

Introduce CrashRecovery Adaptor

This will enable us to move CrashRecovery files out of platform into
separate apex behind flag.
Platform would be using:
1. Pre-modularization adaptor: When CrashRecovery is part of platoform
2. Post-modularization adaptor: When CrashRecovery apex is created.

We will control this behaviour using RELEASE_CRASHRECOVERY build flag.

Bug: 289203818
Test: device boots and crashrecovery service is started
Flag: build.release_crashrecovery_module
Change-Id: Ib3cd7e428a85dfa85654221c46fdab4d3c5a7954
parent bb1810c4
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
filegroup {
    name: "crashrecovery-platform-adaptor-srcs",
    srcs: select(soong_config_variable("ANDROID", "release_crashrecovery_module"), {
        "true": [
            "postModularization/java/**/*.java",
        ],
        default: [
            "preModularization/java/**/*.java",
        ],
    }),
    visibility: ["//frameworks/base:__subpackages__"],
}
+72 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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 com.android.server.crashrecovery;

import android.content.Context;

import com.android.server.PackageWatchdog;
import com.android.server.SystemServiceManager;

import java.util.List;

/**
 * This class mediates calls to hidden APIs in CrashRecovery module.
 * This class is used when the CrashRecovery classes are moved to separate module.
 *
 * @hide
 */
public class CrashRecoveryAdaptor {
    private static final String TAG = "CrashRecoveryAdaptor";
    private static final String CRASHRECOVERY_MODULE_LIFECYCLE_CLASS =
            "com.android.server.crashrecovery.CrashRecoveryModule$Lifecycle";

    /**  Start CrashRecoveryModule LifeCycleService */
    public static void initializeCrashrecoveryModuleService(
            SystemServiceManager mSystemServiceManager) {
        mSystemServiceManager.startService(CRASHRECOVERY_MODULE_LIFECYCLE_CLASS);
    }

    /**  Does Nothing */
    public static void packageWatchdogNoteBoot(Context mSystemContext) {
        // do nothing
    }

    /**  Does Nothing */
    public static void packageWatchdogWriteNow(Context mContext) {
        // do nothing
    }

    /**  Does Nothing */
    public static void packageWatchdogOnPackagesReady(PackageWatchdog mPackageWatchdog) {
        // do nothing
    }

    /**  Does Nothing */
    public static void rescuePartyRegisterHealthObserver(Context mSystemContext) {
        // do nothing
    }

    /**  Does Nothing */
    public static void rescuePartyOnSettingsProviderPublished(Context mContext) {
        // do nothing
    }

    /**  Does Nothing */
    public static void rescuePartyResetDeviceConfigForPackages(List<String> packageNames) {
        // do nothing
    }
}
+71 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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 com.android.server.crashrecovery;

import android.content.Context;

import com.android.server.PackageWatchdog;
import com.android.server.RescueParty;
import com.android.server.SystemServiceManager;

import java.util.List;

/**
 * This class mediates calls to hidden APIs in CrashRecovery module.
 * This class is used when CrashRecovery classes are still in platform.
 *
 * @hide
 */
public class CrashRecoveryAdaptor {
    private static final String TAG = "CrashRecoveryAdaptor";

    /**  Start CrashRecoveryModule LifeCycleService */
    public static void initializeCrashrecoveryModuleService(
            SystemServiceManager mSystemServiceManager) {
        mSystemServiceManager.startService(CrashRecoveryModule.Lifecycle.class);
    }

    /**  Forward calls to PackageWatchdog noteboot  */
    public static void packageWatchdogNoteBoot(Context mSystemContext) {
        PackageWatchdog.getInstance(mSystemContext).noteBoot();
    }

    /**  Forward calls to PackageWatchdog writeNow */
    public static void packageWatchdogWriteNow(Context mContext) {
        PackageWatchdog.getInstance(mContext).writeNow();
    }

    /**  Forward calls to PackageWatchdog OnPackagesReady */
    public static void packageWatchdogOnPackagesReady(PackageWatchdog mPackageWatchdog) {
        mPackageWatchdog.onPackagesReady();
    }

    /**  Forward calls to RescueParty RegisterHealthObserver */
    public static void rescuePartyRegisterHealthObserver(Context mSystemContext) {
        RescueParty.registerHealthObserver(mSystemContext);
    }

    /**  Forward calls to RescueParty OnSettingsProviderPublished */
    public static void rescuePartyOnSettingsProviderPublished(Context mContext) {
        RescueParty.onSettingsProviderPublished(mContext);
    }

    /**  Forward calls to RescueParty ResetDeviceConfigForPackages */
    public static void rescuePartyResetDeviceConfigForPackages(List<String> packageNames) {
        RescueParty.resetDeviceConfigForPackages(packageNames);
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ platform_filegroup {
                "java/**/*.java",
                "java/**/*.aidl",
                ":statslog-crashrecovery-java-gen",
                ":crashrecovery-platform-adaptor-srcs",
            ],
        },
    },
+2 −1
Original line number Diff line number Diff line
@@ -441,6 +441,7 @@ import com.android.server.am.LowMemDetector.MemFactor;
import com.android.server.appop.AppOpsService;
import com.android.server.compat.PlatformCompat;
import com.android.server.contentcapture.ContentCaptureManagerInternal;
import com.android.server.crashrecovery.CrashRecoveryAdaptor;
import com.android.server.crashrecovery.CrashRecoveryHelper;
import com.android.server.criticalevents.CriticalEventLog;
import com.android.server.firewall.IntentFirewall;
@@ -2210,7 +2211,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                mService.mBroadcastController.startBroadcastObservers();
            } else if (phase == PHASE_THIRD_PARTY_APPS_CAN_START) {
                if (!refactorCrashrecovery()) {
                    mService.mPackageWatchdog.onPackagesReady();
                    CrashRecoveryAdaptor.packageWatchdogOnPackagesReady(mService.mPackageWatchdog);
                } else {
                    mService.mCrashRecoveryHelper.registerConnectivityModuleHealthListener();
                }
Loading