• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 package com.android.launcher3;
17 
18 import android.app.Application;
19 
20 import com.android.launcher3.dagger.DaggerLauncherAppComponent;
21 import com.android.launcher3.dagger.LauncherAppComponent;
22 import com.android.launcher3.dagger.LauncherBaseAppComponent;
23 import com.android.launcher3.util.TraceHelper;
24 
25 /**
26  * Main application class for Launcher
27  */
28 public class LauncherApplication extends Application {
29 
30     private volatile LauncherBaseAppComponent mAppComponent;
31     @Override
onCreate()32     public void onCreate() {
33         super.onCreate();
34         MainProcessInitializer.initialize(this);
35     }
36 
getAppComponent()37     public LauncherAppComponent getAppComponent() {
38         if (mAppComponent == null) {
39             synchronized (this) {
40                 // Check for null again, as it may have been assigned on a different thread. This
41                 // avoids holding synchronization locks everytime.
42                 if (mAppComponent == null) {
43                     // Initialize the dagger component on demand as content providers can get
44                     // accessed before the Launcher application (b/36917845#comment4)
45                     initDaggerComponent(DaggerLauncherAppComponent.builder()
46                             .iconsDbName(LauncherFiles.APP_ICONS_DB));
47                 }
48             }
49         }
50         // Since supertype setters will return a supertype.builder and @Component.Builder types
51         // must not have any generic types.
52         // We need to cast mAppComponent to {@link LauncherAppComponent} since appContext()
53         // method is defined in the super class LauncherBaseComponent#Builder.
54         return (LauncherAppComponent) mAppComponent;
55     }
56 
57     /**
58      * Init with the desired dagger component.
59      */
initDaggerComponent(LauncherBaseAppComponent.Builder componentBuilder)60     public void initDaggerComponent(LauncherBaseAppComponent.Builder componentBuilder) {
61         mAppComponent = componentBuilder
62                 .appContext(this)
63                 .setSafeModeEnabled(TraceHelper.allowIpcs(
64                         "isSafeMode", () -> getPackageManager().isSafeMode()))
65                 .build();
66     }
67 }
68