List of usage examples for android.content Context startServiceAsUser
@Nullable @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) @UnsupportedAppUsage public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
From source file:org.wso2.emm.agent.utils.CommonUtils.java
public static void callSystemAppInit(Context context) { if (Constants.SYSTEM_APP_ENABLED) { Intent intent = new Intent(Constants.SYSTEM_APP_SERVICE_START_ACTION); Intent explicitIntent = createExplicitFromImplicitIntent(context, intent); if (explicitIntent != null) { intent = explicitIntent;/*from w w w. j a v a 2s. co m*/ } context.startServiceAsUser(intent, android.os.Process.myUserHandle()); } else { Log.e(TAG, "System app not enabled."); } }
From source file:org.wso2.emm.agent.utils.CommonUtils.java
/** * Call EMM system app in COPE mode.//from w w w. jav a 2s . c om * @param context - Application context. * @param operation - Operation code. * @param command - Shell command to be executed. * @param appUri - App package/APK URI when an app operation executed. */ public static void callSystemApp(Context context, String operation, String command, String appUri) { if (Constants.SYSTEM_APP_ENABLED) { Intent intent = new Intent(Constants.SYSTEM_APP_SERVICE_START_ACTION); Intent explicitIntent = createExplicitFromImplicitIntent(context, intent); if (explicitIntent != null) { intent = explicitIntent; } intent.putExtra(Constants.OPERATION_CODE, operation); intent.setPackage(Constants.AGENT_PACKAGE); if (appUri != null) { intent.putExtra("appUri", appUri); } if (command != null) { if (Constants.Operation.UPGRADE_FIRMWARE.equals(operation)) { try { JSONObject upgradeData = new JSONObject(command); if (upgradeData .isNull(context.getResources().getString(R.string.firmware_upgrade_automatic_retry)) && Preference.hasPreferenceKey(context, context.getResources().getString(R.string.is_automatic_firmware_upgrade))) { boolean isFirmwareUpgradeAutoRetry = Preference.getBoolean(context, context.getResources().getString(R.string.is_automatic_firmware_upgrade)); upgradeData.put( context.getResources().getString(R.string.firmware_upgrade_automatic_retry), isFirmwareUpgradeAutoRetry); command = upgradeData.toString(); Log.d(TAG, "Updated payload: " + command); } else if (!upgradeData.isNull( context.getResources().getString(R.string.firmware_upgrade_automatic_retry))) { Preference.putBoolean(context, context.getResources().getString(R.string.is_automatic_firmware_upgrade), upgradeData.getBoolean(context.getResources() .getString(R.string.firmware_upgrade_automatic_retry))); } else { upgradeData.put( context.getResources().getString(R.string.firmware_upgrade_automatic_retry), true); Preference.putBoolean(context, context.getResources().getString(R.string.is_automatic_firmware_upgrade), true); Log.d(TAG, "Updated payload: " + command); } } catch (JSONException e) { Log.e(TAG, "Could not parse Firmware upgrade operation", e); } intent.putExtra("operationId", Preference.getInt(context, "firmwareOperationId")); } intent.putExtra("command", command); } context.startServiceAsUser(intent, android.os.Process.myUserHandle()); } else { Log.e(TAG, "System app not enabled."); } }