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

Commit 7a172565 authored by Chen Xu's avatar Chen Xu
Browse files

allow CBR to write SMS database

This is to support KR government requirement: CBR message should be available in
SMS.inbox. The solution is to insert CBR message once displayed to
users. this feature is disabled by default and OEM can turn it on for
specific mcc per country/carrier regulations.

Bug: 144749813
Test: Manual test on different messenger apps.
Change-Id: I5535cefb32e89694094299f3b89321f735983ef1
Merged-in: I5535cefb32e89694094299f3b89321f735983ef1
parent a4ddee21
Loading
Loading
Loading
Loading
+18 −9
Original line number Original line Diff line number Diff line
@@ -542,13 +542,16 @@ public final class SmsApplication {


        // Assign permission to special system apps
        // Assign permission to special system apps
        assignExclusiveSmsPermissionsToSystemApp(context, packageManager, appOps,
        assignExclusiveSmsPermissionsToSystemApp(context, packageManager, appOps,
                PHONE_PACKAGE_NAME);
                PHONE_PACKAGE_NAME, true);
        assignExclusiveSmsPermissionsToSystemApp(context, packageManager, appOps,
        assignExclusiveSmsPermissionsToSystemApp(context, packageManager, appOps,
                BLUETOOTH_PACKAGE_NAME);
                BLUETOOTH_PACKAGE_NAME, true);
        assignExclusiveSmsPermissionsToSystemApp(context, packageManager, appOps,
        assignExclusiveSmsPermissionsToSystemApp(context, packageManager, appOps,
                MMS_SERVICE_PACKAGE_NAME);
                MMS_SERVICE_PACKAGE_NAME, true);
        assignExclusiveSmsPermissionsToSystemApp(context, packageManager, appOps,
        assignExclusiveSmsPermissionsToSystemApp(context, packageManager, appOps,
                TELEPHONY_PROVIDER_PACKAGE_NAME);
                TELEPHONY_PROVIDER_PACKAGE_NAME, true);
        // CellbroadcastReceiver is a mainline module thus skip signature match.
        assignExclusiveSmsPermissionsToSystemApp(context, packageManager, appOps,
                CellBroadcastUtils.getDefaultCellBroadcastReceiverPackageName(context), false);


        // Give AppOps permission to UID 1001 which contains multiple
        // Give AppOps permission to UID 1001 which contains multiple
        // apps, all of them should be able to write to telephony provider.
        // apps, all of them should be able to write to telephony provider.
@@ -738,17 +741,23 @@ public final class SmsApplication {
     * @param packageManager The package manager instance
     * @param packageManager The package manager instance
     * @param appOps The AppOps manager instance
     * @param appOps The AppOps manager instance
     * @param packageName The package name of the system app
     * @param packageName The package name of the system app
     * @param sigatureMatch whether to check signature match
     */
     */
    private static void assignExclusiveSmsPermissionsToSystemApp(Context context,
    private static void assignExclusiveSmsPermissionsToSystemApp(Context context,
            PackageManager packageManager, AppOpsManager appOps, String packageName) {
            PackageManager packageManager, AppOpsManager appOps, String packageName,
            boolean sigatureMatch) {
        // First check package signature matches the caller's package signature.
        // First check package signature matches the caller's package signature.
        // Since this class is only used internally by the system, this check makes sure
        // Since this class is only used internally by the system, this check makes sure
        // the package signature matches system signature.
        // the package signature matches system signature.
        final int result = packageManager.checkSignatures(context.getPackageName(), packageName);
        if (sigatureMatch) {
            final int result = packageManager.checkSignatures(context.getPackageName(),
                    packageName);
            if (result != PackageManager.SIGNATURE_MATCH) {
            if (result != PackageManager.SIGNATURE_MATCH) {
                Log.e(LOG_TAG, packageName + " does not have system signature");
                Log.e(LOG_TAG, packageName + " does not have system signature");
                return;
                return;
            }
            }
        }

        try {
        try {
            PackageInfo info = packageManager.getPackageInfo(packageName, 0);
            PackageInfo info = packageManager.getPackageInfo(packageName, 0);
            int mode = appOps.unsafeCheckOp(AppOpsManager.OPSTR_WRITE_SMS, info.applicationInfo.uid,
            int mode = appOps.unsafeCheckOp(AppOpsManager.OPSTR_WRITE_SMS, info.applicationInfo.uid,