blob: 13f4fc4b0dcb5b863c622c9b87d1a95e30499cee [file] [log] [blame]
Makoto Onukidf7e4812018-09-24 14:31:25 -07001/*
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 Onuki05d64cb2019-02-01 16:04:16 -080016package android.service.carrier;
Makoto Onukidf7e4812018-09-24 14:31:25 -070017
Makoto Onuki05d64cb2019-02-01 16:04:16 -080018import android.app.Service;
Makoto Onukidf7e4812018-09-24 14:31:25 -070019import android.content.ComponentName;
20import android.content.Intent;
21import 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 Onuki05d64cb2019-02-01 16:04:16 -080028 * <p>The service must have an
29 * {@link android.telephony.TelephonyManager#ACTION_CARRIER_MESSAGING_CLIENT_SERVICE}
Makoto Onukidf7e4812018-09-24 14:31:25 -070030 * action in the intent handler, and be protected with
Makoto Onuki05d64cb2019-02-01 16:04:16 -080031 * {@link android.Manifest.permission#BIND_CARRIER_MESSAGING_CLIENT_SERVICE}.
32 * However the service does not have to be exported.
Makoto Onukidf7e4812018-09-24 14:31:25 -070033 *
Makoto Onuki8c7c5cc2018-10-02 09:29:58 -070034 * <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 Onukidf7e4812018-09-24 14:31:25 -070038 * {@link android.content.pm.PackageManager#setComponentEnabledSetting(ComponentName, int, int)}
Makoto Onuki8c7c5cc2018-10-02 09:29:58 -070039 * 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 Onukidf7e4812018-09-24 14:31:25 -070041 *
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 Onuki8c7c5cc2018-10-02 09:29:58 -070047 *
48 * <p>Example: First, define a subclass in the application:
49 * <pre>
Makoto Onuki05d64cb2019-02-01 16:04:16 -080050 * public class MyCarrierMessagingClientService extends CarrierMessagingClientService {
Makoto Onuki8c7c5cc2018-10-02 09:29:58 -070051 * }
52 * </pre>
53 * Then, declare it in its {@code AndroidManifest.xml}:
54 * <pre>
55 * &lt;service
Makoto Onuki05d64cb2019-02-01 16:04:16 -080056 * android:name=".MyCarrierMessagingClientService"
Makoto Onuki8c7c5cc2018-10-02 09:29:58 -070057 * android:exported="false"
58 * android:process=":persistent"
Makoto Onuki05d64cb2019-02-01 16:04:16 -080059 * android:permission="android.permission.BIND_CARRIER_MESSAGING_CLIENT_SERVICE"&gt;
Makoto Onuki8c7c5cc2018-10-02 09:29:58 -070060 * &lt;intent-filter&gt;
Makoto Onuki05d64cb2019-02-01 16:04:16 -080061 * &lt;action android:name="android.telephony.action.CARRIER_MESSAGING_CLIENT_SERVICE" /&gt;
Makoto Onuki8c7c5cc2018-10-02 09:29:58 -070062 * &lt;/intent-filter&gt;
63 * &lt;/service&gt;
64 * </pre>
Makoto Onukidf7e4812018-09-24 14:31:25 -070065 */
Makoto Onuki05d64cb2019-02-01 16:04:16 -080066public class CarrierMessagingClientService extends Service {
67 private final ICarrierMessagingClientServiceImpl mImpl;
Makoto Onukidf7e4812018-09-24 14:31:25 -070068
Makoto Onuki05d64cb2019-02-01 16:04:16 -080069 public CarrierMessagingClientService() {
70 mImpl = new ICarrierMessagingClientServiceImpl();
Makoto Onukidf7e4812018-09-24 14:31:25 -070071 }
72
73 @Override
74 public final IBinder onBind(Intent intent) {
75 return mImpl.asBinder();
76 }
77
Makoto Onuki05d64cb2019-02-01 16:04:16 -080078 private class ICarrierMessagingClientServiceImpl extends ICarrierMessagingClientService.Stub {
Makoto Onukidf7e4812018-09-24 14:31:25 -070079 }
80}