Makoto Onuki | df7e481 | 2018-09-24 14:31:25 -0700 | [diff] [blame] | 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 | */ |
Makoto Onuki | 05d64cb | 2019-02-01 16:04:16 -0800 | [diff] [blame] | 16 | package android.service.carrier; |
Makoto Onuki | df7e481 | 2018-09-24 14:31:25 -0700 | [diff] [blame] | 17 | |
Makoto Onuki | 05d64cb | 2019-02-01 16:04:16 -0800 | [diff] [blame] | 18 | import android.app.Service; |
Makoto Onuki | df7e481 | 2018-09-24 14:31:25 -0700 | [diff] [blame] | 19 | import android.content.ComponentName; |
| 20 | import android.content.Intent; |
| 21 | import android.os.IBinder; |
| 22 | |
| 23 | /** |
| 24 | * If the default SMS app has a service that extends this class, the system always tries to bind |
| 25 | * it so that the process is always running, which allows the app to have a persistent connection |
| 26 | * to the server. |
| 27 | * |
Makoto Onuki | 05d64cb | 2019-02-01 16:04:16 -0800 | [diff] [blame] | 28 | * <p>The service must have an |
| 29 | * {@link android.telephony.TelephonyManager#ACTION_CARRIER_MESSAGING_CLIENT_SERVICE} |
Makoto Onuki | df7e481 | 2018-09-24 14:31:25 -0700 | [diff] [blame] | 30 | * action in the intent handler, and be protected with |
Makoto Onuki | 05d64cb | 2019-02-01 16:04:16 -0800 | [diff] [blame] | 31 | * {@link android.Manifest.permission#BIND_CARRIER_MESSAGING_CLIENT_SERVICE}. |
| 32 | * However the service does not have to be exported. |
Makoto Onuki | df7e481 | 2018-09-24 14:31:25 -0700 | [diff] [blame] | 33 | * |
Makoto Onuki | 8c7c5cc | 2018-10-02 09:29:58 -0700 | [diff] [blame] | 34 | * <p>The service must be associated with a non-main process, meaning it must have an |
| 35 | * {@code android:process} tag in its manifest entry. |
| 36 | * |
| 37 | * <p>An app can use |
Makoto Onuki | df7e481 | 2018-09-24 14:31:25 -0700 | [diff] [blame] | 38 | * {@link android.content.pm.PackageManager#setComponentEnabledSetting(ComponentName, int, int)} |
Makoto Onuki | 8c7c5cc | 2018-10-02 09:29:58 -0700 | [diff] [blame] | 39 | * to disable or enable the service. An app should use it to disable the service when it no longer |
| 40 | * needs to be running. |
Makoto Onuki | df7e481 | 2018-09-24 14:31:25 -0700 | [diff] [blame] | 41 | * |
| 42 | * <p>When the owner process crashes, the service will be re-bound automatically after a |
| 43 | * back-off. |
| 44 | * |
| 45 | * <p>Note the process may still be killed if the system is under heavy memory pressure, in which |
| 46 | * case the process will be re-started later. |
Makoto Onuki | 8c7c5cc | 2018-10-02 09:29:58 -0700 | [diff] [blame] | 47 | * |
| 48 | * <p>Example: First, define a subclass in the application: |
| 49 | * <pre> |
Makoto Onuki | 05d64cb | 2019-02-01 16:04:16 -0800 | [diff] [blame] | 50 | * public class MyCarrierMessagingClientService extends CarrierMessagingClientService { |
Makoto Onuki | 8c7c5cc | 2018-10-02 09:29:58 -0700 | [diff] [blame] | 51 | * } |
| 52 | * </pre> |
| 53 | * Then, declare it in its {@code AndroidManifest.xml}: |
| 54 | * <pre> |
| 55 | * <service |
Makoto Onuki | 05d64cb | 2019-02-01 16:04:16 -0800 | [diff] [blame] | 56 | * android:name=".MyCarrierMessagingClientService" |
Makoto Onuki | 8c7c5cc | 2018-10-02 09:29:58 -0700 | [diff] [blame] | 57 | * android:exported="false" |
| 58 | * android:process=":persistent" |
Makoto Onuki | 05d64cb | 2019-02-01 16:04:16 -0800 | [diff] [blame] | 59 | * android:permission="android.permission.BIND_CARRIER_MESSAGING_CLIENT_SERVICE"> |
Makoto Onuki | 8c7c5cc | 2018-10-02 09:29:58 -0700 | [diff] [blame] | 60 | * <intent-filter> |
Makoto Onuki | 05d64cb | 2019-02-01 16:04:16 -0800 | [diff] [blame] | 61 | * <action android:name="android.telephony.action.CARRIER_MESSAGING_CLIENT_SERVICE" /> |
Makoto Onuki | 8c7c5cc | 2018-10-02 09:29:58 -0700 | [diff] [blame] | 62 | * </intent-filter> |
| 63 | * </service> |
| 64 | * </pre> |
Makoto Onuki | df7e481 | 2018-09-24 14:31:25 -0700 | [diff] [blame] | 65 | */ |
Makoto Onuki | 05d64cb | 2019-02-01 16:04:16 -0800 | [diff] [blame] | 66 | public class CarrierMessagingClientService extends Service { |
| 67 | private final ICarrierMessagingClientServiceImpl mImpl; |
Makoto Onuki | df7e481 | 2018-09-24 14:31:25 -0700 | [diff] [blame] | 68 | |
Makoto Onuki | 05d64cb | 2019-02-01 16:04:16 -0800 | [diff] [blame] | 69 | public CarrierMessagingClientService() { |
| 70 | mImpl = new ICarrierMessagingClientServiceImpl(); |
Makoto Onuki | df7e481 | 2018-09-24 14:31:25 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public final IBinder onBind(Intent intent) { |
| 75 | return mImpl.asBinder(); |
| 76 | } |
| 77 | |
Makoto Onuki | 05d64cb | 2019-02-01 16:04:16 -0800 | [diff] [blame] | 78 | private class ICarrierMessagingClientServiceImpl extends ICarrierMessagingClientService.Stub { |
Makoto Onuki | df7e481 | 2018-09-24 14:31:25 -0700 | [diff] [blame] | 79 | } |
| 80 | } |