|
2 | 2 |
|
3 | 3 | import static app.revanced.integrations.sponsorblock.StringRef.str; |
4 | 4 |
|
| 5 | +import android.content.Context; |
5 | 6 | import android.content.Intent; |
6 | 7 | import android.content.pm.PackageManager; |
7 | 8 | import android.net.Uri; |
8 | 9 | import android.widget.Toast; |
9 | 10 |
|
| 11 | +import java.util.Objects; |
| 12 | + |
10 | 13 | import app.revanced.integrations.utils.LogHelper; |
11 | 14 | import app.revanced.integrations.utils.ReVancedUtils; |
12 | 15 |
|
13 | 16 | public class MicroGSupport { |
14 | 17 | private static final String MICROG_VENDOR = "com.mgoogle"; |
15 | 18 | private static final String MICROG_PACKAGE_NAME = "com.mgoogle.android.gms"; |
16 | 19 | 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 | + } |
17 | 31 |
|
18 | 32 | public static void checkAvailability() { |
19 | | - var context = ReVancedUtils.getContext(); |
20 | | - assert context != null; |
| 33 | + var context = Objects.requireNonNull(ReVancedUtils.getContext()); |
| 34 | + |
21 | 35 | try { |
22 | 36 | context.getPackageManager().getPackageInfo(MICROG_PACKAGE_NAME, PackageManager.GET_ACTIVITIES); |
23 | | - LogHelper.printDebug(() -> "MicroG is installed on the device"); |
24 | 37 | } 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 | + } |
27 | 41 |
|
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")); |
32 | 46 | } |
33 | 47 | } |
34 | 48 | } |
0 commit comments