Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.content.ContextWrapper;
import android.content.Intent;
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.os.PowerManager;
import android.provider.Settings;
import android.util.Log;
Expand All @@ -22,7 +21,6 @@
import org.microg.gms.base.core.R;

import static android.os.Build.VERSION.SDK_INT;
import static android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS;

public class ForegroundServiceContext extends ContextWrapper {
private static final String TAG = "ForegroundService";
Expand Down Expand Up @@ -106,8 +104,7 @@ private static Notification buildForegroundNotification(Context context, String
String secondLine = context.getString(R.string.foreground_service_notification_big_text, appTitle);

// Open battery optimizations settings
@SuppressLint("BatteryLife") Intent batteryOptimizationIntent = new Intent(ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
.setData(Uri.parse("package:" + context.getPackageName()));
Intent batteryOptimizationIntent = ForegroundServiceOemUtils.getBatteryOptimizationIntent(context);

PendingIntent batteryPendingIntent = PendingIntent.getActivity(
context, 0, batteryOptimizationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package org.microg.gms.common;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.provider.Settings;
import android.util.Log;
import android.widget.Toast;

import java.util.Locale;

public class ForegroundServiceOemUtils {
private static final String TAG = "BatteryOptimizationOemUtils";

private static final String[] KNOWN_RESTRICTED_MANUFACTURERS = {
"huawei", "xiaomi", "oneplus", "samsung", "meizu", "asus", "wiko",
"lenovo", "oppo", "vivo", "realme", "motorola", "blackview", "tecno",
"sony", "unihertz"
};

public static String getDkmaSlug() {
String manufacturer = Build.MANUFACTURER.toLowerCase(Locale.ROOT);

for (String brand : KNOWN_RESTRICTED_MANUFACTURERS) {
if (manufacturer.contains(brand)) {
return brand;
}
}

return ""; // Oem not listed, hide dontkillmyapp option
}

public static Intent getDkmaIntent(String slug) {
String url = "https://dontkillmyapp.com/" + slug;
return new Intent(Intent.ACTION_VIEW, Uri.parse(url));
}

public static boolean isXiaomi() {
return Build.MANUFACTURER.toLowerCase(Locale.ROOT).contains("xiaomi");
}

public static Intent getBatteryOptimizationIntent(Context context) {
// Temporary fix issues: https://github.com/MorpheApp/MicroG-RE/issues/112
if (isXiaomi()) {
return new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
} else {
return new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
.setData(Uri.parse("package:" + context.getPackageName()));
}
}

public interface IntentLauncher {
void launch(Intent intent);
}

public static void openBatteryOptimizationSettings(Context context, IntentLauncher launcher) {
Intent intent = getBatteryOptimizationIntent(context);
try {
launcher.launch(intent);
} catch (Exception e) {
if (!Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS.equals(intent.getAction())) {
try {
launcher.launch(new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS));
} catch (Exception e2) {
Log.w(TAG, "Failed to launch battery optimization settings", e2);
}
} else {
Log.w(TAG, "Failed to launch battery optimization settings", e);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ interface CheckResolver {
}

enum Result {
Positive, Negative, Unknown
Positive, Negative, Neutral, Unknown
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import static android.view.View.VISIBLE;
import static android.view.View.INVISIBLE;
import static org.microg.tools.selfcheck.SelfCheckGroup.Result.Negative;
import static org.microg.tools.selfcheck.SelfCheckGroup.Result.Neutral;
import static org.microg.tools.selfcheck.SelfCheckGroup.Result.Positive;
import static org.microg.tools.selfcheck.SelfCheckGroup.Result.Unknown;

Expand Down Expand Up @@ -166,9 +167,11 @@ public void addResult(String name, SelfCheckGroup.Result result, String resoluti
if (showIcon) {
resultIcon.setVisibility(VISIBLE);
if (result == Positive) {
resultIcon.setActivated(true);
resultIcon.setImageResource(R.drawable.ic_positive);
} else if (result == Negative) {
resultIcon.setActivated(false);
resultIcon.setImageResource(R.drawable.ic_negative);
} else if (result == Neutral) {
resultIcon.setImageResource(R.drawable.ic_neutral);
} else {
resultIcon.setVisibility(INVISIBLE);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorOutline"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="@android:color/white"
android:pathData="M320,520L640,520Q657,520 668.5,508.5Q680,497 680,480Q680,463 668.5,451.5Q657,440 640,440L320,440Q303,440 291.5,451.5Q280,463 280,480Q280,497 291.5,508.5Q303,520 320,520ZM480,880Q397,880 324,848.5Q251,817 197,763Q143,709 111.5,636Q80,563 80,480Q80,397 111.5,324Q143,251 197,197Q251,143 324,111.5Q397,80 480,80Q563,80 636,111.5Q709,143 763,197Q817,251 848.5,324Q880,397 880,480Q880,563 848.5,636Q817,709 763,763Q709,817 636,848.5Q563,880 480,880Z" />
</vector>
79 changes: 47 additions & 32 deletions play-services-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,25 @@
<provider
android:name="org.microg.gms.gservices.GServicesProvider"
android:authorities="${basePackageName}.android.gsf.gservices"
android:exported="true" />
android:exported="true"
tools:ignore="ExportedContentProvider" />
<provider
android:name="org.microg.gms.settings.GoogleSettingsProvider"
android:authorities="${basePackageName}.settings"
android:exported="true" />
android:exported="true"
tools:ignore="ExportedContentProvider" />

<!-- Device Checkin -->

<service android:name="org.microg.gms.checkin.CheckinService">
<service android:name="org.microg.gms.checkin.CheckinService"
tools:ignore="ExportedService,IntentFilterExportedReceiver">
<intent-filter>
<action android:name="com.google.android.gms.checkin.BIND_TO_SERVICE" />
</intent-filter>
</service>

<receiver android:name="org.microg.gms.checkin.TriggerReceiver">
<receiver android:name="org.microg.gms.checkin.TriggerReceiver"
tools:ignore="IntentFilterExportedReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.AIRPLANE_MODE" />
Expand All @@ -146,7 +150,8 @@
<!-- Cloud Messaging -->
<service
android:name="org.microg.gms.gcm.PushRegisterService"
android:process=":persistent">
android:process=":persistent"
tools:ignore="ExportedService,IntentFilterExportedReceiver">
<intent-filter>
<action android:name="${basePackageName}.android.c2dm.intent.REGISTER" />
<action android:name="${basePackageName}.android.c2dm.intent.UNREGISTER" />
Expand All @@ -157,7 +162,8 @@

<receiver
android:name="org.microg.gms.gcm.PushRegisterReceiver"
android:process=":persistent">
android:process=":persistent"
tools:ignore="ExportedReceiver,IntentFilterExportedReceiver">
<intent-filter>
<action android:name="${basePackageName}.iid.TOKEN_REQUEST" />
</intent-filter>
Expand All @@ -169,7 +175,8 @@

<receiver
android:name="org.microg.gms.gcm.SendReceiver"
android:process=":persistent">
android:process=":persistent"
tools:ignore="ExportedReceiver,IntentFilterExportedReceiver">
<intent-filter>
<action android:name="${basePackageName}.android.gcm.intent.SEND" />
</intent-filter>
Expand All @@ -181,7 +188,8 @@

<receiver
android:name="org.microg.gms.gcm.TriggerReceiver"
android:process=":persistent">
android:process=":persistent"
tools:ignore="IntentFilterExportedReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.AIRPLANE_MODE" />
Expand All @@ -204,7 +212,8 @@

<receiver
android:name="org.microg.gms.gcm.UnregisterReceiver"
android:process=":persistent">
android:process=":persistent"
tools:ignore="IntentFilterExportedReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_DATA_CLEARED" />
<action android:name="android.intent.action.PACKAGE_FULLY_REMOVED" />
Expand All @@ -216,7 +225,8 @@

<!-- People -->

<service android:name="org.microg.gms.people.PeopleService">
<service android:name="org.microg.gms.people.PeopleService"
tools:ignore="ExportedService,IntentFilterExportedReceiver">
<intent-filter>
<action android:name="com.google.android.gms.people.service.START" />
<category android:name="android.intent.category.DEFAULT" />
Expand All @@ -236,7 +246,8 @@

<!-- Auth -->

<service android:name="org.microg.gms.auth.loginservice.GoogleLoginService">
<service android:name="org.microg.gms.auth.loginservice.GoogleLoginService"
tools:ignore="ExportedService,IntentFilterExportedReceiver">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
Expand Down Expand Up @@ -288,7 +299,8 @@

<service
android:name=".auth.GetToken"
android:exported="true" />
android:exported="true"
tools:ignore="ExportedService" />

<activity
android:name=".auth.TokenActivity"
Expand All @@ -298,36 +310,42 @@
<provider
android:name="org.microg.gms.auth.AccountContentProvider"
android:authorities="${basePackageName}.android.gms.auth.accounts"
android:exported="true" />
android:exported="true"
tools:ignore="ExportedContentProvider" />

<activity
android:name="org.microg.gms.auth.credentials.CredentialPickerActivity"
android:exported="true"
android:process=":ui">
<intent-filter>
<action android:name="${basePackageName}.android.gms.auth.api.credentials.PICKER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

<service android:name="org.microg.gms.auth.credentials.CredentialsService">
<service android:name="org.microg.gms.auth.credentials.CredentialsService"
tools:ignore="ExportedService,IntentFilterExportedReceiver">
<intent-filter>
<action android:name="${basePackageName}.android.gms.auth.api.credentials.service.START" />
</intent-filter>
</service>

<service android:name="org.microg.gms.auth.proxy.AuthProxyService">
<service android:name="org.microg.gms.auth.proxy.AuthProxyService"
tools:ignore="ExportedService,IntentFilterExportedReceiver">
<intent-filter>
<action android:name="${basePackageName}.android.gms.auth.service.START" />
</intent-filter>
</service>

<service android:name="org.microg.gms.auth.appcert.AppCertService">
<service android:name="org.microg.gms.auth.appcert.AppCertService"
tools:ignore="ExportedService,IntentFilterExportedReceiver">
<intent-filter>
<action android:name="${basePackageName}.android.gms.auth.be.appcert.AppCertService" />
</intent-filter>
</service>

<service android:name="org.microg.gms.credential.CredentialManagerService">
<service android:name="org.microg.gms.credential.CredentialManagerService"
tools:ignore="ExportedService,IntentFilterExportedReceiver">
<intent-filter>
<action android:name="${basePackageName}.android.gms.credential.manager.service.firstparty.START" />
</intent-filter>
Expand All @@ -344,14 +362,16 @@
</intent-filter>
</activity>

<service android:name="org.microg.gms.signin.SignInService">
<service android:name="org.microg.gms.signin.SignInService"
tools:ignore="ExportedService,IntentFilterExportedReceiver">
<intent-filter>
<action android:name="${basePackageName}.android.gms.signin.service.START" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>

<service android:name="org.microg.gms.auth.signin.AuthSignInService">
<service android:name="org.microg.gms.auth.signin.AuthSignInService"
tools:ignore="ExportedService,IntentFilterExportedReceiver">
<intent-filter>
<action android:name="${basePackageName}.android.gms.auth.api.signin.service.START" />
<category android:name="android.intent.category.DEFAULT" />
Expand Down Expand Up @@ -411,11 +431,10 @@
<!-- microG Settings embedded in System Settings on SDK 23 and newer -->
<activity-alias
android:name="org.microg.gms.ui.SettingsActivityLink"
android:exported="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/gms_app_name"
android:process=":ui"
android:targetActivity="org.microg.gms.ui.MainSettingsActivity"
android:taskAffinity="org.microg.gms.settings">
android:targetActivity="org.microg.gms.ui.MainSettingsActivity">
<intent-filter>
<action android:name="com.android.settings.action.EXTRA_SETTINGS" />
</intent-filter>
Expand All @@ -435,9 +454,7 @@
<activity-alias
android:name="com.google.android.gms.app.settings.GoogleSettingsLink"
android:exported="true"
android:process=":ui"
android:targetActivity="org.microg.gms.ui.MainSettingsActivity"
android:taskAffinity="org.microg.gms.settings">
android:targetActivity="org.microg.gms.ui.MainSettingsActivity">
</activity-alias>

<activity
Expand Down Expand Up @@ -485,12 +502,8 @@

<activity-alias
android:name="org.microg.gms.accountsettings.ui.ManagerActivity"
android:excludeFromRecents="true"
android:exported="true"
android:process=":ui"
android:targetActivity="org.microg.gms.ui.AccountManagerActivity"
android:taskAffinity="org.microg.gms.settings"
android:theme="@style/AppTheme.Login">
android:targetActivity="org.microg.gms.ui.AccountManagerActivity">
<intent-filter tools:ignore="AppLinkUrlError">
<action android:name="com.google.android.gms.accountsettings.action.VIEW_SETTINGS" />
<action android:name="${basePackageName}.android.gms.accountsettings.action.VIEW_SETTINGS" />
Expand All @@ -506,14 +519,16 @@

<service
android:name="org.microg.gms.auth.SignInService"
android:exported="true">
android:exported="true"
tools:ignore="ExportedService">
<intent-filter>
<action android:name="com.google.android.gms.signin.service.START" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>

<service android:name="org.microg.gms.DummyService">
<service android:name="org.microg.gms.DummyService"
tools:ignore="ExportedService,IntentFilterExportedReceiver">
<intent-filter>
<action android:name="com.google.android.contextmanager.service.ContextManagerService.START" />
<action android:name="com.google.android.gms.accounts.ACCOUNT_SERVICE" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ class AccountsFragment : PreferenceFragmentCompat() {

private fun setupPreferenceListeners() {
findPreference<Preference>("pref_privacy")?.setOnPreferenceClickListener {
findNavController().navigate(requireContext(), R.id.privacyFragment)
val activity = requireActivity()

if (activity is AccountManagerActivity) {
activity.replaceFragment(PrivacyFragment())
} else {
findNavController().navigate(R.id.privacyFragment)
}
true
}
findPreference<Preference>("pref_manage_accounts")?.setOnPreferenceClickListener {
Expand Down
Loading