blob: 767c1d1a49c6fc4be308f085189df5d39a8e274b [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 Onukida79fb62019-02-28 11:34:31 -080018import android.annotation.NonNull;
19import android.annotation.Nullable;
Makoto Onuki05d64cb2019-02-01 16:04:16 -080020import android.app.Service;
Makoto Onukidf7e4812018-09-24 14:31:25 -070021import android.content.ComponentName;
22import android.content.Intent;
23import android.os.IBinder;
24
25/**
26 * If the default SMS app has a service that extends this class, the system always tries to bind
27 * it so that the process is always running, which allows the app to have a persistent connection
28 * to the server.
29 *
Makoto Onuki05d64cb2019-02-01 16:04:16 -080030 * <p>The service must have an
31 * {@link android.telephony.TelephonyManager#ACTION_CARRIER_MESSAGING_CLIENT_SERVICE}
Makoto Onukidf7e4812018-09-24 14:31:25 -070032 * action in the intent handler, and be protected with
Makoto Onuki05d64cb2019-02-01 16:04:16 -080033 * {@link android.Manifest.permission#BIND_CARRIER_MESSAGING_CLIENT_SERVICE}.
34 * However the service does not have to be exported.
Makoto Onukidf7e4812018-09-24 14:31:25 -070035 *
Makoto Onuki8c7c5cc2018-10-02 09:29:58 -070036 * <p>The service must be associated with a non-main process, meaning it must have an
37 * {@code android:process} tag in its manifest entry.
38 *
39 * <p>An app can use
Makoto Onukidf7e4812018-09-24 14:31:25 -070040 * {@link android.content.pm.PackageManager#setComponentEnabledSetting(ComponentName, int, int)}
Makoto Onuki8c7c5cc2018-10-02 09:29:58 -070041 * to disable or enable the service. An app should use it to disable the service when it no longer
42 * needs to be running.
Makoto Onukidf7e4812018-09-24 14:31:25 -070043 *
44 * <p>When the owner process crashes, the service will be re-bound automatically after a
45 * back-off.
46 *
47 * <p>Note the process may still be killed if the system is under heavy memory pressure, in which
48 * case the process will be re-started later.
Makoto Onuki8c7c5cc2018-10-02 09:29:58 -070049 *
50 * <p>Example: First, define a subclass in the application:
51 * <pre>
Makoto Onuki05d64cb2019-02-01 16:04:16 -080052 * public class MyCarrierMessagingClientService extends CarrierMessagingClientService {
Makoto Onuki8c7c5cc2018-10-02 09:29:58 -070053 * }
54 * </pre>
55 * Then, declare it in its {@code AndroidManifest.xml}:
56 * <pre>
57 * &lt;service
Makoto Onuki05d64cb2019-02-01 16:04:16 -080058 * android:name=".MyCarrierMessagingClientService"
Makoto Onuki8c7c5cc2018-10-02 09:29:58 -070059 * android:exported="false"
60 * android:process=":persistent"
Makoto Onuki05d64cb2019-02-01 16:04:16 -080061 * android:permission="android.permission.BIND_CARRIER_MESSAGING_CLIENT_SERVICE"&gt;
Makoto Onuki8c7c5cc2018-10-02 09:29:58 -070062 * &lt;intent-filter&gt;
Makoto Onuki05d64cb2019-02-01 16:04:16 -080063 * &lt;action android:name="android.telephony.action.CARRIER_MESSAGING_CLIENT_SERVICE" /&gt;
Makoto Onuki8c7c5cc2018-10-02 09:29:58 -070064 * &lt;/intent-filter&gt;
65 * &lt;/service&gt;
66 * </pre>
Makoto Onukidf7e4812018-09-24 14:31:25 -070067 */
Makoto Onuki05d64cb2019-02-01 16:04:16 -080068public class CarrierMessagingClientService extends Service {
69 private final ICarrierMessagingClientServiceImpl mImpl;
Makoto Onukidf7e4812018-09-24 14:31:25 -070070
Makoto Onuki05d64cb2019-02-01 16:04:16 -080071 public CarrierMessagingClientService() {
72 mImpl = new ICarrierMessagingClientServiceImpl();
Makoto Onukidf7e4812018-09-24 14:31:25 -070073 }
74
75 @Override
Makoto Onukida79fb62019-02-28 11:34:31 -080076 @NonNull
77 public final IBinder onBind(@Nullable Intent intent) {
Makoto Onukidf7e4812018-09-24 14:31:25 -070078 return mImpl.asBinder();
79 }
80
Makoto Onuki05d64cb2019-02-01 16:04:16 -080081 private class ICarrierMessagingClientServiceImpl extends ICarrierMessagingClientService.Stub {
Makoto Onukidf7e4812018-09-24 14:31:25 -070082 }
83}