Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
| 5 | * in compliance with the License. You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License |
| 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 11 | * or implied. See the License for the specific language governing permissions and limitations under |
| 12 | * the License. |
| 13 | */ |
| 14 | |
| 15 | package android.service.carrier; |
| 16 | |
Andrew Flynn | ceaed68 | 2015-06-09 12:36:58 +0000 | [diff] [blame] | 17 | import android.annotation.CallSuper; |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 18 | import android.app.Service; |
| 19 | import android.content.Intent; |
Jonathan Basseri | 49b54d6 | 2017-07-25 13:34:36 -0700 | [diff] [blame] | 20 | import android.os.Bundle; |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 21 | import android.os.IBinder; |
Jonathan Basseri | 4f9ad167 | 2015-05-12 10:06:32 -0700 | [diff] [blame] | 22 | import android.os.PersistableBundle; |
Andrew Flynn | ceaed68 | 2015-06-09 12:36:58 +0000 | [diff] [blame] | 23 | import android.os.RemoteException; |
Jonathan Basseri | 49b54d6 | 2017-07-25 13:34:36 -0700 | [diff] [blame] | 24 | import android.os.ResultReceiver; |
Andrew Flynn | ceaed68 | 2015-06-09 12:36:58 +0000 | [diff] [blame] | 25 | import android.os.ServiceManager; |
Jonathan Basseri | 49b54d6 | 2017-07-25 13:34:36 -0700 | [diff] [blame] | 26 | import android.util.Log; |
Andrew Flynn | ceaed68 | 2015-06-09 12:36:58 +0000 | [diff] [blame] | 27 | |
| 28 | import com.android.internal.telephony.ITelephonyRegistry; |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 29 | |
| 30 | /** |
Zach Johnson | 42ecc9e | 2015-05-22 15:56:09 -0700 | [diff] [blame] | 31 | * A service that exposes carrier-specific functionality to the system. |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 32 | * <p> |
| 33 | * To extend this class, you must declare the service in your manifest file to require the |
Zach Johnson | cdaaa91 | 2015-05-13 16:25:12 -0700 | [diff] [blame] | 34 | * {@link android.Manifest.permission#BIND_CARRIER_SERVICES} permission and include an intent |
Zach Johnson | 08a244c | 2015-06-19 18:12:27 -0700 | [diff] [blame] | 35 | * filter with the {@link #CARRIER_SERVICE_INTERFACE}. If the service should have a long-lived |
Ricardo Loo Foronda | f2a8aea | 2017-10-26 17:02:31 -0700 | [diff] [blame] | 36 | * binding, set <code>android.service.carrier.LONG_LIVED_BINDING</code> to <code>true</code> in the |
| 37 | * service's metadata. For example: |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 38 | * </p> |
| 39 | * |
| 40 | * <pre>{@code |
Zach Johnson | 42ecc9e | 2015-05-22 15:56:09 -0700 | [diff] [blame] | 41 | * <service android:name=".MyCarrierService" |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 42 | * android:label="@string/service_name" |
Zach Johnson | cdaaa91 | 2015-05-13 16:25:12 -0700 | [diff] [blame] | 43 | * android:permission="android.permission.BIND_CARRIER_SERVICES"> |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 44 | * <intent-filter> |
Zach Johnson | 08a244c | 2015-06-19 18:12:27 -0700 | [diff] [blame] | 45 | * <action android:name="android.service.carrier.CarrierService" /> |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 46 | * </intent-filter> |
Zach Johnson | 08a244c | 2015-06-19 18:12:27 -0700 | [diff] [blame] | 47 | * <meta-data android:name="android.service.carrier.LONG_LIVED_BINDING" |
| 48 | * android:value="true" /> |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 49 | * </service> |
| 50 | * }</pre> |
| 51 | */ |
Zach Johnson | 42ecc9e | 2015-05-22 15:56:09 -0700 | [diff] [blame] | 52 | public abstract class CarrierService extends Service { |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 53 | |
Jonathan Basseri | 49b54d6 | 2017-07-25 13:34:36 -0700 | [diff] [blame] | 54 | private static final String LOG_TAG = "CarrierService"; |
| 55 | |
Zach Johnson | 08a244c | 2015-06-19 18:12:27 -0700 | [diff] [blame] | 56 | public static final String CARRIER_SERVICE_INTERFACE = "android.service.carrier.CarrierService"; |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 57 | |
Andrew Flynn | ceaed68 | 2015-06-09 12:36:58 +0000 | [diff] [blame] | 58 | private static ITelephonyRegistry sRegistry; |
| 59 | |
Zach Johnson | 42ecc9e | 2015-05-22 15:56:09 -0700 | [diff] [blame] | 60 | private final ICarrierService.Stub mStubWrapper; |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 61 | |
Zach Johnson | 42ecc9e | 2015-05-22 15:56:09 -0700 | [diff] [blame] | 62 | public CarrierService() { |
| 63 | mStubWrapper = new ICarrierServiceWrapper(); |
Andrew Flynn | ceaed68 | 2015-06-09 12:36:58 +0000 | [diff] [blame] | 64 | if (sRegistry == null) { |
| 65 | sRegistry = ITelephonyRegistry.Stub.asInterface( |
| 66 | ServiceManager.getService("telephony.registry")); |
| 67 | } |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Override this method to set carrier configuration. |
| 72 | * <p> |
| 73 | * This method will be called by telephony services to get carrier-specific configuration |
| 74 | * values. The returned config will be saved by the system until, |
| 75 | * <ol> |
| 76 | * <li>The carrier app package is updated, or</li> |
| 77 | * <li>The carrier app requests a reload with |
Jonathan Basseri | 5ea0c8f | 2015-06-08 12:25:55 -0700 | [diff] [blame] | 78 | * {@link android.telephony.CarrierConfigManager#notifyConfigChangedForSubId |
| 79 | * notifyConfigChangedForSubId}.</li> |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 80 | * </ol> |
| 81 | * This method can be called after a SIM card loads, which may be before or after boot. |
| 82 | * </p> |
| 83 | * <p> |
| 84 | * This method should not block for a long time. If expensive operations (e.g. network access) |
| 85 | * are required, this method can schedule the work and return null. Then, use |
Jonathan Basseri | 5ea0c8f | 2015-06-08 12:25:55 -0700 | [diff] [blame] | 86 | * {@link android.telephony.CarrierConfigManager#notifyConfigChangedForSubId |
| 87 | * notifyConfigChangedForSubId} to trigger a reload when the config is ready. |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 88 | * </p> |
| 89 | * <p> |
| 90 | * Implementations should use the keys defined in {@link android.telephony.CarrierConfigManager |
Jonathan Basseri | 4f9ad167 | 2015-05-12 10:06:32 -0700 | [diff] [blame] | 91 | * CarrierConfigManager}. Any configuration values not set in the returned {@link |
| 92 | * PersistableBundle} may be overridden by the system's default configuration service. |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 93 | * </p> |
| 94 | * |
| 95 | * @param id contains details about the current carrier that can be used do decide what |
chen xu | d95965a | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 96 | * configuration values to return. Instead of using details like MCCMNC to decide |
| 97 | * current carrier, it also contains subscription carrier id |
| 98 | * {@link android.telephony.TelephonyManager#getSimCarrierId()}, a platform-wide |
| 99 | * unique identifier for each carrier, CarrierConfigService can directly use carrier |
| 100 | * id as the key to look up the carrier info. |
Jonathan Basseri | 4f9ad167 | 2015-05-12 10:06:32 -0700 | [diff] [blame] | 101 | * @return a {@link PersistableBundle} object containing the configuration or null if default |
| 102 | * values should be used. |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 103 | */ |
Jonathan Basseri | 4f9ad167 | 2015-05-12 10:06:32 -0700 | [diff] [blame] | 104 | public abstract PersistableBundle onLoadConfig(CarrierIdentifier id); |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 105 | |
Andrew Flynn | ceaed68 | 2015-06-09 12:36:58 +0000 | [diff] [blame] | 106 | /** |
| 107 | * Informs the system of an intentional upcoming carrier network change by |
| 108 | * a carrier app. This call is optional and is only used to allow the |
| 109 | * system to provide alternative UI while telephony is performing an action |
| 110 | * that may result in intentional, temporary network lack of connectivity. |
| 111 | * <p> |
| 112 | * Based on the active parameter passed in, this method will either show or |
| 113 | * hide the alternative UI. There is no timeout associated with showing |
| 114 | * this UX, so a carrier app must be sure to call with active set to false |
| 115 | * sometime after calling with it set to true. |
| 116 | * <p> |
| 117 | * Requires Permission: |
| 118 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} |
Jeff Davidson | 8e1a493 | 2016-11-18 12:45:11 -0800 | [diff] [blame] | 119 | * or the calling app has carrier privileges. |
Andrew Flynn | ceaed68 | 2015-06-09 12:36:58 +0000 | [diff] [blame] | 120 | * |
| 121 | * @param active Whether the carrier network change is or shortly will be |
| 122 | * active. Set this value to true to begin showing |
| 123 | * alternative UI and false to stop. |
Jeff Davidson | 8e1a493 | 2016-11-18 12:45:11 -0800 | [diff] [blame] | 124 | * @see android.telephony.TelephonyManager#hasCarrierPrivileges |
Andrew Flynn | ceaed68 | 2015-06-09 12:36:58 +0000 | [diff] [blame] | 125 | */ |
| 126 | public final void notifyCarrierNetworkChange(boolean active) { |
| 127 | try { |
| 128 | if (sRegistry != null) sRegistry.notifyCarrierNetworkChange(active); |
| 129 | } catch (RemoteException | NullPointerException ex) {} |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * If overriding this method, call through to the super method for any unknown actions. |
| 134 | * {@inheritDoc} |
| 135 | */ |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 136 | @Override |
Andrew Flynn | ceaed68 | 2015-06-09 12:36:58 +0000 | [diff] [blame] | 137 | @CallSuper |
| 138 | public IBinder onBind(Intent intent) { |
Zach Johnson | 08a244c | 2015-06-19 18:12:27 -0700 | [diff] [blame] | 139 | return mStubWrapper; |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | /** |
Zach Johnson | 42ecc9e | 2015-05-22 15:56:09 -0700 | [diff] [blame] | 143 | * A wrapper around ICarrierService that forwards calls to implementations of |
| 144 | * {@link CarrierService}. |
Jonathan Basseri | 49b54d6 | 2017-07-25 13:34:36 -0700 | [diff] [blame] | 145 | * @hide |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 146 | */ |
Jonathan Basseri | 49b54d6 | 2017-07-25 13:34:36 -0700 | [diff] [blame] | 147 | public class ICarrierServiceWrapper extends ICarrierService.Stub { |
| 148 | /** @hide */ |
| 149 | public static final int RESULT_OK = 0; |
| 150 | /** @hide */ |
| 151 | public static final int RESULT_ERROR = 1; |
| 152 | /** @hide */ |
| 153 | public static final String KEY_CONFIG_BUNDLE = "config_bundle"; |
| 154 | |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 155 | @Override |
Jonathan Basseri | 49b54d6 | 2017-07-25 13:34:36 -0700 | [diff] [blame] | 156 | public void getCarrierConfig(CarrierIdentifier id, ResultReceiver result) { |
| 157 | try { |
| 158 | Bundle data = new Bundle(); |
| 159 | data.putParcelable(KEY_CONFIG_BUNDLE, CarrierService.this.onLoadConfig(id)); |
| 160 | result.send(RESULT_OK, data); |
| 161 | } catch (Exception e) { |
| 162 | Log.e(LOG_TAG, "Error in onLoadConfig: " + e.getMessage(), e); |
| 163 | result.send(RESULT_ERROR, null); |
| 164 | } |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | } |