Merge "Expose ProvisioningManager API for IMS configurations"

This commit is contained in:
Brad Ebinger
2018-11-15 22:07:29 +00:00
committed by Gerrit Code Review
6 changed files with 359 additions and 61 deletions

View File

@@ -6236,6 +6236,22 @@ package android.telephony.ims {
method public void receiveSessionModifyResponse(int, android.telecom.VideoProfile, android.telecom.VideoProfile);
}
public class ProvisioningManager {
method public static android.telephony.ims.ProvisioningManager createForSubscriptionId(android.content.Context, int);
method public int getProvisioningIntValue(int);
method public java.lang.String getProvisioningStringValue(int);
method public void registerProvisioningChangedCallback(java.util.concurrent.Executor, android.telephony.ims.ProvisioningManager.Callback);
method public int setProvisioningIntValue(int, int);
method public int setProvisioningStringValue(int, java.lang.String);
method public void unregisterProvisioningChangedCallback(android.telephony.ims.ProvisioningManager.Callback);
}
public static class ProvisioningManager.Callback {
ctor public ProvisioningManager.Callback();
method public void onProvisioningIntChanged(int, int);
method public void onProvisioningStringChanged(int, java.lang.String);
}
}
package android.telephony.ims.feature {

View File

@@ -292,7 +292,7 @@ public class ImsMmTelManager {
* Create an instance of ImsManager for the subscription id specified.
*
* @param context
* @param subId The ID of the subscription that this ImsManager will use.
* @param subId The ID of the subscription that this ImsMmTelManager will use.
* @see android.telephony.SubscriptionManager#getActiveSubscriptionInfoList()
* @throws IllegalArgumentException if the subscription is invalid or
* the subscription ID is not an active subscription.

View File

@@ -0,0 +1,252 @@
/*
* Copyright (C) 2018 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 android.telephony.ims;
import android.Manifest;
import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.content.Context;
import android.os.Binder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.telephony.SubscriptionManager;
import android.telephony.ims.aidl.IImsConfigCallback;
import android.telephony.ims.stub.ImsConfigImplBase;
import com.android.internal.telephony.ITelephony;
import java.util.concurrent.Executor;
/**
* Manages IMS provisioning and configuration parameters, as well as callbacks for apps to listen
* to changes in these configurations.
*
* Note: IMS provisioning keys are defined per carrier or OEM using OMA-DM or other provisioning
* applications and may vary.
* @hide
*/
@SystemApi
public class ProvisioningManager {
/**
* Callback for IMS provisioning changes.
*/
public static class Callback {
private static class CallbackBinder extends IImsConfigCallback.Stub {
private final Callback mLocalConfigurationCallback;
private Executor mExecutor;
private CallbackBinder(Callback localConfigurationCallback) {
mLocalConfigurationCallback = localConfigurationCallback;
}
@Override
public final void onIntConfigChanged(int item, int value) {
Binder.withCleanCallingIdentity(() ->
mExecutor.execute(() ->
mLocalConfigurationCallback.onProvisioningIntChanged(item, value)));
}
@Override
public final void onStringConfigChanged(int item, String value) {
Binder.withCleanCallingIdentity(() ->
mExecutor.execute(() ->
mLocalConfigurationCallback.onProvisioningStringChanged(item,
value)));
}
private void setExecutor(Executor executor) {
mExecutor = executor;
}
}
private final CallbackBinder mBinder = new CallbackBinder(this);
/**
* Called when a provisioning item has changed.
* @param item the IMS provisioning key constant, as defined by the OEM.
* @param value the new integer value of the IMS provisioning key.
*/
public void onProvisioningIntChanged(int item, int value) {
// Base Implementation
}
/**
* Called when a provisioning item has changed.
* @param item the IMS provisioning key constant, as defined by the OEM.
* @param value the new String value of the IMS configuration constant.
*/
public void onProvisioningStringChanged(int item, String value) {
// Base Implementation
}
/**@hide*/
public final IImsConfigCallback getBinder() {
return mBinder;
}
/**@hide*/
public void setExecutor(Executor executor) {
mBinder.setExecutor(executor);
}
}
private int mSubId;
/**
* Create a new {@link ProvisioningManager} for the subscription specified.
* @param context The context that this manager will use.
* @param subId The ID of the subscription that this ProvisioningManager will use.
* @see android.telephony.SubscriptionManager#getActiveSubscriptionInfoList()
* @throws IllegalArgumentException if the subscription is invalid or
* the subscription ID is not an active subscription.
*/
public static ProvisioningManager createForSubscriptionId(Context context, int subId) {
if (!SubscriptionManager.isValidSubscriptionId(subId)
|| !getSubscriptionManager(context).isActiveSubscriptionId(subId)) {
throw new IllegalArgumentException("Invalid subscription ID");
}
return new ProvisioningManager(subId);
}
private ProvisioningManager(int subId) {
mSubId = subId;
}
/**
* Register a new {@link Callback} to listen to changes to changes in
* IMS provisioning. Use {@link SubscriptionManager.OnSubscriptionsChangedListener} to listen to
* Subscription changed events and call
* {@link #unregisterProvisioningChangedCallback(Callback)} to clean up after a
* subscription is removed.
* @param executor The {@link Executor} to call the callback methods on
* @param callback The provisioning callbackto be registered.
* @see #unregisterProvisioningChangedCallback(Callback)
* @see SubscriptionManager.OnSubscriptionsChangedListener
*/
@RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
public void registerProvisioningChangedCallback(@CallbackExecutor Executor executor,
@NonNull Callback callback) {
callback.setExecutor(executor);
try {
getITelephony().registerImsProvisioningChangedCallback(mSubId,
callback.getBinder());
} catch (RemoteException e) {
throw e.rethrowAsRuntimeException();
}
}
/**
* Unregister an existing {@link Callback}. Ensure to call this method when cleaning
* up to avoid memory leaks or when the subscription is removed.
* @param callback The existing {@link Callback} to be removed.
* @see #registerProvisioningChangedCallback(Executor, Callback)
*/
@RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
public void unregisterProvisioningChangedCallback(@NonNull Callback callback) {
try {
getITelephony().unregisterImsProvisioningChangedCallback(mSubId,
callback.getBinder());
} catch (RemoteException e) {
throw e.rethrowAsRuntimeException();
}
}
/**
* Query for the integer value associated with the provided key.
* @param key An integer that represents the provisioning key, which is defined by the OEM.
* @return an integer value for the provided key.
* @throws IllegalArgumentException if the key provided was invalid.
*/
@RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
public int getProvisioningIntValue(int key) {
try {
return getITelephony().getImsProvisioningInt(mSubId, key);
} catch (RemoteException e) {
throw e.rethrowAsRuntimeException();
}
}
/**
* Query for the String value associated with the provided key.
* @param key An integer that represents the provisioning key, which is defined by the OEM.
* @return a String value for the provided key, or {@code null} if the key doesn't exist.
* @throws IllegalArgumentException if the key provided was invalid.
*/
@RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
public String getProvisioningStringValue(int key) {
try {
return getITelephony().getImsProvisioningString(mSubId, key);
} catch (RemoteException e) {
throw e.rethrowAsRuntimeException();
}
}
/**
* Set the integer value associated with the provided key.
* @param key An integer that represents the provisioning key, which is defined by the OEM.
* @param value a integer value for the provided key.
* @return the result of setting the configuration value.
*/
@RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
public @ImsConfigImplBase.SetConfigResult int setProvisioningIntValue(int key, int value) {
try {
return getITelephony().setImsProvisioningInt(mSubId, key, value);
} catch (RemoteException e) {
throw e.rethrowAsRuntimeException();
}
}
/**
* Set the String value associated with the provided key.
*
* @param key An integer that represents the provisioning key, which is defined by the OEM.
* @param value a String value for the provided key.
* @return the result of setting the configuration value.
*/
@RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
public @ImsConfigImplBase.SetConfigResult int setProvisioningStringValue(int key,
String value) {
try {
return getITelephony().setImsProvisioningString(mSubId, key, value);
} catch (RemoteException e) {
throw e.rethrowAsRuntimeException();
}
}
private static SubscriptionManager getSubscriptionManager(Context context) {
SubscriptionManager manager = context.getSystemService(SubscriptionManager.class);
if (manager == null) {
throw new RuntimeException("Could not find SubscriptionManager.");
}
return manager;
}
private static ITelephony getITelephony() {
ITelephony binder = ITelephony.Stub.asInterface(
ServiceManager.getService(Context.TELEPHONY_SERVICE));
if (binder == null) {
throw new RuntimeException("Could not find Telephony Service.");
}
return binder;
}
}

View File

@@ -16,9 +16,9 @@
package android.telephony.ims.stub;
import android.annotation.IntDef;
import android.annotation.SystemApi;
import android.content.Context;
import android.content.Intent;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.telephony.ims.aidl.IImsConfig;
@@ -28,6 +28,8 @@ import android.util.Log;
import com.android.ims.ImsConfig;
import com.android.internal.annotations.VisibleForTesting;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.ref.WeakReference;
import java.util.HashMap;
@@ -214,41 +216,6 @@ public class ImsConfigImplBase {
}
}
/**
* Callback that the framework uses for receiving Configuration change updates.
* {@hide}
*/
public static class Callback extends IImsConfigCallback.Stub {
@Override
public final void onIntConfigChanged(int item, int value) throws RemoteException {
onConfigChanged(item, value);
}
@Override
public final void onStringConfigChanged(int item, String value) throws RemoteException {
onConfigChanged(item, value);
}
/**
* Called when the IMS configuration has changed.
* @param item the IMS configuration key constant, as defined in ImsConfig.
* @param value the new integer value of the IMS configuration constant.
*/
public void onConfigChanged(int item, int value) {
// Base Implementation
}
/**
* Called when the IMS configuration has changed.
* @param item the IMS configuration key constant, as defined in ImsConfig.
* @param value the new String value of the IMS configuration constant.
*/
public void onConfigChanged(int item, String value) {
// Base Implementation
}
}
/**
* The configuration requested resulted in an unknown result. This may happen if the
* IMS configurations are unavailable.
@@ -263,6 +230,16 @@ public class ImsConfigImplBase {
*/
public static final int CONFIG_RESULT_FAILED = 1;
/**
* @hide
*/
@Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = "CONFIG_RESULT_", value = {
CONFIG_RESULT_SUCCESS,
CONFIG_RESULT_FAILED
})
public @interface SetConfigResult {}
private final RemoteCallbackList<IImsConfigCallback> mCallbacks = new RemoteCallbackList<>();
ImsConfigStub mImsConfigStub;
@@ -279,17 +256,16 @@ public class ImsConfigImplBase {
}
/**
* Adds a {@link Callback} to the list of callbacks notified when a value in the configuration
* changes.
* Adds a {@link android.telephony.ims.ProvisioningManager.Callback} to the list of callbacks
* notified when a value in the configuration changes.
* @param c callback to add.
*/
private void addImsConfigCallback(IImsConfigCallback c) {
mCallbacks.register(c);
}
/**
* Removes a {@link Callback} to the list of callbacks notified when a value in the
* configuration changes.
*
* Removes a {@link android.telephony.ims.ProvisioningManager.Callback} to the list of callbacks
* notified when a value in the configuration changes.
* @param c callback to remove.
*/
private void removeImsConfigCallback(IImsConfigCallback c) {
@@ -370,10 +346,9 @@ public class ImsConfigImplBase {
*
* @param item an integer key.
* @param value an integer containing the configuration value.
* @return the result of setting the configuration value, defined as either
* {@link #CONFIG_RESULT_FAILED} or {@link #CONFIG_RESULT_SUCCESS}.
* @return the result of setting the configuration value.
*/
public int setConfig(int item, int value) {
public @SetConfigResult int setConfig(int item, int value) {
// Base Implementation - To be overridden.
return CONFIG_RESULT_FAILED;
}
@@ -383,10 +358,9 @@ public class ImsConfigImplBase {
*
* @param item an integer key.
* @param value a String containing the new configuration value.
* @return Result of setting the configuration value, defined as either
* {@link #CONFIG_RESULT_FAILED} or {@link #CONFIG_RESULT_SUCCESS}.
* @return Result of setting the configuration value.
*/
public int setConfig(int item, String value) {
public @SetConfigResult int setConfig(int item, String value) {
// Base Implementation - To be overridden.
return CONFIG_RESULT_FAILED;
}

View File

@@ -16,12 +16,17 @@
package com.android.ims;
import android.content.Context;
import android.os.Handler;
import android.os.HandlerExecutor;
import android.os.Looper;
import android.os.RemoteException;
import android.telephony.Rlog;
import android.telephony.ims.ImsReasonInfo;
import android.telephony.ims.ProvisioningManager;
import android.telephony.ims.aidl.IImsConfig;
import android.telephony.ims.stub.ImsConfigImplBase;
import android.telephony.ims.aidl.IImsConfigCallback;
import java.util.concurrent.Executor;
/**
* Provides APIs to get/set the IMS service feature/capability/parameters.
@@ -29,8 +34,10 @@ import android.telephony.ims.stub.ImsConfigImplBase;
* 1) Items provisioned by the operator.
* 2) Items configured by user. Mainly service feature class.
*
* @deprecated Use {@link ProvisioningManager} to change these configurations in the ImsService.
* @hide
*/
@Deprecated
public class ImsConfig {
private static final String TAG = "ImsConfig";
private boolean DBG = true;
@@ -46,7 +53,7 @@ public class ImsConfig {
/**
* Broadcast action: the configuration was changed
* @deprecated Use {@link ImsConfig#addConfigCallback(ImsConfigImplBase.Callback)} instead.
* @deprecated Use {@link android.telephony.ims.ProvisioningManager.Callback} instead.
* @hide
*/
public static final String ACTION_IMS_CONFIG_CHANGED =
@@ -673,13 +680,25 @@ public class ImsConfig {
}
/**
* Adds a {@link ImsConfigImplBase.Callback} to the ImsService to notify when a Configuration
* Adds a {@link ProvisioningManager.Callback} to the ImsService to notify when a Configuration
* item has changed.
*
* Make sure to call {@link #removeConfigCallback(ImsConfigImplBase.Callback)} when finished
* Make sure to call {@link #removeConfigCallback(IImsConfigCallback)} when finished
* using this callback.
*/
public void addConfigCallback(ImsConfigImplBase.Callback callback) throws ImsException {
public void addConfigCallback(ProvisioningManager.Callback callback) throws ImsException {
callback.setExecutor(getThreadExecutor());
addConfigCallback(callback.getBinder());
}
/**
* Adds a {@link IImsConfigCallback} to the ImsService to notify when a Configuration
* item has changed.
*
* Make sure to call {@link #removeConfigCallback(IImsConfigCallback)} when finished
* using this callback.
*/
public void addConfigCallback(IImsConfigCallback callback) throws ImsException {
if (DBG) Rlog.d(TAG, "addConfigCallback: " + callback);
try {
miConfig.addImsConfigCallback(callback);
@@ -690,10 +709,9 @@ public class ImsConfig {
}
/**
* Removes a {@link ImsConfigImplBase.Callback} from the ImsService that was previously added
* by {@link #addConfigCallback(ImsConfigImplBase.Callback)}.
* Removes an existing {@link IImsConfigCallback} from the ImsService.
*/
public void removeConfigCallback(ImsConfigImplBase.Callback callback) throws ImsException {
public void removeConfigCallback(IImsConfigCallback callback) throws ImsException {
if (DBG) Rlog.d(TAG, "removeConfigCallback: " + callback);
try {
miConfig.removeImsConfigCallback(callback);
@@ -709,4 +727,11 @@ public class ImsConfig {
public boolean isBinderAlive() {
return miConfig.asBinder().isBinderAlive();
}
private Executor getThreadExecutor() {
if (Looper.myLooper() == null) {
Looper.prepare();
}
return new HandlerExecutor(new Handler(Looper.myLooper()));
}
}

View File

@@ -40,6 +40,7 @@ import android.telephony.TelephonyHistogram;
import android.telephony.VisualVoicemailSmsFilterSettings;
import android.telephony.ims.aidl.IImsCapabilityCallback;
import android.telephony.ims.aidl.IImsConfig;
import android.telephony.ims.aidl.IImsConfigCallback;
import android.telephony.ims.aidl.IImsMmTelFeature;
import android.telephony.ims.aidl.IImsRcsFeature;
import android.telephony.ims.aidl.IImsRegistration;
@@ -1569,24 +1570,24 @@ interface ITelephony {
/**
* Adds an IMS registration status callback for the subscription id specified.
*/
oneway void addImsRegistrationCallback(int subId, IImsRegistrationCallback c,
void addImsRegistrationCallback(int subId, IImsRegistrationCallback c,
String callingPackage);
/**
* Removes an existing IMS registration status callback for the subscription specified.
*/
oneway void removeImsRegistrationCallback(int subId, IImsRegistrationCallback c,
void removeImsRegistrationCallback(int subId, IImsRegistrationCallback c,
String callingPackage);
/**
* Adds an IMS MmTel capabilities callback for the subscription specified.
*/
oneway void addMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
void addMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
String callingPackage);
/**
* Removes an existing IMS MmTel capabilities callback for the subscription specified.
*/
oneway void removeMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
void removeMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
String callingPackage);
/**
@@ -1691,4 +1692,34 @@ interface ITelephony {
* Return a list of certs in hex string from loaded carrier privileges access rules.
*/
List<String> getCertsFromCarrierPrivilegeAccessRules(int subId);
/**
* Register an IMS provisioning change callback with Telephony.
*/
void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback);
/**
* unregister an existing IMS provisioning change callback.
*/
void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback);
/**
* Return an integer containing the provisioning value for the specified provisioning key.
*/
int getImsProvisioningInt(int subId, int key);
/**
* return a String containing the provisioning value for the provisioning key specified.
*/
String getImsProvisioningString(int subId, int key);
/**
* Set the integer provisioning value for the provisioning key specified.
*/
int setImsProvisioningInt(int subId, int key, int value);
/**
* Set the String provisioning value for the provisioning key specified.
*/
int setImsProvisioningString(int subId, int key, String value);
}