[Call Screening]Handling Package Uninstall
Rename PhoneAccountBroadcastReceiver class into
AppUninstallBroadcastReceiver. Detect the scenario
where the default call screening app gets uninstalled
and remove it as the default call screening app,
once happening, set default call screening as "null".
Bug: 116758854
Test: create two call screening applications, set them to default
and uninstall, observing the default call screening is null or not.
Change-Id: Idb2f4bd5da0a20ebaa4f1c77ea9349c8c30a8c17
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 9ea8f4c..9abe7e7 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -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" />
diff --git a/src/com/android/server/telecom/components/PhoneAccountBroadcastReceiver.java b/src/com/android/server/telecom/components/AppUninstallBroadcastReceiver.java
similarity index 70%
rename from src/com/android/server/telecom/components/PhoneAccountBroadcastReceiver.java
rename to src/com/android/server/telecom/components/AppUninstallBroadcastReceiver.java
index 7737cd8..cc9ec28 100644
--- a/src/com/android/server/telecom/components/PhoneAccountBroadcastReceiver.java
+++ b/src/com/android/server/telecom/components/AppUninstallBroadcastReceiver.java
@@ -19,9 +19,12 @@
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 @@
* 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 @@
String packageName = uri.getSchemeSpecificPart();
handlePackageRemoved(context, packageName);
+ handleUninstallOfCallScreeningService(context, packageName);
}
}
@@ -69,4 +79,17 @@
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);
+ }
+ }
}