1 /* 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 17 package android.service.carrier; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.SystemApi; 22 import android.annotation.WorkerThread; 23 import android.app.Service; 24 import android.content.ContentValues; 25 import android.content.Intent; 26 import android.os.IBinder; 27 import android.util.Log; 28 29 import android.service.carrier.IApnSourceService; 30 31 import 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 44 public 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 65 @NonNull onBind(@ullable Intent intent)66 public IBinder onBind(@Nullable Intent intent) { 67 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 79 @NonNull onRestoreApns(int subId)80 public abstract List<ContentValues> onRestoreApns(int subId); 81 } 82