1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
| package com.lody.virtual.server;
import android.content.ComponentName; import android.content.ContentProvider; import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.database.Cursor; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.IBinder; import android.os.RemoteException; import android.os.ResultReceiver;
import com.lody.virtual.client.core.VirtualCore; import com.lody.virtual.client.ipc.ServiceManagerNative; import com.lody.virtual.client.stub.KeepAliveService; import com.lody.virtual.helper.compat.BundleCompat; import com.lody.virtual.helper.compat.NotificationChannelCompat; import com.lody.virtual.server.accounts.VAccountManagerService; import com.lody.virtual.server.am.VActivityManagerService; import com.lody.virtual.server.content.VContentService; import com.lody.virtual.server.device.VDeviceManagerService; import com.lody.virtual.server.interfaces.IServiceFetcher; import com.lody.virtual.server.job.VJobSchedulerService; import com.lody.virtual.server.location.VirtualLocationService; import com.lody.virtual.server.notification.VNotificationManagerService; import com.lody.virtual.server.pm.VAppManagerService; import com.lody.virtual.server.pm.VPackageManagerService; import com.lody.virtual.server.pm.VUserManagerService; import com.lody.virtual.server.vs.VirtualStorageService;
public final class BinderProvider extends ContentProvider {
private final ServiceFetcher mServiceFetcher = new ServiceFetcher(); private static boolean sInitialized = false;
@Override public boolean onCreate() { return init(); }
public static boolean isInitialized() { return sInitialized; }
private boolean init() { if (sInitialized) { return false; } Context context = getContext(); if (context != null) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannelCompat.checkOrCreateChannel(context, NotificationChannelCompat.DAEMON_ID, "daemon"); NotificationChannelCompat.checkOrCreateChannel(context, NotificationChannelCompat.DEFAULT_ID, "default"); } try { context.startService(new Intent(context, KeepAliveService.class)); } catch (Exception e) { e.printStackTrace(); } }
if (!VirtualCore.get().isStartup()) { return false; } VPackageManagerService.systemReady(); addService(ServiceManagerNative.PACKAGE, VPackageManagerService.get()); addService(ServiceManagerNative.ACTIVITY, VActivityManagerService.get()); addService(ServiceManagerNative.USER, VUserManagerService.get()); VAppManagerService.systemReady(); addService(ServiceManagerNative.APP, VAppManagerService.get()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { addService(ServiceManagerNative.JOB, VJobSchedulerService.get()); } VNotificationManagerService.systemReady(context); addService(ServiceManagerNative.NOTIFICATION, VNotificationManagerService.get()); VAppManagerService.get().scanApps(); VAccountManagerService.systemReady(); VContentService.systemReady(); addService(ServiceManagerNative.ACCOUNT, VAccountManagerService.get()); addService(ServiceManagerNative.CONTENT, VContentService.get()); addService(ServiceManagerNative.VS, VirtualStorageService.get()); addService(ServiceManagerNative.DEVICE, VDeviceManagerService.get()); addService(ServiceManagerNative.VIRTUAL_LOC, VirtualLocationService.get()); sInitialized = true; return true; }
private void addService(String name, IBinder service) { ServiceCache.addService(name, service); }
@Override public Bundle call(String method, String arg, Bundle extras) { if (!sInitialized) { init(); } if ("@".equals(method)) { Bundle bundle = new Bundle(); BundleCompat.putBinder(bundle, "_VA_|_binder_", mServiceFetcher); return bundle; } return null; }
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { return null; }
@Override public String getType(Uri uri) { return null; }
@Override public Uri insert(Uri uri, ContentValues values) { return null; }
@Override public int delete(Uri uri, String selection, String[] selectionArgs) { return 0; }
@Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { return 0; }
private class ServiceFetcher extends IServiceFetcher.Stub { @Override public IBinder getService(String name) throws RemoteException { if (name != null) { return ServiceCache.getService(name); } return null; }
@Override public void addService(String name, IBinder service) throws RemoteException { if (name != null && service != null) { ServiceCache.addService(name, service); } }
@Override public void removeService(String name) throws RemoteException { if (name != null) { ServiceCache.removeService(name); } } } }
|