• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.managedprovisioning;
18 
19 import android.app.Activity;
20 import android.app.Application;
21 import android.content.ComponentName;
22 
23 import com.android.managedprovisioning.preprovisioning.EncryptionController;
24 
25 /**
26  * A base {@link Application} that is meant to be extended.
27  *
28  * <p>{@code ManagedProvisioning} inheritors are required to extend this class. They
29  * can map their own {@link Activity} classes to existing {@code ManagedProvisioning}
30  * screens by calling {@link #setOverrideActivity(ManagedProvisioningScreens, Class)}.
31  *
32  * <p>By default, the existing {@code ManagedProvisioning} {@link Activity} classes are used.
33  */
34 public abstract class ManagedProvisioningBaseApplication extends Application {
35     private final ScreenManager mScreenManager =
36             new ScreenManager(ScreenManager.DEFAULT_SCREEN_TO_ACTIVITY_MAP);
37     private EncryptionController mEncryptionController;
38 
39     @Override
onCreate()40     public void onCreate() {
41         super.onCreate();
42         mEncryptionController = EncryptionController.getInstance(
43                 this,
44                 new ComponentName(
45                         /* pkg= */ this,
46                         getActivityClassForScreen(ManagedProvisioningScreens.POST_ENCRYPT)));
47     }
48 
getEncryptionController()49     public final EncryptionController getEncryptionController() {
50         return mEncryptionController;
51     }
52 
53     /**
54      * Maps the provided {@code screen} to the provided {@code activityClass}.
55      *
56      * <p>When ManagedProvisioning wants to launch any of the screens in {@link
57      * ManagedProvisioningScreens}, instead of its base {@link Activity} implementation, it will
58      * launch the class provided here.
59      */
setOverrideActivity( ManagedProvisioningScreens screen, Class<? extends Activity> activityClass)60     public final void setOverrideActivity(
61             ManagedProvisioningScreens screen, Class<? extends Activity> activityClass) {
62         mScreenManager.setOverrideActivity(screen, activityClass);
63     }
64 
65     /**
66      * Retrieves the {@link Activity} class associated with the provided {@code screen}.
67      *
68      * <p>If no screens were set via {@link #setOverrideActivity(ManagedProvisioningScreens,
69      * Class)}, the base ManagedProvisioning {@link Activity} implementation will be returned.
70      */
71     public final Class<? extends Activity>
getActivityClassForScreen(ManagedProvisioningScreens screen)72             getActivityClassForScreen(ManagedProvisioningScreens screen) {
73         return mScreenManager.getActivityClassForScreen(screen);
74     }
75 }
76