Java 类android.os.ServiceManager 实例源码
项目:lineagex86
文件:ZenModeConditionSelection.java
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()));
}
}
项目:aosp_screen_stabilization
文件:StabilizationService.java
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);
}
}
项目:AppOpsX
文件:AppOpsHandler.java
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);
}
项目:AppOpsX
文件:RemoteHandler.java
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);
}
}
项目:PowerToggles
文件:GprsStateTracker.java
@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;
}
}
项目:lineagex86
文件:NotificationStation.java
@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);
}
}
项目:Brevent
文件:OpsItemAdapter.java
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;
}
}
项目:Brevent
文件:BreventActivity.java
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);
}
}
}
项目:Brevent
文件:BreventActivity.java
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);
}
}
}
项目:AppOpsX
文件:AppOpsHandler.java
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());
}
}
项目:Scalpel_Android
文件:Sca.java
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();
}
项目:Scalpel_Android
文件:Sca.java
private void doStop() {
IBinder scaBinder = ServiceManager.getService("sca");
if (scaBinder == null) {
sent(new Feedback(Response.STOP_FAILURE_NOT_STARTED, "Sca server not started."));
}
}
项目:EnhancedPUMA
文件:MyUiAutomatorTestCase.java
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);
}
项目:PowerToggles
文件:CmdUsbT.java
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;
}
}
项目:PowerToggles
文件:CmdNfc.java
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;
}
}
项目:PowerToggles
文件:RecentAppsCommand.java
@Override
public void toggleState(Context context) {
Globals.collapseStatusBar(context);
try{
IStatusBarService.Stub.asInterface(ServiceManager.getService("statusbar")).toggleRecentApps();
} catch (final Throwable e) {
Debug.log(e);
}
}
项目:DeepInVirtualApp
文件:ActivityManagerPatch.java
@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);
}
项目:PhoneProfiles
文件:CmdGoToSleep.java
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;
}
}
项目:PhoneProfiles
文件:CmdNfc.java
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;
}
}
项目:PhoneProfilesPlus
文件:CmdGoToSleep.java
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;
}
}
项目:PhoneProfilesPlus
文件:CmdNfc.java
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;
}
}
项目:droidel
文件:ActivityThread.java
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);
}
项目:droidel
文件:ActivityThread.java
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;
}
项目:droidel
文件:Instrumentation.java
/**
* 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!
}
}
项目:PUMA
文件:MyUiAutomatorTestCase.java
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);
}
项目:ATRILD
文件:Main.java
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");
}
}
}
项目:plustwo
文件:SysInfoApplication.java
@Override
public void onCreate() {
super.onCreate();
//Add our new custom service with ServiceManager
mService = new SysInfoServiceImpl();
ServiceManager.addService(REMOTE_NAME, mService);
}
项目:BasicService
文件:BasicManager.java
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 + "]");
}
}
项目:backup
文件:BackupManagerController.java
public BackupManagerController() {
backupManager = IBackupManager.Stub.asInterface(ServiceManager.getService("backup"));
packageManager = IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
}
项目:Brevent
文件:OpsItemAdapter.java
private static IPackageManager getPackageManager() {
return IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
}
项目:prevent
文件:PreventRunningUtils.java
private static ActivityManagerService getAms() {
if (ams == null) {
ams = (ActivityManagerService) ServiceManager.getService(Context.ACTIVITY_SERVICE);
}
return ams;
}
项目:Scalpel_Android
文件:ScaHookService.java
@Override
public void setRadioPower(boolean on) throws RemoteException {
Binder.clearCallingIdentity();
ITelephony telephony = ITelephony.Stub.asInterface(ServiceManager.getService("phone"));
telephony.setRadioPower(on);
}
项目:Scalpel_Android
文件:TelephonyManagerProxy.java
public TelephonyManagerProxy() {
mService = ITelephony.Stub.asInterface(ServiceManager.getService("phone"));
Sca.log("TelephonyManagerProxy startup, mService=" + mService);
}
项目:plustwo
文件:SysInfoManager.java
private SysInfoManager(Context context) {
mService = ISysInfoService.Stub.asInterface(
ServiceManager.getService(REMOTE_NAME));
}
项目:android-inputinjector
文件:InjectionManager.java
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");
}
}
}
项目:BasicService
文件:BasicServiceApp.java
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 + "]");
}
项目:AppOpsX
文件:AppOpsHandler.java
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());
}