• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.server.art.prereboot;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.content.Context;
22 import android.os.ArtModuleServiceManager;
23 import android.os.Build;
24 import android.os.CancellationSignal;
25 
26 import androidx.annotation.RequiresApi;
27 
28 import com.android.server.art.proto.BatchDexoptParamsProto;
29 import com.android.server.pm.PackageManagerLocal;
30 
31 /**
32  * The interface for the entry point of Pre-reboot Dexopt, called through reflection from an old
33  * version of the ART module. This interface must be kept stable from one version of the ART module
34  * to another. In principle, a method here should be kept as long as devices that receive Mainline
35  * updates call it from their old factory installed modules, unless there is a good reason to drop
36  * the Pre-reboot Dexopt support earlier for certain versions of the ART module.
37  *
38  * Dropping the support for certain versions will only make devices lose the opportunity to optimize
39  * apps before the reboot, but it won't cause severe results such as crashes because even the oldest
40  * version that uses this interface can elegantly handle reflection exceptions.
41  *
42  * During Pre-reboot Dexopt, the new version of this code is run.
43  *
44  * Methods in this interface must not take an instance of a class defined in `service-art.jar`. See
45  * comments in {@link PreRebootDriver#runFromChroot} for the reason.
46  *
47  * @hide
48  */
49 @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM)
50 public interface PreRebootManagerInterface {
51     /** Since Android V. For backward compatibility only. */
run(@onNull ArtModuleServiceManager artModuleServiceManager, @NonNull Context context, @NonNull CancellationSignal cancellationSignal)52     void run(@NonNull ArtModuleServiceManager artModuleServiceManager, @NonNull Context context,
53             @NonNull CancellationSignal cancellationSignal) throws SystemRequirementException;
54 
55     /**
56      * Since Android B. The current API.
57      *
58      * @param snapshot The snapshot that {@code batchDexoptParamsProto} is created with.
59      * @param batchDexoptParamsProto {@link BatchDexoptParamsProto}, in binary format.
60      */
run(@onNull ArtModuleServiceManager artModuleServiceManager, @NonNull Context context, @NonNull CancellationSignal cancellationSignal, @NonNull PackageManagerLocal.FilteredSnapshot snapshot, @Nullable byte[] batchDexoptParamsProto)61     void run(@NonNull ArtModuleServiceManager artModuleServiceManager, @NonNull Context context,
62             @NonNull CancellationSignal cancellationSignal,
63             @NonNull PackageManagerLocal.FilteredSnapshot snapshot,
64             @Nullable byte[] batchDexoptParamsProto) throws SystemRequirementException;
65 
66     public static class SystemRequirementException extends Exception {
SystemRequirementException(@onNull String message)67         public SystemRequirementException(@NonNull String message) {
68             super(message);
69         }
70     }
71 }
72