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 android.os; 17 18 import android.Manifest; 19 import android.annotation.NonNull; 20 import android.annotation.RequiresPermission; 21 import android.annotation.SystemApi; 22 import android.annotation.SystemService; 23 import android.annotation.TestApi; 24 import android.content.Context; 25 import android.util.ArraySet; 26 import android.util.Log; 27 28 import java.util.Collections; 29 import java.util.List; 30 import java.util.Map; 31 import java.util.Set; 32 33 34 /** 35 * Allows apps outside the system process to access various bits of configuration defined in 36 * /etc/sysconfig and its counterparts on OEM and vendor partitions. 37 * 38 * TODO: Intended for access by system mainline modules only. Marking as SystemApi until the 39 * module-only API surface is available. 40 * @hide 41 */ 42 @SystemApi 43 @TestApi 44 @SystemService(Context.SYSTEM_CONFIG_SERVICE) 45 public class SystemConfigManager { 46 private static final String TAG = SystemConfigManager.class.getSimpleName(); 47 48 private final ISystemConfig mInterface; 49 50 /** @hide **/ SystemConfigManager()51 public SystemConfigManager() { 52 mInterface = ISystemConfig.Stub.asInterface( 53 ServiceManager.getService(Context.SYSTEM_CONFIG_SERVICE)); 54 } 55 56 /** 57 * Returns a set of package names for carrier apps that are preinstalled on the device but 58 * should be disabled until the matching carrier's SIM is inserted into the device. 59 * @return A set of package names. 60 */ 61 @RequiresPermission(Manifest.permission.READ_CARRIER_APP_INFO) getDisabledUntilUsedPreinstalledCarrierApps()62 public @NonNull Set<String> getDisabledUntilUsedPreinstalledCarrierApps() { 63 try { 64 List<String> apps = mInterface.getDisabledUntilUsedPreinstalledCarrierApps(); 65 return new ArraySet<>(apps); 66 } catch (RemoteException e) { 67 Log.e(TAG, "Caught remote exception"); 68 return Collections.emptySet(); 69 } 70 } 71 72 /** 73 * Returns a map that describes helper apps associated with carrier apps that, like the apps 74 * returned by {@link #getDisabledUntilUsedPreinstalledCarrierApps()}, should be disabled until 75 * the correct SIM is inserted into the device. 76 * @return A map with keys corresponding to package names returned by 77 * {@link #getDisabledUntilUsedPreinstalledCarrierApps()} and values as lists of package 78 * names of helper apps. 79 */ 80 @RequiresPermission(Manifest.permission.READ_CARRIER_APP_INFO) 81 public @NonNull Map<String, List<String>> getDisabledUntilUsedPreinstalledCarrierAssociatedApps()82 getDisabledUntilUsedPreinstalledCarrierAssociatedApps() { 83 try { 84 return (Map<String, List<String>>) 85 mInterface.getDisabledUntilUsedPreinstalledCarrierAssociatedApps(); 86 } catch (RemoteException e) { 87 Log.e(TAG, "Caught remote exception"); 88 return Collections.emptyMap(); 89 } 90 } 91 92 /** 93 * Returns a map that describes helper apps associated with carrier apps that, like the apps 94 * returned by {@link #getDisabledUntilUsedPreinstalledCarrierApps()}, should be disabled until 95 * the correct SIM is inserted into the device. 96 * 97 * <p>TODO(b/159069037) expose this and get rid of the other method that omits SDK version. 98 * 99 * @return A map with keys corresponding to package names returned by 100 * {@link #getDisabledUntilUsedPreinstalledCarrierApps()} and values as lists of package 101 * names of helper apps and the SDK versions when they were first added. 102 * 103 * @hide 104 */ 105 @RequiresPermission(Manifest.permission.READ_CARRIER_APP_INFO) 106 public @NonNull Map<String, List<CarrierAssociatedAppEntry>> getDisabledUntilUsedPreinstalledCarrierAssociatedAppEntries()107 getDisabledUntilUsedPreinstalledCarrierAssociatedAppEntries() { 108 try { 109 return (Map<String, List<CarrierAssociatedAppEntry>>) 110 mInterface.getDisabledUntilUsedPreinstalledCarrierAssociatedAppEntries(); 111 } catch (RemoteException e) { 112 Log.e(TAG, "Caught remote exception", e); 113 return Collections.emptyMap(); 114 } 115 } 116 } 117