android.os.ServiceManager Java Examples

The following examples show how to use android.os.ServiceManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Input.java    From JsDroidCmd with Mozilla Public License 2.0 6 votes vote down vote up
public static boolean open() {
	IInputMethodManager mImm;
	mImm = IInputMethodManager.Stub.asInterface(ServiceManager
			.getService("input_method"));
	try {
		List<String> inputList = list();
		for (int i = 0; i < inputList.size(); i++) {
			String _id = inputList.get(i);
			if (_id.contains("CmdInputService")) {
				id = _id;
				break;
			}
		}
		mImm.setInputMethodEnabled(id, true);
		mImm.setInputMethod(null, id);
		return true;
	} catch (RemoteException e) {
	}
	return false;
}
 
Example #2
Source File: AccessibilityManager.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void tryConnectToServiceLocked(IAccessibilityManager service) {
    if (service == null) {
        IBinder iBinder = ServiceManager.getService(Context.ACCESSIBILITY_SERVICE);
        if (iBinder == null) {
            return;
        }
        service = IAccessibilityManager.Stub.asInterface(iBinder);
    }

    try {
        final long userStateAndRelevantEvents = service.addClient(mClient, mUserId);
        setStateLocked(IntPair.first(userStateAndRelevantEvents));
        mRelevantEventTypes = IntPair.second(userStateAndRelevantEvents);
        mService = service;
    } catch (RemoteException re) {
        Log.e(LOG_TAG, "AccessibilityManagerService is dead", re);
    }
}
 
Example #3
Source File: ActivityManagerShellCommand.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
int runGetInactive(PrintWriter pw) throws RemoteException {
    int userId = UserHandle.USER_CURRENT;

    String opt;
    while ((opt=getNextOption()) != null) {
        if (opt.equals("--user")) {
            userId = UserHandle.parseUserArg(getNextArgRequired());
        } else {
            getErrPrintWriter().println("Error: Unknown option: " + opt);
            return -1;
        }
    }
    String packageName = getNextArgRequired();

    IUsageStatsManager usm = IUsageStatsManager.Stub.asInterface(ServiceManager.getService(
            Context.USAGE_STATS_SERVICE));
    boolean isIdle = usm.isAppInactive(packageName, userId);
    pw.println("Idle=" + isIdle);
    return 0;
}
 
Example #4
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
public Object createService(ContextImpl ctx) {
    IBinder b = ServiceManager.getService(POWER_SERVICE);
    IPowerManager service = IPowerManager.Stub.asInterface(b);
    if (service == null) {
        Log.wtf(TAG, "Failed to get power manager service.");
    }
    return new PowerManager(ctx.getOuterContext(),
            service, ctx.mMainThread.getHandler());
}
 
Example #5
Source File: NotificationListenerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Request that the listener be rebound, after a previous call to {@link #requestUnbind}.
 *
 * <p>This method will fail for listeners that have
 * not been granted the permission by the user.
 */
public static void requestRebind(ComponentName componentName) {
    INotificationManager noMan = INotificationManager.Stub.asInterface(
            ServiceManager.getService(Context.NOTIFICATION_SERVICE));
    try {
        noMan.requestBindListener(componentName);
    } catch (RemoteException ex) {
        throw ex.rethrowFromSystemServer();
    }
}
 
Example #6
Source File: SystemServiceRegistry.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public RttManager createService(ContextImpl ctx) throws ServiceNotFoundException {
    IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_RTT_RANGING_SERVICE);
    IWifiRttManager service = IWifiRttManager.Stub.asInterface(b);
    return new RttManager(ctx.getOuterContext(),
            new WifiRttManager(ctx.getOuterContext(), service));
}
 
Example #7
Source File: Input.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
public static List<String> list() {
	List<String> ret = new ArrayList<String>();
	IInputMethodManager mImm;
	mImm = IInputMethodManager.Stub.asInterface(ServiceManager
			.getService("input_method"));
	try {

		for (InputMethodInfo info : mImm.getInputMethodList()) {
			ret.add(info.getId());
		}
	} catch (RemoteException e) {
	}
	return ret;
}
 
Example #8
Source File: ActivityManagerShellCommand.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
int runSetStandbyBucket(PrintWriter pw) throws RemoteException {
    int userId = UserHandle.USER_CURRENT;

    String opt;
    while ((opt=getNextOption()) != null) {
        if (opt.equals("--user")) {
            userId = UserHandle.parseUserArg(getNextArgRequired());
        } else {
            getErrPrintWriter().println("Error: Unknown option: " + opt);
            return -1;
        }
    }
    String packageName = getNextArgRequired();
    String value = getNextArgRequired();
    int bucket = bucketNameToBucketValue(value);
    if (bucket < 0) return -1;
    boolean multiple = peekNextArg() != null;


    IUsageStatsManager usm = IUsageStatsManager.Stub.asInterface(ServiceManager.getService(
            Context.USAGE_STATS_SERVICE));
    if (!multiple) {
        usm.setAppStandbyBucket(packageName, bucketNameToBucketValue(value), userId);
    } else {
        ArrayList<AppStandbyInfo> bucketInfoList = new ArrayList<>();
        bucketInfoList.add(new AppStandbyInfo(packageName, bucket));
        while ((packageName = getNextArg()) != null) {
            value = getNextArgRequired();
            bucket = bucketNameToBucketValue(value);
            if (bucket < 0) continue;
            bucketInfoList.add(new AppStandbyInfo(packageName, bucket));
        }
        ParceledListSlice<AppStandbyInfo> slice = new ParceledListSlice<>(bucketInfoList);
        usm.setAppStandbyBuckets(slice, userId);
    }
    return 0;
}
 
Example #9
Source File: CmdWifiAP.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
static boolean setWifiAP(boolean enable, boolean doNotChangeWifi) {
    //PPApplication.logE("CmdWifiAP.setWifiAP", "START enable="+enable);
    //PPApplication.logE("CmdWifiAP.setWifiAP", "START doNotChangeWifi="+doNotChangeWifi);
    final String packageName = PPApplication.PACKAGE_NAME;
    try {
        IConnectivityManager connectivityAdapter = IConnectivityManager.Stub.asInterface(ServiceManager.getService("connectivity"));  // service list | grep IConnectivityManager
        //PPApplication.logE("CmdWifiAP.setWifiAP", "connectivityAdapter="+connectivityAdapter);
        if (enable) {
            if (!doNotChangeWifi) {
                IWifiManager wifiAdapter = IWifiManager.Stub.asInterface(ServiceManager.getService("wifi"));  // service list | grep IWifiManager
                //PPApplication.logE("CmdWifiAP.setWifiAP", "wifiAdapter="+wifiAdapter);
                int wifiState = wifiAdapter.getWifiEnabledState();
                boolean isWifiEnabled = ((wifiState == WifiManager.WIFI_STATE_ENABLED) || (wifiState == WifiManager.WIFI_STATE_ENABLING));
                //PPApplication.logE("CmdWifiAP.setWifiAP", "isWifiEnabled="+isWifiEnabled);
                if (isWifiEnabled)
                    wifiAdapter.setWifiEnabled(packageName, false);
            }

            ResultReceiver dummyResultReceiver = new ResultReceiver(null);
            connectivityAdapter.startTethering(0, dummyResultReceiver, false, packageName);
        } else {
            connectivityAdapter.stopTethering(0, packageName);
        }

        //PPApplication.logE("CmdWifiAP.setWifiAP", "END=");
        return true;
    } catch (java.lang.SecurityException ee) {
        //Log.e("CmdWifiAP.setWifiAP", Log.getStackTraceString(ee));
        //PPApplication.logToCrashlytics("E/CmdWifiAP.setWifiAP: " + Log.getStackTraceString(ee));
        //PPApplication.recordException(e);
        //PPApplication.logE("CmdWifiAP.setWifiAP", Log.getStackTraceString(e));
        return false;
    } catch (Throwable e) {
        //Log.e("CmdWifiAP.setWifiAP", Log.getStackTraceString(e));
        PPApplication.recordException(e);
        //PPApplication.logE("CmdWifiAP.setWifiAP", Log.getStackTraceString(e));
        return false;
    }
}
 
Example #10
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
/**
 * Ensure that given directories exist, trying to create them if missing. If
 * unable to create, they are filtered by replacing with {@code null}.
 */
private File[] ensureExternalDirsExistOrFilter(File[] dirs) {
    File[] result = new File[dirs.length];
    for (int i = 0; i < dirs.length; i++) {
        File dir = dirs[i];
        if (!dir.exists()) {
            if (!dir.mkdirs()) {
                // recheck existence in case of cross-process race
                if (!dir.exists()) {
                    // Failing to mkdir() may be okay, since we might not have
                    // enough permissions; ask vold to create on our behalf.
                    final IStorageManager storageManager = IStorageManager.Stub.asInterface(
                            ServiceManager.getService("mount"));
                    try {
                        final int res = storageManager.mkdirs(
                                getPackageName(), dir.getAbsolutePath());
                        if (res != 0) {
                            Log.w(TAG, "Failed to ensure " + dir + ": " + res);
                            dir = null;
                        }
                    } catch (Exception e) {
                        Log.w(TAG, "Failed to ensure " + dir + ": " + e);
                        dir = null;
                    }
                }
            }
        }
        result[i] = dir;
    }
    return result;
}
 
Example #11
Source File: Sandman.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static void startDream(Context context, boolean docked) {
    try {
        IDreamManager dreamManagerService = IDreamManager.Stub.asInterface(
                ServiceManager.getService(DreamService.DREAM_SERVICE));
        if (dreamManagerService != null && !dreamManagerService.isDreaming()) {
            if (docked) {
                Slog.i(TAG, "Activating dream while docked.");

                // Wake up.
                // The power manager will wake up the system automatically when it starts
                // receiving power from a dock but there is a race between that happening
                // and the UI mode manager starting a dream.  We want the system to already
                // be awake by the time this happens.  Otherwise the dream may not start.
                PowerManager powerManager =
                        (PowerManager)context.getSystemService(Context.POWER_SERVICE);
                powerManager.wakeUp(SystemClock.uptimeMillis(),
                        "android.service.dreams:DREAM");
            } else {
                Slog.i(TAG, "Activating dream by user request.");
            }

            // Dream.
            dreamManagerService.dream();
        }
    } catch (RemoteException ex) {
        Slog.e(TAG, "Could not start dream when docked.", ex);
    }
}
 
Example #12
Source File: ContextHubManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/** @throws ServiceNotFoundException
 * @hide */
public ContextHubManager(Context context, Looper mainLooper) throws ServiceNotFoundException {
    mMainLooper = mainLooper;
    mService = IContextHubService.Stub.asInterface(
            ServiceManager.getServiceOrThrow(Context.CONTEXTHUB_SERVICE));
    try {
        mService.registerCallback(mClientCallback);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
 
Example #13
Source File: ImmersiveModeConfirmation.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
void systemReady() {
    IVrManager vrManager = IVrManager.Stub.asInterface(
            ServiceManager.getService(Context.VR_SERVICE));
    if (vrManager != null) {
        try {
            vrManager.registerListener(mVrStateCallbacks);
            mVrModeEnabled = vrManager.getVrModeState();
        } catch (RemoteException re) {
        }
    }
}
 
Example #14
Source File: AppOpsHandler.java    From AppOpsX with MIT License 5 votes vote down vote up
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());
    }


  }
 
Example #15
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
public Object createService(ContextImpl ctx) {
    IBinder b = ServiceManager.getService(POWER_SERVICE);
    IPowerManager service = IPowerManager.Stub.asInterface(b);
    if (service == null) {
        Log.wtf(TAG, "Failed to get power manager service.");
    }
    return new PowerManager(ctx.getOuterContext(),
            service, ctx.mMainThread.getHandler());
}
 
Example #16
Source File: SystemServiceRegistry.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public WallpaperManager createService(ContextImpl ctx)
        throws ServiceNotFoundException {
    final IBinder b;
    if (ctx.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.P) {
        b = ServiceManager.getServiceOrThrow(Context.WALLPAPER_SERVICE);
    } else {
        b = ServiceManager.getService(Context.WALLPAPER_SERVICE);
    }
    IWallpaperManager service = IWallpaperManager.Stub.asInterface(b);
    return new WallpaperManager(service, ctx.getOuterContext(),
            ctx.mMainThread.getHandler());
}
 
Example #17
Source File: Installer.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void connect() {
    IBinder binder = ServiceManager.getService("installd");
    if (binder != null) {
        try {
            binder.linkToDeath(new DeathRecipient() {
                @Override
                public void binderDied() {
                    Slog.w(TAG, "installd died; reconnecting");
                    connect();
                }
            }, 0);
        } catch (RemoteException e) {
            binder = null;
        }
    }

    if (binder != null) {
        mInstalld = IInstalld.Stub.asInterface(binder);
        try {
            invalidateMounts();
        } catch (InstallerException ignored) {
        }
    } else {
        Slog.w(TAG, "installd not found; trying again");
        BackgroundThread.getHandler().postDelayed(() -> {
            connect();
        }, DateUtils.SECOND_IN_MILLIS);
    }
}
 
Example #18
Source File: JsWindow.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
static private INotificationManager getService() {
	if (sService != null) {
		return sService;
	}
	sService = INotificationManager.Stub.asInterface(ServiceManager
			.getService("notification"));
	return sService;
}
 
Example #19
Source File: SystemServiceRegistry.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public WifiScanner createService(ContextImpl ctx) throws ServiceNotFoundException {
    IBinder b = ServiceManager.getServiceOrThrow(Context.WIFI_SCANNING_SERVICE);
    IWifiScanner service = IWifiScanner.Stub.asInterface(b);
    return new WifiScanner(ctx.getOuterContext(), service,
            ConnectivityThread.getInstanceLooper());
}
 
Example #20
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
static DropBoxManager createDropBoxManager() {
    IBinder b = ServiceManager.getService(DROPBOX_SERVICE);
    IDropBoxManagerService service = IDropBoxManagerService.Stub.asInterface(b);
    if (service == null) {
        // Don't return a DropBoxManager that will NPE upon use.
        // This also avoids caching a broken DropBoxManager in
        // getDropBoxManager during early boot, before the
        // DROPBOX_SERVICE is registered.
        return null;
    }
    return new DropBoxManager(service);
}
 
Example #21
Source File: ActivityThread.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #22
Source File: Instrumentation.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
/**
 * 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!
    }
}
 
Example #23
Source File: SystemTextClassifier.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public SystemTextClassifier(Context context, TextClassificationConstants settings)
            throws ServiceManager.ServiceNotFoundException {
    mManagerService = ITextClassifierService.Stub.asInterface(
            ServiceManager.getServiceOrThrow(Context.TEXT_CLASSIFICATION_SERVICE));
    mSettings = Preconditions.checkNotNull(settings);
    mFallback = context.getSystemService(TextClassificationManager.class)
            .getTextClassifier(TextClassifier.LOCAL);
    mPackageName = Preconditions.checkNotNull(context.getPackageName());
}
 
Example #24
Source File: AppWidgetHost.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static void bindService(Context context) {
    synchronized (sServiceLock) {
        if (sServiceInitialized) {
            return;
        }
        sServiceInitialized = true;
        PackageManager packageManager = context.getPackageManager();
        if (!packageManager.hasSystemFeature(PackageManager.FEATURE_APP_WIDGETS)
                && !context.getResources().getBoolean(R.bool.config_enableAppWidgetService)) {
            return;
        }
        IBinder b = ServiceManager.getService(Context.APPWIDGET_SERVICE);
        sService = IAppWidgetService.Stub.asInterface(b);
    }
}
 
Example #25
Source File: SettingsHelper.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
private void setAutoRestore(boolean enabled) {
    try {
        IBackupManager bm = IBackupManager.Stub.asInterface(
                ServiceManager.getService(Context.BACKUP_SERVICE));
        if (bm != null) {
            bm.setAutoRestore(enabled);
        }
    } catch (RemoteException e) {}
}
 
Example #26
Source File: SystemServiceRegistry.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public AutofillManager createService(ContextImpl ctx) throws ServiceNotFoundException {
    // Get the services without throwing as this is an optional feature
    IBinder b = ServiceManager.getService(Context.AUTOFILL_MANAGER_SERVICE);
    IAutoFillManager service = IAutoFillManager.Stub.asInterface(b);
    return new AutofillManager(ctx.getOuterContext(), service);
}
 
Example #27
Source File: KeyguardStateMonitor.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public KeyguardStateMonitor(Context context, IKeyguardService service, StateCallback callback) {
    mLockPatternUtils = new LockPatternUtils(context);
    mCurrentUserId = ActivityManager.getCurrentUser();
    mCallback = callback;

    mKeystoreService = IKeystoreService.Stub.asInterface(ServiceManager
            .getService("android.security.keystore"));

    try {
        service.addStateMonitorCallback(this);
    } catch (RemoteException e) {
        Slog.w(TAG, "Remote Exception", e);
    }
}
 
Example #28
Source File: SystemServiceRegistry.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public CompanionDeviceManager createService(ContextImpl ctx)
        throws ServiceNotFoundException {
    ICompanionDeviceManager service = null;
    // If the feature not present, don't try to look up every time
    if (ctx.getPackageManager().hasSystemFeature(
            PackageManager.FEATURE_COMPANION_DEVICE_SETUP)) {
        service = ICompanionDeviceManager.Stub.asInterface(
                ServiceManager.getServiceOrThrow(Context.COMPANION_DEVICE_SERVICE));
    }
    return new CompanionDeviceManager(service, ctx.getOuterContext());
}
 
Example #29
Source File: InputManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Gets an instance of the input manager.
 *
 * @return The input manager instance.
 *
 * @hide
 */
public static InputManager getInstance() {
    synchronized (InputManager.class) {
        if (sInstance == null) {
            try {
                sInstance = new InputManager(IInputManager.Stub
                        .asInterface(ServiceManager.getServiceOrThrow(Context.INPUT_SERVICE)));
            } catch (ServiceNotFoundException e) {
                throw new IllegalStateException(e);
            }
        }
        return sInstance;
    }
}
 
Example #30
Source File: OtaDexoptService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public static OtaDexoptService main(Context context,
        PackageManagerService packageManagerService) {
    OtaDexoptService ota = new OtaDexoptService(context, packageManagerService);
    ServiceManager.addService("otadexopt", ota);

    // Now it's time to check whether we need to move any A/B artifacts.
    ota.moveAbArtifacts(packageManagerService.mInstaller);

    return ota;
}