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

Commit 726d9a0d authored by Ahmad Khalil's avatar Ahmad Khalil
Browse files

Add tests to the Sound Picker app.

Bug: 275540178
Test: com.android.soundpicker.RingtonePickerActivityTest
Change-Id: I57e80577f5786f3e6d9d4eff93666868b0c7b3e4
parent 5966e38d
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -7,21 +7,24 @@ package {
    default_applicable_licenses: ["frameworks_base_license"],
}

android_app {
    name: "SoundPicker",
    defaults: ["platform_app_defaults"],
    manifest: "AndroidManifest.xml",

    static_libs: [
        "androidx.appcompat_appcompat",
android_library {
    name: "SoundPickerLib",
    srcs: [
        "src/**/*.java",
    ],
    resource_dirs: [
        "res",
    ],
    srcs: [
        "src/**/*.java",
    static_libs: [
        "androidx.appcompat_appcompat",
    ],
}

android_app {
    name: "SoundPicker",
    defaults: ["platform_app_defaults"],
    manifest: "AndroidManifest.xml",
    static_libs: ["SoundPickerLib"],
    platform_apis: true,
    certificate: "media",
    privileged: true,
+6 −34
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@ import android.os.Handler;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.MediaStore;
import android.provider.Settings;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
@@ -194,16 +193,7 @@ public final class RingtonePickerActivity extends AlertActivity implements
        mHasDefaultItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
        mUriForDefaultItem = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI);
        if (mUriForDefaultItem == null) {
            if (mType == RingtoneManager.TYPE_NOTIFICATION) {
                mUriForDefaultItem = Settings.System.DEFAULT_NOTIFICATION_URI;
            } else if (mType == RingtoneManager.TYPE_ALARM) {
                mUriForDefaultItem = Settings.System.DEFAULT_ALARM_ALERT_URI;
            } else if (mType == RingtoneManager.TYPE_RINGTONE) {
                mUriForDefaultItem = Settings.System.DEFAULT_RINGTONE_URI;
            } else {
                // or leave it null for silence.
                mUriForDefaultItem = Settings.System.DEFAULT_RINGTONE_URI;
            }
            mUriForDefaultItem = RingtonePickerViewModel.getDefaultItemUriByType(mType);
        }

        // Get whether to show the 'Silent' item
@@ -242,17 +232,9 @@ public final class RingtonePickerActivity extends AlertActivity implements
            p.mPositiveButtonListener = this;
        }
        p.mOnPrepareListViewListener = this;

        p.mTitle = intent.getCharSequenceExtra(RingtoneManager.EXTRA_RINGTONE_TITLE);
        if (p.mTitle == null) {
          if (mType == RingtoneManager.TYPE_ALARM) {
              p.mTitle = getString(com.android.internal.R.string.ringtone_picker_title_alarm);
          } else if (mType == RingtoneManager.TYPE_NOTIFICATION) {
              p.mTitle =
                  getString(com.android.internal.R.string.ringtone_picker_title_notification);
          } else {
              p.mTitle = getString(com.android.internal.R.string.ringtone_picker_title);
          }
            p.mTitle = getString(RingtonePickerViewModel.getTitleByType(mType));
        }

        setupAlert();
@@ -435,13 +417,8 @@ public final class RingtonePickerActivity extends AlertActivity implements
    }

    private int addDefaultRingtoneItem(ListView listView) {
        if (mType == RingtoneManager.TYPE_NOTIFICATION) {
            return addStaticItem(listView, R.string.notification_sound_default);
        } else if (mType == RingtoneManager.TYPE_ALARM) {
            return addStaticItem(listView, R.string.alarm_sound_default);
        }

        return addStaticItem(listView, R.string.ringtone_default);
        return addStaticItem(listView,
                RingtonePickerViewModel.getDefaultRingtoneItemTextByType(mType));
    }

    private int addSilentItem(ListView listView) {
@@ -453,13 +430,8 @@ public final class RingtonePickerActivity extends AlertActivity implements
                false /* attachToRoot */);
        TextView text = (TextView)view.findViewById(R.id.add_new_sound_text);

        if (mType == RingtoneManager.TYPE_ALARM) {
            text.setText(R.string.add_alarm_text);
        } else if (mType == RingtoneManager.TYPE_NOTIFICATION) {
            text.setText(R.string.add_notification_text);
        } else {
            text.setText(R.string.add_ringtone_text);
        }
        text.setText(RingtonePickerViewModel.getAddNewItemTextByType(mType));

        listView.addFooterView(view);
    }

+75 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.soundpicker;

import android.annotation.StringRes;
import android.media.RingtoneManager;
import android.net.Uri;
import android.provider.Settings;

/**
 * View model for {@link RingtonePickerActivity}.
 */
public final class RingtonePickerViewModel {

    @StringRes
    static int getTitleByType(int ringtoneType) {
        switch (ringtoneType) {
            case RingtoneManager.TYPE_ALARM:
                return com.android.internal.R.string.ringtone_picker_title_alarm;
            case RingtoneManager.TYPE_NOTIFICATION:
                return com.android.internal.R.string.ringtone_picker_title_notification;
            default:
                return com.android.internal.R.string.ringtone_picker_title;
        }
    }

    static Uri getDefaultItemUriByType(int ringtoneType) {
        switch (ringtoneType) {
            case RingtoneManager.TYPE_ALARM:
                return Settings.System.DEFAULT_ALARM_ALERT_URI;
            case RingtoneManager.TYPE_NOTIFICATION:
                return Settings.System.DEFAULT_NOTIFICATION_URI;
            default:
                return Settings.System.DEFAULT_RINGTONE_URI;
        }
    }

    @StringRes
    static int getAddNewItemTextByType(int ringtoneType) {
        switch (ringtoneType) {
            case RingtoneManager.TYPE_ALARM:
                return R.string.add_alarm_text;
            case RingtoneManager.TYPE_NOTIFICATION:
                return R.string.add_notification_text;
            default:
                return R.string.add_ringtone_text;
        }
    }

    @StringRes
    static int getDefaultRingtoneItemTextByType(int ringtoneType) {
        switch (ringtoneType) {
            case RingtoneManager.TYPE_ALARM:
                return R.string.alarm_sound_default;
            case RingtoneManager.TYPE_NOTIFICATION:
                return R.string.notification_sound_default;
            default:
                return R.string.ringtone_default;
        }
    }
}
+36 −0
Original line number Diff line number Diff line
// Copyright 2023, The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package {
    default_applicable_licenses: ["frameworks_base_license"],
}

android_test {
    name: "SoundPickerTests",
    certificate: "platform",
    libs: [
        "android.test.runner",
        "android.test.base",
    ],
    static_libs: [
        "androidx.test.core",
        "androidx.test.rules",
        "androidx.test.ext.junit",
        "mockito-target-minus-junit4",
        "SoundPickerLib",
    ],
    srcs: [
        "src/**/*.java",
    ],
}
+11 −0
Original line number Diff line number Diff line
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.android.soundpicker.tests">

    <application android:debuggable="true">
        <uses-library android:name="android.test.runner" />
    </application>
    <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
        android:targetPackage="com.android.soundpicker.tests"
        android:label="Sound picker tests">
    </instrumentation>
</manifest>
Loading