Listening only for "android" package for overlay changes

Bug: 130917995
Change-Id: I37160a886a0afdc02dca8f7da6e8aa54c795882d
This commit is contained in:
Sunny Goyal 2019-04-22 09:01:26 -07:00
parent bf81b2ca0c
commit 8b0cb4113f
4 changed files with 26 additions and 20 deletions

View File

@ -20,8 +20,8 @@ import static android.content.Intent.ACTION_PACKAGE_ADDED;
import static android.content.Intent.ACTION_PACKAGE_CHANGED;
import static android.content.Intent.ACTION_PACKAGE_REMOVED;
import static com.android.systemui.shared.system.PackageManagerWrapper
.ACTION_PREFERRED_ACTIVITY_CHANGED;
import static com.android.launcher3.util.PackageManagerHelper.getPackageFilter;
import static com.android.systemui.shared.system.PackageManagerWrapper.ACTION_PREFERRED_ACTIVITY_CHANGED;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@ -29,7 +29,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ResolveInfo;
import android.os.PatternMatcher;
import com.android.systemui.shared.system.PackageManagerWrapper;
@ -109,13 +108,9 @@ public final class OverviewComponentObserver {
}
mUpdateRegisteredPackage = defaultHome.getPackageName();
IntentFilter updateReceiver = new IntentFilter(ACTION_PACKAGE_ADDED);
updateReceiver.addAction(ACTION_PACKAGE_CHANGED);
updateReceiver.addAction(ACTION_PACKAGE_REMOVED);
updateReceiver.addDataScheme("package");
updateReceiver.addDataSchemeSpecificPart(mUpdateRegisteredPackage,
PatternMatcher.PATTERN_LITERAL);
mContext.registerReceiver(mOtherHomeAppUpdateReceiver, updateReceiver);
mContext.registerReceiver(mOtherHomeAppUpdateReceiver, getPackageFilter(
mUpdateRegisteredPackage, ACTION_PACKAGE_ADDED, ACTION_PACKAGE_CHANGED,
ACTION_PACKAGE_REMOVED));
}
}

View File

@ -16,15 +16,15 @@
package com.android.quickstep;
import static com.android.launcher3.util.PackageManagerHelper.getPackageFilter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.util.Log;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.systemui.shared.system.QuickStepContract;
import java.util.ArrayList;
import java.util.List;
@ -70,8 +70,6 @@ public class SysUINavigationMode {
mContext = context;
initializeMode();
IntentFilter filter = new IntentFilter(ACTION_OVERLAY_CHANGED);
filter.addDataScheme("package");
mContext.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@ -81,7 +79,7 @@ public class SysUINavigationMode {
dispatchModeChange();
}
}
}, filter);
}, getPackageFilter("android", ACTION_OVERLAY_CHANGED));
}
private void initializeMode() {

View File

@ -16,8 +16,9 @@
package com.android.launcher3;
import static com.android.launcher3.config.FeatureFlags.APPLY_CONFIG_AT_RUNTIME;
import static com.android.launcher3.Utilities.getDevicePrefs;
import static com.android.launcher3.config.FeatureFlags.APPLY_CONFIG_AT_RUNTIME;
import static com.android.launcher3.util.PackageManagerHelper.getPackageFilter;
import android.annotation.TargetApi;
import android.appwidget.AppWidgetHostView;
@ -25,7 +26,6 @@ import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
@ -578,9 +578,7 @@ public class InvariantDeviceProfile {
private final String ACTION_OVERLAY_CHANGED = "android.intent.action.OVERLAY_CHANGED";
OverlayMonitor(Context context) {
IntentFilter filter = new IntentFilter(ACTION_OVERLAY_CHANGED);
filter.addDataScheme("package");
context.registerReceiver(this, filter);
context.registerReceiver(this, getPackageFilter("android", ACTION_OVERLAY_CHANGED));
}
@Override

View File

@ -21,6 +21,7 @@ import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.LauncherActivityInfo;
import android.content.pm.PackageManager;
@ -30,6 +31,7 @@ import android.graphics.Rect;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.PatternMatcher;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.Log;
@ -200,4 +202,17 @@ public class PackageManagerHelper {
}
}
}
/**
* Creates an intent filter to listen for actions with a specific package in the data field.
*/
public static IntentFilter getPackageFilter(String pkg, String... actions) {
IntentFilter packageFilter = new IntentFilter();
for (String action : actions) {
packageFilter.addAction(action);
}
packageFilter.addDataScheme("package");
packageFilter.addDataSchemeSpecificPart(pkg, PatternMatcher.PATTERN_LITERAL);
return packageFilter;
}
}