Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a8e094b6 authored by Hai Zhang's avatar Hai Zhang Committed by android-build-merger
Browse files

Merge changes from topics "role-dialer-dialog", "role-sms-dialog" into qt-dev

am: caaa7684

Change-Id: I585270b37b6fd77abdb138cb118eb2f8bce506cd
parents 90f84aba caaa7684
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -183,6 +183,10 @@
                <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"
+50 −0
Original line number Diff line number Diff line
@@ -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);
@@ -172,6 +180,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}.
     *