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.Context; 23 import android.os.ISystemConfig; 24 25 import java.util.ArrayList; 26 import java.util.List; 27 import java.util.Map; 28 29 /** 30 * Service class that runs inside the system_server process to handle queries to 31 * {@link com.android.server.SystemConfig}. 32 * @hide 33 */ 34 public class SystemConfigService extends SystemService { 35 private final Context mContext; 36 37 private final ISystemConfig.Stub mInterface = new ISystemConfig.Stub() { 38 @Override 39 public List<String> getDisabledUntilUsedPreinstalledCarrierApps() { 40 mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_CARRIER_APP_INFO, 41 "getDisabledUntilUsedPreInstalledCarrierApps requires READ_CARRIER_APP_INFO"); 42 return new ArrayList<>( 43 SystemConfig.getInstance().getDisabledUntilUsedPreinstalledCarrierApps()); 44 } 45 46 @Override 47 public Map getDisabledUntilUsedPreinstalledCarrierAssociatedApps() { 48 mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_CARRIER_APP_INFO, 49 "getDisabledUntilUsedPreInstalledCarrierAssociatedApps requires" 50 + " READ_CARRIER_APP_INFO"); 51 return SystemConfig.getInstance() 52 .getDisabledUntilUsedPreinstalledCarrierAssociatedApps().entrySet().stream() 53 .collect(toMap( 54 Map.Entry::getKey, 55 e -> e.getValue().stream().map(app -> app.packageName) 56 .collect(toList()))); 57 } 58 59 @Override 60 public Map getDisabledUntilUsedPreinstalledCarrierAssociatedAppEntries() { 61 mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_CARRIER_APP_INFO, 62 "getDisabledUntilUsedPreInstalledCarrierAssociatedAppEntries requires" 63 + " READ_CARRIER_APP_INFO"); 64 return SystemConfig.getInstance() 65 .getDisabledUntilUsedPreinstalledCarrierAssociatedApps(); 66 } 67 }; 68 SystemConfigService(Context context)69 public SystemConfigService(Context context) { 70 super(context); 71 mContext = context; 72 } 73 74 @Override onStart()75 public void onStart() { 76 publishBinderService(Context.SYSTEM_CONFIG_SERVICE, mInterface); 77 } 78 } 79