Unregister app if fully removed or data is cleared

This fixes a bug where apps were not properly unregistered on Android
8.0+ systems. Also update the log message.
This commit is contained in:
voidstarstar 2019-04-03 15:41:22 -04:00 committed by Marvin W
parent 2a21b8ad11
commit 7b651aaaad
2 changed files with 10 additions and 3 deletions

View File

@ -250,7 +250,8 @@
<receiver android:name="org.microg.gms.gcm.UnregisterReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_DATA_CLEARED"/>
<action android:name="android.intent.action.PACKAGE_FULLY_REMOVED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<data android:scheme="package"/>

View File

@ -8,7 +8,10 @@ import android.util.Log;
import java.util.List;
import static android.content.Intent.ACTION_PACKAGE_REMOVED;
import static android.content.Intent.ACTION_PACKAGE_DATA_CLEARED;
import static android.content.Intent.ACTION_PACKAGE_FULLY_REMOVED;
import static android.content.Intent.EXTRA_DATA_REMOVED;
import static android.content.Intent.EXTRA_REPLACING;
public class UnregisterReceiver extends BroadcastReceiver {
private static final String TAG = "GmsGcmUnregisterRcvr";
@ -16,10 +19,13 @@ public class UnregisterReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, Intent intent) {
Log.d(TAG, "Package changed: " + intent);
if (ACTION_PACKAGE_REMOVED.contains(intent.getAction()) && intent.getBooleanExtra(EXTRA_DATA_REMOVED, false)) {
if ((ACTION_PACKAGE_REMOVED.contains(intent.getAction()) && intent.getBooleanExtra(EXTRA_DATA_REMOVED, false) &&
!intent.getBooleanExtra(EXTRA_REPLACING, false)) ||
ACTION_PACKAGE_FULLY_REMOVED.contains(intent.getAction()) ||
ACTION_PACKAGE_DATA_CLEARED.contains(intent.getAction())) {
final GcmDatabase database = new GcmDatabase(context);
final String packageName = intent.getData().getSchemeSpecificPart();
Log.d(TAG, "Package removed: " + packageName);
Log.d(TAG, "Package removed or data cleared: " + packageName);
final GcmDatabase.App app = database.getApp(packageName);
if (app != null) {
new Thread(new Runnable() {