1 /*
2  * Copyright (C) 2020 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.systemui.car.sideloaded;
18 
19 import android.app.IActivityTaskManager;
20 import android.os.RemoteException;
21 import android.util.Log;
22 
23 import com.android.systemui.CoreStartable;
24 import com.android.systemui.dagger.SysUISingleton;
25 
26 import javax.inject.Inject;
27 
28 /**
29  * Controller responsible for detecting unsafe apps.
30  */
31 @SysUISingleton
32 public class SideLoadedAppController implements CoreStartable {
33     private static final String TAG = SideLoadedAppController.class.getSimpleName();
34 
35     private IActivityTaskManager mActivityTaskManager;
36     private SideLoadedAppListener mSideLoadedAppListener;
37     private SideLoadedAppDetector mSideLoadedAppDetector;
38     private SideLoadedAppStateController mSideLoadedAppStateController;
39 
40     @Inject
SideLoadedAppController( IActivityTaskManager activityTaskManager, SideLoadedAppDetector sideLoadedAppDetector, SideLoadedAppListener sideLoadedAppListener, SideLoadedAppStateController sideLoadedAppStateController)41     public SideLoadedAppController(
42             IActivityTaskManager activityTaskManager,
43             SideLoadedAppDetector sideLoadedAppDetector,
44             SideLoadedAppListener sideLoadedAppListener,
45             SideLoadedAppStateController sideLoadedAppStateController) {
46         mSideLoadedAppDetector = sideLoadedAppDetector;
47         mActivityTaskManager = activityTaskManager;
48         mSideLoadedAppListener = sideLoadedAppListener;
49         mSideLoadedAppStateController = sideLoadedAppStateController;
50     }
51 
52     @Override
start()53     public void start() {
54     }
55 
56     @Override
onBootCompleted()57     public void onBootCompleted() {
58         Log.i(TAG, "OnBootCompleted");
59 
60         try {
61             mActivityTaskManager.registerTaskStackListener(mSideLoadedAppListener);
62         } catch (RemoteException e) {
63             Log.e(TAG, "Could not register car side loaded app listener.", e);
64         }
65 
66         if (mSideLoadedAppDetector.hasUnsafeInstalledApps()) {
67             mSideLoadedAppStateController.onUnsafeInstalledAppsDetected();
68         }
69     }
70 }
71