blob: d53eb37ca7869d401778a9b4c19f873bacb46d2f [file] [log] [blame]
Jordan Liud60a4c02018-11-12 16:39:20 -08001/*
2 * Copyright (C) 2018 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
17package android.service.carrier;
18
19import android.annotation.SystemApi;
20import android.annotation.WorkerThread;
21import android.app.Service;
22import android.content.ContentValues;
23import android.content.Intent;
24import android.os.IBinder;
25import android.util.Log;
26
27import com.android.internal.telephony.IApnSourceService;
28
29import java.util.List;
30
31/**
32 * A service that the system can call to restore default APNs.
33 * <p>
34 * To extend this class, specify the full name of your implementation in the resource file
35 * {@code packages/providers/TelephonyProvider/res/values/config.xml} as the
36 * {@code apn_source_service}.
37 * </p>
38 *
39 * @hide
40 */
41@SystemApi
42public abstract class ApnService extends Service {
43
44 private static final String LOG_TAG = "ApnService";
45
46 private final IApnSourceService.Stub mBinder = new IApnSourceService.Stub() {
47 /**
48 * Retreive APNs for the default slot index.
49 */
50 @Override
51 public ContentValues[] getApns(int subId) {
52 try {
53 List<ContentValues> apns = ApnService.this.onRestoreApns(subId);
54 return apns.toArray(new ContentValues[apns.size()]);
55 } catch (Exception e) {
56 Log.e(LOG_TAG, "Error in getApns for subId=" + subId + ": " + e.getMessage(), e);
57 return null;
58 }
59 }
60 };
61
62 @Override
63 public IBinder onBind(Intent intent) {
64 return mBinder;
65 }
66
67 /**
68 * Override this method to restore default user APNs with a carrier service instead of the
69 * built in platform xml APNs list.
70 * <p>
71 * This method is called by the TelephonyProvider when the user requests restoring the default
72 * APNs. It should return a list of ContentValues representing the default APNs for the given
73 * subId.
74 */
75 @WorkerThread
76 public abstract List<ContentValues> onRestoreApns(int subId);
77}