Skip to content

Commit

Permalink
fix: Android 14 register receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Oct 20, 2024
1 parent 5d8d2e1 commit 4a9fdd9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.FileProvider;
import androidx.multidex.MultiDex;

Expand Down Expand Up @@ -690,6 +691,20 @@ public boolean openApkInstall(Activity activity, TLRPC.Document document) {
return exists;
}

@Nullable
public static Intent registerReceiverNotExported(@Nullable BroadcastReceiver receiver, IntentFilter filter) {
return ApplicationLoader.registerReceiverNotExported(ApplicationLoader.applicationContext, receiver, filter);
}

@Nullable
public static Intent registerReceiverNotExported(Context context, @Nullable BroadcastReceiver receiver, IntentFilter filter) {
if (SDK_INT < 33) {
return context.registerReceiver(receiver, filter);
} else {
return context.registerReceiver(receiver, filter, Context.RECEIVER_NOT_EXPORTED);
}
}

public boolean showUpdateAppPopup(Context context, TLRPC.TL_help_appUpdate update, int account) {
try {
(new UpdateAppAlertDialog(context, update, account)).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public View createView(Context context) {
filter.addAction(Intent.ACTION_MEDIA_UNMOUNTABLE);
filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
filter.addDataScheme("file");
ApplicationLoader.applicationContext.registerReceiver(receiver, filter);
ApplicationLoader.registerReceiverNotExported(receiver, filter);
}

actionBar.setBackgroundColor(Theme.getColor(Theme.key_dialogBackground));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,7 @@ public static void installUpdate(Activity context, TLRPC.Document document) {

private static InstallReceiver register(Context context, Runnable onSuccess) {
var receiver = new InstallReceiver(context, ApplicationLoader.getApplicationId(), onSuccess);
var filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
filter.addDataScheme("package");
context.registerReceiver(receiver, filter);
context.registerReceiver(receiver, new IntentFilter(ApkInstaller.class.getName()));
ApplicationLoader.registerReceiverNotExported(context, receiver, new IntentFilter(ApkInstaller.class.getName()));
return receiver;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
package tw.nekomimi.nekogram.helpers;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.os.PatternMatcher;

import androidx.annotation.RequiresApi;

import com.google.android.exoplayer2.util.Log;

import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.ui.ActionBar.Theme;

import java.util.HashMap;

@RequiresApi(api = Build.VERSION_CODES.S)
public class MonetHelper {
private static final HashMap<String, Integer> ids = new HashMap<>();
private static final String ACTION_OVERLAY_CHANGED = "android.intent.action.OVERLAY_CHANGED";
private static final OverlayChangeReceiver overlayChangeReceiver = new OverlayChangeReceiver();

static {
ids.put("a1_0", android.R.color.system_accent1_0);
Expand Down Expand Up @@ -111,39 +102,4 @@ public static int getColor(String color, boolean amoled) {
return 0;
}
}

private static class OverlayChangeReceiver extends BroadcastReceiver {

public void register(Context context) {
IntentFilter packageFilter = new IntentFilter(ACTION_OVERLAY_CHANGED);
packageFilter.addDataScheme("package");
packageFilter.addDataSchemeSpecificPart("android", PatternMatcher.PATTERN_LITERAL);
context.registerReceiver(this, packageFilter);
}

public void unregister(Context context) {
context.unregisterReceiver(this);
}

@Override
public void onReceive(Context context, Intent intent) {
if (ACTION_OVERLAY_CHANGED.equals(intent.getAction())) {
if (Theme.getActiveTheme().isMonet()) {
Theme.applyTheme(Theme.getActiveTheme());
}
}
}
}

public static void registerReceiver(Context context) {
overlayChangeReceiver.register(context);
}

public static void unregisterReceiver(Context context) {
try {
overlayChangeReceiver.unregister(context);
} catch (IllegalArgumentException e) {
FileLog.e(e);
}
}
}

This file was deleted.

0 comments on commit 4a9fdd9

Please sign in to comment.