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

Commit 1b4b8dfe authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Utilize CARRIER_APP_NAMES to for SIM notification/dialog"

parents c902e4c5 2d75c5b4
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;

import java.util.concurrent.TimeUnit;
@@ -35,12 +36,19 @@ public class InstallCarrierAppTrampolineActivity extends Activity {
    private static final String LOG_TAG = "CarrierAppInstall";
    private static final int INSTALL_CARRIER_APP_DIALOG_REQUEST = 1;

    // TODO(b/73648962): Move DOWNLOAD_RESULT and CARRIER_NAME to a shared location
    /**
     * This must remain in sync with
     * {@link com.android.simappdialog.InstallCarrierAppActivity#DOWNLOAD_RESULT}
     */
    private static final int DOWNLOAD_RESULT = 2;

    /**
     * This must remain in sync with
     * {@link com.android.simappdialog.InstallCarrierAppActivity#BUNDLE_KEY_CARRIER_NAME}
     */
    private static final String CARRIER_NAME = "carrier_name";

    /** Bundle key for the name of the package to be downloaded */
    private static final String BUNDLE_KEY_PACKAGE_NAME = "package_name";

@@ -81,6 +89,10 @@ public class InstallCarrierAppTrampolineActivity extends Activity {
                Resources.getSystem().getString(
                        com.android.internal.R.string.config_carrierAppInstallDialogComponent));
        showDialogIntent.setComponent(dialogComponentName);
        String appName = InstallCarrierAppUtils.getAppNameFromPackageName(this, mPackageName);
        if (!TextUtils.isEmpty(appName)) {
            showDialogIntent.putExtra(CARRIER_NAME, appName);
        }

        if (showDialogIntent.resolveActivity(getPackageManager()) == null) {
            Log.d(LOG_TAG, "Could not resolve activity for installing the carrier app");
+55 −3
Original line number Diff line number Diff line
@@ -30,15 +30,21 @@ import android.net.Uri;
import android.os.SystemClock;
import android.provider.Settings;
import android.service.notification.StatusBarNotification;
import android.text.TextUtils;

import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.util.NotificationChannelController;

import java.util.Arrays;
import java.util.List;

/**
 * Utility methods for installing the carrier app when a SIM is insterted without the carrier app
 * for that SIM installed.
 */
class InstallCarrierAppUtils {
@VisibleForTesting
public class InstallCarrierAppUtils {
    // TODO(b/72714040) centralize notification IDs
    private static final int ACTIVATE_CELL_SERVICE_NOTIFICATION_ID = 12;
    private static CarrierAppInstallReceiver sCarrierAppInstallReceiver = null;
@@ -47,8 +53,14 @@ class InstallCarrierAppUtils {
        Resources res = Resources.getSystem();
        String title = res.getString(
                com.android.internal.R.string.install_carrier_app_notification_title);
        // TODO(b/70042722): insert correct app name
        String message = res.getString(R.string.install_carrier_app_notification_text);
        String appName = getAppNameFromPackageName(context, pkgName);
        String message;
        if (TextUtils.isEmpty(appName)) {
            message = res.getString(R.string.install_carrier_app_notification_text);
        } else {
            message = res.getString(R.string.install_carrier_app_notification_text_app_name,
                    appName);
        }
        String downloadButtonText = res.getString(R.string.install_carrier_app_notification_button);

        boolean persistent = Settings.Global.getInt(
@@ -150,6 +162,46 @@ class InstallCarrierAppUtils {
        return false;
    }

    static String getAppNameFromPackageName(Context context, String packageName) {
        String whitelistSetting = Settings.Global.getString(
                context.getContentResolver(),
                Settings.Global.CARRIER_APP_NAMES);
        return getAppNameFromPackageName(packageName, whitelistSetting);
    }

    /**
     * @param packageName the name of the package.  Will be used as a key into the map
     * @param mapString map of package name to application name in the format:
     *                  packageName1:appName1;packageName2:appName2;
     * @return the name of the application for the package name provided.
     */
    @VisibleForTesting
    public static String getAppNameFromPackageName(String packageName, String mapString) {
        packageName = packageName.toLowerCase();
        final String pairDelim = "\\s*;\\s*";
        final String keyValueDelim = "\\s*:\\s*";

        if (TextUtils.isEmpty(mapString)) {
            return null;
        }

        List<String> keyValuePairList = Arrays.asList(mapString.split(pairDelim));

        if (keyValuePairList.isEmpty()) {
            return null;
        }

        for (String keyValueString: keyValuePairList) {
            String[] keyValue = keyValueString.split(keyValueDelim);

            if (keyValue.length == 2) {
                if (keyValue[0].equals(packageName)) {
                    return keyValue[1];
                }
            }
        }
        return null;
    }
    private static NotificationManager getNotificationManager(Context context) {
        return (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    }
+83 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.internal.telephony.uicc;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import android.support.test.filters.SmallTest;

import org.junit.Test;

/**
 * Tests for {@link InstallCarrierAppUtils}
 */
public class InstallCarrierAppUtilsTest {
    @Test
    @SmallTest
    public void testParseAppNameMapFromString_emptyMap() {
        String appNameKey = "com.app.package1";
        String mapString = "";
        String appName =
                InstallCarrierAppUtils.getAppNameFromPackageName(appNameKey, mapString);
        assertNull(appName);
    }

    @Test
    @SmallTest
    public void testParseAppNameMapFromString_completeMap() {
        String appName1Key = "com.app.package1";
        String appName2Key = "com.app.package2";
        String expectedAppName1 = "AppName1";
        String expectedAppName2 = "AppName2";
        String mapString = appName1Key + ":" + expectedAppName1 + ";"
                + appName2Key + ":" + expectedAppName2 + ";";

        String appName1 =
                InstallCarrierAppUtils.getAppNameFromPackageName(appName1Key, mapString);
        String appName2 =
                InstallCarrierAppUtils.getAppNameFromPackageName(appName2Key, mapString);
        assertEquals(expectedAppName1, appName1);
        assertEquals(expectedAppName2, appName2);
    }

    @Test
    @SmallTest
    public void testParseAppNameMapFromString_packageCaseMismatch() {
        String appNameKey = "com.app.package1";
        String expectedAppName = "AppName1";
        String mapString = appNameKey + ":" + expectedAppName + ";";

        String appNameCaseTestKey = "cOm.ApP.pAcKaGe1";
        String appName1 =
                InstallCarrierAppUtils.getAppNameFromPackageName(appNameCaseTestKey, mapString);
        assertEquals(expectedAppName, appName1);
    }

    @Test
    @SmallTest
    public void testParseAppNameMapFromString_packageNotFound() {
        String appNameKey = "com.app.package1";
        String expectedAppName = "AppName1";
        String mapString = appNameKey + ":" + expectedAppName + ";";

        String missingAppNameKey = "AppName3";
        String missingAppName =
                InstallCarrierAppUtils.getAppNameFromPackageName(missingAppNameKey, mapString);
        assertNull(missingAppName);
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -175,6 +175,7 @@ public class UiccProfileTest extends TelephonyTest {
    }

    @Test
    @SmallTest
    public void testParseWhitelistMapFromString() {
        String whitelist = "";
        Map<String, String> parsedMap = UiccProfile.parseToCertificateToPackageMap(whitelist);