summaryrefslogtreecommitdiffstats
path: root/services/core/java/com/android/server/telecom/TelecomLoaderService.java
diff options
context:
space:
mode:
authorSantos Cordon <santoscordon@google.com>2014-11-21 15:20:15 -0800
committerSantos Cordon <santoscordon@google.com>2014-12-08 23:30:10 +0000
commit5d2c1e69ecb851121177396ac376dee1fb41d421 (patch)
treea51a21da5660fa306eb1f6da4a88c17edd59981a /services/core/java/com/android/server/telecom/TelecomLoaderService.java
parent4df65bf1eb454814954421403da9f8b5fcb82180 (diff)
downloadframeworks_base-5d2c1e69ecb851121177396ac376dee1fb41d421.zip
frameworks_base-5d2c1e69ecb851121177396ac376dee1fb41d421.tar.gz
frameworks_base-5d2c1e69ecb851121177396ac376dee1fb41d421.tar.bz2
(Telecom-system part 3) Adding Telecom Loader Service
Bug: 18112269 Change-Id: I85ab03156bf906fdc72b459c4c68240ab3bf1894
Diffstat (limited to 'services/core/java/com/android/server/telecom/TelecomLoaderService.java')
-rw-r--r--services/core/java/com/android/server/telecom/TelecomLoaderService.java106
1 files changed, 106 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/telecom/TelecomLoaderService.java b/services/core/java/com/android/server/telecom/TelecomLoaderService.java
new file mode 100644
index 0000000..64a67fc
--- /dev/null
+++ b/services/core/java/com/android/server/telecom/TelecomLoaderService.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.telecom;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.UserHandle;
+import android.util.Slog;
+
+import com.android.server.SystemService;
+
+/**
+ * Starts the telecom component by binding to its ITelecomService implementation. Telecom is setup
+ * to run in the system-server process so once it is loaded into memory it will stay running.
+ * @hide
+ */
+public class TelecomLoaderService extends SystemService {
+ private static final String TAG = "TelecomLoaderService";
+
+ private class TelecomServiceConnection implements ServiceConnection {
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ // Normally, we would listen for death here, but since telecom runs in the same process
+ // as this loader (process="system") thats redundant here.
+ try {
+ service.linkToDeath(new IBinder.DeathRecipient() {
+ @Override
+ public void binderDied() {
+ connectToTelecom();
+ }
+ }, 0);
+
+ ServiceManager.addService(Context.TELECOM_SERVICE, service);
+ } catch (RemoteException e) {
+ Slog.w(TAG, "Failed linking to death.");
+ }
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ connectToTelecom();
+ }
+ }
+
+ private static final ComponentName SERVICE_COMPONENT = new ComponentName(
+ "com.android.server.telecom",
+ "com.android.server.telecom.TelecomService");
+
+ private static final String SERVICE_ACTION = "com.android.ITelecomService";
+
+ private final Context mContext;
+ private TelecomServiceConnection mServiceConnection;
+
+ public TelecomLoaderService(Context context) {
+ super(context);
+ mContext = context;
+ }
+
+ @Override
+ public void onStart() {
+ }
+
+ @Override
+ public void onBootPhase(int phase) {
+ if (phase == PHASE_ACTIVITY_MANAGER_READY) {
+ connectToTelecom();
+ }
+ }
+
+ private void connectToTelecom() {
+ if (mServiceConnection != null) {
+ // TODO: Is unbinding worth doing or wait for system to rebind?
+ mContext.unbindService(mServiceConnection);
+ mServiceConnection = null;
+ }
+
+ TelecomServiceConnection serviceConnection = new TelecomServiceConnection();
+ Intent intent = new Intent(SERVICE_ACTION);
+ intent.setComponent(SERVICE_COMPONENT);
+ int flags = Context.BIND_IMPORTANT | Context.BIND_AUTO_CREATE;
+
+ // Bind to Telecom and register the service
+ if (mContext.bindServiceAsUser(intent, serviceConnection, flags, UserHandle.OWNER)) {
+ mServiceConnection = serviceConnection;
+ }
+ }
+}