• 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.car;
18 
19 import android.content.Context;
20 import android.content.Intent;
21 
22 import com.android.car.internal.NotificationHelperBase;
23 import com.android.internal.annotations.VisibleForTesting;
24 
25 import java.lang.reflect.Constructor;
26 
27 /**
28  * Declared all dependencies into builtin package, mostly for Activity / class / method names.
29  *
30  * <p> This is for tracking all dependencies done through java reflection.
31  */
32 public final class BuiltinPackageDependency {
BuiltinPackageDependency()33     private BuiltinPackageDependency() {};
34 
35     /** Package name of builtin, Will be necessary to send Intent. */
36     public static final String BUILTIN_CAR_SERVICE_PACKAGE_NAME = "com.android.car";
37 
38     /** {@code com.android.car.am.ContinuousBlankActivity} */
39     public static final String BLANK_ACTIVITY_CLASS = "com.android.car.am.ContinuousBlankActivity";
40 
41     /** {@code com.android.car.pm.CarSafetyAccessibilityService} */
42     public static final String CAR_ACCESSIBILITY_SERVICE_CLASS =
43             "com.android.car.pm.CarSafetyAccessibilityService";
44 
45     /** {@code com.android.car.PerUserCarService} */
46     public static final String PER_USER_CAR_SERVICE_CLASS = "com.android.car.PerUserCarService";
47 
48     public static final String EVS_HAL_WRAPPER_CLASS = "com.android.car.evs.EvsHalWrapperImpl";
49 
50     /** {@code com.android.car.admin.NotificationHelper} class. */
51     @VisibleForTesting
52     public static final String NOTIFICATION_HELPER_CLASS =
53             "com.android.car.admin.NotificationHelper";
54 
55     /** {@code com.android.car.CarService} class. */
56     private static final String CAR_SERVICE_CLASS = "com.android.car.CarService";
57 
58     /** {@code com.android.car.CarService#VERSION_MINOR_INT} */
59     private static final String CAR_SERVICE_VERSION_MINOR_INT = "VERSION_MINOR_INT";
60 
61     /** Returns {@code ComponentName} string for builtin package component */
getComponentName(String className)62     public static String getComponentName(String className) {
63         return new StringBuilder()
64                 .append(BUILTIN_CAR_SERVICE_PACKAGE_NAME)
65                 .append('/')
66                 .append(className)
67                 .toString();
68     }
69 
70     /** Sets builtin package's class to the passed Intent and returns the Intent. */
addClassNameToIntent(Context context, Intent intent, String className)71     public static Intent addClassNameToIntent(Context context, Intent intent, String className) {
72         intent.setClassName(context.getPackageName(), className);
73         return intent;
74     }
75 
76     /**
77      * Creates {@link NotificationHelperBase} implemented from Builtin Car service.
78      *
79      * @param builtinContext {@code Context} of the builtin CarService where the
80      *                       NotificationHelper's code is loaded.
81      */
createNotificationHelper(Context builtinContext)82     public static NotificationHelperBase createNotificationHelper(Context builtinContext) {
83         try {
84             Class helperClass = builtinContext.getClassLoader().loadClass(
85                     NOTIFICATION_HELPER_CLASS);
86             // Use default constructor always
87             Constructor constructor = helperClass.getConstructor(new Class[]{Context.class});
88             return (NotificationHelperBase) constructor.newInstance(builtinContext);
89         } catch (Exception e) {
90             throw new IllegalStateException("Cannot load class:" + NOTIFICATION_HELPER_CLASS, e);
91         }
92     }
93 }
94