mirror of
https://github.com/TeamVanced/VancedMicroG
synced 2024-12-05 02:12:54 +01:00
Temporary whitelist support for Doze (#732)
Fixes #338 Co-Authored-By: @ccaapton <6211551+ccaapton@users.noreply.github.com> Co-Authored-By: @ale5000-git <15793015+ale5000-git@users.noreply.github.com>
This commit is contained in:
parent
e7f37e17a8
commit
60023887d1
@ -90,6 +90,7 @@
|
||||
|
||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||
<uses-permission android:name="android.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST" tools:ignore="ProtectedPermissions"/>
|
||||
|
||||
<uses-sdk tools:overrideLibrary="com.takisoft.fix.support.v7.preference,android.support.graphics.drawable.animated,android.arch.lifecycle,android.arch.lifecycle.livedata.core,android.arch.lifecycle.viewmodel,android.arch.core"/>
|
||||
|
||||
|
@ -35,6 +35,7 @@ import android.os.Messenger;
|
||||
import android.os.Parcelable;
|
||||
import android.os.PowerManager;
|
||||
import android.os.SystemClock;
|
||||
import android.os.UserHandle;
|
||||
import android.support.v4.content.WakefulBroadcastReceiver;
|
||||
import android.util.Log;
|
||||
|
||||
@ -52,6 +53,7 @@ import org.microg.gms.gcm.mcs.LoginResponse;
|
||||
import org.microg.gms.gcm.mcs.Setting;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@ -452,12 +454,13 @@ public class McsService extends Service implements Handler.Callback {
|
||||
}
|
||||
|
||||
private void handleAppMessage(DataMessageStanza msg) {
|
||||
database.noteAppMessage(msg.category, msg.getSerializedSize());
|
||||
GcmDatabase.App app = database.getApp(msg.category);
|
||||
String packageName = msg.category;
|
||||
database.noteAppMessage(packageName, msg.getSerializedSize());
|
||||
GcmDatabase.App app = database.getApp(packageName);
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(ACTION_C2DM_RECEIVE);
|
||||
intent.setPackage(msg.category);
|
||||
intent.setPackage(packageName);
|
||||
intent.putExtra(EXTRA_FROM, msg.from);
|
||||
intent.putExtra(EXTRA_MESSAGE_ID, msg.id);
|
||||
if (app.wakeForDelivery) {
|
||||
@ -472,7 +475,7 @@ public class McsService extends Service implements Handler.Callback {
|
||||
|
||||
String receiverPermission;
|
||||
try {
|
||||
String name = msg.category + ".permission.C2D_MESSAGE";
|
||||
String name = packageName + ".permission.C2D_MESSAGE";
|
||||
getPackageManager().getPermissionInfo(name, 0);
|
||||
receiverPermission = name;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
@ -486,6 +489,25 @@ public class McsService extends Service implements Handler.Callback {
|
||||
for (ResolveInfo resolveInfo : infos) {
|
||||
logd("Target: " + resolveInfo);
|
||||
Intent targetIntent = new Intent(intent);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && app.wakeForDelivery) {
|
||||
try {
|
||||
Field field = Context.class.getField("DEVICE_IDLE_CONTROLLER");
|
||||
IBinder binder = (IBinder) Class.forName("android.os.ServiceManager")
|
||||
.getMethod("getService", String.class).invoke(null, field.get(null));
|
||||
if (binder != null) {
|
||||
Object deviceIdleController = Class.forName("android.os.IDeviceIdleController$Stub")
|
||||
.getMethod("asInterface", IBinder.class).invoke(null, binder);
|
||||
int userId = (int) UserHandle.class.getMethod("getUserId", int.class)
|
||||
.invoke(null, getPackageManager().getApplicationInfo(packageName, 0).uid);
|
||||
logd("Adding app " + packageName + " for userId " + userId + " to the temp whitelist");
|
||||
deviceIdleController.getClass()
|
||||
.getMethod("addPowerSaveTempWhitelistApp", String.class, long.class, int.class, String.class)
|
||||
.invoke(deviceIdleController, packageName, 10000, userId, "GCM Push");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, e);
|
||||
}
|
||||
}
|
||||
targetIntent.setComponent(new ComponentName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name));
|
||||
sendOrderedBroadcast(targetIntent, receiverPermission);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user