diff options
author | Svetoslav <svetoslavganov@google.com> | 2015-04-30 18:01:37 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-04-30 18:01:38 +0000 |
commit | b0d9f5e87cd4c7dc7d1cd4a52aec3bf2e07b63d3 (patch) | |
tree | f0f142f9cede52775df173eea61e9655d82bc767 | |
parent | c2d55f13a21fe6a288601deab6832c704c998781 (diff) | |
parent | d08c8ddcf7bab2beaf212fb7607da15f51ebc09c (diff) | |
download | voip-b0d9f5e87cd4c7dc7d1cd4a52aec3bf2e07b63d3.tar.gz |
Merge "Add SIP app op - voip" into mnc-dev
-rw-r--r-- | src/java/android/net/sip/ISipService.aidl | 18 | ||||
-rw-r--r-- | src/java/android/net/sip/SipManager.java | 31 | ||||
-rw-r--r-- | src/java/com/android/server/sip/SipService.java | 76 |
3 files changed, 77 insertions, 48 deletions
diff --git a/src/java/android/net/sip/ISipService.aidl b/src/java/android/net/sip/ISipService.aidl index 3250bf9..84750c7 100644 --- a/src/java/android/net/sip/ISipService.aidl +++ b/src/java/android/net/sip/ISipService.aidl @@ -25,19 +25,19 @@ import android.net.sip.SipProfile; * {@hide} */ interface ISipService { - void open(in SipProfile localProfile); + void open(in SipProfile localProfile, String opPackageName); void open3(in SipProfile localProfile, in PendingIntent incomingCallPendingIntent, - in ISipSessionListener listener); - void close(in String localProfileUri); - boolean isOpened(String localProfileUri); - boolean isRegistered(String localProfileUri); + in ISipSessionListener listener, String opPackageName); + void close(in String localProfileUri, String opPackageName); + boolean isOpened(String localProfileUri, String opPackageName); + boolean isRegistered(String localProfileUri, String opPackageName); void setRegistrationListener(String localProfileUri, - ISipSessionListener listener); + ISipSessionListener listener, String opPackageName); ISipSession createSession(in SipProfile localProfile, - in ISipSessionListener listener); - ISipSession getPendingSession(String callId); + in ISipSessionListener listener, String opPackageName); + ISipSession getPendingSession(String callId, String opPackageName); - SipProfile[] getListOfProfiles(); + SipProfile[] getListOfProfiles(String opPackageName); } diff --git a/src/java/android/net/sip/SipManager.java b/src/java/android/net/sip/SipManager.java index 715acfb..b483d5d 100644 --- a/src/java/android/net/sip/SipManager.java +++ b/src/java/android/net/sip/SipManager.java @@ -188,7 +188,7 @@ public class SipManager { */ public void open(SipProfile localProfile) throws SipException { try { - mSipService.open(localProfile); + mSipService.open(localProfile, mContext.getOpPackageName()); } catch (RemoteException e) { throw new SipException("open()", e); } @@ -232,7 +232,8 @@ public class SipManager { } try { mSipService.open3(localProfile, incomingCallPendingIntent, - createRelay(listener, localProfile.getUriString())); + createRelay(listener, localProfile.getUriString()), + mContext.getOpPackageName()); } catch (RemoteException e) { throw new SipException("open()", e); } @@ -251,7 +252,8 @@ public class SipManager { SipRegistrationListener listener) throws SipException { try { mSipService.setRegistrationListener( - localProfileUri, createRelay(listener, localProfileUri)); + localProfileUri, createRelay(listener, localProfileUri), + mContext.getOpPackageName()); } catch (RemoteException e) { throw new SipException("setRegistrationListener()", e); } @@ -266,7 +268,7 @@ public class SipManager { */ public void close(String localProfileUri) throws SipException { try { - mSipService.close(localProfileUri); + mSipService.close(localProfileUri, mContext.getOpPackageName()); } catch (RemoteException e) { throw new SipException("close()", e); } @@ -282,7 +284,7 @@ public class SipManager { */ public boolean isOpened(String localProfileUri) throws SipException { try { - return mSipService.isOpened(localProfileUri); + return mSipService.isOpened(localProfileUri, mContext.getOpPackageName()); } catch (RemoteException e) { throw new SipException("isOpened()", e); } @@ -303,7 +305,7 @@ public class SipManager { */ public boolean isRegistered(String localProfileUri) throws SipException { try { - return mSipService.isRegistered(localProfileUri); + return mSipService.isRegistered(localProfileUri, mContext.getOpPackageName()); } catch (RemoteException e) { throw new SipException("isRegistered()", e); } @@ -405,7 +407,8 @@ public class SipManager { } try { - ISipSession session = mSipService.getPendingSession(callId); + ISipSession session = mSipService.getPendingSession(callId, + mContext.getOpPackageName()); if (session == null) { throw new SipException("No pending session for the call"); } @@ -487,7 +490,8 @@ public class SipManager { SipRegistrationListener listener) throws SipException { try { ISipSession session = mSipService.createSession(localProfile, - createRelay(listener, localProfile.getUriString())); + createRelay(listener, localProfile.getUriString()), + mContext.getOpPackageName()); if (session == null) { throw new SipException( "SipService.createSession() returns null"); @@ -512,7 +516,8 @@ public class SipManager { SipRegistrationListener listener) throws SipException { try { ISipSession session = mSipService.createSession(localProfile, - createRelay(listener, localProfile.getUriString())); + createRelay(listener, localProfile.getUriString()), + mContext.getOpPackageName()); if (session == null) { throw new SipException( "SipService.createSession() returns null"); @@ -537,7 +542,8 @@ public class SipManager { throws SipException { try { String callId = getCallId(incomingCallIntent); - ISipSession s = mSipService.getPendingSession(callId); + ISipSession s = mSipService.getPendingSession(callId, + mContext.getOpPackageName()); return ((s == null) ? null : new SipSession(s)); } catch (RemoteException e) { throw new SipException("getSessionFor()", e); @@ -560,7 +566,8 @@ public class SipManager { public SipSession createSipSession(SipProfile localProfile, SipSession.Listener listener) throws SipException { try { - ISipSession s = mSipService.createSession(localProfile, null); + ISipSession s = mSipService.createSession(localProfile, null, + mContext.getOpPackageName()); if (s == null) { throw new SipException( "Failed to create SipSession; network unavailable?"); @@ -578,7 +585,7 @@ public class SipManager { */ public SipProfile[] getListOfProfiles() { try { - return mSipService.getListOfProfiles(); + return mSipService.getListOfProfiles(mContext.getOpPackageName()); } catch (RemoteException e) { return new SipProfile[0]; } diff --git a/src/java/com/android/server/sip/SipService.java b/src/java/com/android/server/sip/SipService.java index 80fe68c..6e1f428 100644 --- a/src/java/com/android/server/sip/SipService.java +++ b/src/java/com/android/server/sip/SipService.java @@ -16,6 +16,7 @@ package com.android.server.sip; +import android.app.AppOpsManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; @@ -74,6 +75,8 @@ public final class SipService extends ISipService.Stub { private WifiManager.WifiLock mWifiLock; private boolean mSipOnWifiOnly; + private final AppOpsManager mAppOps; + private SipKeepAliveProcessCallback mSipKeepAliveProcessCallback; private MyExecutor mExecutor = new MyExecutor(); @@ -118,12 +121,14 @@ public final class SipService extends ISipService.Stub { context.getSystemService(Context.POWER_SERVICE)); mTimer = new SipWakeupTimer(context, mExecutor); + mAppOps = mContext.getSystemService(AppOpsManager.class); } @Override - public synchronized SipProfile[] getListOfProfiles() { - mContext.enforceCallingOrSelfPermission( - android.Manifest.permission.USE_SIP, null); + public synchronized SipProfile[] getListOfProfiles(String opPackageName) { + if (!canUseSip(opPackageName, "getListOfProfiles")) { + return new SipProfile[0]; + } boolean isCallerRadio = isCallerRadio(); ArrayList<SipProfile> profiles = new ArrayList<SipProfile>(); for (SipSessionGroupExt group : mSipGroups.values()) { @@ -135,9 +140,10 @@ public final class SipService extends ISipService.Stub { } @Override - public synchronized void open(SipProfile localProfile) { - mContext.enforceCallingOrSelfPermission( - android.Manifest.permission.USE_SIP, null); + public synchronized void open(SipProfile localProfile, String opPackageName) { + if (!canUseSip(opPackageName, "open")) { + return; + } localProfile.setCallingUid(Binder.getCallingUid()); try { createGroup(localProfile); @@ -150,9 +156,11 @@ public final class SipService extends ISipService.Stub { @Override public synchronized void open3(SipProfile localProfile, PendingIntent incomingCallPendingIntent, - ISipSessionListener listener) { - mContext.enforceCallingOrSelfPermission( - android.Manifest.permission.USE_SIP, null); + ISipSessionListener listener, + String opPackageName) { + if (!canUseSip(opPackageName, "open3")) { + return; + } localProfile.setCallingUid(Binder.getCallingUid()); if (incomingCallPendingIntent == null) { if (DBG) log("open3: incomingCallPendingIntent cannot be null; " @@ -188,9 +196,10 @@ public final class SipService extends ISipService.Stub { } @Override - public synchronized void close(String localProfileUri) { - mContext.enforceCallingOrSelfPermission( - android.Manifest.permission.USE_SIP, null); + public synchronized void close(String localProfileUri, String opPackageName) { + if (!canUseSip(opPackageName, "close")) { + return; + } SipSessionGroupExt group = mSipGroups.get(localProfileUri); if (group == null) return; if (!isCallerCreatorOrRadio(group)) { @@ -206,9 +215,10 @@ public final class SipService extends ISipService.Stub { } @Override - public synchronized boolean isOpened(String localProfileUri) { - mContext.enforceCallingOrSelfPermission( - android.Manifest.permission.USE_SIP, null); + public synchronized boolean isOpened(String localProfileUri, String opPackageName) { + if (!canUseSip(opPackageName, "isOpened")) { + return false; + } SipSessionGroupExt group = mSipGroups.get(localProfileUri); if (group == null) return false; if (isCallerCreatorOrRadio(group)) { @@ -220,9 +230,10 @@ public final class SipService extends ISipService.Stub { } @Override - public synchronized boolean isRegistered(String localProfileUri) { - mContext.enforceCallingOrSelfPermission( - android.Manifest.permission.USE_SIP, null); + public synchronized boolean isRegistered(String localProfileUri, String opPackageName) { + if (!canUseSip(opPackageName, "isRegistered")) { + return false; + } SipSessionGroupExt group = mSipGroups.get(localProfileUri); if (group == null) return false; if (isCallerCreatorOrRadio(group)) { @@ -235,9 +246,10 @@ public final class SipService extends ISipService.Stub { @Override public synchronized void setRegistrationListener(String localProfileUri, - ISipSessionListener listener) { - mContext.enforceCallingOrSelfPermission( - android.Manifest.permission.USE_SIP, null); + ISipSessionListener listener, String opPackageName) { + if (!canUseSip(opPackageName, "setRegistrationListener")) { + return; + } SipSessionGroupExt group = mSipGroups.get(localProfileUri); if (group == null) return; if (isCallerCreator(group)) { @@ -249,10 +261,11 @@ public final class SipService extends ISipService.Stub { @Override public synchronized ISipSession createSession(SipProfile localProfile, - ISipSessionListener listener) { + ISipSessionListener listener, String opPackageName) { if (DBG) log("createSession: profile" + localProfile); - mContext.enforceCallingOrSelfPermission( - android.Manifest.permission.USE_SIP, null); + if (!canUseSip(opPackageName, "createSession")) { + return null; + } localProfile.setCallingUid(Binder.getCallingUid()); if (mNetworkType == -1) { if (DBG) log("createSession: mNetworkType==-1 ret=null"); @@ -268,9 +281,10 @@ public final class SipService extends ISipService.Stub { } @Override - public synchronized ISipSession getPendingSession(String callId) { - mContext.enforceCallingOrSelfPermission( - android.Manifest.permission.USE_SIP, null); + public synchronized ISipSession getPendingSession(String callId, String opPackageName) { + if (!canUseSip(opPackageName, "getPendingSession")) { + return null; + } if (callId == null) return null; return mPendingSessions.get(callId); } @@ -449,6 +463,14 @@ public final class SipService extends ISipService.Stub { return false; } + private boolean canUseSip(String packageName, String message) { + mContext.enforceCallingOrSelfPermission( + android.Manifest.permission.USE_SIP, message); + + return mAppOps.noteOp(AppOpsManager.OP_USE_SIP, Binder.getCallingUid(), + packageName) == AppOpsManager.MODE_ALLOWED; + } + private class SipSessionGroupExt extends SipSessionAdapter { private static final String SSGE_TAG = "SipSessionGroupExt"; private static final boolean SSGE_DBG = true; |