CarrierService.java revision 42ecc9eb902ef90876cd345a906c24e0d58720a3
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
15package android.service.carrier;
16
17import android.app.Service;
18import android.content.Intent;
19import android.os.IBinder;
20import android.os.PersistableBundle;
21
22/**
23 * A service that exposes carrier-specific functionality to the system.
24 * <p>
25 * To extend this class, you must declare the service in your manifest file to require the
26 * {@link android.Manifest.permission#BIND_CARRIER_SERVICES} permission and include an intent
27 * filter with the {@link #SERVICE_INTERFACE} action. For example:
28 * </p>
29 *
30 * <pre>{@code
31 * <service android:name=".MyCarrierService"
32 *       android:label="@string/service_name"
33 *       android:permission="android.permission.BIND_CARRIER_SERVICES">
34 *  <intent-filter>
35 *      <action android:name="android.service.carrier.CarrierService" />
36 *  </intent-filter>
37 * </service>
38 * }</pre>
39 */
40public abstract class CarrierService extends Service {
41
42    public static final String SERVICE_INTERFACE = "android.service.carrier.CarrierService";
43
44    private final ICarrierService.Stub mStubWrapper;
45
46    public CarrierService() {
47        mStubWrapper = new ICarrierServiceWrapper();
48    }
49
50    /**
51     * Override this method to set carrier configuration.
52     * <p>
53     * This method will be called by telephony services to get carrier-specific configuration
54     * values. The returned config will be saved by the system until,
55     * <ol>
56     * <li>The carrier app package is updated, or</li>
57     * <li>The carrier app requests a reload with
58     * {@link android.telephony.CarrierConfigManager#reloadCarrierConfigForSubId
59     * reloadCarrierConfigForSubId}.</li>
60     * </ol>
61     * This method can be called after a SIM card loads, which may be before or after boot.
62     * </p>
63     * <p>
64     * This method should not block for a long time. If expensive operations (e.g. network access)
65     * are required, this method can schedule the work and return null. Then, use
66     * {@link android.telephony.CarrierConfigManager#reloadCarrierConfigForSubId
67     * reloadCarrierConfigForSubId} to trigger a reload when the config is ready.
68     * </p>
69     * <p>
70     * Implementations should use the keys defined in {@link android.telephony.CarrierConfigManager
71     * CarrierConfigManager}. Any configuration values not set in the returned {@link
72     * PersistableBundle} may be overridden by the system's default configuration service.
73     * </p>
74     *
75     * @param id contains details about the current carrier that can be used do decide what
76     *            configuration values to return.
77     * @return a {@link PersistableBundle} object containing the configuration or null if default
78     *         values should be used.
79     */
80    public abstract PersistableBundle onLoadConfig(CarrierIdentifier id);
81
82    /** @hide */
83    @Override
84    public final IBinder onBind(Intent intent) {
85        if (!SERVICE_INTERFACE.equals(intent.getAction())) {
86            return null;
87        }
88        return mStubWrapper;
89    }
90
91    /**
92     * A wrapper around ICarrierService that forwards calls to implementations of
93     * {@link CarrierService}.
94     *
95     * @hide
96     */
97    private class ICarrierServiceWrapper extends ICarrierService.Stub {
98
99        @Override
100        public PersistableBundle getCarrierConfig(CarrierIdentifier id) {
101            return CarrierService.this.onLoadConfig(id);
102        }
103    }
104}
105