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

Commit b75417ce authored by tonyzhu's avatar tonyzhu Committed by android-build-merger
Browse files

[Call Screening]Handling Package Uninstall

am: 8ba94c5d

Change-Id: I373304bca2d1edcfc36c29e3440403196a9e0352
parents 44d066c0 8ba94c5d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -238,7 +238,7 @@
            </intent-filter>
        </receiver>

        <receiver android:name=".components.PhoneAccountBroadcastReceiver"
        <receiver android:name=".components.AppUninstallBroadcastReceiver"
                android:process="system">
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_FULLY_REMOVED" />
+25 −2
Original line number Diff line number Diff line
@@ -19,9 +19,12 @@ package com.android.server.telecom.components;
import com.android.server.telecom.PhoneAccountRegistrar;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.UserHandle;
import android.provider.Settings;
import android.telecom.TelecomManager;

import java.lang.String;
@@ -30,14 +33,20 @@ import java.lang.String;
 * Captures {@code android.intent.action.ACTION_PACKAGE_FULLY_REMOVED} intents and triggers the
 * removal of associated {@link android.telecom.PhoneAccount}s via the
 * {@link com.android.telecom.PhoneAccountRegistrar}.
 *
 * Note: This class listens for the {@code PACKAGE_FULLY_REMOVED} intent rather than
 * {@code PACKAGE_REMOVED} as {@code PACKAGE_REMOVED} is triggered on re-installation of the same
 * package, where {@code PACKAGE_FULLY_REMOVED} is triggered only when an application is completely
 * uninstalled.  This is desirable as we do not wish to un-register all
 * uninstalled.
 *
 * This is desirable as we do not wish to un-register all
 * {@link android.telecom.PhoneAccount}s associated with a package being re-installed to ensure
 * the enabled state of the accounts is retained.
 *
 * When default call screening application is removed, set
 * {@link Settings.Secure.CALL_SCREENING_DEFAULT_APPLICATION} as null into provider.
 */
public class PhoneAccountBroadcastReceiver extends BroadcastReceiver {
public class AppUninstallBroadcastReceiver extends BroadcastReceiver {
    /**
     * Receives the intents the class is configured to received.
     *
@@ -54,6 +63,7 @@ public class PhoneAccountBroadcastReceiver extends BroadcastReceiver {

            String packageName = uri.getSchemeSpecificPart();
            handlePackageRemoved(context, packageName);
            handleUninstallOfCallScreeningService(context, packageName);
        }
    }

@@ -69,4 +79,17 @@ public class PhoneAccountBroadcastReceiver extends BroadcastReceiver {
            telecomManager.clearAccountsForPackage(packageName);
        }
    }

    private void handleUninstallOfCallScreeningService(Context context, String packageName) {
        String defaultCallScreeningApp = Settings.Secure
            .getStringForUser(context.getContentResolver(),
                Settings.Secure.CALL_SCREENING_DEFAULT_COMPONENT, UserHandle.USER_CURRENT);

        ComponentName componentName = ComponentName.unflattenFromString(defaultCallScreeningApp);

        if (componentName != null && componentName.getPackageName().equals(packageName)) {
            Settings.Secure.putStringForUser(context.getContentResolver(),
                Settings.Secure.CALL_SCREENING_DEFAULT_COMPONENT, null, UserHandle.USER_CURRENT);
        }
    }
}