• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.permissioncontroller;
18 
19 import android.app.Application;
20 import android.content.ComponentName;
21 import android.content.pm.PackageItemInfo;
22 import android.content.pm.PackageManager;
23 import android.util.ArrayMap;
24 
25 import com.android.permissioncontroller.role.model.Role;
26 import com.android.permissioncontroller.role.model.Roles;
27 import com.android.permissioncontroller.role.ui.SpecialAppAccessListActivity;
28 
29 public final class PermissionControllerApplication extends Application {
30 
31     private static PermissionControllerApplication sInstance;
32 
33     @Override
onCreate()34     public void onCreate() {
35         super.onCreate();
36 
37         sInstance = this;
38 
39         PackageItemInfo.forceSafeLabels();
40         updateSpecialAppAccessListActivityEnabledState();
41     }
42 
43     /**
44      * Statically gets the {@link PermissionControllerApplication} instance
45      */
get()46     public static PermissionControllerApplication get() {
47         return sInstance;
48     }
49 
updateSpecialAppAccessListActivityEnabledState()50     private void updateSpecialAppAccessListActivityEnabledState() {
51         ArrayMap<String, Role> roles = Roles.get(this);
52         boolean hasVisibleSpecialAppAccess = false;
53         int rolesSize = roles.size();
54         for (int i = 0; i < rolesSize; i++) {
55             Role role = roles.valueAt(i);
56 
57             if (!role.isAvailable(this) || !role.isVisible(this)) {
58                 continue;
59             }
60             if (!role.isExclusive()) {
61                 hasVisibleSpecialAppAccess = true;
62                 break;
63             }
64         }
65 
66         PackageManager packageManager = getPackageManager();
67         ComponentName componentName = new ComponentName(this, SpecialAppAccessListActivity.class);
68         int enabledState = hasVisibleSpecialAppAccess
69                 ? PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
70                 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
71         packageManager.setComponentEnabledSetting(componentName, enabledState,
72                 PackageManager.DONT_KILL_APP);
73     }
74 }
75