summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2019-05-11 03:01:50 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-05-11 03:01:50 +0000
commitcaaa768476bd7d731da952c88d699e2eeba64558 (patch)
treea8eadb67b2ec3adae018896f71328399c65e9036
parenta267cbec530e9fea2ff17b14baee0c85441d292e (diff)
parent00b3239fbfd93ee8f41625d819a9d02798092c1c (diff)
downloadandroid_packages_apps_PackageInstaller-caaa768476bd7d731da952c88d699e2eeba64558.tar.gz
android_packages_apps_PackageInstaller-caaa768476bd7d731da952c88d699e2eeba64558.tar.bz2
android_packages_apps_PackageInstaller-caaa768476bd7d731da952c88d699e2eeba64558.zip
Merge changes from topics "role-dialer-dialog", "role-sms-dialog" into qt-dev
* changes: Replace ChangeDefaultDialerDialog with RequestRoleActivity. Replace SmsDefaultDialog with RequestRoleActivity.
-rw-r--r--AndroidManifest.xml7
-rw-r--r--src/com/android/packageinstaller/role/ui/RequestRoleActivity.java116
2 files changed, 94 insertions, 29 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 15f81b7e..c2e44217 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -179,11 +179,14 @@
<action android:name="android.app.role.action.REQUEST_ROLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
- <!-- TODO: STOPSHIP: give this a priority greater than 1 to override Settings. -->
- <intent-filter android:priority="0">
+ <intent-filter android:priority="2">
<action android:name="android.provider.Telephony.ACTION_CHANGE_DEFAULT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
+ <intent-filter android:priority="1001">
+ <action android:name="android.telecom.action.CHANGE_DEFAULT_DIALER" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
</activity>
<activity android:name="com.android.packageinstaller.role.ui.DefaultAppListActivity"
diff --git a/src/com/android/packageinstaller/role/ui/RequestRoleActivity.java b/src/com/android/packageinstaller/role/ui/RequestRoleActivity.java
index 8fa75c89..44d37400 100644
--- a/src/com/android/packageinstaller/role/ui/RequestRoleActivity.java
+++ b/src/com/android/packageinstaller/role/ui/RequestRoleActivity.java
@@ -20,9 +20,10 @@ import android.app.role.RoleManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
-import android.os.Build;
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;
@@ -32,6 +33,7 @@ import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;
import com.android.packageinstaller.PermissionControllerStatsLog;
+import com.android.packageinstaller.permission.utils.CollectionUtils;
import com.android.packageinstaller.role.model.Role;
import com.android.packageinstaller.role.model.Roles;
import com.android.packageinstaller.role.model.UserDeniedManager;
@@ -60,7 +62,19 @@ public class RequestRoleActivity extends FragmentActivity {
mRoleName = getIntent().getStringExtra(Intent.EXTRA_ROLE_NAME);
mPackageName = getCallingPackage();
- ensureSmsDefaultDialogCompatibility();
+ if (!handleChangeDefaultDialerDialogCompatibility()) {
+ reportRequestResult(
+ PermissionControllerStatsLog.ROLE_REQUEST_RESULT_REPORTED__RESULT__IGNORED);
+ finish();
+ return;
+ }
+
+ if (!handleSmsDefaultDialogCompatibility()) {
+ reportRequestResult(
+ PermissionControllerStatsLog.ROLE_REQUEST_RESULT_REPORTED__RESULT__IGNORED);
+ finish();
+ return;
+ }
if (TextUtils.isEmpty(mRoleName)) {
Log.w(LOG_TAG, "Role name cannot be null or empty: " + mRoleName);
@@ -167,47 +181,95 @@ public class RequestRoleActivity extends FragmentActivity {
}
/**
- * @see com.android.settings.SmsDefaultDialog
+ * 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 void ensureSmsDefaultDialogCompatibility() {
+ private boolean handleChangeDefaultDialerDialogCompatibility() {
Intent intent = getIntent();
- if (!Objects.equals(intent.getAction(), Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT)) {
- return;
- }
- if (intent.hasExtra(Intent.EXTRA_ROLE_NAME)) {
- // Don't allow calling legacy interface with a role name.
- return;
+ if (!Objects.equals(intent.getAction(), TelecomManager.ACTION_CHANGE_DEFAULT_DIALER)) {
+ return true;
}
- Log.w(LOG_TAG, "Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT is deprecated; please use"
+ Log.w(LOG_TAG, "TelecomManager.ACTION_CHANGE_DEFAULT_DIALER is deprecated; please use"
+ " RoleManager.createRequestRoleIntent() and Activity.startActivityForResult()"
+ " instead");
- if (intent.hasExtra(Intent.EXTRA_PACKAGE_NAME)) {
- Log.w(LOG_TAG, "Intent.EXTRA_PACKAGE_NAME is deprecated, and will be ignored in most"
- + " cases. For SMS backup, please use the new backup role instead.");
- }
- mRoleName = null;
+ mRoleName = RoleManager.ROLE_DIALER;
mPackageName = null;
- String packageName = getCallingPackage();
- if (packageName == null) {
- return;
+ 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;
}
- ApplicationInfo applicationInfo = PackageUtils.getApplicationInfo(packageName, this);
- if (applicationInfo == null || applicationInfo.targetSdkVersion >= Build.VERSION_CODES.Q) {
- return;
+
+ 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
+ * {@code false} is returned.
+ */
+ private boolean handleSmsDefaultDialogCompatibility() {
+ Intent intent = getIntent();
+ if (!Objects.equals(intent.getAction(), Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT)) {
+ return true;
}
+ Log.w(LOG_TAG, "Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT is deprecated; please use"
+ + " RoleManager.createRequestRoleIntent() and Activity.startActivityForResult()"
+ + " instead");
+
mRoleName = RoleManager.ROLE_SMS;
- mPackageName = packageName;
+ mPackageName = null;
+
+ String callingPackageName = getCallingPackage();
+ String extraPackageName = intent.getStringExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME);
+ if (extraPackageName == null) {
+ // Launch the settings activity to show the list.
+ // TODO: Return RESULT_OK if any changes were made?
+ Intent defaultAppActivityIntent = DefaultAppActivity.createIntent(
+ RoleManager.ROLE_SMS, Process.myUserHandle(), this)
+ .addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
+ startActivity(defaultAppActivityIntent);
+ return false;
+ }
+
+ if (Objects.equals(extraPackageName, callingPackageName)) {
+ // Requesting for itself is okay.
+ mPackageName = extraPackageName;
+ return true;
+ }
RoleManager roleManager = getSystemService(RoleManager.class);
- if (roleManager.getRoleHolders(RoleManager.ROLE_SMS).contains(mPackageName)) {
- if (intent.hasExtra(Intent.EXTRA_PACKAGE_NAME)) {
- mPackageName = intent.getStringExtra(Intent.EXTRA_PACKAGE_NAME);
- }
+ String holderPackageName = CollectionUtils.firstOrNull(roleManager.getRoleHolders(
+ RoleManager.ROLE_SMS));
+ 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;
}
private void reportRequestResult(int result) {