diff options
author | Hai Zhang <zhanghai@google.com> | 2019-04-30 19:03:41 +0800 |
---|---|---|
committer | Hai Zhang <zhanghai@google.com> | 2019-05-06 17:11:21 -0700 |
commit | 00b3239fbfd93ee8f41625d819a9d02798092c1c (patch) | |
tree | 4cbd9378c541dca26a8ef3db6eb7c842a01c290a /src/com/android/packageinstaller/role/ui/RequestRoleActivity.java | |
parent | 489c81882c6224f4c161e6401735db9d395160df (diff) | |
download | android_packages_apps_PackageInstaller-00b3239fbfd93ee8f41625d819a9d02798092c1c.tar.gz android_packages_apps_PackageInstaller-00b3239fbfd93ee8f41625d819a9d02798092c1c.tar.bz2 android_packages_apps_PackageInstaller-00b3239fbfd93ee8f41625d819a9d02798092c1c.zip |
Replace ChangeDefaultDialerDialog with RequestRoleActivity.
For apps targeting pre-Q, we allow specifying the package name of the
application itself, or another package name if the calling app is the
current default dialer app. For apps targeting Q or later, we'll
cancel the activity launch in ActivityStackSupervisor.
Bug: 124452117
Bug: 131204827
Test: presubmit
Change-Id: I4ec52108321903b3875007246a95b434172849c1
Diffstat (limited to 'src/com/android/packageinstaller/role/ui/RequestRoleActivity.java')
-rw-r--r-- | src/com/android/packageinstaller/role/ui/RequestRoleActivity.java | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/com/android/packageinstaller/role/ui/RequestRoleActivity.java b/src/com/android/packageinstaller/role/ui/RequestRoleActivity.java index a58b256b..44d37400 100644 --- a/src/com/android/packageinstaller/role/ui/RequestRoleActivity.java +++ b/src/com/android/packageinstaller/role/ui/RequestRoleActivity.java @@ -23,6 +23,7 @@ import android.content.pm.ApplicationInfo; import android.os.Bundle; import android.os.Process; import android.provider.Telephony; +import android.telecom.TelecomManager; import android.text.TextUtils; import android.util.Log; import android.view.WindowManager; @@ -61,6 +62,13 @@ public class RequestRoleActivity extends FragmentActivity { mRoleName = getIntent().getStringExtra(Intent.EXTRA_ROLE_NAME); mPackageName = getCallingPackage(); + if (!handleChangeDefaultDialerDialogCompatibility()) { + reportRequestResult( + PermissionControllerStatsLog.ROLE_REQUEST_RESULT_REPORTED__RESULT__IGNORED); + finish(); + return; + } + if (!handleSmsDefaultDialogCompatibility()) { reportRequestResult( PermissionControllerStatsLog.ROLE_REQUEST_RESULT_REPORTED__RESULT__IGNORED); @@ -173,6 +181,48 @@ public class RequestRoleActivity extends FragmentActivity { } /** + * Handle compatibility with the old + * {@link com.android.server.telecom.components.ChangeDefaultDialerDialog}. + * + * @return whether we should continue requesting the role. The activity should be finished if + * {@code false} is returned. + */ + private boolean handleChangeDefaultDialerDialogCompatibility() { + Intent intent = getIntent(); + if (!Objects.equals(intent.getAction(), TelecomManager.ACTION_CHANGE_DEFAULT_DIALER)) { + return true; + } + + Log.w(LOG_TAG, "TelecomManager.ACTION_CHANGE_DEFAULT_DIALER is deprecated; please use" + + " RoleManager.createRequestRoleIntent() and Activity.startActivityForResult()" + + " instead"); + + mRoleName = RoleManager.ROLE_DIALER; + mPackageName = null; + + String callingPackageName = getCallingPackage(); + String extraPackageName = intent.getStringExtra( + TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME); + if (Objects.equals(extraPackageName, callingPackageName)) { + // Requesting for itself is okay. + mPackageName = extraPackageName; + return true; + } + + RoleManager roleManager = getSystemService(RoleManager.class); + String holderPackageName = CollectionUtils.firstOrNull(roleManager.getRoleHolders( + RoleManager.ROLE_DIALER)); + if (Objects.equals(callingPackageName, holderPackageName)) { + // Giving away its own role is okay. + mPackageName = extraPackageName; + return true; + } + + // If we reach here it's not okay. + return false; + } + + /** * Handle compatibility with the old {@link com.android.settings.SmsDefaultDialog}. * * @return whether we should continue requesting the role. The activity should be finished if |