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

Commit 4f2ac32

Browse files
authored
Merge pull request #77 from Oizaro/master
MicroG 0.2.16.204713
2 parents 6bfd8eb + ad6efef commit 4f2ac32

30 files changed

+435
-211
lines changed

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ allprojects {
4545
apply plugin: 'idea'
4646

4747
group = 'org.microg.gms'
48-
version = "0.2.14.204218"
49-
ext.appVersionCode = 204215004
48+
version = "0.2.16.204713"
49+
ext.appVersionCode = 204713001
5050
ext.isReleaseVersion = false
5151
}
5252

play-services-basement/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ apply plugin: 'kotlin-android'
1919
apply plugin: 'kotlin-android-extensions'
2020

2121
dependencies {
22-
api "org.microg:safe-parcel:$safeParcelVersion"
22+
api "org.microg:safe-parcel:1.7.0"
2323

2424
implementation "androidx.annotation:annotation:$annotationVersion"
2525
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.21'

play-services-basement/src/main/java/org/microg/gms/common/GmsService.java

+10
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public enum GmsService {
4646
CREDENTIALS(68, "com.google.android.gms.auth.api.credentials.service.START"),
4747
MEASUREMENT(93, "com.google.android.gms.measurement.START"),
4848
GASS(116, "com.google.android.gms.gass.START"),
49+
IDENTITY_SIGN_IN(212, "com.google.android.gms.auth.api.identity.service.signin.START"),
4950
;
5051

5152
public int SERVICE_ID;
@@ -65,6 +66,15 @@ public static GmsService byServiceId(int serviceId) {
6566
return UNKNOWN;
6667
}
6768

69+
public static GmsService byAction(String action) {
70+
for (GmsService service : values()) {
71+
for (String serviceAction : service.SECONDARY_ACTIONS) {
72+
if (serviceAction.equals(action)) return service;
73+
}
74+
}
75+
return UNKNOWN;
76+
}
77+
6878
public static String nameFromServiceId(int serviceId) {
6979
return byServiceId(serviceId).toString(serviceId);
7080
}

play-services-core/src/main/AndroidManifest.xml

+22-9
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@
8080
tools:ignore="ProtectedPermissions" />
8181

8282
<application
83-
android:forceQueryable="true"
84-
android:allowBackup="false"
83+
android:allowBackup="true"
84+
android:fullBackupOnly="true"
8585
android:extractNativeLibs="true"
86+
android:forceQueryable="true"
8687
android:icon="@mipmap/ic_launcher"
8788
android:label="@string/app_name"
8889
android:networkSecurityConfig="@xml/network_security_config">
@@ -144,7 +145,8 @@
144145

145146
<!-- Cloud Messaging -->
146147
<service
147-
android:name="org.microg.gms.gcm.PushRegisterService">
148+
android:name="org.microg.gms.gcm.PushRegisterService"
149+
android:process=":persistent">
148150
<intent-filter>
149151
<action android:name="com.mgoogle.android.c2dm.intent.REGISTER" />
150152
<action android:name="com.mgoogle.android.c2dm.intent.UNREGISTER" />
@@ -153,24 +155,33 @@
153155
</intent-filter>
154156
</service>
155157

156-
<receiver android:name="org.microg.gms.gcm.PushRegisterReceiver">
158+
<receiver
159+
android:name="org.microg.gms.gcm.PushRegisterReceiver"
160+
android:process=":persistent">
157161
<intent-filter>
158162
<action android:name="com.mgoogle.iid.TOKEN_REQUEST" />
159163
</intent-filter>
160164
</receiver>
161165

162-
<service android:name="org.microg.gms.gcm.McsService" />
166+
<service
167+
android:name="org.microg.gms.gcm.McsService"
168+
android:process=":persistent" />
163169

164170
<receiver
165-
android:name="org.microg.gms.gcm.SendReceiver">
171+
android:name="org.microg.gms.gcm.SendReceiver"
172+
android:process=":persistent">
166173
<intent-filter>
167174
<action android:name="com.google.android.gcm.intent.SEND" />
168175
</intent-filter>
169176
</receiver>
170177

171-
<receiver android:name="org.microg.gms.gcm.ServiceInfoReceiver" />
178+
<receiver
179+
android:name="org.microg.gms.gcm.ServiceInfoReceiver"
180+
android:process=":persistent" />
172181

173-
<receiver android:name="org.microg.gms.gcm.TriggerReceiver">
182+
<receiver
183+
android:name="org.microg.gms.gcm.TriggerReceiver"
184+
android:process=":persistent">
174185
<intent-filter>
175186
<action android:name="android.intent.action.BOOT_COMPLETED" />
176187
<action android:name="android.intent.action.AIRPLANE_MODE" />
@@ -191,7 +202,9 @@
191202
</intent-filter>
192203
</receiver>
193204

194-
<receiver android:name="org.microg.gms.gcm.UnregisterReceiver">
205+
<receiver
206+
android:name="org.microg.gms.gcm.UnregisterReceiver"
207+
android:process=":persistent">
195208
<intent-filter>
196209
<action android:name="android.intent.action.PACKAGE_DATA_CLEARED" />
197210
<action android:name="android.intent.action.PACKAGE_FULLY_REMOVED" />

play-services-core/src/main/java/org/microg/gms/checkin/CheckinPrefs.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ public class CheckinPrefs implements SharedPreferences.OnSharedPreferenceChangeL
2222

2323
public static CheckinPrefs get(Context context) {
2424
if (INSTANCE == null) {
25-
if (!context.getPackageName().equals(PackageUtils.getProcessName())) {
26-
Log.w("Preferences", CheckinPrefs.class.getName() + " initialized outside main process", new RuntimeException());
27-
}
25+
PackageUtils.warnIfNotMainProcess(context, CheckinPrefs.class);
2826
if (context == null) return new CheckinPrefs(null);
2927
INSTANCE = new CheckinPrefs(context.getApplicationContext());
3028
}

play-services-core/src/main/java/org/microg/gms/checkin/CheckinService.java

+3
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@
3232

3333
import androidx.legacy.content.WakefulBroadcastReceiver;
3434

35+
import com.mgoogle.android.gms.R;
3536
import com.google.android.gms.checkin.internal.ICheckinService;
3637

3738
import org.microg.gms.auth.AuthConstants;
39+
import org.microg.gms.common.ForegroundServiceInfo;
3840
import org.microg.gms.common.ForegroundServiceContext;
3941
import org.microg.gms.gcm.McsService;
4042
import org.microg.gms.people.PeopleManager;
4143

44+
@ForegroundServiceInfo(value = "Google device registration", res = R.string.service_name_checkin)
4245
public class CheckinService extends IntentService {
4346
private static final String TAG = "GmsCheckinSvc";
4447
public static final long MAX_VALID_CHECKIN_AGE = 24 * 60 * 60 * 1000; // 12 hours

play-services-core/src/main/java/org/microg/gms/common/ForegroundServiceContext.java

+34-3
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,46 @@ private boolean isIgnoringBatteryOptimizations() {
4848
return powerManager.isIgnoringBatteryOptimizations(getPackageName());
4949
}
5050

51+
private static String getServiceName(Service service) {
52+
String serviceName = null;
53+
try {
54+
ForegroundServiceInfo annotation = service.getClass().getAnnotation(ForegroundServiceInfo.class);
55+
if (annotation != null) {
56+
if (annotation.res() != 0) {
57+
try {
58+
serviceName = service.getString(annotation.res());
59+
} catch (Exception ignored) {
60+
}
61+
}
62+
if (serviceName == null) {
63+
serviceName = annotation.value();
64+
}
65+
}
66+
} catch (Exception ignored) {
67+
}
68+
if (serviceName == null) {
69+
serviceName = service.getClass().getSimpleName();
70+
}
71+
return serviceName;
72+
}
73+
5174
public static void completeForegroundService(Service service, Intent intent, String tag) {
5275
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
5376
&& intent != null
5477
&& intent.getBooleanExtra(EXTRA_FOREGROUND, false)) {
55-
Log.d(tag, "Started in foreground mode.");
56-
service.startForeground(tag.hashCode(), buildForegroundNotification(service));
78+
String serviceName = getServiceName(service);
79+
Log.d(tag, "Started " + serviceName + " in foreground mode.");
80+
try {
81+
Notification notification = buildForegroundNotification(service, serviceName);
82+
service.startForeground(serviceName.hashCode(), notification);
83+
Log.d(tag, "Notification: " + notification.toString());
84+
} catch (Exception e) {
85+
Log.w(tag, e);
86+
}
5787
}
5888
}
5989

60-
private static Notification buildForegroundNotification(Context context) {
90+
private static Notification buildForegroundNotification(Context context, String serviceName) {
6191
Intent notificationIntent = new Intent();
6292
notificationIntent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
6393
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@@ -70,6 +100,7 @@ private static Notification buildForegroundNotification(Context context) {
70100
context.getResources().getString(R.string.notification_service_name),
71101
NotificationManager.IMPORTANCE_LOW);
72102
Channel.setShowBadge(false);
103+
Channel.setVibrationPattern(new long[]{0});
73104
Channel.setLockscreenVisibility(0);
74105
context.getSystemService(NotificationManager.class).createNotificationChannel(Channel);
75106
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2020, microG Project Team
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package org.microg.gms.common;
7+
8+
import java.lang.annotation.ElementType;
9+
import java.lang.annotation.Retention;
10+
import java.lang.annotation.RetentionPolicy;
11+
import java.lang.annotation.Target;
12+
13+
@Retention(RetentionPolicy.RUNTIME)
14+
@Target(ElementType.TYPE)
15+
public @interface ForegroundServiceInfo {
16+
String value();
17+
int res() default 0;
18+
}

play-services-core/src/main/java/org/microg/gms/common/PackageUtils.java

+31
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import android.content.pm.PackageManager;
2525
import android.content.pm.Signature;
2626
import android.os.Binder;
27+
import android.util.Log;
2728

2829
import androidx.annotation.Nullable;
2930

@@ -255,6 +256,36 @@ public static String getProcessName() {
255256
}
256257
}
257258

259+
public static boolean isPersistentProcess() {
260+
String processName = getProcessName();
261+
if (processName == null) {
262+
Log.w("GmsPackageUtils", "Can't determine process name of current process");
263+
return false;
264+
}
265+
return processName.endsWith(":persistent");
266+
}
267+
268+
public static boolean isMainProcess(Context context) {
269+
String processName = getProcessName();
270+
if (processName == null) {
271+
Log.w("GmsPackageUtils", "Can't determine process name of current process");
272+
return false;
273+
}
274+
return processName.equals(context.getPackageName());
275+
}
276+
277+
public static void warnIfNotPersistentProcess(Class<?> clazz) {
278+
if (!isPersistentProcess()) {
279+
Log.w("GmsPackageUtils", clazz.getSimpleName() + " initialized outside persistent process", new RuntimeException());
280+
}
281+
}
282+
283+
public static void warnIfNotMainProcess(Context context, Class<?> clazz) {
284+
if (!isMainProcess(context)) {
285+
Log.w("GmsPackageUtils", clazz.getSimpleName() + " initialized outside main process", new RuntimeException());
286+
}
287+
}
288+
258289
public static String sha1sum(byte[] bytes) {
259290
MessageDigest md;
260291
try {

0 commit comments

Comments
 (0)