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