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

Commit 5bd46ed2 authored by Eugene Susla's avatar Eugene Susla
Browse files

Don't crash on unknown CDM profile name

We should support the case of new profiles added in PermissionController

Test: manual
Bug: 165951651
Change-Id: Ia647dfbd815785c2ed5a45d0416816489b9d4914
parent c516ebea
Loading
Loading
Loading
Loading
+6 −11
Original line number Diff line number Diff line
@@ -55,6 +55,8 @@ import java.util.Objects;
        genBuilder = false)
public final class AssociationRequest implements Parcelable {

    private static final String LOG_TAG = AssociationRequest.class.getSimpleName();

    /**
     * Device profile: watch.
     *
@@ -115,13 +117,6 @@ public final class AssociationRequest implements Parcelable {
        mDeviceProfilePrivilegesDescription = desc;
    }

    private void onConstructed() {
        if (mDeviceProfile != null
                && !Objects.equals(mDeviceProfile, DEVICE_PROFILE_WATCH)) {
            throw new IllegalArgumentException("Invalid device profile: " + mDeviceProfile);
        }
    }

    /** @hide */
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    public boolean isSingleDevice() {
@@ -252,7 +247,7 @@ public final class AssociationRequest implements Parcelable {
        this.mCallingPackage = callingPackage;
        this.mDeviceProfilePrivilegesDescription = deviceProfilePrivilegesDescription;

        onConstructed();
        // onConstructed(); // You can define this method to get a callback
    }

    /**
@@ -386,7 +381,7 @@ public final class AssociationRequest implements Parcelable {
        this.mCallingPackage = callingPackage;
        this.mDeviceProfilePrivilegesDescription = deviceProfilePrivilegesDescription;

        onConstructed();
        // onConstructed(); // You can define this method to get a callback
    }

    @DataClass.Generated.Member
@@ -404,10 +399,10 @@ public final class AssociationRequest implements Parcelable {
    };

    @DataClass.Generated(
            time = 1610132130920L,
            time = 1611692924843L,
            codegenVersion = "1.0.22",
            sourceFile = "frameworks/base/core/java/android/companion/AssociationRequest.java",
            inputSignatures = "public static final  java.lang.String DEVICE_PROFILE_WATCH\nprivate  boolean mSingleDevice\nprivate @com.android.internal.util.DataClass.PluralOf(\"deviceFilter\") @android.annotation.NonNull java.util.List<android.companion.DeviceFilter<?>> mDeviceFilters\nprivate @android.annotation.Nullable @android.companion.AssociationRequest.DeviceProfile java.lang.String mDeviceProfile\nprivate @android.annotation.Nullable java.lang.String mCallingPackage\nprivate @android.annotation.Nullable java.lang.String mDeviceProfilePrivilegesDescription\npublic  void setCallingPackage(java.lang.String)\npublic  void setDeviceProfilePrivilegesDescription(java.lang.String)\nprivate  void onConstructed()\npublic @android.compat.annotation.UnsupportedAppUsage boolean isSingleDevice()\npublic @android.annotation.NonNull @android.compat.annotation.UnsupportedAppUsage java.util.List<android.companion.DeviceFilter<?>> getDeviceFilters()\nclass AssociationRequest extends java.lang.Object implements [android.os.Parcelable]\nprivate  boolean mSingleDevice\nprivate @android.annotation.Nullable java.util.ArrayList<android.companion.DeviceFilter<?>> mDeviceFilters\nprivate @android.annotation.Nullable java.lang.String mDeviceProfile\npublic @android.annotation.NonNull android.companion.AssociationRequest.Builder setSingleDevice(boolean)\npublic @android.annotation.NonNull android.companion.AssociationRequest.Builder addDeviceFilter(android.companion.DeviceFilter<?>)\npublic @android.annotation.NonNull android.companion.AssociationRequest.Builder setDeviceProfile(java.lang.String)\npublic @android.annotation.NonNull @java.lang.Override android.companion.AssociationRequest build()\nclass Builder extends android.provider.OneTimeUseBuilder<android.companion.AssociationRequest> implements []\n@com.android.internal.util.DataClass(genToString=true, genEqualsHashCode=true, genHiddenGetters=true, genParcelable=true, genHiddenConstructor=true, genBuilder=false)")
            inputSignatures = "private static final  java.lang.String LOG_TAG\npublic static final  java.lang.String DEVICE_PROFILE_WATCH\nprivate  boolean mSingleDevice\nprivate @com.android.internal.util.DataClass.PluralOf(\"deviceFilter\") @android.annotation.NonNull java.util.List<android.companion.DeviceFilter<?>> mDeviceFilters\nprivate @android.annotation.Nullable @android.companion.AssociationRequest.DeviceProfile java.lang.String mDeviceProfile\nprivate @android.annotation.Nullable java.lang.String mCallingPackage\nprivate @android.annotation.Nullable java.lang.String mDeviceProfilePrivilegesDescription\npublic  void setCallingPackage(java.lang.String)\npublic  void setDeviceProfilePrivilegesDescription(java.lang.String)\npublic @android.compat.annotation.UnsupportedAppUsage boolean isSingleDevice()\npublic @android.annotation.NonNull @android.compat.annotation.UnsupportedAppUsage java.util.List<android.companion.DeviceFilter<?>> getDeviceFilters()\nclass AssociationRequest extends java.lang.Object implements [android.os.Parcelable]\nprivate  boolean mSingleDevice\nprivate @android.annotation.Nullable java.util.ArrayList<android.companion.DeviceFilter<?>> mDeviceFilters\nprivate @android.annotation.Nullable java.lang.String mDeviceProfile\npublic @android.annotation.NonNull android.companion.AssociationRequest.Builder setSingleDevice(boolean)\npublic @android.annotation.NonNull android.companion.AssociationRequest.Builder addDeviceFilter(android.companion.DeviceFilter<?>)\npublic @android.annotation.NonNull android.companion.AssociationRequest.Builder setDeviceProfile(java.lang.String)\npublic @android.annotation.NonNull @java.lang.Override android.companion.AssociationRequest build()\nclass Builder extends android.provider.OneTimeUseBuilder<android.companion.AssociationRequest> implements []\n@com.android.internal.util.DataClass(genToString=true, genEqualsHashCode=true, genHiddenGetters=true, genParcelable=true, genHiddenConstructor=true, genBuilder=false)")
    @Deprecated
    private void __metadata() {}

+11 −7
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.companiondevicemanager;

import static android.companion.BluetoothDeviceFilterUtils.getDeviceMacAddress;
import static android.text.TextUtils.emptyIfNull;
import static android.text.TextUtils.isEmpty;
import static android.text.TextUtils.withoutPrefix;
import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;

@@ -67,7 +68,13 @@ public class DeviceChooserActivity extends Activity {
        getWindow().addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);

        String deviceProfile = getRequest().getDeviceProfile();
        String profileName = getDeviceProfileName(deviceProfile);
        String profilePrivacyDisclaimer = emptyIfNull(getRequest()
                .getDeviceProfilePrivilegesDescription())
                .replace("APP_NAME", getCallingAppName());
        boolean useDeviceProfile = deviceProfile != null && !isEmpty(profilePrivacyDisclaimer);
        String profileName = useDeviceProfile
                ? getDeviceProfileName(deviceProfile)
                : getString(R.string.profile_name_generic);

        if (getRequest().isSingleDevice()) {
            setContentView(R.layout.device_confirmation);
@@ -110,15 +117,12 @@ public class DeviceChooserActivity extends Activity {

        TextView profileSummary = findViewById(R.id.profile_summary);

        if (deviceProfile != null) {
            String privacyDisclaimer = emptyIfNull(getRequest()
                    .getDeviceProfilePrivilegesDescription())
                    .replace("APP_NAME", getCallingAppName());
        if (useDeviceProfile) {
            profileSummary.setVisibility(View.VISIBLE);
            profileSummary.setText(getString(R.string.profile_summary,
                    getCallingAppName(),
                    profileName,
                    privacyDisclaimer));
                    profilePrivacyDisclaimer));
        } else {
            profileSummary.setVisibility(View.GONE);
        }
@@ -142,7 +146,7 @@ public class DeviceChooserActivity extends Activity {
                return getString(R.string.profile_name_watch);
            }
            default: {
                Log.wtf(LOG_TAG,
                Log.w(LOG_TAG,
                        "No localized profile name found for device profile: " + deviceProfile);
                return withoutPrefix("android.app.role.COMPANION_DEVICE_", deviceProfile)
                        .toLowerCase()
+1 −1
Original line number Diff line number Diff line
@@ -926,7 +926,7 @@ public class CompanionDeviceManagerService extends SystemService implements Bind
        mPermissionControllerManager.getPrivilegesDescriptionStringForProfile(
                deviceProfile, FgThread.getExecutor(), desc -> {
                        try {
                            result.complete(requireNonNull(desc));
                            result.complete(desc);
                        } catch (Exception e) {
                            result.completeExceptionally(e);
                        }