From 3424c02e6b931a8bbd651ae75217bebd008b2605 Mon Sep 17 00:00:00 2001 From: Hung-ying Tyan Date: Fri, 27 Aug 2010 18:08:19 +0800 Subject: Add software features for SIP and VOIP and block SipService creation and SIP API if the feature is not available. Change-Id: Icf780af1ac20dda4d8180cea3e5b20e21a8350bc --- api/current.xml | 22 +++++++++++++++ core/java/android/content/pm/PackageManager.java | 16 ++++++++++- data/etc/android.software.sip.voip.xml | 21 ++++++++++++++ data/etc/android.software.sip.xml | 20 +++++++++++++ services/java/com/android/server/SystemServer.java | 9 ++++-- .../java/com/android/server/sip/SipService.java | 13 +++++++-- voip/java/android/net/sip/SipManager.java | 33 ++++++++++++++++------ 7 files changed, 118 insertions(+), 16 deletions(-) create mode 100644 data/etc/android.software.sip.voip.xml create mode 100644 data/etc/android.software.sip.xml diff --git a/api/current.xml b/api/current.xml index 8309a33..3c08549 100644 --- a/api/current.xml +++ b/api/current.xml @@ -49119,6 +49119,28 @@ visibility="public" > + + + + + + + + + + + diff --git a/data/etc/android.software.sip.xml b/data/etc/android.software.sip.xml new file mode 100644 index 0000000..d9fcaad --- /dev/null +++ b/data/etc/android.software.sip.xml @@ -0,0 +1,20 @@ + + + + + + + diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index 1a209e2..4a286e7 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -418,10 +418,13 @@ class ServerThread extends Thread { } try { - Slog.i(TAG, "Sip Service"); - ServiceManager.addService("sip", new SipService(context)); + SipService sipService = SipService.create(context); + if (sipService != null) { + Slog.i(TAG, "Sip Service"); + ServiceManager.addService("sip", sipService); + } } catch (Throwable e) { - Slog.e(TAG, "Failure starting DiskStats Service", e); + Slog.e(TAG, "Failure starting SIP Service", e); } } diff --git a/services/java/com/android/server/sip/SipService.java b/services/java/com/android/server/sip/SipService.java index 3dcaff6..626b488 100644 --- a/services/java/com/android/server/sip/SipService.java +++ b/services/java/com/android/server/sip/SipService.java @@ -53,8 +53,6 @@ import java.util.TimerTask; import java.util.TreeSet; import javax.sip.SipException; -/** - */ public final class SipService extends ISipService.Stub { private static final String TAG = "SipService"; private static final int EXPIRY_TIME = 3600; @@ -78,7 +76,16 @@ public final class SipService extends ISipService.Stub { private ConnectivityReceiver mConnectivityReceiver; - public SipService(Context context) { + /** + * Creates a {@code SipService} instance. Returns null if SIP API is not + * supported. + */ + public static SipService create(Context context) { + return (SipManager.isApiSupported(context) ? new SipService(context) + : null); + } + + private SipService(Context context) { Log.v(TAG, " service started!"); mContext = context; mConnectivityReceiver = new ConnectivityReceiver(); diff --git a/voip/java/android/net/sip/SipManager.java b/voip/java/android/net/sip/SipManager.java index 287a13a..40792b9 100644 --- a/voip/java/android/net/sip/SipManager.java +++ b/voip/java/android/net/sip/SipManager.java @@ -18,6 +18,7 @@ package android.net.sip; import android.content.Context; import android.content.Intent; +import android.content.pm.PackageManager; import android.os.IBinder; import android.os.Looper; import android.os.RemoteException; @@ -69,22 +70,36 @@ public class SipManager { private ISipService mSipService; /** - * Creates a manager instance and initializes the background SIP service. - * Will be removed once the SIP service is integrated into framework. + * Gets a manager instance. Returns null if SIP API is not supported. * - * @param context context to start the SIP service - * @return the manager instance + * @param context application context for checking if SIP API is supported + * @return the manager instance or null if SIP API is not supported */ - public static SipManager getInstance(final Context context) { - final SipManager manager = new SipManager(); - manager.createSipService(context); - return manager; + public static SipManager getInstance(Context context) { + return (isApiSupported(context) ? new SipManager() : null); + } + + /** + * Returns true if the SIP API is supported by the system. + */ + public static boolean isApiSupported(Context context) { + return context.getPackageManager().hasSystemFeature( + PackageManager.FEATURE_SIP); + } + + /** + * Returns true if the system supports SIP-based VoIP. + */ + public static boolean isVoipSupported(Context context) { + return context.getPackageManager().hasSystemFeature( + PackageManager.FEATURE_SIP_VOIP) && isApiSupported(context); } private SipManager() { + createSipService(); } - private void createSipService(Context context) { + private void createSipService() { if (mSipService != null) return; IBinder b = ServiceManager.getService(Context.SIP_SERVICE); mSipService = ISipService.Stub.asInterface(b); -- cgit v1.1