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 package com.android.server; 17 18 import static java.util.stream.Collectors.toList; 19 import static java.util.stream.Collectors.toMap; 20 21 import android.Manifest; 22 import android.content.ComponentName; 23 import android.content.Context; 24 import android.os.ISystemConfig; 25 import android.util.ArrayMap; 26 import android.util.ArraySet; 27 import android.util.SparseArray; 28 29 import com.android.internal.util.ArrayUtils; 30 31 import java.util.ArrayList; 32 import java.util.List; 33 import java.util.Map; 34 35 /** 36 * Service class that runs inside the system_server process to handle queries to 37 * {@link com.android.server.SystemConfig}. 38 * @hide 39 */ 40 public class SystemConfigService extends SystemService { 41 private final Context mContext; 42 43 private final ISystemConfig.Stub mInterface = new ISystemConfig.Stub() { 44 @Override 45 public List<String> getDisabledUntilUsedPreinstalledCarrierApps() { 46 mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_CARRIER_APP_INFO, 47 "getDisabledUntilUsedPreInstalledCarrierApps requires READ_CARRIER_APP_INFO"); 48 return new ArrayList<>( 49 SystemConfig.getInstance().getDisabledUntilUsedPreinstalledCarrierApps()); 50 } 51 52 @Override 53 public Map getDisabledUntilUsedPreinstalledCarrierAssociatedApps() { 54 mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_CARRIER_APP_INFO, 55 "getDisabledUntilUsedPreInstalledCarrierAssociatedApps requires" 56 + " READ_CARRIER_APP_INFO"); 57 return SystemConfig.getInstance() 58 .getDisabledUntilUsedPreinstalledCarrierAssociatedApps().entrySet().stream() 59 .collect(toMap( 60 Map.Entry::getKey, 61 e -> e.getValue().stream().map(app -> app.packageName) 62 .collect(toList()))); 63 } 64 65 @Override 66 public Map getDisabledUntilUsedPreinstalledCarrierAssociatedAppEntries() { 67 mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_CARRIER_APP_INFO, 68 "getDisabledUntilUsedPreInstalledCarrierAssociatedAppEntries requires" 69 + " READ_CARRIER_APP_INFO"); 70 return SystemConfig.getInstance() 71 .getDisabledUntilUsedPreinstalledCarrierAssociatedApps(); 72 } 73 74 @Override 75 public int[] getSystemPermissionUids(String permissionName) { 76 mContext.enforceCallingOrSelfPermission(Manifest.permission.GET_RUNTIME_PERMISSIONS, 77 "getSystemPermissionUids requires GET_RUNTIME_PERMISSIONS"); 78 final List<Integer> uids = new ArrayList<>(); 79 final SparseArray<ArraySet<String>> systemPermissions = 80 SystemConfig.getInstance().getSystemPermissions(); 81 for (int i = 0; i < systemPermissions.size(); i++) { 82 final ArraySet<String> permissions = systemPermissions.valueAt(i); 83 if (permissions != null && permissions.contains(permissionName)) { 84 uids.add(systemPermissions.keyAt(i)); 85 } 86 } 87 return ArrayUtils.convertToIntArray(uids); 88 } 89 90 @Override 91 public List<ComponentName> getEnabledComponentOverrides(String packageName) { 92 ArrayMap<String, Boolean> systemComponents = SystemConfig.getInstance() 93 .getComponentsEnabledStates(packageName); 94 List<ComponentName> enabledComponent = new ArrayList<>(); 95 if (systemComponents != null) { 96 for (Map.Entry<String, Boolean> entry : systemComponents.entrySet()) { 97 if (Boolean.TRUE.equals(entry.getValue())) { 98 enabledComponent.add(new ComponentName(packageName, entry.getKey())); 99 } 100 } 101 } 102 return enabledComponent; 103 } 104 105 @Override 106 public List<ComponentName> getDefaultVrComponents() { 107 getContext().enforceCallingOrSelfPermission(Manifest.permission.QUERY_ALL_PACKAGES, 108 "Caller must hold " + Manifest.permission.QUERY_ALL_PACKAGES); 109 return new ArrayList<>(SystemConfig.getInstance().getDefaultVrComponents()); 110 } 111 }; 112 SystemConfigService(Context context)113 public SystemConfigService(Context context) { 114 super(context); 115 mContext = context; 116 } 117 118 @Override onStart()119 public void onStart() { 120 publishBinderService(Context.SYSTEM_CONFIG_SERVICE, mInterface); 121 } 122 } 123