Hall Liu | b38ad5f | 2019-12-23 18:11:10 -0800 | [diff] [blame] | 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 | |
Hunter Knepshield | 1172ffa | 2020-06-15 19:42:15 -0700 | [diff] [blame] | 18 | import static java.util.stream.Collectors.toList; |
| 19 | import static java.util.stream.Collectors.toMap; |
| 20 | |
Hall Liu | b38ad5f | 2019-12-23 18:11:10 -0800 | [diff] [blame] | 21 | import android.Manifest; |
| 22 | import android.content.Context; |
| 23 | import android.os.ISystemConfig; |
paulhu | ba70fa8 | 2021-01-27 11:21:09 +0800 | [diff] [blame] | 24 | import android.util.ArraySet; |
| 25 | import android.util.SparseArray; |
| 26 | |
| 27 | import com.android.internal.util.ArrayUtils; |
Hall Liu | b38ad5f | 2019-12-23 18:11:10 -0800 | [diff] [blame] | 28 | |
| 29 | import java.util.ArrayList; |
| 30 | import java.util.List; |
| 31 | import java.util.Map; |
| 32 | |
| 33 | /** |
| 34 | * Service class that runs inside the system_server process to handle queries to |
| 35 | * {@link com.android.server.SystemConfig}. |
| 36 | * @hide |
| 37 | */ |
| 38 | public class SystemConfigService extends SystemService { |
| 39 | private final Context mContext; |
| 40 | |
| 41 | private final ISystemConfig.Stub mInterface = new ISystemConfig.Stub() { |
| 42 | @Override |
| 43 | public List<String> getDisabledUntilUsedPreinstalledCarrierApps() { |
| 44 | mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_CARRIER_APP_INFO, |
| 45 | "getDisabledUntilUsedPreInstalledCarrierApps requires READ_CARRIER_APP_INFO"); |
| 46 | return new ArrayList<>( |
| 47 | SystemConfig.getInstance().getDisabledUntilUsedPreinstalledCarrierApps()); |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public Map getDisabledUntilUsedPreinstalledCarrierAssociatedApps() { |
| 52 | mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_CARRIER_APP_INFO, |
| 53 | "getDisabledUntilUsedPreInstalledCarrierAssociatedApps requires" |
| 54 | + " READ_CARRIER_APP_INFO"); |
| 55 | return SystemConfig.getInstance() |
Hunter Knepshield | 1172ffa | 2020-06-15 19:42:15 -0700 | [diff] [blame] | 56 | .getDisabledUntilUsedPreinstalledCarrierAssociatedApps().entrySet().stream() |
| 57 | .collect(toMap( |
| 58 | Map.Entry::getKey, |
| 59 | e -> e.getValue().stream().map(app -> app.packageName) |
| 60 | .collect(toList()))); |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public Map getDisabledUntilUsedPreinstalledCarrierAssociatedAppEntries() { |
| 65 | mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_CARRIER_APP_INFO, |
| 66 | "getDisabledUntilUsedPreInstalledCarrierAssociatedAppEntries requires" |
| 67 | + " READ_CARRIER_APP_INFO"); |
| 68 | return SystemConfig.getInstance() |
Hall Liu | b38ad5f | 2019-12-23 18:11:10 -0800 | [diff] [blame] | 69 | .getDisabledUntilUsedPreinstalledCarrierAssociatedApps(); |
| 70 | } |
paulhu | ba70fa8 | 2021-01-27 11:21:09 +0800 | [diff] [blame] | 71 | |
| 72 | @Override |
| 73 | public int[] getSystemPermissionUids(String permissionName) { |
| 74 | mContext.enforceCallingOrSelfPermission(Manifest.permission.GET_RUNTIME_PERMISSIONS, |
| 75 | "getSystemPermissionUids requires GET_RUNTIME_PERMISSIONS"); |
| 76 | final List<Integer> uids = new ArrayList<>(); |
| 77 | final SparseArray<ArraySet<String>> systemPermissions = |
| 78 | SystemConfig.getInstance().getSystemPermissions(); |
| 79 | for (int i = 0; i < systemPermissions.size(); i++) { |
| 80 | final ArraySet<String> permissions = systemPermissions.valueAt(i); |
| 81 | if (permissions != null && permissions.contains(permissionName)) { |
| 82 | uids.add(systemPermissions.keyAt(i)); |
| 83 | } |
| 84 | } |
| 85 | return ArrayUtils.convertToIntArray(uids); |
| 86 | } |
Hall Liu | b38ad5f | 2019-12-23 18:11:10 -0800 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | public SystemConfigService(Context context) { |
| 90 | super(context); |
| 91 | mContext = context; |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public void onStart() { |
| 96 | publishBinderService(Context.SYSTEM_CONFIG_SERVICE, mInterface); |
| 97 | } |
| 98 | } |