Skip to content
This repository was archived by the owner on Oct 26, 2024. It is now read-only.

Commit 6e31b78

Browse files
reisoSumAtrIX
andauthored
feat(youtube/microg-support): check if Vanced MicroG is running in the background (#301)
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de> Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
1 parent 057e599 commit 6e31b78

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

app/src/main/java/app/revanced/integrations/patches/MicroGSupport.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,47 @@
22

33
import static app.revanced.integrations.sponsorblock.StringRef.str;
44

5+
import android.content.Context;
56
import android.content.Intent;
67
import android.content.pm.PackageManager;
78
import android.net.Uri;
89
import android.widget.Toast;
910

11+
import java.util.Objects;
12+
1013
import app.revanced.integrations.utils.LogHelper;
1114
import app.revanced.integrations.utils.ReVancedUtils;
1215

1316
public class MicroGSupport {
1417
private static final String MICROG_VENDOR = "com.mgoogle";
1518
private static final String MICROG_PACKAGE_NAME = "com.mgoogle.android.gms";
1619
private static final String VANCED_MICROG_DOWNLOAD_LINK = "https://github.com/TeamVanced/VancedMicroG/releases/latest";
20+
private static final String DONT_KILL_MY_APP_LINK = "https://dontkillmyapp.com";
21+
private static final Uri VANCED_MICROG_PROVIDER = Uri.parse("content://com.mgoogle.android.gsf.gservices/prefix");
22+
23+
private static void startIntent(Context context, String uriString, String message) {
24+
Toast.makeText(context, message, Toast.LENGTH_LONG).show();
25+
26+
var intent = new Intent(Intent.ACTION_VIEW);
27+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
28+
intent.setData(Uri.parse(uriString));
29+
context.startActivity(intent);
30+
}
1731

1832
public static void checkAvailability() {
19-
var context = ReVancedUtils.getContext();
20-
assert context != null;
33+
var context = Objects.requireNonNull(ReVancedUtils.getContext());
34+
2135
try {
2236
context.getPackageManager().getPackageInfo(MICROG_PACKAGE_NAME, PackageManager.GET_ACTIVITIES);
23-
LogHelper.printDebug(() -> "MicroG is installed on the device");
2437
} catch (PackageManager.NameNotFoundException exception) {
25-
LogHelper.printException(() -> ("MicroG was not found"), exception);
26-
Toast.makeText(context, str("microg_not_installed_warning"), Toast.LENGTH_LONG).show();
38+
LogHelper.printException(() -> ("Vanced MicroG was not found"), exception);
39+
startIntent(context, VANCED_MICROG_DOWNLOAD_LINK, str("microg_not_installed_warning"));
40+
}
2741

28-
var intent = new Intent(Intent.ACTION_VIEW);
29-
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
30-
intent.setData(Uri.parse(VANCED_MICROG_DOWNLOAD_LINK));
31-
context.startActivity(intent);
42+
try (var client = context.getContentResolver().acquireContentProviderClient(VANCED_MICROG_PROVIDER)) {
43+
if (client != null) return;
44+
LogHelper.printException(() -> ("Vanced MicroG is not running in the background"));
45+
startIntent(context, DONT_KILL_MY_APP_LINK, str("microg_not_running_warning"));
3246
}
3347
}
3448
}

0 commit comments

Comments
 (0)