Remove ability to enable/disable phoneaccounts (3/6)
Enabling/disabling of phone accounts was only used for SIP accounts and
is no longer necessary for the purpose it was put in.
- Remove all references to enabling/disabling phone accounts
+ Rename getEnabledPhoneAccounts to getCallCapablePhoneAccounts
Bug: 17510811
Change-Id: I5e8a59fe2aaac2563fe4bf97138975e30b45aa3c
diff --git a/src/com/android/server/telecom/CallsManager.java b/src/com/android/server/telecom/CallsManager.java
index 2636c2f..583c4d6 100644
--- a/src/com/android/server/telecom/CallsManager.java
+++ b/src/com/android/server/telecom/CallsManager.java
@@ -319,9 +319,9 @@
// as if a phoneAccount was not specified (does the default behavior instead).
// Note: We will not attempt to dial with a requested phoneAccount if it is disabled.
if (phoneAccountHandle != null) {
- List<PhoneAccountHandle> enabledAccounts =
- app.getPhoneAccountRegistrar().getEnabledPhoneAccounts(handle.getScheme());
- if (!enabledAccounts.contains(phoneAccountHandle)) {
+ List<PhoneAccountHandle> accounts =
+ app.getPhoneAccountRegistrar().getCallCapablePhoneAccounts(handle.getScheme());
+ if (!accounts.contains(phoneAccountHandle)) {
phoneAccountHandle = null;
}
}
diff --git a/src/com/android/server/telecom/ConnectionServiceWrapper.java b/src/com/android/server/telecom/ConnectionServiceWrapper.java
index 669f9a5..b858067 100644
--- a/src/com/android/server/telecom/ConnectionServiceWrapper.java
+++ b/src/com/android/server/telecom/ConnectionServiceWrapper.java
@@ -931,7 +931,7 @@
// Make a list of ConnectionServices that are listed as being associated with SIM accounts
final Set<ConnectionServiceWrapper> simServices = Collections.newSetFromMap(
new ConcurrentHashMap<ConnectionServiceWrapper, Boolean>(8, 0.9f, 1));
- for (PhoneAccountHandle handle : registrar.getEnabledPhoneAccounts()) {
+ for (PhoneAccountHandle handle : registrar.getCallCapablePhoneAccounts()) {
PhoneAccount account = registrar.getPhoneAccount(handle);
if ((account.getCapabilities() & PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION) != 0) {
ConnectionServiceWrapper service =
diff --git a/src/com/android/server/telecom/PhoneAccountRegistrar.java b/src/com/android/server/telecom/PhoneAccountRegistrar.java
index ed2ca05..4e098b4 100644
--- a/src/com/android/server/telecom/PhoneAccountRegistrar.java
+++ b/src/com/android/server/telecom/PhoneAccountRegistrar.java
@@ -18,8 +18,6 @@
import android.Manifest;
import android.content.Intent;
-import android.content.pm.ActivityInfo;
-import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
@@ -120,7 +118,7 @@
}
}
- List<PhoneAccountHandle> outgoing = getEnabledPhoneAccounts(uriScheme);
+ List<PhoneAccountHandle> outgoing = getCallCapablePhoneAccounts(uriScheme);
switch (outgoing.size()) {
case 0:
// There are no accounts, so there can be no default
@@ -265,43 +263,42 @@
}
/**
- * Determines the number of enabled and disabled {@link PhoneAccount}s.
+ * Determines the number of all {@link PhoneAccount}s.
*
- * @return The number of enabled and disabled {@link PhoneAccount}s
+ * @return The total number {@link PhoneAccount}s.
*/
public int getAllPhoneAccountsCount() {
return mState.accounts.size();
}
/**
- * Retrieves a list of all enabled call provider phone accounts.
+ * Retrieves a list of all call provider phone accounts.
*
* @return The phone account handles.
*/
- public List<PhoneAccountHandle> getEnabledPhoneAccounts() {
+ public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
return getPhoneAccountHandles(PhoneAccount.CAPABILITY_CALL_PROVIDER);
}
/**
- * Retrieves a list of all enabled phone account call provider phone accounts supporting the
+ * Retrieves a list of all phone account call provider phone accounts supporting the
* specified URI scheme.
*
* @param uriScheme The URI scheme.
* @return The phone account handles.
*/
- public List<PhoneAccountHandle> getEnabledPhoneAccounts(String uriScheme) {
- return getPhoneAccountHandles(PhoneAccount.CAPABILITY_CALL_PROVIDER, uriScheme,
- false /* includeDisabled */);
+ public List<PhoneAccountHandle> getCallCapablePhoneAccounts(String uriScheme) {
+ return getPhoneAccountHandles(PhoneAccount.CAPABILITY_CALL_PROVIDER, uriScheme);
}
/**
- * Retrieves a list of all enabled phone account handles with the connection manager capability.
+ * Retrieves a list of all phone account handles with the connection manager capability.
*
* @return The phone account handles.
*/
public List<PhoneAccountHandle> getConnectionManagerPhoneAccounts() {
return getPhoneAccountHandles(PhoneAccount.CAPABILITY_CONNECTION_MANAGER,
- null /* supportedUriScheme */, false /* includeDisabled */);
+ null /* supportedUriScheme */);
}
public PhoneAccount getPhoneAccount(PhoneAccountHandle handle) {
@@ -313,44 +310,6 @@
return null;
}
- /**
- * Changes the enabled state of the {@link PhoneAccount} identified by a
- * {@link PhoneAccountHandle}.
- *
- * @param handle The {@link PhoneAccountHandle}.
- * @param isEnabled The new enabled state of the {@link PhoneAccount}.
- */
- public void setPhoneAccountEnabled(PhoneAccountHandle handle, boolean isEnabled) {
- PhoneAccount existing = getPhoneAccount(handle);
- if (existing.isEnabled() == isEnabled) {
- return;
- }
-
- // Do not permit PhoneAccounts which are marked as always enabled to be disabled.
- if (existing.hasCapabilities(PhoneAccount.CAPABILITY_ALWAYS_ENABLED)) {
- return;
- }
-
- // If we are disabling the current default outgoing phone account or Sim call manager we
- // need to null out those preferences.
- if (!isEnabled) {
- if (mState.defaultOutgoing != null && mState.defaultOutgoing.equals(handle)) {
- setUserSelectedOutgoingPhoneAccount(null);
- }
-
- if (mState.simCallManager != null && mState.simCallManager.equals(handle)) {
- setSimCallManager(null);
- }
- }
-
- PhoneAccount.Builder builder = existing.toBuilder().setEnabled(isEnabled);
- PhoneAccount replacement = builder.build();
- addOrReplacePhoneAccount(replacement);
-
- // Notify the package which registered this PhoneAccount of its new enabled state.
- notifyPhoneAccountEnabledStateChanged(replacement.getAccountHandle(), isEnabled);
- }
-
// TODO: Should we implement an artificial limit for # of accounts associated with a single
// ComponentName?
public void registerPhoneAccount(PhoneAccount account) {
@@ -363,13 +322,6 @@
"PhoneAccount connection service requires BIND_CONNECTION_SERVICE permission.");
}
- // If there is an existing PhoneAccount already registered with this handle, copy its
- // enabled state to the new phone account.
- PhoneAccount existing = getPhoneAccount(account.getAccountHandle());
- if (existing != null) {
- account = account.toBuilder().setEnabled(existing.isEnabled()).build();
- }
-
addOrReplacePhoneAccount(account);
}
@@ -488,26 +440,21 @@
* @param flags Flags which the {@code PhoneAccount} must have.
*/
private List<PhoneAccountHandle> getPhoneAccountHandles(int flags) {
- return getPhoneAccountHandles(flags, null, false /* includeDisabled */);
+ return getPhoneAccountHandles(flags, null);
}
/**
* Returns a list of phone account handles with the specified flag, supporting the specified
- * URI scheme. By default, only enabled phone accounts are included, unless the
- * {@code includeDisabled} parameter is set {@code true}.
+ * URI scheme.
*
* @param flags Flags which the {@code PhoneAccount} must have.
* @param uriScheme URI schemes the PhoneAccount must handle. {@code Null} bypasses the
* URI scheme check.
- * @param includeDisabled When {@code true}, the list of phone accounts handles includes those
- * which are marked as disabled.
*/
- private List<PhoneAccountHandle> getPhoneAccountHandles(int flags, String uriScheme,
- boolean includeDisabled) {
+ private List<PhoneAccountHandle> getPhoneAccountHandles(int flags, String uriScheme) {
List<PhoneAccountHandle> accountHandles = new ArrayList<>();
for (PhoneAccount m : mState.accounts) {
- if ((includeDisabled || m.isEnabled()) && m.hasCapabilities(flags) &&
- (uriScheme == null || m.supportsUriScheme(uriScheme))) {
+ if (m.hasCapabilities(flags) && (uriScheme == null || m.supportsUriScheme(uriScheme))) {
accountHandles.add(m.getAccountHandle());
}
}
@@ -515,46 +462,6 @@
}
/**
- * Notifies the package which registered a {@link PhoneAccount} that it has been enabled.
- * Only broadcasts the intent if the package has a {@link android.content.BroadcastReceiver}
- * registered for the intent.
- *
- * @param phoneAccountHandle The {@link PhoneAccountHandle} which has been enabled or disabled.
- * @param isEnabled {@code True} if the {@link PhoneAccount} is enabled, false otherwise.
- */
- private void notifyPhoneAccountEnabledStateChanged(PhoneAccountHandle phoneAccountHandle,
- boolean isEnabled) {
- Intent intent;
-
- if (isEnabled) {
- intent = new Intent(TelecomManager.ACTION_PHONE_ACCOUNT_ENABLED);
- } else {
- intent = new Intent(TelecomManager.ACTION_PHONE_ACCOUNT_DISABLED);
- }
- intent.setPackage(phoneAccountHandle.getComponentName().getPackageName());
- intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle);
-
- if (isReceiverListening(intent)) {
- Log.i(this, "notifyPhoneAccountEnabledState %s %s", phoneAccountHandle,
- (isEnabled ? "enabled" : "disabled"));
- mContext.sendBroadcast(intent);
- }
- }
-
- /**
- * Determines there is a {@link android.content.BroadcastReceiver} listening for an
- * {@link Intent}.
- *
- * @param intent The {@link Intent}.
- * @return {@code True} if there is a listener.
- */
- private boolean isReceiverListening(Intent intent) {
- PackageManager pm = mContext.getPackageManager();
- final List<ResolveInfo> activities = pm.queryBroadcastReceivers(intent, 0);
- return !(activities.isEmpty());
- }
-
- /**
* The state of this {@code PhoneAccountRegistrar}.
*/
@VisibleForTesting
@@ -840,7 +747,6 @@
private static final String LABEL = "label";
private static final String SHORT_DESCRIPTION = "short_description";
private static final String SUPPORTED_URI_SCHEMES = "supported_uri_schemes";
- private static final String ENABLED = "enabled";
private static final String TRUE = "true";
private static final String FALSE = "false";
@@ -863,7 +769,6 @@
writeTextSafely(LABEL, o.getLabel(), serializer);
writeTextSafely(SHORT_DESCRIPTION, o.getShortDescription(), serializer);
writeStringList(SUPPORTED_URI_SCHEMES, o.getSupportedUriSchemes(), serializer);
- writeTextSafely(ENABLED, o.isEnabled() ? TRUE : FALSE, serializer);
serializer.endTag(null, CLASS_PHONE_ACCOUNT);
}
@@ -881,7 +786,6 @@
String label = null;
String shortDescription = null;
List<String> supportedUriSchemes = null;
- boolean enabled = false;
while (XmlUtils.nextElementWithin(parser, outerDepth)) {
if (parser.getName().equals(ACCOUNT_HANDLE)) {
@@ -909,9 +813,6 @@
shortDescription = parser.getText();
} else if (parser.getName().equals(SUPPORTED_URI_SCHEMES)) {
supportedUriSchemes = readStringList(parser);
- } else if (parser.getName().equals(ENABLED)) {
- parser.next();
- enabled = parser.getText().equals(TRUE);
}
}
@@ -936,17 +837,6 @@
}
}
- // Prior to version 3, PhoneAccounts didn't include the enabled option. Enable
- // all TelephonyConnectionService phone accounts by default.
- if (version < 3) {
- ComponentName telephonyComponentName = new ComponentName("com.android.phone",
- "com.android.services.telephony.TelephonyConnectionService");
-
- if (accountHandle.getComponentName().equals(telephonyComponentName)) {
- enabled = true;
- }
- }
-
return PhoneAccount.builder(accountHandle, label)
.setAddress(address)
.setSubscriptionAddress(subscriptionAddress)
@@ -954,7 +844,6 @@
.setIconResId(iconResId)
.setShortDescription(shortDescription)
.setSupportedUriSchemes(supportedUriSchemes)
- .setEnabled(enabled)
.build();
}
return null;
diff --git a/src/com/android/server/telecom/TelecomServiceImpl.java b/src/com/android/server/telecom/TelecomServiceImpl.java
index 750c77a..2f5fa68 100644
--- a/src/com/android/server/telecom/TelecomServiceImpl.java
+++ b/src/com/android/server/telecom/TelecomServiceImpl.java
@@ -193,11 +193,11 @@
}
@Override
- public List<PhoneAccountHandle> getEnabledPhoneAccounts() {
+ public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
try {
- return mPhoneAccountRegistrar.getEnabledPhoneAccounts();
+ return mPhoneAccountRegistrar.getCallCapablePhoneAccounts();
} catch (Exception e) {
- Log.e(this, e, "getEnabledPhoneAccounts");
+ Log.e(this, e, "getCallCapablePhoneAccounts");
throw e;
}
}
@@ -205,7 +205,7 @@
@Override
public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
try {
- return mPhoneAccountRegistrar.getEnabledPhoneAccounts(uriScheme);
+ return mPhoneAccountRegistrar.getCallCapablePhoneAccounts(uriScheme);
} catch (Exception e) {
Log.e(this, e, "getPhoneAccountsSupportingScheme");
throw e;
@@ -294,24 +294,7 @@
enforceRegisterProviderOrSubscriptionPermission();
}
- // If the account is marked as enabled or has CAPABILITY_ALWAYS_ENABLED set, check to
- // ensure the caller has modify permission. If they do not, set the account to be
- // disabled and remove CAPABILITY_ALWAYS_ENABLED.
- if (account.isEnabled() ||
- account.hasCapabilities(PhoneAccount.CAPABILITY_ALWAYS_ENABLED)) {
- try {
- enforceModifyPermission();
- } catch (SecurityException e) {
- // Caller does not have modify permission, so change account to disabled by
- // default and remove the CAPABILITY_ALWAYS_ENABLED capability.
- int capabilities = account.getCapabilities() &
- ~PhoneAccount.CAPABILITY_ALWAYS_ENABLED;
- account = account.toBuilder()
- .setEnabled(false)
- .setCapabilities(capabilities)
- .build();
- }
- }
+ enforceModifyPermission();
mPhoneAccountRegistrar.registerPhoneAccount(account);
} catch (Exception e) {
@@ -321,17 +304,6 @@
}
@Override
- public void setPhoneAccountEnabled(PhoneAccountHandle account, boolean isEnabled) {
- try {
- enforceModifyPermission();
- mPhoneAccountRegistrar.setPhoneAccountEnabled(account, isEnabled);
- } catch (Exception e) {
- Log.e(this, e, "setPhoneAccountEnabled %s %d", account, isEnabled ? 1 : 0);
- throw e;
- }
- }
-
- @Override
public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
try {
enforcePhoneAccountModificationForPackage(
diff --git a/tests/src/com/android/server/telecom/testapps/CallServiceNotifier.java b/tests/src/com/android/server/telecom/testapps/CallServiceNotifier.java
index f620b27..b82f4af 100644
--- a/tests/src/com/android/server/telecom/testapps/CallServiceNotifier.java
+++ b/tests/src/com/android/server/telecom/testapps/CallServiceNotifier.java
@@ -144,7 +144,7 @@
public void showAllPhoneAccounts(Context context) {
TelecomManager telecomManager =
(TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
- List<PhoneAccountHandle> accounts = telecomManager.getEnabledPhoneAccounts();
+ List<PhoneAccountHandle> accounts = telecomManager.getCallCapablePhoneAccounts();
Toast.makeText(context, accounts.toString(), Toast.LENGTH_LONG).show();
}
diff --git a/tests/src/com/android/server/telecom/tests/unit/PhoneAccountRegistrarTest.java b/tests/src/com/android/server/telecom/tests/unit/PhoneAccountRegistrarTest.java
index b3aa626..b1f6e9e 100644
--- a/tests/src/com/android/server/telecom/tests/unit/PhoneAccountRegistrarTest.java
+++ b/tests/src/com/android/server/telecom/tests/unit/PhoneAccountRegistrarTest.java
@@ -207,7 +207,7 @@
public void testAccounts() throws Exception {
assertEquals(4, mRegistrar.getAllPhoneAccountHandles().size());
- assertEquals(3, mRegistrar.getEnabledPhoneAccounts().size());
+ assertEquals(3, mRegistrar.getCallCapablePhoneAccounts().size());
assertEquals(null, mRegistrar.getSimCallManager());
assertEquals(null, mRegistrar.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL));
}