public ZenModeConditionSelection(Context context, int zenMode) { super(context); mContext = context; mZenMode = zenMode; mConditions = new ArrayList<Condition>(); setLayoutTransition(new LayoutTransition()); final int p = mContext.getResources().getDimensionPixelSize(R.dimen.content_margin_left); setPadding(p, p, p, 0); mNoMan = INotificationManager.Stub.asInterface( ServiceManager.getService(Context.NOTIFICATION_SERVICE)); final RadioButton b = newRadioButton(null); b.setText(mContext.getString(com.android.internal.R.string.zen_mode_forever)); b.setChecked(true); for (int i = ZenModeConfig.MINUTE_BUCKETS.length - 1; i >= 0; --i) { handleCondition(ZenModeConfig.toTimeCondition(mContext, ZenModeConfig.MINUTE_BUCKETS[i], UserHandle.myUserId())); } }
private void setSurfaceFlingerTranslate(int x, int y) { try { if (flinger == null) flinger = ServiceManager.getService("SurfaceFlinger"); if (flinger == null) { Log.wtf(TAG, "SurfaceFlinger is null"); return; } Parcel data = Parcel.obtain(); data.writeInterfaceToken("android.ui.ISurfaceComposer"); data.writeInt(x); data.writeInt(y); flinger.transact(2020, data, null, 0); data.recycle(); } catch(Exception e) { Log.e(TAG, "SurfaceFlinger error", e); } }
private OpsResult runGetForOps(OpsCommands.Builder builder) throws Throwable { final IAppOpsService appOpsService = IAppOpsService.Stub.asInterface( ServiceManager.getService(Context.APP_OPS_SERVICE)); List opsForPackage = appOpsService.getPackagesForOps(builder.getOps()); ArrayList<PackageOps> packageOpses = new ArrayList<>(); if (opsForPackage != null) { for (Object o : opsForPackage) { PackageOps packageOps = ReflectUtils.opsConvert(o); addSupport(appOpsService, packageOps, builder.getUserHandleId(), builder.isReqNet()); packageOpses.add(packageOps); } } return new OpsResult(packageOpses, null); }
private void findFromService(SystemServiceCaller caller) { try { IBinder service = ServiceManager.getService(caller.getServiceName()); String aidl = service.getInterfaceDescriptor(); Class aClass = sClassCache.get(aidl); if (aClass == null) { aClass = Class.forName(aidl + "$Stub", false, null); sClassCache.put(aidl, aClass); } Object asInterface = MethodUtils.invokeStaticMethod(aClass, "asInterface", new Object[]{service}, new Class[]{IBinder.class}); Method method = MethodUtils.getAccessibleMethod(aClass, caller.getMethodName(), caller.getParamsType()); if (method != null && asInterface != null) { sFindValue.recycle(); sFindValue.put(asInterface, method); } } catch (Throwable e) { e.printStackTrace(); FLog.log(e); } }
@Thunk static boolean setStateL(boolean newState) { try { ITelephony stub = ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE)); ReflectionUtil rUtil = new ReflectionUtil(stub); if (rUtil.getMethod("setDataEnabled", Boolean.TYPE) != null) { rUtil.invokeSetter("setDataEnabled", Boolean.TYPE, newState); } else { Method altMethod = rUtil.getMethod("setDataEnabled", Integer.TYPE, Boolean.TYPE); if (altMethod != null) { int subId = ISub.Stub.asInterface(ServiceManager.getService("isub")).getDefaultSubId(); final Object[] values = new Object[] { subId, newState }; altMethod.invoke(stub, values); } else { return false; } } return true; } catch (Throwable e) { Debug.log(e); return false; } }
@Override public void onAttach(Activity activity) { logd("onAttach(%s)", activity.getClass().getSimpleName()); super.onAttach(activity); mContext = activity; mPm = mContext.getPackageManager(); mNoMan = INotificationManager.Stub.asInterface( ServiceManager.getService(Context.NOTIFICATION_SERVICE)); try { mListener.registerAsSystemService(mContext, new ComponentName(mContext.getPackageName(), this.getClass().getCanonicalName()), ActivityManager.getCurrentUser()); } catch (RemoteException e) { Log.e(TAG, "Cannot register listener", e); } }
static List getOpsForPackage(String packageName) { IBinder service = ServiceManager.getService(Context.APP_OPS_SERVICE); IAppOpsService appOpsService = IAppOpsService.Stub.asInterface(service); int packageUid = getPackageUid(packageName, BreventApplication.getOwner()); try { return appOpsService.getOpsForPackage(packageUid, packageName, null); } catch (RemoteException | RuntimeException e) { UILog.w("Can't getOpsForPackage", e); return null; } }
private void expandNotificationsPanel() { if (!notificationEventMade) { try { IStatusBarService service = IStatusBarService.Stub .asInterface(ServiceManager.getService("statusbar")); service.expandNotificationsPanel(); notificationEventMade = true; } catch (RemoteException | RuntimeException | LinkageError e) { UILog.w("Can't expandNotificationsPanel: " + e.getMessage(), e); } } }
private void collapsePanels() { if (notificationEventMade) { try { IStatusBarService service = IStatusBarService.Stub .asInterface(ServiceManager.getService("statusbar")); service.collapsePanels(); notificationEventMade = false; } catch (RemoteException | RuntimeException | LinkageError e) { UILog.w("Can't collapsePanels: " + e.getMessage(), e); } } }
private void runSet(OpsCommands.Builder builder) throws Throwable { final int uid = Helper.getPackageUid(builder.getPackageName(), builder.getUserHandleId()); if (OtherOp.isOtherOp(builder.getOpInt())) { setOther(builder, uid); } else { final IAppOpsService appOpsService = IAppOpsService.Stub.asInterface( ServiceManager.getService(Context.APP_OPS_SERVICE)); appOpsService .setMode(builder.getOpInt(), uid, builder.getPackageName(), builder.getModeInt()); } }
private void doStart() { IBinder scaBinder = ServiceManager.getService("sca"); log("scaBinder:" + scaBinder); if (scaBinder != null) { sent(new Feedback(Response.START_FAILURE_ALREADY_STARTED, "Sca server already started.")); return; } ServiceManager.addService(ScaContext.SCA_SERVICE, ScaHookService.get(), true); ServiceManager.addService(ScaContext.SCA_TELEPHONY_SERVICE, new TelephonyManagerProxy(), true); ServiceManager.addService(ScaContext.SCA_POWER_SERVICE, new PowerManagerProxy().asBinder(), true); com.nick.commands.sca.IScaService me = com.nick.commands.sca.IScaService.Stub.asInterface(ServiceManager.getService(ScaContext.SCA_SERVICE)); ITelephony telephony = ITelephony.Stub.asInterface(ServiceManager.getService(ScaContext.SCA_TELEPHONY_SERVICE)); IPowerManager power = IPowerManager.Stub.asInterface(ServiceManager.getService(ScaContext.SCA_POWER_SERVICE)); log("Sca service:" + me); log("Sca phone service:" + telephony); log("Sca power service:" + power); if (me == null) { sent(new Feedback(Response.START_FAILURE_SYSTEM_ERR, "Sca server startup failure, have you installed?")); return; } sent(new Feedback(Response.START_OK, "Sca server startup success.")); ServiceKeeper keeper = new ServiceKeeper(); keeper.keep(); }
private void doStop() { IBinder scaBinder = ServiceManager.getService("sca"); if (scaBinder == null) { sent(new Feedback(Response.STOP_FAILURE_NOT_STARTED, "Sca server not started.")); } }
private void setDummyIme() throws RemoteException { IInputMethodManager im = IInputMethodManager.Stub.asInterface(ServiceManager.getService(Context.INPUT_METHOD_SERVICE)); List<InputMethodInfo> infos = im.getInputMethodList(); String id = null; for (InputMethodInfo info : infos) { if (DUMMY_IME_PACKAGE.equals(info.getComponent().getPackageName())) { id = info.getId(); } } if (id == null) { throw new RuntimeException(String.format("Required testing fixture missing: IME package (%s)", DUMMY_IME_PACKAGE)); } im.setInputMethod(null, id); }
public static boolean run(boolean newState) { try { return IConnectivityManager.Stub.asInterface(ServiceManager.getService(Context.CONNECTIVITY_SERVICE)).setUsbTethering(newState) == 0; } catch (Throwable e) { Debug.log(e); return false; } }
public static boolean run(boolean newValue) { try { INfcAdapter adapter = INfcAdapter.Stub.asInterface(ServiceManager.getService("nfc")); return newValue ? adapter.enable() : adapter.disable(true); } catch (Throwable e) { return false; } }
@Override public void toggleState(Context context) { Globals.collapseStatusBar(context); try{ IStatusBarService.Stub.asInterface(ServiceManager.getService("statusbar")).toggleRecentApps(); } catch (final Throwable e) { Debug.log(e); } }
@Override public void inject() throws Throwable { Field f_gDefault = ActivityManagerNative.class.getDeclaredField("gDefault"); if (!f_gDefault.isAccessible()) { f_gDefault.setAccessible(true); } if (f_gDefault.getType() == IActivityManager.class) { f_gDefault.set(null, getHookObject().getProxyObject()); } else if (f_gDefault.getType() == Singleton.class) { Singleton gDefault = (Singleton) f_gDefault.get(null); Field f_mInstance = Singleton.class.getDeclaredField("mInstance"); if (!f_mInstance.isAccessible()) { f_mInstance.setAccessible(true); } f_mInstance.set(gDefault, getHookObject().getProxyObject()); } else { // 不会经过这里 throw new UnsupportedOperationException("Singleton is not visible in AMN."); } HookBinder<IActivityManager> hookAMBinder = new HookBinder<IActivityManager>() { @Override protected IBinder queryBaseBinder() { return ServiceManager.getService(Context.ACTIVITY_SERVICE); } @Override protected IActivityManager createInterface(IBinder baseBinder) { return getHookObject().getProxyObject(); } }; hookAMBinder.injectService(Context.ACTIVITY_SERVICE); }
private static boolean run() { try { IPowerManager adapter = IPowerManager.Stub.asInterface(ServiceManager.getService("power")); adapter.goToSleep(SystemClock.uptimeMillis(), 0, 0); return true; } catch (Throwable e) { return false; } }
static boolean run(boolean newValue) { try { INfcAdapter adapter = INfcAdapter.Stub.asInterface(ServiceManager.getService("nfc")); return newValue ? adapter.enable() : adapter.disable(true); } catch (Throwable e) { return false; } }
public final void bindApplication(String processName, ApplicationInfo appInfo, List<ProviderInfo> providers, ComponentName instrumentationName, String profileFile, ParcelFileDescriptor profileFd, boolean autoStopProfiler, Bundle instrumentationArgs, IInstrumentationWatcher instrumentationWatcher, IUiAutomationConnection instrumentationUiConnection, int debugMode, boolean enableOpenGlTrace, boolean isRestrictedBackupMode, boolean persistent, Configuration config, CompatibilityInfo compatInfo, Map<String, IBinder> services, Bundle coreSettings) { if (services != null) { // Setup the service cache in the ServiceManager ServiceManager.initServiceCache(services); } setCoreSettings(coreSettings); AppBindData data = new AppBindData(); data.processName = processName; data.appInfo = appInfo; data.providers = providers; data.instrumentationName = instrumentationName; data.instrumentationArgs = instrumentationArgs; data.instrumentationWatcher = instrumentationWatcher; data.instrumentationUiAutomationConnection = instrumentationUiConnection; data.debugMode = debugMode; data.enableOpenGlTrace = enableOpenGlTrace; data.restrictedBackupMode = isRestrictedBackupMode; data.persistent = persistent; data.config = config; data.compatInfo = compatInfo; data.initProfileFile = profileFile; data.initProfileFd = profileFd; data.initAutoStopProfiler = false; sendMessage(H.BIND_APPLICATION, data); }
public static IPackageManager getPackageManager() { if (sPackageManager != null) { //Slog.v("PackageManager", "returning cur default = " + sPackageManager); return sPackageManager; } IBinder b = ServiceManager.getService("package"); //Slog.v("PackageManager", "default service binder = " + b); sPackageManager = IPackageManager.Stub.asInterface(b); //Slog.v("PackageManager", "default service = " + sPackageManager); return sPackageManager; }
/** * Force the global system in or out of touch mode. This can be used if * your instrumentation relies on the UI being in one more or the other * when it starts. * * @param inTouch Set to true to be in touch mode, false to be in * focus mode. */ public void setInTouchMode(boolean inTouch) { try { IWindowManager.Stub.asInterface( ServiceManager.getService("window")).setInTouchMode(inTouch); } catch (RemoteException e) { // Shouldn't happen! } }
public void start() { Log.i(LOG_TAG, "Start RILD system service "); String app = "fi.dungeon.atrild"; // FIXME find a way not to hardcode /data String file = "/data/data/" + app + "/shared_prefs/" + app + "_preferences.xml"; mPrefs = new ReadOnlyPreferences(new File(file)); // Set all preferences before start for (String key : mPrefs.getAll().keySet()) { if (!"enabled".equals(key)) { onSharedPreferenceChanged(mPrefs, key); } } mPrefs.registerOnSharedPreferenceChangeListener(this); if (mPrefs.getBoolean("enabled", false)) { Log.i(LOG_TAG, "Starting RILD.."); RILDModule.getSingleton().start(); } else { Log.i(LOG_TAG, "Not starting RILD.."); } IRILStatImpl mStat = new IRILStatImpl(); if (ServiceManager.getService(IRILStatImpl.SERVICE_NAME) == null) { ServiceManager.addService(IRILStatImpl.SERVICE_NAME, mStat); } // Main loop sleeps forever while (true) { try { // TODO Could we join some thread Thread.sleep(120000L); } catch (InterruptedException e) { Log.e(LOG_TAG, "Interrupted"); } } }
@Override public void onCreate() { super.onCreate(); //Add our new custom service with ServiceManager mService = new SysInfoServiceImpl(); ServiceManager.addService(REMOTE_NAME, mService); }
private BasicManager() { Log.d(TAG, "Connecting to IBasicService by name [" + REMOTE_SERVICE_NAME + "]"); this.service = IBasicService.Stub.asInterface( ServiceManager.getService(REMOTE_SERVICE_NAME)); if (this.service == null) { throw new IllegalStateException("Failed to find IBasicService by name [" + REMOTE_SERVICE_NAME + "]"); } }
public BackupManagerController() { backupManager = IBackupManager.Stub.asInterface(ServiceManager.getService("backup")); packageManager = IPackageManager.Stub.asInterface(ServiceManager.getService("package")); }
private static IPackageManager getPackageManager() { return IPackageManager.Stub.asInterface(ServiceManager.getService("package")); }
private static ActivityManagerService getAms() { if (ams == null) { ams = (ActivityManagerService) ServiceManager.getService(Context.ACTIVITY_SERVICE); } return ams; }
@Override public void setRadioPower(boolean on) throws RemoteException { Binder.clearCallingIdentity(); ITelephony telephony = ITelephony.Stub.asInterface(ServiceManager.getService("phone")); telephony.setRadioPower(on); }
public TelephonyManagerProxy() { mService = ITelephony.Stub.asInterface(ServiceManager.getService("phone")); Sca.log("TelephonyManagerProxy startup, mService=" + mService); }
private SysInfoManager(Context context) { mService = ISysInfoService.Stub.asInterface( ServiceManager.getService(REMOTE_NAME)); }
public InjectionManager(Context c) { if(Integer.valueOf(android.os.Build.VERSION.SDK_INT) < android.os.Build.VERSION_CODES.JELLY_BEAN) { mWmbinder = ServiceManager.getService( INTERNAL_SERVICE_PRE_JELLY ); mWinMan = IWindowManager.Stub.asInterface( mWmbinder ); printDeclaredMethods(mWinMan.getClass()); //TODO: Implement full injection support for pre Jelly Bean solutions } else { mInputManager = c.getSystemService(Context.INPUT_SERVICE); try { //printDeclaredMethods(mInputManager.getClass()); //Unveil hidden methods mInjectEventMethod = mInputManager.getClass().getDeclaredMethod("injectInputEvent", new Class[] { InputEvent.class, Integer.TYPE }); mInjectEventMethod.setAccessible(true); Field eventAsync = mInputManager.getClass().getDeclaredField("INJECT_INPUT_EVENT_MODE_ASYNC"); Field eventResult = mInputManager.getClass().getDeclaredField("INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT"); Field eventFinish = mInputManager.getClass().getDeclaredField("INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH"); eventAsync.setAccessible(true); eventResult.setAccessible(true); eventFinish.setAccessible(true); INJECT_INPUT_EVENT_MODE_ASYNC = eventAsync.getInt(mInputManager.getClass()); INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT = eventResult.getInt(mInputManager.getClass()); INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH = eventFinish.getInt(mInputManager.getClass()); } catch (NoSuchMethodException nsme) { Log.e(TAG, "Critical methods not available"); } catch (NoSuchFieldException nsfe) { Log.e(TAG, "Critical fields not available"); } catch (IllegalAccessException iae) { Log.e(TAG, "Critical fields not accessable"); } } }
public void onCreate() { super.onCreate(); this.serviceImpl = new IBasicServiceImpl(this); ServiceManager.addService(REMOTE_SERVICE_NAME, this.serviceImpl); Log.d(TAG, "Registered [" + serviceImpl.getClass().getName() + "] as [" + REMOTE_SERVICE_NAME + "]"); }
private void runReset(OpsCommands.Builder builder) throws Throwable { final IAppOpsService appOpsService = IAppOpsService.Stub.asInterface( ServiceManager.getService(Context.APP_OPS_SERVICE)); appOpsService.resetAllModes(builder.getUserHandleId(), builder.getPackageName()); }