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

Commit c39e4bf5 authored by Heemin Seog's avatar Heemin Seog
Browse files

Restrict showing "new ringtone" for missing picker

Automotive builds can come without a file picker. In such cases, the
RingtonePickerActivity shouldn't need to show the "Add New Ringtone"
list item.

Bug: 138454052
Test: manual
Change-Id: Iceb5555493420898d6eafe79e3299d5bd3a77a98
parent 95eb6ea0
Loading
Loading
Loading
Loading
+15 −6
Original line number Diff line number Diff line
@@ -52,7 +52,6 @@ import com.android.internal.app.AlertActivity;
import com.android.internal.app.AlertController;

import java.io.IOException;
import java.util.Objects;
import java.util.regex.Pattern;

/**
@@ -154,10 +153,7 @@ public final class RingtonePickerActivity extends AlertActivity implements
            if (which == mCursor.getCount() + mStaticItemCount) {
                // The "Add new ringtone" item was clicked. Start a file picker intent to select
                // only audio files (MIME type "audio/*")
                final Intent chooseFile = new Intent(Intent.ACTION_GET_CONTENT);
                chooseFile.setType("audio/*");
                chooseFile.putExtra(Intent.EXTRA_MIME_TYPES,
                        new String[] { "audio/*", "application/ogg" });
                final Intent chooseFile = getMediaFilePickerIntent();
                startActivityForResult(chooseFile, ADD_FILE_REQUEST_CODE);
                return;
            }
@@ -375,7 +371,8 @@ public final class RingtonePickerActivity extends AlertActivity implements
            setSuccessResultWithRingtone(getCurrentlySelectedRingtoneUri());
        }
        // If external storage is available, add a button to install sounds from storage.
        if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        if (resolvesMediaFilePicker()
                && Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            addNewSoundItem(listView);
        }

@@ -633,6 +630,18 @@ public final class RingtonePickerActivity extends AlertActivity implements
        return ringtoneManagerPos + mStaticItemCount;
    }

    private Intent getMediaFilePickerIntent() {
        final Intent chooseFile = new Intent(Intent.ACTION_GET_CONTENT);
        chooseFile.setType("audio/*");
        chooseFile.putExtra(Intent.EXTRA_MIME_TYPES,
                new String[] { "audio/*", "application/ogg" });
        return chooseFile;
    }

    private boolean resolvesMediaFilePicker() {
        return getMediaFilePickerIntent().resolveActivity(getPackageManager()) != null;
    }

    private static class LocalizedCursor extends CursorWrapper {

        final int mTitleIndex;