Merge "Fix legacy role holder resolution for assistant, dialer and SMS." into qt-qpr1-dev

This commit is contained in:
TreeHugger Robot
2019-08-22 19:11:38 +00:00
committed by Android (Google) Code Review
2 changed files with 49 additions and 46 deletions

View File

@@ -24,20 +24,17 @@ import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal; import android.content.pm.PackageManagerInternal;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.Debug;
import android.provider.Settings; import android.provider.Settings;
import android.telecom.TelecomManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.util.Slog; import android.util.Slog;
import com.android.internal.R;
import com.android.internal.telephony.SmsApplication; import com.android.internal.telephony.SmsApplication;
import com.android.internal.util.CollectionUtils; import com.android.internal.util.CollectionUtils;
import com.android.server.LocalServices; import com.android.server.LocalServices;
import com.android.server.role.RoleManagerService; import com.android.server.role.RoleManagerService;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@@ -67,14 +64,25 @@ public class LegacyRoleResolutionPolicy implements RoleManagerService.RoleHolder
public List<String> getRoleHolders(@NonNull String roleName, @UserIdInt int userId) { public List<String> getRoleHolders(@NonNull String roleName, @UserIdInt int userId) {
switch (roleName) { switch (roleName) {
case RoleManager.ROLE_ASSISTANT: { case RoleManager.ROLE_ASSISTANT: {
String legacyAssistant = Settings.Secure.getStringForUser( String packageName;
mContext.getContentResolver(), Settings.Secure.ASSISTANT, userId); String setting = Settings.Secure.getStringForUser(mContext.getContentResolver(),
if (legacyAssistant == null || legacyAssistant.isEmpty()) { Settings.Secure.ASSISTANT, userId);
return Collections.emptyList(); // AssistUtils was using the default assistant app if Settings.Secure.ASSISTANT is
// null, while only an empty string means user selected "None".
if (setting != null) {
if (!setting.isEmpty()) {
ComponentName componentName = ComponentName.unflattenFromString(setting);
packageName = componentName != null ? componentName.getPackageName() : null;
} else {
packageName = null;
}
} else if (mContext.getPackageManager().isDeviceUpgrading()) {
String defaultAssistant = mContext.getString(R.string.config_defaultAssistant);
packageName = !TextUtils.isEmpty(defaultAssistant) ? defaultAssistant : null;
} else { } else {
return Collections.singletonList( packageName = null;
ComponentName.unflattenFromString(legacyAssistant).getPackageName());
} }
return CollectionUtils.singletonOrEmpty(packageName);
} }
case RoleManager.ROLE_BROWSER: { case RoleManager.ROLE_BROWSER: {
PackageManagerInternal packageManagerInternal = LocalServices.getService( PackageManagerInternal packageManagerInternal = LocalServices.getService(
@@ -84,44 +92,36 @@ public class LegacyRoleResolutionPolicy implements RoleManagerService.RoleHolder
return CollectionUtils.singletonOrEmpty(packageName); return CollectionUtils.singletonOrEmpty(packageName);
} }
case RoleManager.ROLE_DIALER: { case RoleManager.ROLE_DIALER: {
String setting = Settings.Secure.getStringForUser( String setting = Settings.Secure.getStringForUser(mContext.getContentResolver(),
mContext.getContentResolver(),
Settings.Secure.DIALER_DEFAULT_APPLICATION, userId); Settings.Secure.DIALER_DEFAULT_APPLICATION, userId);
return CollectionUtils.singletonOrEmpty(!TextUtils.isEmpty(setting) String packageName;
? setting if (!TextUtils.isEmpty(setting)) {
: mContext.getSystemService(TelecomManager.class).getSystemDialerPackage()); packageName = setting;
} else if (mContext.getPackageManager().isDeviceUpgrading()) {
// DefaultDialerManager was using the default dialer app if
// Settings.Secure.DIALER_DEFAULT_APPLICATION is invalid.
// TelecomManager.getSystemDialerPackage() won't work because it might not
// be ready.
packageName = mContext.getString(R.string.config_defaultDialer);
} else {
packageName = null;
}
return CollectionUtils.singletonOrEmpty(packageName);
} }
case RoleManager.ROLE_SMS: { case RoleManager.ROLE_SMS: {
// Moved over from SmsApplication#getApplication String setting = Settings.Secure.getStringForUser(mContext.getContentResolver(),
String result = Settings.Secure.getStringForUser(
mContext.getContentResolver(),
Settings.Secure.SMS_DEFAULT_APPLICATION, userId); Settings.Secure.SMS_DEFAULT_APPLICATION, userId);
// TODO: STOPSHIP: Remove the following code once we read the value of String packageName;
// config_defaultSms in RoleControllerService. if (!TextUtils.isEmpty(setting)) {
if (result == null) { packageName = setting;
Collection<SmsApplication.SmsApplicationData> applications = } else if (mContext.getPackageManager().isDeviceUpgrading()) {
SmsApplication.getApplicationCollectionAsUser(mContext, userId); // SmsApplication was using the default SMS app if
SmsApplication.SmsApplicationData applicationData; // Settings.Secure.DIALER_DEFAULT_APPLICATION is invalid.
String defaultPackage = mContext.getResources() packageName = mContext.getString(R.string.config_defaultSms);
.getString(com.android.internal.R.string.default_sms_application); } else {
applicationData = packageName = null;
SmsApplication.getApplicationForPackage(applications, defaultPackage);
if (applicationData == null) {
// Are there any applications?
if (applications.size() != 0) {
applicationData =
(SmsApplication.SmsApplicationData) applications.toArray()[0];
}
}
if (DEBUG) {
Log.i(LOG_TAG, "Found default sms app: " + applicationData
+ " among: " + applications + " from " + Debug.getCallers(4));
}
SmsApplication.SmsApplicationData app = applicationData;
result = app == null ? null : app.mPackageName;
} }
return CollectionUtils.singletonOrEmpty(result); return CollectionUtils.singletonOrEmpty(packageName);
} }
case RoleManager.ROLE_HOME: { case RoleManager.ROLE_HOME: {
PackageManager packageManager = mContext.getPackageManager(); PackageManager packageManager = mContext.getPackageManager();

View File

@@ -1281,9 +1281,12 @@ public class VoiceInteractionManagerService extends SystemService {
RoleObserver(@NonNull @CallbackExecutor Executor executor) { RoleObserver(@NonNull @CallbackExecutor Executor executor) {
mRm.addOnRoleHoldersChangedListenerAsUser(executor, this, UserHandle.ALL); mRm.addOnRoleHoldersChangedListenerAsUser(executor, this, UserHandle.ALL);
UserHandle currentUser = UserHandle.of(LocalServices.getService( // Sync only if assistant role has been initialized.
ActivityManagerInternal.class).getCurrentUserId()); if (mRm.isRoleAvailable(RoleManager.ROLE_ASSISTANT)) {
onRoleHoldersChanged(RoleManager.ROLE_ASSISTANT, currentUser); UserHandle currentUser = UserHandle.of(LocalServices.getService(
ActivityManagerInternal.class).getCurrentUserId());
onRoleHoldersChanged(RoleManager.ROLE_ASSISTANT, currentUser);
}
} }
private @NonNull String getDefaultRecognizer(@NonNull UserHandle user) { private @NonNull String getDefaultRecognizer(@NonNull UserHandle user) {