Set EUID to 1000 to fix notification and get modules list for Flyme (#2549)
Add more logs for LSPNotificationManager
Seteuid to 1000
This reverts commit 0a26993039.
This commit is contained in:
parent
495686b532
commit
d972bf4bd6
|
|
@ -7,6 +7,8 @@ import android.os.IBinder;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
|
import android.system.ErrnoException;
|
||||||
|
import android.system.Os;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
@ -69,72 +71,87 @@ public class BridgeService {
|
||||||
};
|
};
|
||||||
|
|
||||||
// For service
|
// For service
|
||||||
|
// This MUST run in main thread
|
||||||
private static synchronized void sendToBridge(IBinder binder, boolean isRestart) {
|
private static synchronized void sendToBridge(IBinder binder, boolean isRestart) {
|
||||||
do {
|
assert Looper.myLooper() == Looper.getMainLooper();
|
||||||
bridgeService = ServiceManager.getService(SERVICE_NAME);
|
|
||||||
if (bridgeService != null && bridgeService.pingBinder()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.i(TAG, "service " + SERVICE_NAME + " is not started, wait 1s.");
|
|
||||||
|
|
||||||
try {
|
|
||||||
//noinspection BusyWait
|
|
||||||
Thread.sleep(1000);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
Log.w(TAG, "sleep" + Log.getStackTraceString(e));
|
|
||||||
}
|
|
||||||
} while (true);
|
|
||||||
|
|
||||||
if (isRestart && listener != null) {
|
|
||||||
listener.onSystemServerRestarted();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
bridgeService.linkToDeath(bridgeRecipient, 0);
|
Os.seteuid(0);
|
||||||
} catch (Throwable e) {
|
} catch (ErrnoException e) {
|
||||||
Log.w(TAG, "linkToDeath " + Log.getStackTraceString(e));
|
Log.e(TAG, "seteuid 0", e);
|
||||||
var snapshot = bridgeService;
|
|
||||||
sendToBridge(binder, snapshot == null || !snapshot.isBinderAlive());
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
do {
|
||||||
|
bridgeService = ServiceManager.getService(SERVICE_NAME);
|
||||||
|
if (bridgeService != null && bridgeService.pingBinder()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.i(TAG, "service " + SERVICE_NAME + " is not started, wait 1s.");
|
||||||
|
|
||||||
|
try {
|
||||||
|
//noinspection BusyWait
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
Log.w(TAG, "sleep" + Log.getStackTraceString(e));
|
||||||
|
}
|
||||||
|
} while (true);
|
||||||
|
|
||||||
|
if (isRestart && listener != null) {
|
||||||
|
listener.onSystemServerRestarted();
|
||||||
|
}
|
||||||
|
|
||||||
Parcel data = Parcel.obtain();
|
|
||||||
Parcel reply = Parcel.obtain();
|
|
||||||
boolean res = false;
|
|
||||||
// try at most three times
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
try {
|
try {
|
||||||
data.writeInterfaceToken(DESCRIPTOR);
|
bridgeService.linkToDeath(bridgeRecipient, 0);
|
||||||
data.writeInt(ACTION.ACTION_SEND_BINDER.ordinal());
|
|
||||||
Log.v(TAG, "binder " + binder.toString());
|
|
||||||
data.writeStrongBinder(binder);
|
|
||||||
if (bridgeService == null) break;
|
|
||||||
res = bridgeService.transact(TRANSACTION_CODE, data, reply, 0);
|
|
||||||
reply.readException();
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Log.e(TAG, "send binder " + Log.getStackTraceString(e));
|
Log.w(TAG, "linkToDeath " + Log.getStackTraceString(e));
|
||||||
var snapshot = bridgeService;
|
var snapshot = bridgeService;
|
||||||
sendToBridge(binder, snapshot == null || !snapshot.isBinderAlive());
|
sendToBridge(binder, snapshot == null || !snapshot.isBinderAlive());
|
||||||
return;
|
return;
|
||||||
} finally {
|
|
||||||
data.recycle();
|
|
||||||
reply.recycle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res) break;
|
Parcel data = Parcel.obtain();
|
||||||
|
Parcel reply = Parcel.obtain();
|
||||||
|
boolean res = false;
|
||||||
|
// try at most three times
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
try {
|
||||||
|
data.writeInterfaceToken(DESCRIPTOR);
|
||||||
|
data.writeInt(ACTION.ACTION_SEND_BINDER.ordinal());
|
||||||
|
Log.v(TAG, "binder " + binder.toString());
|
||||||
|
data.writeStrongBinder(binder);
|
||||||
|
if (bridgeService == null) break;
|
||||||
|
res = bridgeService.transact(TRANSACTION_CODE, data, reply, 0);
|
||||||
|
reply.readException();
|
||||||
|
} catch (Throwable e) {
|
||||||
|
Log.e(TAG, "send binder " + Log.getStackTraceString(e));
|
||||||
|
var snapshot = bridgeService;
|
||||||
|
sendToBridge(binder, snapshot == null || !snapshot.isBinderAlive());
|
||||||
|
return;
|
||||||
|
} finally {
|
||||||
|
data.recycle();
|
||||||
|
reply.recycle();
|
||||||
|
}
|
||||||
|
|
||||||
Log.w(TAG, "no response from bridge, retry in 1s");
|
if (res) break;
|
||||||
|
|
||||||
|
Log.w(TAG, "no response from bridge, retry in 1s");
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (listener != null) {
|
||||||
|
listener.onResponseFromBridgeService(res);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Os.seteuid(1000);
|
||||||
} catch (InterruptedException ignored) {
|
} catch (ErrnoException e) {
|
||||||
|
Log.e(TAG, "seteuid 1000", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listener != null) {
|
|
||||||
listener.onResponseFromBridgeService(res);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void send(LSPosedService service, Listener listener) {
|
public static void send(LSPosedService service, Listener listener) {
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ public class LSPNotificationManager {
|
||||||
private static final IBinder.DeathRecipient recipient = new IBinder.DeathRecipient() {
|
private static final IBinder.DeathRecipient recipient = new IBinder.DeathRecipient() {
|
||||||
@Override
|
@Override
|
||||||
public void binderDied() {
|
public void binderDied() {
|
||||||
Log.w(TAG, "nm is dead");
|
Log.w(TAG, "notificationManager is dead");
|
||||||
binder.unlinkToDeath(this, 0);
|
binder.unlinkToDeath(this, 0);
|
||||||
binder = null;
|
binder = null;
|
||||||
notificationManager = null;
|
notificationManager = null;
|
||||||
|
|
@ -96,11 +96,16 @@ public class LSPNotificationManager {
|
||||||
|
|
||||||
private static boolean hasNotificationChannelForSystem(
|
private static boolean hasNotificationChannelForSystem(
|
||||||
INotificationManager nm, String channelId) throws RemoteException {
|
INotificationManager nm, String channelId) throws RemoteException {
|
||||||
|
NotificationChannel channel;
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
return nm.getNotificationChannelForPackage("android", 1000, channelId, null, false) != null;
|
channel = nm.getNotificationChannelForPackage("android", 1000, channelId, null, false);
|
||||||
} else {
|
} else {
|
||||||
return nm.getNotificationChannelForPackage("android", 1000, channelId, false) != null;
|
channel = nm.getNotificationChannelForPackage("android", 1000, channelId, false);
|
||||||
}
|
}
|
||||||
|
if(channel != null) {
|
||||||
|
Log.d(TAG, "hasNotificationChannelForSystem: " + channel);
|
||||||
|
}
|
||||||
|
return channel != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createNotificationChannel(INotificationManager nm) throws RemoteException {
|
private static void createNotificationChannel(INotificationManager nm) throws RemoteException {
|
||||||
|
|
@ -112,6 +117,7 @@ public class LSPNotificationManager {
|
||||||
NotificationManager.IMPORTANCE_HIGH);
|
NotificationManager.IMPORTANCE_HIGH);
|
||||||
updated.setShowBadge(false);
|
updated.setShowBadge(false);
|
||||||
if (hasNotificationChannelForSystem(nm, UPDATED_CHANNEL_ID)) {
|
if (hasNotificationChannelForSystem(nm, UPDATED_CHANNEL_ID)) {
|
||||||
|
Log.d(TAG, "update notification channel: " + UPDATED_CHANNEL_ID);
|
||||||
nm.updateNotificationChannelForPackage("android", 1000, updated);
|
nm.updateNotificationChannelForPackage("android", 1000, updated);
|
||||||
} else {
|
} else {
|
||||||
list.add(updated);
|
list.add(updated);
|
||||||
|
|
@ -122,6 +128,7 @@ public class LSPNotificationManager {
|
||||||
NotificationManager.IMPORTANCE_MIN);
|
NotificationManager.IMPORTANCE_MIN);
|
||||||
status.setShowBadge(false);
|
status.setShowBadge(false);
|
||||||
if (hasNotificationChannelForSystem(nm, STATUS_CHANNEL_ID)) {
|
if (hasNotificationChannelForSystem(nm, STATUS_CHANNEL_ID)) {
|
||||||
|
Log.d(TAG, "update notification channel: " + STATUS_CHANNEL_ID);
|
||||||
nm.updateNotificationChannelForPackage("android", 1000, status);
|
nm.updateNotificationChannelForPackage("android", 1000, status);
|
||||||
} else {
|
} else {
|
||||||
list.add(status);
|
list.add(status);
|
||||||
|
|
@ -132,11 +139,13 @@ public class LSPNotificationManager {
|
||||||
NotificationManager.IMPORTANCE_HIGH);
|
NotificationManager.IMPORTANCE_HIGH);
|
||||||
scope.setShowBadge(false);
|
scope.setShowBadge(false);
|
||||||
if (hasNotificationChannelForSystem(nm, SCOPE_CHANNEL_ID)) {
|
if (hasNotificationChannelForSystem(nm, SCOPE_CHANNEL_ID)) {
|
||||||
|
Log.d(TAG, "update notification channel: " + SCOPE_CHANNEL_ID);
|
||||||
nm.updateNotificationChannelForPackage("android", 1000, scope);
|
nm.updateNotificationChannelForPackage("android", 1000, scope);
|
||||||
} else {
|
} else {
|
||||||
list.add(scope);
|
list.add(scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.d(TAG, "create notification channels for android: " + list);
|
||||||
nm.createNotificationChannelsForPackage("android", 1000, new ParceledListSlice<>(list));
|
nm.createNotificationChannelsForPackage("android", 1000, new ParceledListSlice<>(list));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue